Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/extensions/requirements_checker.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/gpu_feature_checker.h" | |
| 10 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 11 #include "chrome/common/extensions/extension.h" | |
| 12 #include "chrome/common/extensions/manifest.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 #include "content/public/common/gpu_feature_type.h" | |
| 15 | |
| 16 namespace keys = extension_manifest_keys; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 const char* kWebGlError = "WebGL is not supported"; | |
|
Aaron Boodman
2012/08/01 03:58:54
These need to be messages in generated_resources.g
Yoyo Zhou
2012/08/02 22:23:30
Naming nit: kWebGLError
eaugusti
2012/08/03 01:06:26
Done.
| |
| 21 const char* kCSS3dError = "CSS3d is not supported"; | |
| 22 #if defined(OS_CHROMEOS) | |
| 23 const char* kPluginsError = "Plugins are not supported"; | |
| 24 #endif | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 namespace extensions { | |
| 29 | |
| 30 RequirementsChecker::RequirementsChecker() | |
| 31 : async_requirement_checks_(0) { | |
|
Aaron Boodman
2012/08/01 03:58:54
Nit: Maybe rename this to pending_requirements_che
eaugusti
2012/08/03 01:06:26
Done.
| |
| 32 } | |
| 33 | |
| 34 RequirementsChecker::~RequirementsChecker() { | |
| 35 } | |
| 36 | |
| 37 void RequirementsChecker::Check(scoped_refptr<const Extension> extension, | |
| 38 base::Callback<void(std::vector<std::string>)> callback, | |
| 39 content::BrowserThread::ID callback_thread) { | |
| 40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 41 | |
| 42 callback_thread_ = callback_thread; | |
| 43 callback_ = callback; | |
| 44 DictionaryValue* requirements_value = NULL; | |
| 45 extension->manifest()->GetDictionary(keys::kRequirements, | |
| 46 &requirements_value); | |
| 47 if (!requirements_value) { | |
| 48 content::BrowserThread::PostTask(callback_thread_, FROM_HERE, | |
| 49 base::Bind(callback, errors_)); | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); | |
| 54 it != requirements_value->end_keys(); ++it) { | |
| 55 DictionaryValue* requirement_value; | |
|
Aaron Boodman
2012/08/01 03:58:54
= NULL;
eaugusti
2012/08/03 01:06:26
Done.
| |
| 56 if (!requirements_value->GetDictionaryWithoutPathExpansion(*it, | |
|
Aaron Boodman
2012/08/01 03:58:54
first param on each line must align.
eaugusti
2012/08/03 01:06:26
Done.
| |
| 57 &requirement_value) || !requirement_value) { | |
| 58 continue; | |
| 59 } | |
| 60 | |
| 61 if (*it == "plugins") { | |
| 62 #if defined(OS_CHROMEOS) | |
| 63 errors_.push_back(kPluginsError); | |
| 64 #endif | |
| 65 } else if (*it == "3D") { | |
| 66 ListValue* features; | |
|
Aaron Boodman
2012/08/01 03:58:54
= NULL;
eaugusti
2012/08/03 01:06:26
Done.
| |
| 67 if (!requirement_value->GetListWithoutPathExpansion("features", | |
| 68 &features) || | |
| 69 !features) { | |
| 70 errors_.push_back("Improperly formatted requirement features for 3D"); | |
|
Yoyo Zhou
2012/08/02 22:23:30
Define literal strings at the top.
eaugusti
2012/08/03 01:06:26
Done.
| |
| 71 continue; | |
|
Aaron Boodman
2012/08/01 03:58:54
This is a different kind of error (whee). This sho
eaugusti
2012/08/03 01:06:26
Done, I like that struct.
| |
| 72 } | |
| 73 | |
| 74 std::string feature; | |
|
Aaron Boodman
2012/08/01 03:58:54
define feature within for block
eaugusti
2012/08/03 01:06:26
Done.
| |
| 75 base::ListValue::iterator it; | |
|
Aaron Boodman
2012/08/01 03:58:54
define it within for statement
eaugusti
2012/08/03 01:06:26
Done.
| |
| 76 for (it = features->begin(); it != features->end(); ++it) { | |
| 77 if ((*it)->GetAsString(&feature)) { | |
| 78 if (feature == "webgl") { | |
| 79 ++async_requirement_checks_; | |
| 80 webgl_checker_ = new GPUFeatureChecker( | |
| 81 content::GPU_FEATURE_TYPE_WEBGL, | |
| 82 base::Bind(&RequirementsChecker::IsWebGLAvailable, | |
| 83 AsWeakPtr())); | |
| 84 } else if (feature == "css3d") { | |
| 85 ++async_requirement_checks_; | |
| 86 css3d_checker_ = new GPUFeatureChecker( | |
| 87 content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING, | |
| 88 base::Bind(&RequirementsChecker::IsCSS3DAvailable, | |
| 89 AsWeakPtr())); | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 if (!async_requirement_checks_) { | |
|
Aaron Boodman
2012/08/01 03:58:54
Don't use boolean comparisons for integers.
eaugusti
2012/08/03 01:06:26
:(
| |
| 97 content::BrowserThread::PostTask(callback_thread_, FROM_HERE, | |
| 98 base::Bind(callback_, errors_)); | |
| 99 return; | |
| 100 } | |
| 101 // Running the GPU checkers down here removes any race condition that arises | |
| 102 // from the use of async_requirement_checks_. | |
|
Aaron Boodman
2012/08/01 03:58:54
Hm, I know that I spec'd RequirementsChecker::Chec
eaugusti
2012/08/03 01:06:26
Done.
| |
| 103 if (webgl_checker_.get()) | |
| 104 webgl_checker_->CheckGPUFeatureAvailability(); | |
| 105 if (css3d_checker_.get()) | |
| 106 css3d_checker_->CheckGPUFeatureAvailability(); | |
| 107 } | |
| 108 | |
| 109 base::WeakPtr<RequirementsChecker> RequirementsChecker::AsWeakPtr() { | |
| 110 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 111 return base::SupportsWeakPtr<RequirementsChecker>::AsWeakPtr(); | |
| 112 } | |
| 113 | |
| 114 void RequirementsChecker::IsWebGLAvailable(bool available) { | |
|
Aaron Boodman
2012/08/01 03:58:54
Traditionally a name like Foo::IsMonkey is asking
eaugusti
2012/08/03 01:06:26
Done.
| |
| 115 if (!available) | |
| 116 errors_.push_back(kWebGlError); | |
| 117 MaybeRunCallback(); | |
| 118 } | |
| 119 | |
| 120 void RequirementsChecker::IsCSS3DAvailable(bool available) { | |
| 121 if (!available) | |
| 122 errors_.push_back(kCSS3dError); | |
| 123 MaybeRunCallback(); | |
| 124 } | |
| 125 | |
| 126 void RequirementsChecker::MaybeRunCallback() { | |
| 127 if (!--async_requirement_checks_) { | |
|
Aaron Boodman
2012/08/01 03:58:54
Compare to zero instead.
eaugusti
2012/08/03 01:06:26
Done.
| |
| 128 content::BrowserThread::PostTask(callback_thread_, FROM_HERE, | |
| 129 base::Bind(callback_, errors_)); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 } // namespace extensions | |
| OLD | NEW |