[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / gpu / gpu_feature_checker.cc
blob2d7c8479ed701a8e02bbbf813956dffd24a8e449
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/gpu/gpu_feature_checker.h"
7 #include "base/logging.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/gpu_data_manager.h"
11 namespace {
13 // A false return value is always valid, but a true one is only valid if full
14 // GPU info has been collected in a GPU process.
15 bool IsFeatureAllowed(content::GpuDataManager* manager,
16 gpu::GpuFeatureType feature) {
17 return (manager->GpuAccessAllowed(NULL) &&
18 !manager->IsFeatureBlacklisted(feature));
21 } // namespace
23 GPUFeatureChecker::GPUFeatureChecker(gpu::GpuFeatureType feature,
24 FeatureAvailableCallback callback)
25 : feature_(feature),
26 callback_(callback) {
29 GPUFeatureChecker::~GPUFeatureChecker() {
32 void GPUFeatureChecker::CheckGPUFeatureAvailability() {
33 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
35 bool finalized = true;
36 #if defined(OS_LINUX)
37 // On Windows and Mac, so far we can always make the final WebGL blacklisting
38 // decision based on partial GPU info; on Linux, we need to launch the GPU
39 // process to collect full GPU info and make the final decision.
40 finalized = false;
41 #endif
43 content::GpuDataManager* manager = content::GpuDataManager::GetInstance();
44 if (manager->IsCompleteGpuInfoAvailable())
45 finalized = true;
47 bool feature_allowed = IsFeatureAllowed(manager, feature_);
48 if (!feature_allowed)
49 finalized = true;
51 if (finalized) {
52 callback_.Run(feature_allowed);
53 } else {
54 // Matched with a Release in OnGpuInfoUpdate.
55 AddRef();
57 manager->AddObserver(this);
58 manager->RequestCompleteGpuInfoIfNeeded();
62 void GPUFeatureChecker::OnGpuInfoUpdate() {
63 content::GpuDataManager* manager = content::GpuDataManager::GetInstance();
64 manager->RemoveObserver(this);
65 bool feature_allowed = IsFeatureAllowed(manager, feature_);
66 callback_.Run(feature_allowed);
68 // Matches the AddRef in HasFeature().
69 Release();