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

Side by Side Diff: chrome/browser/extensions/unpacked_installer.cc

Issue 2751013002: Simplify ExtensionInstallChecker into a single-use class (Closed)
Patch Set: todo Created 3 years, 9 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/unpacked_installer.h" 5 #include "chrome/browser/extensions/unpacked_installer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
12 #include "chrome/browser/extensions/extension_error_reporter.h" 13 #include "chrome/browser/extensions/extension_error_reporter.h"
14 #include "chrome/browser/extensions/extension_install_checker.h"
13 #include "chrome/browser/extensions/extension_install_prompt.h" 15 #include "chrome/browser/extensions/extension_install_prompt.h"
14 #include "chrome/browser/extensions/extension_management.h" 16 #include "chrome/browser/extensions/extension_management.h"
15 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/permissions_updater.h" 18 #include "chrome/browser/extensions/permissions_updater.h"
17 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" 20 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h"
19 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 21 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
20 #include "components/crx_file/id_util.h" 22 #include "components/crx_file/id_util.h"
21 #include "components/sync/model/string_ordinal.h" 23 #include "components/sync/model/string_ordinal.h"
22 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // static 105 // static
104 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( 106 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create(
105 ExtensionService* extension_service) { 107 ExtensionService* extension_service) {
106 DCHECK(extension_service); 108 DCHECK(extension_service);
107 return scoped_refptr<UnpackedInstaller>( 109 return scoped_refptr<UnpackedInstaller>(
108 new UnpackedInstaller(extension_service)); 110 new UnpackedInstaller(extension_service));
109 } 111 }
110 112
111 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) 113 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service)
112 : service_weak_(extension_service->AsWeakPtr()), 114 : service_weak_(extension_service->AsWeakPtr()),
115 profile_(extension_service->profile()),
113 prompt_for_plugins_(true), 116 prompt_for_plugins_(true),
114 require_modern_manifest_version_(true), 117 require_modern_manifest_version_(true),
115 be_noisy_on_failure_(true), 118 be_noisy_on_failure_(true) {
116 install_checker_(extension_service->profile()) {
117 DCHECK_CURRENTLY_ON(BrowserThread::UI); 119 DCHECK_CURRENTLY_ON(BrowserThread::UI);
118 } 120 }
119 121
120 UnpackedInstaller::~UnpackedInstaller() { 122 UnpackedInstaller::~UnpackedInstaller() {
121 } 123 }
122 124
123 void UnpackedInstaller::Load(const base::FilePath& path_in) { 125 void UnpackedInstaller::Load(const base::FilePath& path_in) {
124 DCHECK(extension_path_.empty()); 126 DCHECK(extension_path_.empty());
125 extension_path_ = path_in; 127 extension_path_ = path_in;
126 BrowserThread::PostTask( 128 BrowserThread::PostTask(
(...skipping 15 matching lines...) Expand all
142 base::ThreadRestrictions::ScopedAllowIO allow_io; 144 base::ThreadRestrictions::ScopedAllowIO allow_io;
143 145
144 extension_path_ = base::MakeAbsoluteFilePath(path_in); 146 extension_path_ = base::MakeAbsoluteFilePath(path_in);
145 147
146 if (!IsLoadingUnpackedAllowed()) { 148 if (!IsLoadingUnpackedAllowed()) {
147 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); 149 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError);
148 return false; 150 return false;
149 } 151 }
150 152
151 std::string error; 153 std::string error;
152 install_checker_.set_extension( 154 extension_ = file_util::LoadExtension(extension_path_, Manifest::COMMAND_LINE,
153 file_util::LoadExtension( 155 GetFlags(), &error);
154 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get());
155 156
156 if (!extension() || 157 if (!extension() ||
157 !extension_l10n_util::ValidateExtensionLocales( 158 !extension_l10n_util::ValidateExtensionLocales(
158 extension_path_, extension()->manifest()->value(), &error)) { 159 extension_path_, extension()->manifest()->value(), &error)) {
159 ReportExtensionLoadError(error); 160 ReportExtensionLoadError(error);
160 return false; 161 return false;
161 } 162 }
162 163
163 if (only_allow_apps && !extension()->is_platform_app()) { 164 if (only_allow_apps && !extension()->is_platform_app()) {
164 #if defined(GOOGLE_CHROME_BUILD) 165 #if defined(GOOGLE_CHROME_BUILD)
(...skipping 23 matching lines...) Expand all
188 DCHECK_CURRENTLY_ON(BrowserThread::UI); 189 DCHECK_CURRENTLY_ON(BrowserThread::UI);
189 if (!service_weak_.get()) 190 if (!service_weak_.get())
190 return; 191 return;
191 192
192 const ExtensionSet& disabled_extensions = 193 const ExtensionSet& disabled_extensions =
193 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions(); 194 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions();
194 if (prompt_for_plugins_ && 195 if (prompt_for_plugins_ &&
195 PluginInfo::HasPlugins(extension()) && 196 PluginInfo::HasPlugins(extension()) &&
196 !disabled_extensions.Contains(extension()->id())) { 197 !disabled_extensions.Contains(extension()->id())) {
197 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( 198 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
198 extension(), 199 extension(), profile_,
199 install_checker_.profile(),
200 base::Bind(&UnpackedInstaller::StartInstallChecks, this)); 200 base::Bind(&UnpackedInstaller::StartInstallChecks, this));
201 prompt->ShowPrompt(); 201 prompt->ShowPrompt();
202 return; 202 return;
203 } 203 }
204 StartInstallChecks(); 204 StartInstallChecks();
205 } 205 }
206 206
207 void UnpackedInstaller::StartInstallChecks() { 207 void UnpackedInstaller::StartInstallChecks() {
208 // TODO(crbug.com/421128): Enable these checks all the time. The reason 208 // TODO(crbug.com/421128): Enable these checks all the time. The reason
209 // they are disabled for extensions loaded from the command-line is that 209 // they are disabled for extensions loaded from the command-line is that
(...skipping 24 matching lines...) Expand all
234 } else if (imported_module && (version_required.IsValid() && 234 } else if (imported_module && (version_required.IsValid() &&
235 imported_module->version()->CompareTo( 235 imported_module->version()->CompareTo(
236 version_required) < 0)) { 236 version_required) < 0)) {
237 ReportExtensionLoadError(kImportMinVersionNewer); 237 ReportExtensionLoadError(kImportMinVersionNewer);
238 return; 238 return;
239 } 239 }
240 } 240 }
241 } 241 }
242 } 242 }
243 243
244 install_checker_.Start( 244 install_checker_ = base::MakeUnique<ExtensionInstallChecker>(
245 profile_, extension_,
245 ExtensionInstallChecker::CHECK_REQUIREMENTS | 246 ExtensionInstallChecker::CHECK_REQUIREMENTS |
246 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, 247 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY,
247 true /* fail fast */, 248 true /* fail fast */);
249 install_checker_->Start(
248 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this)); 250 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this));
249 } 251 }
250 252
251 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) { 253 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) {
252 DCHECK_CURRENTLY_ON(BrowserThread::UI); 254 DCHECK_CURRENTLY_ON(BrowserThread::UI);
253 255
254 if (!install_checker_.policy_error().empty()) { 256 if (!install_checker_->policy_error().empty()) {
255 ReportExtensionLoadError(install_checker_.policy_error()); 257 ReportExtensionLoadError(install_checker_->policy_error());
256 return; 258 return;
257 } 259 }
258 260
259 if (!install_checker_.requirement_errors().empty()) { 261 if (!install_checker_->requirement_errors().empty()) {
260 ReportExtensionLoadError( 262 ReportExtensionLoadError(
261 base::JoinString(install_checker_.requirement_errors(), " ")); 263 base::JoinString(install_checker_->requirement_errors(), " "));
262 return; 264 return;
263 } 265 }
264 266
265 InstallExtension(); 267 InstallExtension();
266 } 268 }
267 269
268 int UnpackedInstaller::GetFlags() { 270 int UnpackedInstaller::GetFlags() {
269 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_); 271 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_);
270 bool allow_file_access = 272 bool allow_file_access =
271 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED); 273 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 BrowserThread::PostTask( 324 BrowserThread::PostTask(
323 BrowserThread::FILE, 325 BrowserThread::FILE,
324 FROM_HERE, 326 FROM_HERE,
325 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); 327 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags()));
326 } 328 }
327 329
328 void UnpackedInstaller::LoadWithFileAccess(int flags) { 330 void UnpackedInstaller::LoadWithFileAccess(int flags) {
329 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 331 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
330 332
331 std::string error; 333 std::string error;
332 install_checker_.set_extension( 334 extension_ = file_util::LoadExtension(extension_path_, Manifest::UNPACKED,
333 file_util::LoadExtension( 335 flags, &error);
334 extension_path_, Manifest::UNPACKED, flags, &error).get());
335 336
336 if (!extension() || 337 if (!extension() ||
337 !extension_l10n_util::ValidateExtensionLocales( 338 !extension_l10n_util::ValidateExtensionLocales(
338 extension_path_, extension()->manifest()->value(), &error)) { 339 extension_path_, extension()->manifest()->value(), &error)) {
339 BrowserThread::PostTask( 340 BrowserThread::PostTask(
340 BrowserThread::UI, 341 BrowserThread::UI,
341 FROM_HERE, 342 FROM_HERE,
342 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); 343 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error));
343 return; 344 return;
344 } 345 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 service_weak_->OnExtensionInstalled( 382 service_weak_->OnExtensionInstalled(
382 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); 383 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately);
383 384
384 if (!callback_.is_null()) { 385 if (!callback_.is_null()) {
385 callback_.Run(extension(), extension_path_, std::string()); 386 callback_.Run(extension(), extension_path_, std::string());
386 callback_.Reset(); 387 callback_.Reset();
387 } 388 }
388 } 389 }
389 390
390 } // namespace extensions 391 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/unpacked_installer.h ('k') | extensions/test/extension_test_notification_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698