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

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

Issue 1240573012: Extension syncing: Introduce a NeedsSync pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext_sync_uninstall
Patch Set: (b); hackfix sync_integration_tests Created 5 years, 5 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/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 10
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 extensions::ExtensionPrefs* extension_prefs, 271 extensions::ExtensionPrefs* extension_prefs,
272 extensions::Blacklist* blacklist, 272 extensions::Blacklist* blacklist,
273 bool autoupdate_enabled, 273 bool autoupdate_enabled,
274 bool extensions_enabled, 274 bool extensions_enabled,
275 extensions::OneShotEvent* ready) 275 extensions::OneShotEvent* ready)
276 : extensions::Blacklist::Observer(blacklist), 276 : extensions::Blacklist::Observer(blacklist),
277 profile_(profile), 277 profile_(profile),
278 system_(extensions::ExtensionSystem::Get(profile)), 278 system_(extensions::ExtensionSystem::Get(profile)),
279 extension_prefs_(extension_prefs), 279 extension_prefs_(extension_prefs),
280 blacklist_(blacklist), 280 blacklist_(blacklist),
281 extension_sync_service_(NULL),
282 registry_(extensions::ExtensionRegistry::Get(profile)), 281 registry_(extensions::ExtensionRegistry::Get(profile)),
283 pending_extension_manager_(profile), 282 pending_extension_manager_(profile),
284 install_directory_(install_directory), 283 install_directory_(install_directory),
285 extensions_enabled_(extensions_enabled), 284 extensions_enabled_(extensions_enabled),
286 show_extensions_prompts_(true), 285 show_extensions_prompts_(true),
287 install_updates_when_idle_(true), 286 install_updates_when_idle_(true),
288 ready_(ready), 287 ready_(ready),
289 update_once_all_providers_are_ready_(false), 288 update_once_all_providers_are_ready_(false),
290 browser_terminating_(false), 289 browser_terminating_(false),
291 installs_delayed_for_gc_(false), 290 installs_delayed_for_gc_(false),
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 profile_, extension.get(), deletion_done_callback); 768 profile_, extension.get(), deletion_done_callback);
770 769
771 UntrackTerminatedExtension(extension->id()); 770 UntrackTerminatedExtension(extension->id());
772 771
773 // Notify interested parties that we've uninstalled this extension. 772 // Notify interested parties that we've uninstalled this extension.
774 ExtensionRegistry::Get(profile_) 773 ExtensionRegistry::Get(profile_)
775 ->TriggerOnUninstalled(extension.get(), reason); 774 ->TriggerOnUninstalled(extension.get(), reason);
776 775
777 // Don't sync the uninstall if we're going to reinstall the extension 776 // Don't sync the uninstall if we're going to reinstall the extension
778 // momentarily. 777 // momentarily.
779 if (extension_sync_service_ && 778 if (reason != extensions::UNINSTALL_REASON_REINSTALL) {
780 reason != extensions::UNINSTALL_REASON_REINSTALL) { 779 ExtensionSyncService::Get(profile_)->SyncUninstallExtension(*extension);
781 extension_sync_service_->SyncUninstallExtension(*extension);
782 } 780 }
783 781
784 delayed_installs_.Remove(extension->id()); 782 delayed_installs_.Remove(extension->id());
785 783
786 extension_prefs_->OnExtensionUninstalled( 784 extension_prefs_->OnExtensionUninstalled(
787 extension->id(), extension->location(), external_uninstall); 785 extension->id(), extension->location(), external_uninstall);
788 786
789 // Track the uninstallation. 787 // Track the uninstallation.
790 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); 788 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
791 789
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 registry_->RemoveDisabled(extension->id()); 857 registry_->RemoveDisabled(extension->id());
860 858
861 NotifyExtensionLoaded(extension); 859 NotifyExtensionLoaded(extension);
862 860
863 // Notify listeners that the extension was enabled. 861 // Notify listeners that the extension was enabled.
864 content::NotificationService::current()->Notify( 862 content::NotificationService::current()->Notify(
865 extensions::NOTIFICATION_EXTENSION_ENABLED, 863 extensions::NOTIFICATION_EXTENSION_ENABLED,
866 content::Source<Profile>(profile_), 864 content::Source<Profile>(profile_),
867 content::Details<const Extension>(extension)); 865 content::Details<const Extension>(extension));
868 866
869 if (extension_sync_service_) 867 ExtensionSyncService::Get(profile_)->SyncExtensionChangeIfNeeded(*extension);
870 extension_sync_service_->SyncEnableExtension(*extension);
871 } 868 }
872 869
873 void ExtensionService::DisableExtension(const std::string& extension_id, 870 void ExtensionService::DisableExtension(const std::string& extension_id,
874 int disable_reasons) { 871 int disable_reasons) {
875 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 872 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
876 873
877 // The extension may have been disabled already. Just add a disable reason. 874 // The extension may have been disabled already. Just add a disable reason.
878 if (!IsExtensionEnabled(extension_id)) { 875 if (!IsExtensionEnabled(extension_id)) {
879 extension_prefs_->AddDisableReasons(extension_id, disable_reasons); 876 extension_prefs_->AddDisableReasons(extension_id, disable_reasons);
880 return; 877 return;
(...skipping 29 matching lines...) Expand all
910 // Move it over to the disabled list. Don't send a second unload notification 907 // Move it over to the disabled list. Don't send a second unload notification
911 // for terminated extensions being disabled. 908 // for terminated extensions being disabled.
912 registry_->AddDisabled(make_scoped_refptr(extension)); 909 registry_->AddDisabled(make_scoped_refptr(extension));
913 if (registry_->enabled_extensions().Contains(extension->id())) { 910 if (registry_->enabled_extensions().Contains(extension->id())) {
914 registry_->RemoveEnabled(extension->id()); 911 registry_->RemoveEnabled(extension->id());
915 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); 912 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
916 } else { 913 } else {
917 registry_->RemoveTerminated(extension->id()); 914 registry_->RemoveTerminated(extension->id());
918 } 915 }
919 916
920 if (extension_sync_service_) 917 ExtensionSyncService::Get(profile_)->SyncExtensionChangeIfNeeded(*extension);
921 extension_sync_service_->SyncDisableExtension(*extension);
922 } 918 }
923 919
924 void ExtensionService::DisableUserExtensions( 920 void ExtensionService::DisableUserExtensions(
925 const std::vector<std::string>& except_ids) { 921 const std::vector<std::string>& except_ids) {
926 extensions::ManagementPolicy* management_policy = 922 extensions::ManagementPolicy* management_policy =
927 system_->management_policy(); 923 system_->management_policy();
928 extensions::ExtensionList to_disable; 924 extensions::ExtensionList to_disable;
929 925
930 const ExtensionSet& enabled_set = registry_->enabled_extensions(); 926 const ExtensionSet& enabled_set = registry_->enabled_extensions();
931 for (ExtensionSet::const_iterator extension = enabled_set.begin(); 927 for (ExtensionSet::const_iterator extension = enabled_set.begin();
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 // Only prefs is checked for the blacklist. We rely on callers to check the 1499 // Only prefs is checked for the blacklist. We rely on callers to check the
1504 // blacklist before calling into here, e.g. CrxInstaller checks before 1500 // blacklist before calling into here, e.g. CrxInstaller checks before
1505 // installation then threads through the install and pending install flow 1501 // installation then threads through the install and pending install flow
1506 // of this class, and we check when loading installed extensions. 1502 // of this class, and we check when loading installed extensions.
1507 registry_->AddBlacklisted(extension); 1503 registry_->AddBlacklisted(extension);
1508 } else if (block_extensions_ && CanBlockExtension(extension)) { 1504 } else if (block_extensions_ && CanBlockExtension(extension)) {
1509 registry_->AddBlocked(extension); 1505 registry_->AddBlocked(extension);
1510 } else if (!reloading && 1506 } else if (!reloading &&
1511 extension_prefs_->IsExtensionDisabled(extension->id())) { 1507 extension_prefs_->IsExtensionDisabled(extension->id())) {
1512 registry_->AddDisabled(extension); 1508 registry_->AddDisabled(extension);
1513 if (extension_sync_service_) 1509 ExtensionSyncService::Get(profile_)->SyncExtensionChangeIfNeeded(
1514 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); 1510 *extension);
1515 content::NotificationService::current()->Notify( 1511 content::NotificationService::current()->Notify(
1516 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 1512 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1517 content::Source<Profile>(profile_), 1513 content::Source<Profile>(profile_),
1518 content::Details<const Extension>(extension)); 1514 content::Details<const Extension>(extension));
1519 1515
1520 // Show the extension disabled error if a permissions increase or a remote 1516 // Show the extension disabled error if a permissions increase or a remote
1521 // installation is the reason it was disabled, and no other reasons exist. 1517 // installation is the reason it was disabled, and no other reasons exist.
1522 int reasons = extension_prefs_->GetDisableReasons(extension->id()); 1518 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1523 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE | 1519 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1524 Extension::DISABLE_REMOTE_INSTALL; 1520 Extension::DISABLE_REMOTE_INSTALL;
(...skipping 16 matching lines...) Expand all
1541 extension->id(), 1537 extension->id(),
1542 extension->ShouldDisplayInNewTabPage() && 1538 extension->ShouldDisplayInNewTabPage() &&
1543 !extension_prefs_->IsEphemeralApp(extension->id())); 1539 !extension_prefs_->IsEphemeralApp(extension->id()));
1544 if (!extension_prefs_->IsEphemeralApp(extension->id())) { 1540 if (!extension_prefs_->IsEphemeralApp(extension->id())) {
1545 extension_prefs_->app_sorting()->EnsureValidOrdinals( 1541 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1546 extension->id(), syncer::StringOrdinal()); 1542 extension->id(), syncer::StringOrdinal());
1547 } 1543 }
1548 } 1544 }
1549 1545
1550 registry_->AddEnabled(extension); 1546 registry_->AddEnabled(extension);
1551 if (extension_sync_service_) 1547 ExtensionSyncService::Get(profile_)->SyncExtensionChangeIfNeeded(
1552 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); 1548 *extension);
1553 NotifyExtensionLoaded(extension); 1549 NotifyExtensionLoaded(extension);
1554 } 1550 }
1555 system_->runtime_data()->SetBeingUpgraded(extension->id(), false); 1551 system_->runtime_data()->SetBeingUpgraded(extension->id(), false);
1556 } 1552 }
1557 1553
1558 void ExtensionService::AddComponentExtension(const Extension* extension) { 1554 void ExtensionService::AddComponentExtension(const Extension* extension) {
1559 const std::string old_version_string( 1555 const std::string old_version_string(
1560 extension_prefs_->GetVersionString(extension->id())); 1556 extension_prefs_->GetVersionString(extension->id()));
1561 const Version old_version(old_version_string); 1557 const Version old_version(old_version_string);
1562 1558
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 if (!other_disable_reasons) { 2051 if (!other_disable_reasons) {
2056 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) 2052 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
2057 GrantPermissionsAndEnableExtension(extension); 2053 GrantPermissionsAndEnableExtension(extension);
2058 else 2054 else
2059 EnableExtension(extension->id()); 2055 EnableExtension(extension->id());
2060 } 2056 }
2061 } 2057 }
2062 2058
2063 registry_->TriggerOnInstalled(extension, true); 2059 registry_->TriggerOnInstalled(extension, true);
2064 2060
2065 if (!is_from_sync && extension_sync_service_) 2061 if (!is_from_sync) {
2066 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); 2062 ExtensionSyncService::Get(profile_)->SyncExtensionChangeIfNeeded(
2063 *extension);
2064 }
2067 } 2065 }
2068 2066
2069 const Extension* ExtensionService::GetPendingExtensionUpdate( 2067 const Extension* ExtensionService::GetPendingExtensionUpdate(
2070 const std::string& id) const { 2068 const std::string& id) const {
2071 return delayed_installs_.GetByID(id); 2069 return delayed_installs_.GetByID(id);
2072 } 2070 }
2073 2071
2074 void ExtensionService::RegisterContentSettings( 2072 void ExtensionService::RegisterContentSettings(
2075 HostContentSettingsMap* host_content_settings_map) { 2073 HostContentSettingsMap* host_content_settings_map) {
2076 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings"); 2074 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
2578 } 2576 }
2579 2577
2580 void ExtensionService::OnProfileDestructionStarted() { 2578 void ExtensionService::OnProfileDestructionStarted() {
2581 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2579 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2582 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2580 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2583 it != ids_to_unload.end(); 2581 it != ids_to_unload.end();
2584 ++it) { 2582 ++it) {
2585 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2583 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2586 } 2584 }
2587 } 2585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698