gpuinfo_manager.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef SHELL_BROWSER_API_GPUINFO_MANAGER_H_
  5. #define SHELL_BROWSER_API_GPUINFO_MANAGER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "content/browser/gpu/gpu_data_manager_impl.h" // nogncheck
  9. #include "content/public/browser/gpu_data_manager.h"
  10. #include "content/public/browser/gpu_data_manager_observer.h"
  11. #include "shell/common/gin_helper/promise.h"
  12. namespace electron {
  13. // GPUInfoManager is a singleton used to manage and fetch GPUInfo
  14. class GPUInfoManager : public content::GpuDataManagerObserver {
  15. public:
  16. static GPUInfoManager* GetInstance();
  17. GPUInfoManager();
  18. ~GPUInfoManager() override;
  19. bool NeedsCompleteGpuInfoCollection() const;
  20. void FetchCompleteInfo(gin_helper::Promise<base::DictionaryValue> promise);
  21. void FetchBasicInfo(gin_helper::Promise<base::DictionaryValue> promise);
  22. void OnGpuInfoUpdate() override;
  23. private:
  24. std::unique_ptr<base::DictionaryValue> EnumerateGPUInfo(
  25. gpu::GPUInfo gpu_info) const;
  26. // These should be posted to the task queue
  27. void CompleteInfoFetcher(gin_helper::Promise<base::DictionaryValue> promise);
  28. void ProcessCompleteInfo();
  29. // This set maintains all the promises that should be fulfilled
  30. // once we have the complete information data
  31. std::vector<gin_helper::Promise<base::DictionaryValue>>
  32. complete_info_promise_set_;
  33. content::GpuDataManagerImpl* gpu_data_manager_;
  34. DISALLOW_COPY_AND_ASSIGN(GPUInfoManager);
  35. };
  36. } // namespace electron
  37. #endif // SHELL_BROWSER_API_GPUINFO_MANAGER_H_