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

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

Issue 2769813004: Revert of Simplify ExtensionInstallChecker into a single-use class (Closed)
Patch Set: 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"
11 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
12 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
13 #include "chrome/browser/extensions/extension_error_reporter.h" 12 #include "chrome/browser/extensions/extension_error_reporter.h"
14 #include "chrome/browser/extensions/extension_install_checker.h"
15 #include "chrome/browser/extensions/extension_install_prompt.h" 13 #include "chrome/browser/extensions/extension_install_prompt.h"
16 #include "chrome/browser/extensions/extension_management.h" 14 #include "chrome/browser/extensions/extension_management.h"
17 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/permissions_updater.h" 16 #include "chrome/browser/extensions/permissions_updater.h"
19 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" 18 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h"
21 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 19 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
22 #include "components/crx_file/id_util.h" 20 #include "components/crx_file/id_util.h"
23 #include "components/sync/model/string_ordinal.h" 21 #include "components/sync/model/string_ordinal.h"
24 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // static 103 // static
106 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( 104 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create(
107 ExtensionService* extension_service) { 105 ExtensionService* extension_service) {
108 DCHECK(extension_service); 106 DCHECK(extension_service);
109 return scoped_refptr<UnpackedInstaller>( 107 return scoped_refptr<UnpackedInstaller>(
110 new UnpackedInstaller(extension_service)); 108 new UnpackedInstaller(extension_service));
111 } 109 }
112 110
113 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) 111 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service)
114 : service_weak_(extension_service->AsWeakPtr()), 112 : service_weak_(extension_service->AsWeakPtr()),
115 profile_(extension_service->profile()),
116 prompt_for_plugins_(true), 113 prompt_for_plugins_(true),
117 require_modern_manifest_version_(true), 114 require_modern_manifest_version_(true),
118 be_noisy_on_failure_(true) { 115 be_noisy_on_failure_(true),
116 install_checker_(extension_service->profile()) {
119 DCHECK_CURRENTLY_ON(BrowserThread::UI); 117 DCHECK_CURRENTLY_ON(BrowserThread::UI);
120 } 118 }
121 119
122 UnpackedInstaller::~UnpackedInstaller() { 120 UnpackedInstaller::~UnpackedInstaller() {
123 } 121 }
124 122
125 void UnpackedInstaller::Load(const base::FilePath& path_in) { 123 void UnpackedInstaller::Load(const base::FilePath& path_in) {
126 DCHECK(extension_path_.empty()); 124 DCHECK(extension_path_.empty());
127 extension_path_ = path_in; 125 extension_path_ = path_in;
128 BrowserThread::PostTask( 126 BrowserThread::PostTask(
(...skipping 15 matching lines...) Expand all
144 base::ThreadRestrictions::ScopedAllowIO allow_io; 142 base::ThreadRestrictions::ScopedAllowIO allow_io;
145 143
146 extension_path_ = base::MakeAbsoluteFilePath(path_in); 144 extension_path_ = base::MakeAbsoluteFilePath(path_in);
147 145
148 if (!IsLoadingUnpackedAllowed()) { 146 if (!IsLoadingUnpackedAllowed()) {
149 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); 147 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError);
150 return false; 148 return false;
151 } 149 }
152 150
153 std::string error; 151 std::string error;
154 extension_ = file_util::LoadExtension(extension_path_, Manifest::COMMAND_LINE, 152 install_checker_.set_extension(
155 GetFlags(), &error); 153 file_util::LoadExtension(
154 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get());
156 155
157 if (!extension() || 156 if (!extension() ||
158 !extension_l10n_util::ValidateExtensionLocales( 157 !extension_l10n_util::ValidateExtensionLocales(
159 extension_path_, extension()->manifest()->value(), &error)) { 158 extension_path_, extension()->manifest()->value(), &error)) {
160 ReportExtensionLoadError(error); 159 ReportExtensionLoadError(error);
161 return false; 160 return false;
162 } 161 }
163 162
164 if (only_allow_apps && !extension()->is_platform_app()) { 163 if (only_allow_apps && !extension()->is_platform_app()) {
165 #if defined(GOOGLE_CHROME_BUILD) 164 #if defined(GOOGLE_CHROME_BUILD)
(...skipping 23 matching lines...) Expand all
189 DCHECK_CURRENTLY_ON(BrowserThread::UI); 188 DCHECK_CURRENTLY_ON(BrowserThread::UI);
190 if (!service_weak_.get()) 189 if (!service_weak_.get())
191 return; 190 return;
192 191
193 const ExtensionSet& disabled_extensions = 192 const ExtensionSet& disabled_extensions =
194 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions(); 193 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions();
195 if (prompt_for_plugins_ && 194 if (prompt_for_plugins_ &&
196 PluginInfo::HasPlugins(extension()) && 195 PluginInfo::HasPlugins(extension()) &&
197 !disabled_extensions.Contains(extension()->id())) { 196 !disabled_extensions.Contains(extension()->id())) {
198 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( 197 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
199 extension(), profile_, 198 extension(),
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_ = base::MakeUnique<ExtensionInstallChecker>( 244 install_checker_.Start(
245 profile_, extension_,
246 ExtensionInstallChecker::CHECK_REQUIREMENTS | 245 ExtensionInstallChecker::CHECK_REQUIREMENTS |
247 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, 246 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY,
248 true /* fail fast */); 247 true /* fail fast */,
249 install_checker_->Start(
250 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this)); 248 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this));
251 } 249 }
252 250
253 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) { 251 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) {
254 DCHECK_CURRENTLY_ON(BrowserThread::UI); 252 DCHECK_CURRENTLY_ON(BrowserThread::UI);
255 253
256 if (!install_checker_->policy_error().empty()) { 254 if (!install_checker_.policy_error().empty()) {
257 ReportExtensionLoadError(install_checker_->policy_error()); 255 ReportExtensionLoadError(install_checker_.policy_error());
258 return; 256 return;
259 } 257 }
260 258
261 if (!install_checker_->requirement_errors().empty()) { 259 if (!install_checker_.requirement_errors().empty()) {
262 ReportExtensionLoadError( 260 ReportExtensionLoadError(
263 base::JoinString(install_checker_->requirement_errors(), " ")); 261 base::JoinString(install_checker_.requirement_errors(), " "));
264 return; 262 return;
265 } 263 }
266 264
267 InstallExtension(); 265 InstallExtension();
268 } 266 }
269 267
270 int UnpackedInstaller::GetFlags() { 268 int UnpackedInstaller::GetFlags() {
271 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_); 269 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_);
272 bool allow_file_access = 270 bool allow_file_access =
273 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED); 271 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 BrowserThread::PostTask( 322 BrowserThread::PostTask(
325 BrowserThread::FILE, 323 BrowserThread::FILE,
326 FROM_HERE, 324 FROM_HERE,
327 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); 325 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags()));
328 } 326 }
329 327
330 void UnpackedInstaller::LoadWithFileAccess(int flags) { 328 void UnpackedInstaller::LoadWithFileAccess(int flags) {
331 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 329 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
332 330
333 std::string error; 331 std::string error;
334 extension_ = file_util::LoadExtension(extension_path_, Manifest::UNPACKED, 332 install_checker_.set_extension(
335 flags, &error); 333 file_util::LoadExtension(
334 extension_path_, Manifest::UNPACKED, flags, &error).get());
336 335
337 if (!extension() || 336 if (!extension() ||
338 !extension_l10n_util::ValidateExtensionLocales( 337 !extension_l10n_util::ValidateExtensionLocales(
339 extension_path_, extension()->manifest()->value(), &error)) { 338 extension_path_, extension()->manifest()->value(), &error)) {
340 BrowserThread::PostTask( 339 BrowserThread::PostTask(
341 BrowserThread::UI, 340 BrowserThread::UI,
342 FROM_HERE, 341 FROM_HERE,
343 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); 342 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error));
344 return; 343 return;
345 } 344 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 service_weak_->OnExtensionInstalled( 381 service_weak_->OnExtensionInstalled(
383 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); 382 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately);
384 383
385 if (!callback_.is_null()) { 384 if (!callback_.is_null()) {
386 callback_.Run(extension(), extension_path_, std::string()); 385 callback_.Run(extension(), extension_path_, std::string());
387 callback_.Reset(); 386 callback_.Reset();
388 } 387 }
389 } 388 }
390 389
391 } // namespace extensions 390 } // 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