gpuinfo_manager.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 ELECTRON_SHELL_BROWSER_API_GPUINFO_MANAGER_H_
  5. #define ELECTRON_SHELL_BROWSER_API_GPUINFO_MANAGER_H_
  6. #include <vector>
  7. #include "base/memory/raw_ptr.h"
  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. // disable copy
  20. GPUInfoManager(const GPUInfoManager&) = delete;
  21. GPUInfoManager& operator=(const GPUInfoManager&) = delete;
  22. bool NeedsCompleteGpuInfoCollection() const;
  23. void FetchCompleteInfo(gin_helper::Promise<base::Value> promise);
  24. void FetchBasicInfo(gin_helper::Promise<base::Value> promise);
  25. void OnGpuInfoUpdate() override;
  26. private:
  27. base::Value::Dict EnumerateGPUInfo(gpu::GPUInfo gpu_info) const;
  28. // These should be posted to the task queue
  29. void CompleteInfoFetcher(gin_helper::Promise<base::Value> promise);
  30. void ProcessCompleteInfo();
  31. // This set maintains all the promises that should be fulfilled
  32. // once we have the complete information data
  33. std::vector<gin_helper::Promise<base::Value>> complete_info_promise_set_;
  34. raw_ptr<content::GpuDataManagerImpl> gpu_data_manager_;
  35. };
  36. } // namespace electron
  37. #endif // ELECTRON_SHELL_BROWSER_API_GPUINFO_MANAGER_H_