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

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

Issue 5535002: Decouple killbit testing from external extension providers (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: update Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions_service.h" 5 #include "chrome/browser/extensions/extensions_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Errors are reported through ExtensionErrorReporter. On success, 201 // Errors are reported through ExtensionErrorReporter. On success,
202 // OnExtensionLoaded() is called. 202 // OnExtensionLoaded() is called.
203 // TODO(erikkay): It might be useful to be able to load a packed extension 203 // TODO(erikkay): It might be useful to be able to load a packed extension
204 // (presumably into memory) without installing it. 204 // (presumably into memory) without installing it.
205 void LoadSingleExtension(const FilePath &path, 205 void LoadSingleExtension(const FilePath &path,
206 scoped_refptr<ExtensionsService> frontend); 206 scoped_refptr<ExtensionsService> frontend);
207 207
208 // Check externally updated extensions for updates and install if necessary. 208 // Check externally updated extensions for updates and install if necessary.
209 // Errors are reported through ExtensionErrorReporter. Succcess is not 209 // Errors are reported through ExtensionErrorReporter. Succcess is not
210 // reported. 210 // reported.
211 void CheckForExternalUpdates(const std::set<std::string>& ids_to_ignore, 211 void CheckForExternalUpdates(scoped_refptr<ExtensionsService> frontend);
212 scoped_refptr<ExtensionsService> frontend);
213 212
214 // For the extension in |version_path| with |id|, check to see if it's an 213 // For the extension in |version_path| with |id|, check to see if it's an
215 // externally managed extension. If so, tell the frontend to uninstall it. 214 // externally managed extension. If so, tell the frontend to uninstall it.
216 void CheckExternalUninstall(scoped_refptr<ExtensionsService> frontend, 215 void CheckExternalUninstall(scoped_refptr<ExtensionsService> frontend,
217 const std::string& id); 216 const std::string& id);
218 217
219 // Clear all ExternalExtensionProviders. 218 // Clear all ExternalExtensionProviders.
220 void ClearProvidersForTesting(); 219 void ClearProvidersForTesting();
221 220
222 // Adds an ExternalExtensionProvider for the service to use during testing. 221 // Adds an ExternalExtensionProvider for the service to use during testing.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 error, NotificationType::EXTENSION_INSTALL_ERROR, alert_on_error_)); 362 error, NotificationType::EXTENSION_INSTALL_ERROR, alert_on_error_));
364 } 363 }
365 364
366 // Some extensions will autoupdate themselves externally from Chrome. These 365 // Some extensions will autoupdate themselves externally from Chrome. These
367 // are typically part of some larger client application package. To support 366 // are typically part of some larger client application package. To support
368 // these, the extension will register its location in the the preferences file 367 // these, the extension will register its location in the the preferences file
369 // (and also, on Windows, in the registry) and this code will periodically 368 // (and also, on Windows, in the registry) and this code will periodically
370 // check that location for a .crx file, which it will then install locally if 369 // check that location for a .crx file, which it will then install locally if
371 // a new version is available. 370 // a new version is available.
372 void ExtensionsServiceBackend::CheckForExternalUpdates( 371 void ExtensionsServiceBackend::CheckForExternalUpdates(
373 const std::set<std::string>& ids_to_ignore,
374 scoped_refptr<ExtensionsService> frontend) { 372 scoped_refptr<ExtensionsService> frontend) {
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
376 374
377 // Note that this installation is intentionally silent (since it didn't 375 // Note that this installation is intentionally silent (since it didn't
378 // go through the front-end). Extensions that are registered in this 376 // go through the front-end). Extensions that are registered in this
379 // way are effectively considered 'pre-bundled', and so implicitly 377 // way are effectively considered 'pre-bundled', and so implicitly
380 // trusted. In general, if something has HKLM or filesystem access, 378 // trusted. In general, if something has HKLM or filesystem access,
381 // they could install an extension manually themselves anyway. 379 // they could install an extension manually themselves anyway.
382 alert_on_error_ = false; 380 alert_on_error_ = false;
383 frontend_ = frontend; 381 frontend_ = frontend;
384 external_extension_added_ = false; 382 external_extension_added_ = false;
385 383
386 // Ask each external extension provider to give us a call back for each 384 // Ask each external extension provider to give us a call back for each
387 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. 385 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
388 ProviderCollection::const_iterator i; 386 ProviderCollection::const_iterator i;
389 for (i = external_extension_providers_.begin(); 387 for (i = external_extension_providers_.begin();
390 i != external_extension_providers_.end(); ++i) { 388 i != external_extension_providers_.end(); ++i) {
391 ExternalExtensionProvider* provider = i->get(); 389 ExternalExtensionProvider* provider = i->get();
392 provider->VisitRegisteredExtension(this, ids_to_ignore); 390 provider->VisitRegisteredExtension(this);
393 } 391 }
394 392
395 if (external_extension_added_ && frontend->updater()) { 393 if (external_extension_added_ && frontend->updater()) {
396 BrowserThread::PostTask( 394 BrowserThread::PostTask(
397 BrowserThread::UI, FROM_HERE, 395 BrowserThread::UI, FROM_HERE,
398 NewRunnableMethod( 396 NewRunnableMethod(
399 frontend->updater(), &ExtensionUpdater::CheckNow)); 397 frontend->updater(), &ExtensionUpdater::CheckNow));
400 } 398 }
401 } 399 }
402 400
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 void ExtensionsService::AddPendingExtensionFromExternalUpdateUrl( 724 void ExtensionsService::AddPendingExtensionFromExternalUpdateUrl(
727 const std::string& id, const GURL& update_url, 725 const std::string& id, const GURL& update_url,
728 Extension::Location location) { 726 Extension::Location location) {
729 // Add the extension to this list of extensions to update. 727 // Add the extension to this list of extensions to update.
730 const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = 728 const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType =
731 PendingExtensionInfo::UNKNOWN; 729 PendingExtensionInfo::UNKNOWN;
732 const bool kIsFromSync = false; 730 const bool kIsFromSync = false;
733 const bool kInstallSilently = true; 731 const bool kInstallSilently = true;
734 const bool kEnableOnInstall = true; 732 const bool kEnableOnInstall = true;
735 const bool kEnableIncognitoOnInstall = false; 733 const bool kEnableIncognitoOnInstall = false;
734 if (extension_prefs_->IsExtensionKilled(id))
735 return;
736 736
737 if (GetExtensionByIdInternal(id, true, true)) { 737 if (GetExtensionByIdInternal(id, true, true)) {
738 LOG(DFATAL) << "Trying to add extension " << id 738 LOG(DFATAL) << "Trying to add extension " << id
739 << " by external update, but it is already installed."; 739 << " by external update, but it is already installed.";
740 return; 740 return;
741 } 741 }
742 742
743 AddPendingExtensionInternal(id, update_url, kExpectedCrxType, kIsFromSync, 743 AddPendingExtensionInternal(id, update_url, kExpectedCrxType, kIsFromSync,
744 kInstallSilently, kEnableOnInstall, 744 kInstallSilently, kEnableOnInstall,
745 kEnableIncognitoOnInstall, 745 kEnableIncognitoOnInstall,
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 bool ExtensionsService::GetBrowserActionVisibility(const Extension* extension) { 1424 bool ExtensionsService::GetBrowserActionVisibility(const Extension* extension) {
1425 return extension_prefs_->GetBrowserActionVisibility(extension); 1425 return extension_prefs_->GetBrowserActionVisibility(extension);
1426 } 1426 }
1427 1427
1428 void ExtensionsService::SetBrowserActionVisibility(const Extension* extension, 1428 void ExtensionsService::SetBrowserActionVisibility(const Extension* extension,
1429 bool visible) { 1429 bool visible) {
1430 extension_prefs_->SetBrowserActionVisibility(extension, visible); 1430 extension_prefs_->SetBrowserActionVisibility(extension, visible);
1431 } 1431 }
1432 1432
1433 void ExtensionsService::CheckForExternalUpdates() { 1433 void ExtensionsService::CheckForExternalUpdates() {
1434 // This installs or updates externally provided extensions.
1435 // TODO(aa): Why pass this list into the provider, why not just filter it
1436 // later?
1437 std::set<std::string> killed_extensions;
1438 extension_prefs_->GetKilledExtensionIds(&killed_extensions);
1439 BrowserThread::PostTask( 1434 BrowserThread::PostTask(
1440 BrowserThread::FILE, FROM_HERE, 1435 BrowserThread::FILE, FROM_HERE,
1441 NewRunnableMethod( 1436 NewRunnableMethod(
1442 backend_.get(), &ExtensionsServiceBackend::CheckForExternalUpdates, 1437 backend_.get(), &ExtensionsServiceBackend::CheckForExternalUpdates,
1443 killed_extensions, scoped_refptr<ExtensionsService>(this))); 1438 scoped_refptr<ExtensionsService>(this)));
1444 } 1439 }
1445 1440
1446 void ExtensionsService::UpdateExternalPolicyExtensionProvider() { 1441 void ExtensionsService::UpdateExternalPolicyExtensionProvider() {
1447 const ListValue* list_pref = 1442 const ListValue* list_pref =
1448 profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList); 1443 profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList);
1449 ListValue* list_copy = NULL; 1444 ListValue* list_copy = NULL;
1450 if (list_pref) 1445 if (list_pref)
1451 list_copy = static_cast<ListValue*>(list_pref->DeepCopy()); 1446 list_copy = static_cast<ListValue*>(list_pref->DeepCopy());
1452 BrowserThread::PostTask( 1447 BrowserThread::PostTask(
1453 BrowserThread::FILE, FROM_HERE, 1448 BrowserThread::FILE, FROM_HERE,
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 backend_.get(), &ExtensionsServiceBackend::AddProviderForTesting, 1920 backend_.get(), &ExtensionsServiceBackend::AddProviderForTesting,
1926 test_provider)); 1921 test_provider));
1927 } 1922 }
1928 1923
1929 void ExtensionsService::OnExternalExtensionFileFound( 1924 void ExtensionsService::OnExternalExtensionFileFound(
1930 const std::string& id, 1925 const std::string& id,
1931 const std::string& version, 1926 const std::string& version,
1932 const FilePath& path, 1927 const FilePath& path,
1933 Extension::Location location) { 1928 Extension::Location location) {
1934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1930 if (extension_prefs_->IsExtensionKilled(id))
1931 return;
1935 1932
1936 // Before even bothering to unpack, check and see if we already have this 1933 // Before even bothering to unpack, check and see if we already have this
1937 // version. This is important because these extensions are going to get 1934 // version. This is important because these extensions are going to get
1938 // installed on every startup. 1935 // installed on every startup.
1939 const Extension* existing = GetExtensionById(id, true); 1936 const Extension* existing = GetExtensionById(id, true);
1940 scoped_ptr<Version> other(Version::GetVersionFromString(version)); 1937 scoped_ptr<Version> other(Version::GetVersionFromString(version));
1941 if (existing) { 1938 if (existing) {
1942 switch (existing->version()->CompareTo(*other)) { 1939 switch (existing->version()->CompareTo(*other)) {
1943 case -1: // existing version is older, we should upgrade 1940 case -1: // existing version is older, we should upgrade
1944 break; 1941 break;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 } 2080 }
2084 2081
2085 void ExtensionsService::SetBeingUpgraded(const Extension* extension, 2082 void ExtensionsService::SetBeingUpgraded(const Extension* extension,
2086 bool value) { 2083 bool value) {
2087 extension_runtime_data_[extension->id()].being_upgraded = value; 2084 extension_runtime_data_[extension->id()].being_upgraded = value;
2088 } 2085 }
2089 2086
2090 PropertyBag* ExtensionsService::GetPropertyBag(const Extension* extension) { 2087 PropertyBag* ExtensionsService::GetPropertyBag(const Extension* extension) {
2091 return &extension_runtime_data_[extension->id()].property_bag; 2088 return &extension_runtime_data_[extension->id()].property_bag;
2092 } 2089 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.h ('k') | chrome/browser/extensions/extensions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698