Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: chrome/browser/gpu_feature_checker.cc

Issue 10891013: Make GpuDataManager thread safe. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gpu_feature_checker.h" 5 #include "chrome/browser/gpu_feature_checker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/gpu_data_manager.h" 9 #include "content/public/browser/gpu_data_manager.h"
10 10
11 namespace { 11 namespace {
12 12
13 // A false return value is always valid, but a true one is only valid if full 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. 14 // GPU info has been collected in a GPU process.
15 bool IsFeatureAllowed(content::GpuDataManager* manager, 15 bool IsFeatureAllowed(content::GpuDataManager* manager,
16 content::GpuFeatureType feature) { 16 content::GpuFeatureType feature) {
17 bool feature_allowed = true; 17 bool feature_allowed = true;
18 if (!manager->GpuAccessAllowed()) { 18 if (!manager->GpuAccessAllowed()) {
19 feature_allowed = false; 19 feature_allowed = false;
20 } else { 20 } else {
21 uint32 blacklist_type = manager->GetGpuFeatureType(); 21 uint32 blacklist_type = manager->GetBlacklistedFeatures();
22 if (blacklist_type & feature) 22 if (blacklist_type & feature)
23 feature_allowed = false; 23 feature_allowed = false;
24 } 24 }
25 return feature_allowed; 25 return feature_allowed;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 GPUFeatureChecker::GPUFeatureChecker(content::GpuFeatureType feature, 30 GPUFeatureChecker::GPUFeatureChecker(content::GpuFeatureType feature,
31 FeatureAvailableCallback callback) 31 FeatureAvailableCallback callback)
32 : feature_(feature), 32 : feature_(feature),
33 callback_(callback) { 33 callback_(callback) {
34 } 34 }
35 35
36 GPUFeatureChecker::~GPUFeatureChecker() { 36 GPUFeatureChecker::~GPUFeatureChecker() {
37 } 37 }
38 38
39 void GPUFeatureChecker::CheckGPUFeatureAvailability() { 39 void GPUFeatureChecker::CheckGPUFeatureAvailability() {
40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
41 41
42 bool finalized = true; 42 bool finalized = true;
43 #if defined(OS_LINUX) 43 #if defined(OS_LINUX)
44 // On Windows and Mac, so far we can always make the final WebGL blacklisting 44 // On Windows and Mac, so far we can always make the final WebGL blacklisting
45 // decision based on partial GPU info; on Linux, we need to launch the GPU 45 // decision based on partial GPU info; on Linux, we need to launch the GPU
46 // process to collect full GPU info and make the final decision. 46 // process to collect full GPU info and make the final decision.
47 finalized = false; 47 finalized = false;
48 #endif 48 #endif
49 49
50 content::GpuDataManager* manager = content::GpuDataManager::GetInstance(); 50 content::GpuDataManager* manager = content::GpuDataManager::GetInstance();
51 if (manager->IsCompleteGPUInfoAvailable()) 51 if (manager->IsCompleteGpuInfoAvailable())
52 finalized = true; 52 finalized = true;
53 53
54 bool feature_allowed = IsFeatureAllowed(manager, feature_); 54 bool feature_allowed = IsFeatureAllowed(manager, feature_);
55 if (!feature_allowed) 55 if (!feature_allowed)
56 finalized = true; 56 finalized = true;
57 57
58 if (finalized) { 58 if (finalized) {
59 callback_.Run(feature_allowed); 59 callback_.Run(feature_allowed);
60 } else { 60 } else {
61 // Matched with a Release in OnGpuInfoUpdate. 61 // Matched with a Release in OnGpuInfoUpdate.
62 AddRef(); 62 AddRef();
63 63
64 manager->AddObserver(this); 64 manager->AddObserver(this);
65 manager->RequestCompleteGpuInfoIfNeeded(); 65 manager->RequestCompleteGpuInfoIfNeeded();
66 } 66 }
67 } 67 }
68 68
69 void GPUFeatureChecker::OnGpuInfoUpdate() { 69 void GPUFeatureChecker::OnGpuInfoUpdate() {
70 content::GpuDataManager* manager = content::GpuDataManager::GetInstance(); 70 content::GpuDataManager* manager = content::GpuDataManager::GetInstance();
71 manager->RemoveObserver(this); 71 manager->RemoveObserver(this);
72 bool feature_allowed = IsFeatureAllowed(manager, feature_); 72 bool feature_allowed = IsFeatureAllowed(manager, feature_);
73 callback_.Run(feature_allowed); 73 callback_.Run(feature_allowed);
74 74
75 // Matches the AddRef in HasFeature(). 75 // Matches the AddRef in HasFeature().
76 Release(); 76 Release();
77 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698