OLD | NEW |
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/extensions/requirements_checker.h" | 5 #include "chrome/browser/extensions/requirements_checker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/gpu/gpu_feature_checker.h" | 9 #include "chrome/browser/gpu/gpu_feature_checker.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 | 58 |
59 if (requirements.webgl) { | 59 if (requirements.webgl) { |
60 ++pending_requirement_checks_; | 60 ++pending_requirement_checks_; |
61 webgl_checker_ = new GPUFeatureChecker( | 61 webgl_checker_ = new GPUFeatureChecker( |
62 gpu::GPU_FEATURE_TYPE_WEBGL, | 62 gpu::GPU_FEATURE_TYPE_WEBGL, |
63 base::Bind(&RequirementsChecker::SetWebGLAvailability, | 63 base::Bind(&RequirementsChecker::SetWebGLAvailability, |
64 AsWeakPtr())); | 64 AsWeakPtr())); |
65 } | 65 } |
66 | 66 |
67 if (requirements.css3d) { | |
68 ++pending_requirement_checks_; | |
69 css3d_checker_ = new GPUFeatureChecker( | |
70 gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING, | |
71 base::Bind(&RequirementsChecker::SetCSS3DAvailability, | |
72 AsWeakPtr())); | |
73 } | |
74 | |
75 if (pending_requirement_checks_ == 0) { | 67 if (pending_requirement_checks_ == 0) { |
76 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 68 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
77 base::Bind(callback_, errors_)); | 69 base::Bind(callback_, errors_)); |
78 // Reset the callback so any ref-counted bound parameters will get released. | 70 // Reset the callback so any ref-counted bound parameters will get released. |
79 callback_.Reset(); | 71 callback_.Reset(); |
80 return; | 72 return; |
81 } | 73 } |
82 // Running the GPU checkers down here removes any race condition that arises | 74 // Running the GPU checkers down here removes any race condition that arises |
83 // from the use of pending_requirement_checks_. | 75 // from the use of pending_requirement_checks_. |
84 if (webgl_checker_.get()) | 76 if (webgl_checker_.get()) |
85 webgl_checker_->CheckGPUFeatureAvailability(); | 77 webgl_checker_->CheckGPUFeatureAvailability(); |
86 if (css3d_checker_.get()) | |
87 css3d_checker_->CheckGPUFeatureAvailability(); | |
88 } | 78 } |
89 | 79 |
90 void RequirementsChecker::SetWebGLAvailability(bool available) { | 80 void RequirementsChecker::SetWebGLAvailability(bool available) { |
91 if (!available) { | 81 if (!available) { |
92 errors_.push_back( | 82 errors_.push_back( |
93 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); | 83 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); |
94 } | 84 } |
95 MaybeRunCallback(); | 85 MaybeRunCallback(); |
96 } | 86 } |
97 | 87 |
98 void RequirementsChecker::SetCSS3DAvailability(bool available) { | |
99 if (!available) { | |
100 errors_.push_back( | |
101 l10n_util::GetStringUTF8(IDS_EXTENSION_CSS3D_NOT_SUPPORTED)); | |
102 } | |
103 MaybeRunCallback(); | |
104 } | |
105 | |
106 void RequirementsChecker::MaybeRunCallback() { | 88 void RequirementsChecker::MaybeRunCallback() { |
107 if (--pending_requirement_checks_ == 0) { | 89 if (--pending_requirement_checks_ == 0) { |
108 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 90 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
109 base::Bind(callback_, errors_)); | 91 base::Bind(callback_, errors_)); |
110 // Reset the callback so any ref-counted bound parameters will get released. | 92 // Reset the callback so any ref-counted bound parameters will get released. |
111 callback_.Reset(); | 93 callback_.Reset(); |
112 errors_.clear(); | 94 errors_.clear(); |
113 } | 95 } |
114 } | 96 } |
115 | 97 |
116 } // namespace extensions | 98 } // namespace extensions |
OLD | NEW |