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

Side by Side Diff: extensions/browser/requirements_checker.cc

Issue 2783813002: Move ChromeRequirementsChecker to //extensions as a PreloadCheck (Closed)
Patch Set: minor test cleanup Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/chrome_requirements_checker.h" 5 #include "extensions/browser/requirements_checker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
8 #include "build/build_config.h" 10 #include "build/build_config.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/gpu_feature_checker.h" 12 #include "content/public/browser/gpu_feature_checker.h"
12 #include "extensions/common/extension.h" 13 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest.h"
14 #include "extensions/common/manifest_handlers/requirements_info.h" 14 #include "extensions/common/manifest_handlers/requirements_info.h"
15 #include "extensions/strings/grit/extensions_strings.h"
15 #include "gpu/config/gpu_feature_type.h" 16 #include "gpu/config/gpu_feature_type.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 18
18 namespace extensions { 19 namespace extensions {
19 20
20 ChromeRequirementsChecker::ChromeRequirementsChecker() 21 RequirementsChecker::RequirementsChecker(const Extension* extension)
21 : pending_requirement_checks_(0), weak_ptr_factory_(this) { 22 : PreloadCheck(extension), weak_ptr_factory_(this) {}
22 }
23 23
24 ChromeRequirementsChecker::~ChromeRequirementsChecker() { 24 RequirementsChecker::~RequirementsChecker() {}
25 }
26 25
27 void ChromeRequirementsChecker::Check( 26 void RequirementsChecker::Start(ResultCallback callback) {
28 const scoped_refptr<const Extension>& extension,
29 const RequirementsCheckedCallback& callback) {
30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
31 28
32 callback_ = callback;
33 const RequirementsInfo& requirements = 29 const RequirementsInfo& requirements =
34 RequirementsInfo::GetRequirements(extension.get()); 30 RequirementsInfo::GetRequirements(extension());
35 31
36 if (requirements.npapi) {
37 #if defined(OS_POSIX) && !defined(OS_MACOSX) 32 #if defined(OS_POSIX) && !defined(OS_MACOSX)
38 errors_.push_back( 33 if (requirements.npapi)
39 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED)); 34 errors_.insert(NPAPI_NOT_SUPPORTED);
40 #endif 35 #endif
41 }
42 36
43 if (requirements.window_shape) {
44 #if !defined(USE_AURA) 37 #if !defined(USE_AURA)
45 errors_.push_back( 38 if (requirements.window_shape)
46 l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED)); 39 errors_.insert(WINDOW_SHAPE_NOT_SUPPORTED);
47 #endif 40 #endif
48 }
49 41
50 if (requirements.webgl) { 42 if (requirements.webgl) {
51 ++pending_requirement_checks_; 43 callback_ = std::move(callback);
52 webgl_checker_ = content::GpuFeatureChecker::Create( 44 webgl_checker_ = content::GpuFeatureChecker::Create(
53 gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL, 45 gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL,
54 base::Bind(&ChromeRequirementsChecker::SetWebGLAvailability, 46 base::Bind(&RequirementsChecker::OnGetWebGLAvailability,
55 weak_ptr_factory_.GetWeakPtr())); 47 weak_ptr_factory_.GetWeakPtr()));
56 }
57
58 if (pending_requirement_checks_ == 0) {
59 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
60 base::Bind(callback_, errors_));
61 // Reset the callback so any ref-counted bound parameters will get released.
62 callback_.Reset();
63 return;
64 }
65 // Running the GPU checkers down here removes any race condition that arises
66 // from the use of pending_requirement_checks_.
67 if (webgl_checker_.get())
68 webgl_checker_->CheckGpuFeatureAvailability(); 48 webgl_checker_->CheckGpuFeatureAvailability();
69 } 49 } else {
70 50 std::move(callback).Run(errors_);
71 void ChromeRequirementsChecker::SetWebGLAvailability(bool available) {
72 if (!available) {
73 errors_.push_back(
74 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
75 }
76 MaybeRunCallback();
77 }
78
79 void ChromeRequirementsChecker::MaybeRunCallback() {
80 if (--pending_requirement_checks_ == 0) {
81 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
82 base::Bind(callback_, errors_));
83 // Reset the callback so any ref-counted bound parameters will get released.
84 callback_.Reset();
85 errors_.clear();
86 } 51 }
87 } 52 }
88 53
54 base::string16 RequirementsChecker::GetErrorMessage() const {
55 // Join the error messages into one string.
56 std::vector<std::string> messages;
57 #if defined(OS_POSIX) && !defined(OS_MACOSX)
58 if (errors_.count(NPAPI_NOT_SUPPORTED)) {
59 messages.push_back(
60 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
61 }
62 #endif
63 if (errors_.count(WEBGL_NOT_SUPPORTED)) {
64 messages.push_back(
65 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
66 }
67 #if !defined(USE_AURA)
68 if (errors_.count(WINDOW_SHAPE_NOT_SUPPORTED)) {
69 messages.push_back(
70 l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED));
71 }
72 #endif
73
74 return base::UTF8ToUTF16(base::JoinString(messages, " "));
75 }
76
77 void RequirementsChecker::OnGetWebGLAvailability(bool available) {
78 DCHECK(callback_);
79 if (!available)
80 errors_.insert(WEBGL_NOT_SUPPORTED);
81 std::move(callback_).Run(errors_);
82 }
83
89 } // namespace extensions 84 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698