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

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

Issue 9706017: Remove Ordinals Setters and Getters from ExtensionService (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 this, profile_, &external_extension_providers_); 438 this, profile_, &external_extension_providers_);
439 } 439 }
440 } 440 }
441 441
442 // Use monochrome icons for Omnibox icons. 442 // Use monochrome icons for Omnibox icons.
443 omnibox_popup_icon_manager_.set_monochrome(true); 443 omnibox_popup_icon_manager_.set_monochrome(true);
444 omnibox_icon_manager_.set_monochrome(true); 444 omnibox_icon_manager_.set_monochrome(true);
445 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, 445 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft,
446 0, kOmniboxIconPaddingRight)); 446 0, kOmniboxIconPaddingRight));
447 447
448 // Set this as the ExtensionService for extension sorting to ensure it
449 // cause syncs if required.
450 extension_prefs_->extension_sorting()->SetExtensionService(this);
451
448 // How long is the path to the Extensions directory? 452 // How long is the path to the Extensions directory?
449 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", 453 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
450 install_directory_.value().length(), 0, 500, 100); 454 install_directory_.value().length(), 0, 500, 100);
451 } 455 }
452 456
453 const ExtensionSet* ExtensionService::extensions() const { 457 const ExtensionSet* ExtensionService::extensions() const {
454 return &extensions_; 458 return &extensions_;
455 } 459 }
456 460
457 const ExtensionSet* ExtensionService::disabled_extensions() const { 461 const ExtensionSet* ExtensionService::disabled_extensions() const {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); 771 SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension);
768 772
769 SyncChange sync_change; 773 SyncChange sync_change;
770 if (sync_bundle) { 774 if (sync_bundle) {
771 ExtensionSyncData extension_sync_data( 775 ExtensionSyncData extension_sync_data(
772 *extension, 776 *extension,
773 IsExtensionEnabled(extension_id), 777 IsExtensionEnabled(extension_id),
774 IsIncognitoEnabled(extension_id), 778 IsIncognitoEnabled(extension_id),
775 extension_prefs_->GetAppNotificationClientId(extension_id), 779 extension_prefs_->GetAppNotificationClientId(extension_id),
776 extension_prefs_->IsAppNotificationDisabled(extension_id), 780 extension_prefs_->IsAppNotificationDisabled(extension_id),
777 GetAppLaunchOrdinal(extension_id), 781 extension_prefs_->extension_sorting()->
778 GetPageOrdinal(extension_id)); 782 GetAppLaunchOrdinal(extension_id),
783 extension_prefs_->extension_sorting()->GetPageOrdinal(extension_id));
779 sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); 784 sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE);
780 } 785 }
781 786
782 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", 787 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
783 extension->GetType(), 100); 788 extension->GetType(), 100);
784 RecordPermissionMessagesHistogram( 789 RecordPermissionMessagesHistogram(
785 extension, "Extensions.Permissions_Uninstall"); 790 extension, "Extensions.Permissions_Uninstall");
786 791
787 TemplateURLService* url_service = 792 TemplateURLService* url_service =
788 TemplateURLServiceFactory::GetForProfile(profile_); 793 TemplateURLServiceFactory::GetForProfile(profile_);
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 1272
1268 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { 1273 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const {
1269 return synced_extensions.find(id) != synced_extensions.end(); 1274 return synced_extensions.find(id) != synced_extensions.end();
1270 } 1275 }
1271 1276
1272 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) 1277 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id)
1273 const { 1278 const {
1274 return pending_sync_data.find(id) != pending_sync_data.end(); 1279 return pending_sync_data.find(id) != pending_sync_data.end();
1275 } 1280 }
1276 1281
1277 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
1278 SyncBundle* sync_bundle = GetSyncBundleForExtension(extension);
1279 if (sync_bundle) {
1280 ExtensionSyncData extension_sync_data(
1281 extension,
1282 IsExtensionEnabled(extension.id()),
1283 IsIncognitoEnabled(extension.id()),
1284 extension_prefs_->GetAppNotificationClientId(extension.id()),
1285 extension_prefs_->IsAppNotificationDisabled(extension.id()),
1286 GetAppLaunchOrdinal(extension.id()),
1287 GetPageOrdinal(extension.id()));
1288
1289 SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange(
1290 sync_bundle->HasExtensionId(extension.id()) ?
1291 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD));
1292 sync_bundle->sync_processor->ProcessSyncChanges(
1293 FROM_HERE, sync_change_list);
1294 sync_bundle->synced_extensions.insert(extension.id());
1295 sync_bundle->pending_sync_data.erase(extension.id());
1296 }
1297 }
1298
1299 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension( 1282 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension(
1300 const Extension& extension) { 1283 const Extension& extension) {
1301 if (app_sync_bundle_.filter(extension)) 1284 if (app_sync_bundle_.filter(extension))
1302 return &app_sync_bundle_; 1285 return &app_sync_bundle_;
1303 else if (extension_sync_bundle_.filter(extension)) 1286 else if (extension_sync_bundle_.filter(extension))
1304 return &extension_sync_bundle_; 1287 return &extension_sync_bundle_;
1305 else 1288 else
1306 return NULL; 1289 return NULL;
1307 } 1290 }
1308 1291
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 // If we have pending extension data for this extension, then this 1436 // If we have pending extension data for this extension, then this
1454 // version is out of date. We'll sync back the version we got from 1437 // version is out of date. We'll sync back the version we got from
1455 // sync. 1438 // sync.
1456 !bundle.HasPendingExtensionId(extension.id())) { 1439 !bundle.HasPendingExtensionId(extension.id())) {
1457 sync_data_list->push_back(ExtensionSyncData( 1440 sync_data_list->push_back(ExtensionSyncData(
1458 extension, 1441 extension,
1459 IsExtensionEnabled(extension.id()), 1442 IsExtensionEnabled(extension.id()),
1460 IsIncognitoEnabled(extension.id()), 1443 IsIncognitoEnabled(extension.id()),
1461 extension_prefs_->GetAppNotificationClientId(extension.id()), 1444 extension_prefs_->GetAppNotificationClientId(extension.id()),
1462 extension_prefs_->IsAppNotificationDisabled(extension.id()), 1445 extension_prefs_->IsAppNotificationDisabled(extension.id()),
1463 GetAppLaunchOrdinal(extension.id()), 1446 extension_prefs_->extension_sorting()->
1464 GetPageOrdinal(extension.id()))); 1447 GetAppLaunchOrdinal(extension.id()),
1448 extension_prefs_->extension_sorting()->
1449 GetPageOrdinal(extension.id())));
1465 } 1450 }
1466 } 1451 }
1467 } 1452 }
1468 1453
1469 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( 1454 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList(
1470 const SyncBundle& bundle) const { 1455 const SyncBundle& bundle) const {
1471 std::vector<ExtensionSyncData> extension_sync_list; 1456 std::vector<ExtensionSyncData> extension_sync_list;
1472 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); 1457 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list);
1473 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); 1458 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list);
1474 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); 1459 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 // incognito flag invalidates the |extension| pointer (it reloads the 1501 // incognito flag invalidates the |extension| pointer (it reloads the
1517 // extension). 1502 // extension).
1518 bool extension_installed = (extension != NULL); 1503 bool extension_installed = (extension != NULL);
1519 int result = extension ? 1504 int result = extension ?
1520 extension->version()->CompareTo(extension_sync_data.version()) : 0; 1505 extension->version()->CompareTo(extension_sync_data.version()) : 0;
1521 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); 1506 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
1522 extension = NULL; // No longer safe to use. 1507 extension = NULL; // No longer safe to use.
1523 1508
1524 if (extension_sync_data.app_launch_ordinal().IsValid() && 1509 if (extension_sync_data.app_launch_ordinal().IsValid() &&
1525 extension_sync_data.page_ordinal().IsValid()) { 1510 extension_sync_data.page_ordinal().IsValid()) {
1526 SetAppLaunchOrdinal(id, extension_sync_data.app_launch_ordinal()); 1511 extension_prefs_->extension_sorting()->SetAppLaunchOrdinal(
1527 SetPageOrdinal(id, extension_sync_data.page_ordinal()); 1512 id,
1513 extension_sync_data.app_launch_ordinal());
1514 extension_prefs_->extension_sorting()->SetPageOrdinal(
1515 id,
1516 extension_sync_data.page_ordinal());
1528 } 1517 }
1529 1518
1530 if (extension_installed) { 1519 if (extension_installed) {
1531 // If the extension is already installed, check if it's outdated. 1520 // If the extension is already installed, check if it's outdated.
1532 if (result < 0) { 1521 if (result < 0) {
1533 // Extension is outdated. 1522 // Extension is outdated.
1534 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; 1523 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data;
1535 CheckForUpdatesSoon(); 1524 CheckForUpdatesSoon();
1536 } 1525 }
1537 if (extension_sync_data.type() == Extension::SYNC_TYPE_APP && 1526 if (extension_sync_data.type() == Extension::SYNC_TYPE_APP &&
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 1642
1654 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { 1643 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
1655 if (extension->is_hosted_app()) 1644 if (extension->is_hosted_app())
1656 return true; 1645 return true;
1657 // Packaged apps and regular extensions need to be enabled specifically for 1646 // Packaged apps and regular extensions need to be enabled specifically for
1658 // incognito (and split mode should be set). 1647 // incognito (and split mode should be set).
1659 return extension->incognito_split_mode() && 1648 return extension->incognito_split_mode() &&
1660 IsIncognitoEnabled(extension->id()); 1649 IsIncognitoEnabled(extension->id());
1661 } 1650 }
1662 1651
1663 StringOrdinal ExtensionService::GetAppLaunchOrdinal(
1664 const std::string& extension_id) const {
1665 return
1666 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(extension_id);
1667 }
1668
1669 void ExtensionService::SetAppLaunchOrdinal(
1670 const std::string& extension_id,
1671 const StringOrdinal& app_launch_ordinal) {
1672 // Only apps should set this value, so we check that it is either an app or
1673 // that it is not yet installed (so we can't be sure it is an app). It is
1674 // possible to be setting this value through syncing before the app is
1675 // installed.
1676 const Extension* ext = GetExtensionById(extension_id, true);
1677 DCHECK(!ext || ext->is_app());
1678
1679 extension_prefs_->extension_sorting()->SetAppLaunchOrdinal(
1680 extension_id, app_launch_ordinal);
1681
1682 const Extension* extension = GetInstalledExtension(extension_id);
1683 if (extension)
1684 SyncExtensionChangeIfNeeded(*extension);
1685 }
1686
1687 StringOrdinal ExtensionService::GetPageOrdinal(
1688 const std::string& extension_id) const {
1689 return extension_prefs_->extension_sorting()->GetPageOrdinal(extension_id);
1690 }
1691
1692 void ExtensionService::SetPageOrdinal(const std::string& extension_id,
1693 const StringOrdinal& page_ordinal) {
1694 // Only apps should set this value, so we check that it is either an app or
1695 // that it is not yet installed (so we can't be sure it is an app). It is
1696 // possible to be setting this value through syncing before the app is
1697 // installed.
1698 const Extension* ext = GetExtensionById(extension_id, true);
1699 DCHECK(!ext || ext->is_app());
1700
1701 extension_prefs_->extension_sorting()->SetPageOrdinal(
1702 extension_id, page_ordinal);
1703
1704 const Extension* extension = GetInstalledExtension(extension_id);
1705 if (extension)
1706 SyncExtensionChangeIfNeeded(*extension);
1707 }
1708
1709 void ExtensionService::OnExtensionMoved( 1652 void ExtensionService::OnExtensionMoved(
1710 const std::string& moved_extension_id, 1653 const std::string& moved_extension_id,
1711 const std::string& predecessor_extension_id, 1654 const std::string& predecessor_extension_id,
1712 const std::string& successor_extension_id) { 1655 const std::string& successor_extension_id) {
1713 extension_prefs_->extension_sorting()->OnExtensionMoved( 1656 extension_prefs_->extension_sorting()->OnExtensionMoved(
1714 moved_extension_id, 1657 moved_extension_id,
1715 predecessor_extension_id, 1658 predecessor_extension_id,
1716 successor_extension_id); 1659 successor_extension_id);
1717 1660
1718 const Extension* extension = GetInstalledExtension(moved_extension_id); 1661 const Extension* extension = GetInstalledExtension(moved_extension_id);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 NOTREACHED(); 1947 NOTREACHED();
2005 1948
2006 // Also garbage-collect themes. We check |profile_| to be 1949 // Also garbage-collect themes. We check |profile_| to be
2007 // defensive; in the future, we may call GarbageCollectExtensions() 1950 // defensive; in the future, we may call GarbageCollectExtensions()
2008 // from somewhere other than Init() (e.g., in a timer). 1951 // from somewhere other than Init() (e.g., in a timer).
2009 if (profile_) { 1952 if (profile_) {
2010 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes(); 1953 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
2011 } 1954 }
2012 } 1955 }
2013 1956
1957 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
1958 SyncBundle* sync_bundle = GetSyncBundleForExtension(extension);
1959 if (sync_bundle) {
1960 ExtensionSyncData extension_sync_data(
1961 extension,
1962 IsExtensionEnabled(extension.id()),
1963 IsIncognitoEnabled(extension.id()),
1964 extension_prefs_->GetAppNotificationClientId(extension.id()),
1965 extension_prefs_->IsAppNotificationDisabled(extension.id()),
1966 extension_prefs_->extension_sorting()->
1967 GetAppLaunchOrdinal(extension.id()),
1968 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
1969
1970 SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange(
1971 sync_bundle->HasExtensionId(extension.id()) ?
1972 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD));
1973 sync_bundle->sync_processor->ProcessSyncChanges(
1974 FROM_HERE, sync_change_list);
1975 sync_bundle->synced_extensions.insert(extension.id());
1976 sync_bundle->pending_sync_data.erase(extension.id());
1977 }
1978 }
1979
2014 void ExtensionService::OnLoadedInstalledExtensions() { 1980 void ExtensionService::OnLoadedInstalledExtensions() {
2015 if (updater_.get()) { 1981 if (updater_.get()) {
2016 updater_->Start(); 1982 updater_->Start();
2017 } 1983 }
2018 1984
2019 ready_ = true; 1985 ready_ = true;
2020 content::NotificationService::current()->Notify( 1986 content::NotificationService::current()->Notify(
2021 chrome::NOTIFICATION_EXTENSIONS_READY, 1987 chrome::NOTIFICATION_EXTENSIONS_READY,
2022 content::Source<Profile>(profile_), 1988 content::Source<Profile>(profile_),
2023 content::NotificationService::NoDetails()); 1989 content::NotificationService::NoDetails());
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
2668 return api_resource_controller_; 2634 return api_resource_controller_;
2669 } 2635 }
2670 2636
2671 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { 2637 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() {
2672 if (!rules_registry_service_.get()) { 2638 if (!rules_registry_service_.get()) {
2673 rules_registry_service_.reset( 2639 rules_registry_service_.reset(
2674 new extensions::RulesRegistryService(profile_)); 2640 new extensions::RulesRegistryService(profile_));
2675 } 2641 }
2676 return rules_registry_service_.get(); 2642 return rules_registry_service_.get();
2677 } 2643 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698