<commit_before>// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "shell/browser/api/gpuinfo_manager.h"

#include <utility>

#include "base/memory/singleton.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/browser/browser_thread.h"
#include "gpu/config/gpu_info_collector.h"
#include "shell/browser/api/gpu_info_enumerator.h"
#include "shell/common/gin_converters/value_converter.h"

namespace electron {

GPUInfoManager* GPUInfoManager::GetInstance() {
  return base::Singleton<GPUInfoManager>::get();
}

GPUInfoManager::GPUInfoManager()
    : gpu_data_manager_(content::GpuDataManagerImpl::GetInstance()) {
  gpu_data_manager_->AddObserver(this);
}

GPUInfoManager::~GPUInfoManager() {
  content::GpuDataManagerImpl::GetInstance()->RemoveObserver(this);
}

// Based on
// https://chromium.googlesource.com/chromium/src.git/+/69.0.3497.106/content/browser/gpu/gpu_data_manager_impl_private.cc#838
bool GPUInfoManager::NeedsCompleteGpuInfoCollection() const {
#if defined(OS_MAC)
  return gpu_data_manager_->GetGPUInfo().gl_vendor.empty();
#elif defined(OS_WIN)
  return gpu_data_manager_->DxdiagDx12VulkanRequested() &&
         gpu_data_manager_->GetGPUInfo().dx_diagnostics.IsEmpty();
#else
  return false;
#endif
}

// Should be posted to the task runner
void GPUInfoManager::ProcessCompleteInfo() {
  const auto result = EnumerateGPUInfo(gpu_data_manager_->GetGPUInfo());<commit_msg>refactor: remove dead code in NeedsCompleteGpuInfoCollection (#30855)<commit_after>// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "shell/browser/api/gpuinfo_manager.h"

#include <utility>

#include "base/memory/singleton.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/browser/browser_thread.h"
#include "gpu/config/gpu_info_collector.h"
#include "shell/browser/api/gpu_info_enumerator.h"
#include "shell/common/gin_converters/value_converter.h"

namespace electron {

GPUInfoManager* GPUInfoManager::GetInstance() {
  return base::Singleton<GPUInfoManager>::get();
}

GPUInfoManager::GPUInfoManager()
    : gpu_data_manager_(content::GpuDataManagerImpl::GetInstance()) {
  gpu_data_manager_->AddObserver(this);
}

GPUInfoManager::~GPUInfoManager() {
  content::GpuDataManagerImpl::GetInstance()->RemoveObserver(this);
}

// Based on
// https://chromium.googlesource.com/chromium/src.git/+/69.0.3497.106/content/browser/gpu/gpu_data_manager_impl_private.cc#838
bool GPUInfoManager::NeedsCompleteGpuInfoCollection() const {
#if defined(OS_WIN)
  return gpu_data_manager_->DxdiagDx12VulkanRequested() &&
         gpu_data_manager_->GetGPUInfo().dx_diagnostics.IsEmpty();
#else
  return false;
#endif
}

// Should be posted to the task runner
void GPUInfoManager::ProcessCompleteInfo() {
  const auto result = EnumerateGPUInfo(gpu_data_manager_->GetGPUInfo());
{'fraction_non_alphanumeric': 0.1278295605858855, 'fraction_numerical': 0.014314247669773635, 'mean_word_length': 6.438118811881188, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3730085', 'n_tokens_mistral': 1019, 'n_tokens_neox': 977, 'n_words': 169}