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

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

Issue 7564037: Apps/Extensions Sync refactoring -- delete most of the old glue, implement new sync API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "chrome/browser/extensions/extension_web_ui.h" 46 #include "chrome/browser/extensions/extension_web_ui.h"
47 #include "chrome/browser/extensions/extension_webnavigation_api.h" 47 #include "chrome/browser/extensions/extension_webnavigation_api.h"
48 #include "chrome/browser/extensions/external_extension_provider_impl.h" 48 #include "chrome/browser/extensions/external_extension_provider_impl.h"
49 #include "chrome/browser/extensions/external_extension_provider_interface.h" 49 #include "chrome/browser/extensions/external_extension_provider_interface.h"
50 #include "chrome/browser/extensions/pending_extension_manager.h" 50 #include "chrome/browser/extensions/pending_extension_manager.h"
51 #include "chrome/browser/net/chrome_url_request_context.h" 51 #include "chrome/browser/net/chrome_url_request_context.h"
52 #include "chrome/browser/prefs/pref_service.h" 52 #include "chrome/browser/prefs/pref_service.h"
53 #include "chrome/browser/profiles/profile.h" 53 #include "chrome/browser/profiles/profile.h"
54 #include "chrome/browser/search_engines/template_url_service.h" 54 #include "chrome/browser/search_engines/template_url_service.h"
55 #include "chrome/browser/search_engines/template_url_service_factory.h" 55 #include "chrome/browser/search_engines/template_url_service_factory.h"
56 #include "chrome/browser/sync/api/sync_change.h"
56 #include "chrome/browser/themes/theme_service.h" 57 #include "chrome/browser/themes/theme_service.h"
57 #include "chrome/browser/themes/theme_service_factory.h" 58 #include "chrome/browser/themes/theme_service_factory.h"
58 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 59 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
59 #include "chrome/browser/ui/webui/favicon_source.h" 60 #include "chrome/browser/ui/webui/favicon_source.h"
60 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" 61 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
61 #include "chrome/common/child_process_logging.h" 62 #include "chrome/common/child_process_logging.h"
62 #include "chrome/common/chrome_notification_types.h" 63 #include "chrome/common/chrome_notification_types.h"
63 #include "chrome/common/chrome_paths.h" 64 #include "chrome/common/chrome_paths.h"
64 #include "chrome/common/chrome_switches.h" 65 #include "chrome/common/chrome_switches.h"
65 #include "chrome/common/extensions/extension.h" 66 #include "chrome/common/extensions/extension.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return NOT_NEEDED; 145 return NOT_NEEDED;
145 } 146 }
146 147
147 static void ForceShutdownPlugin(const FilePath& plugin_path) { 148 static void ForceShutdownPlugin(const FilePath& plugin_path) {
148 PluginProcessHost* plugin = 149 PluginProcessHost* plugin =
149 PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path); 150 PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path);
150 if (plugin) 151 if (plugin)
151 plugin->ForceShutdown(); 152 plugin->ForceShutdown();
152 } 153 }
153 154
155 static bool IsSyncableExtension(const Extension& extension) {
156 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION;
157 }
158
159 static bool IsSyncableApp(const Extension& extension) {
160 return extension.GetSyncType() == Extension::SYNC_TYPE_APP;
161 }
162
154 // Manages an ExtensionInstallUI for a particular extension. 163 // Manages an ExtensionInstallUI for a particular extension.
155 class SimpleExtensionLoadPrompt : public ExtensionInstallUI::Delegate { 164 class SimpleExtensionLoadPrompt : public ExtensionInstallUI::Delegate {
156 public: 165 public:
157 SimpleExtensionLoadPrompt(Profile* profile, 166 SimpleExtensionLoadPrompt(Profile* profile,
158 base::WeakPtr<ExtensionService> extension_service, 167 base::WeakPtr<ExtensionService> extension_service,
159 const Extension* extension); 168 const Extension* extension);
160 ~SimpleExtensionLoadPrompt(); 169 ~SimpleExtensionLoadPrompt();
161 170
162 void ShowPrompt(); 171 void ShowPrompt();
163 172
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 const Extension* ExtensionService::GetInstalledAppForRenderer( 519 const Extension* ExtensionService::GetInstalledAppForRenderer(
511 int renderer_child_id) { 520 int renderer_child_id) {
512 InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id); 521 InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id);
513 if (i == installed_app_hosts_.end()) 522 if (i == installed_app_hosts_.end())
514 return NULL; 523 return NULL;
515 return i->second; 524 return i->second;
516 } 525 }
517 526
518 // static 527 // static
519 // This function is used to implement the command-line switch 528 // This function is used to implement the command-line switch
520 // --uninstall-extension. The LOG statements within this function are used to 529 // --uninstall-extension, and to uninstall an extension via sync. The LOG
521 // inform the user if the uninstall cannot be done. 530 // statements within this function are used to inform the user if the uninstall
531 // cannot be done.
522 bool ExtensionService::UninstallExtensionHelper( 532 bool ExtensionService::UninstallExtensionHelper(
523 ExtensionService* extensions_service, 533 ExtensionService* extensions_service,
524 const std::string& extension_id) { 534 const std::string& extension_id) {
525 535
526 const Extension* extension = 536 const Extension* extension =
527 extensions_service->GetInstalledExtension(extension_id); 537 extensions_service->GetInstalledExtension(extension_id);
528 538
529 // We can't call UninstallExtension with an invalid extension ID. 539 // We can't call UninstallExtension with an invalid extension ID.
530 if (!extension) { 540 if (!extension) {
531 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " 541 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 NotificationService::current()->Notify( 858 NotificationService::current()->Notify(
849 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, 859 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
850 Source<Profile>(profile_), 860 Source<Profile>(profile_),
851 Details<const Extension>(extension)); 861 Details<const Extension>(extension));
852 if (error != NULL) { 862 if (error != NULL) {
853 *error = errors::kCannotUninstallManagedExtension; 863 *error = errors::kCannotUninstallManagedExtension;
854 } 864 }
855 return false; 865 return false;
856 } 866 }
857 867
868 // Extract the data we need for sync now, but don't actually sync until we've
869 // completed the uninstallation.
870 SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension);
871
872 SyncChange sync_change;
873 if (sync_bundle) {
874 ExtensionSyncData extension_sync_data(*extension,
875 IsExtensionEnabled(extension_id),
876 IsIncognitoEnabled(extension_id));
877 sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE);
878 }
879
858 UninstalledExtensionInfo uninstalled_extension_info(*extension); 880 UninstalledExtensionInfo uninstalled_extension_info(*extension);
859 881
860 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", 882 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
861 extension->GetType(), 100); 883 extension->GetType(), 100);
862 RecordPermissionMessagesHistogram( 884 RecordPermissionMessagesHistogram(
863 extension, "Extensions.Permissions_Uninstall"); 885 extension, "Extensions.Permissions_Uninstall");
864 886
865 TemplateURLService* url_service = 887 TemplateURLService* url_service =
866 TemplateURLServiceFactory::GetForProfile(profile_); 888 TemplateURLServiceFactory::GetForProfile(profile_);
867 if (url_service) 889 if (url_service)
(...skipping 19 matching lines...) Expand all
887 909
888 ClearExtensionData(extension_url); 910 ClearExtensionData(extension_url);
889 UntrackTerminatedExtension(extension_id); 911 UntrackTerminatedExtension(extension_id);
890 912
891 // Notify interested parties that we've uninstalled this extension. 913 // Notify interested parties that we've uninstalled this extension.
892 NotificationService::current()->Notify( 914 NotificationService::current()->Notify(
893 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 915 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
894 Source<Profile>(profile_), 916 Source<Profile>(profile_),
895 Details<UninstalledExtensionInfo>(&uninstalled_extension_info)); 917 Details<UninstalledExtensionInfo>(&uninstalled_extension_info));
896 918
919 if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) {
920 SyncChangeList sync_change_list(1);
921 sync_change_list[0] = sync_change;
922 sync_bundle->sync_processor->ProcessSyncChanges(
923 FROM_HERE, sync_change_list);
924 sync_bundle->synced_extensions.erase(extension_id);
925 }
926
897 return true; 927 return true;
898 } 928 }
899 929
900 void ExtensionService::ClearExtensionData(const GURL& extension_url) { 930 void ExtensionService::ClearExtensionData(const GURL& extension_url) {
901 scoped_refptr<ExtensionDataDeleter> deleter( 931 scoped_refptr<ExtensionDataDeleter> deleter(
902 new ExtensionDataDeleter(profile_, extension_url)); 932 new ExtensionDataDeleter(profile_, extension_url));
903 deleter->StartDeleting(); 933 deleter->StartDeleting();
904 } 934 }
905 935
906 bool ExtensionService::IsExtensionEnabled( 936 bool ExtensionService::IsExtensionEnabled(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 extensions_.push_back(make_scoped_refptr(extension)); 975 extensions_.push_back(make_scoped_refptr(extension));
946 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), 976 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
947 disabled_extensions_.end(), 977 disabled_extensions_.end(),
948 extension); 978 extension);
949 disabled_extensions_.erase(iter); 979 disabled_extensions_.erase(iter);
950 980
951 // Make sure any browser action contained within it is not hidden. 981 // Make sure any browser action contained within it is not hidden.
952 extension_prefs_->SetBrowserActionVisibility(extension, true); 982 extension_prefs_->SetBrowserActionVisibility(extension, true);
953 983
954 NotifyExtensionLoaded(extension); 984 NotifyExtensionLoaded(extension);
985
986 SyncExtensionUpdateIfNeeded(*extension);
955 } 987 }
956 988
957 void ExtensionService::DisableExtension(const std::string& extension_id) { 989 void ExtensionService::DisableExtension(const std::string& extension_id) {
958 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 990 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
959 991
960 // The extension may have been disabled already. 992 // The extension may have been disabled already.
961 if (!IsExtensionEnabled(extension_id)) 993 if (!IsExtensionEnabled(extension_id))
962 return; 994 return;
963 995
964 const Extension* extension = GetInstalledExtension(extension_id); 996 const Extension* extension = GetInstalledExtension(extension_id);
(...skipping 16 matching lines...) Expand all
981 if (iter != extensions_.end()) { 1013 if (iter != extensions_.end()) {
982 extensions_.erase(iter); 1014 extensions_.erase(iter);
983 } else { 1015 } else {
984 iter = std::find(terminated_extensions_.begin(), 1016 iter = std::find(terminated_extensions_.begin(),
985 terminated_extensions_.end(), 1017 terminated_extensions_.end(),
986 extension); 1018 extension);
987 terminated_extensions_.erase(iter); 1019 terminated_extensions_.erase(iter);
988 } 1020 }
989 1021
990 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE); 1022 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
1023
1024 SyncExtensionUpdateIfNeeded(*extension);
991 } 1025 }
992 1026
993 void ExtensionService::GrantPermissions(const Extension* extension) { 1027 void ExtensionService::GrantPermissions(const Extension* extension) {
994 CHECK(extension); 1028 CHECK(extension);
995 1029
996 // We only maintain the granted permissions prefs for extensions that can't 1030 // We only maintain the granted permissions prefs for extensions that can't
997 // silently increase their permissions. 1031 // silently increase their permissions.
998 if (extension->CanSilentlyIncreasePermissions()) 1032 if (extension->CanSilentlyIncreasePermissions())
999 return; 1033 return;
1000 1034
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 } 1645 }
1612 1646
1613 void ExtensionService::CheckForUpdatesSoon() { 1647 void ExtensionService::CheckForUpdatesSoon() {
1614 if (updater()) { 1648 if (updater()) {
1615 updater()->CheckSoon(); 1649 updater()->CheckSoon();
1616 } else { 1650 } else {
1617 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; 1651 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
1618 } 1652 }
1619 } 1653 }
1620 1654
1621 ExtensionSyncData ExtensionService::GetSyncDataHelper( 1655 void ExtensionService::SyncExtensionUpdateIfNeeded(const Extension& extension) {
1622 const Extension& extension) const { 1656 SyncBundle* sync_bundle = GetSyncBundleForExtension(extension);
1623 const std::string& id = extension.id(); 1657 if (sync_bundle) {
1624 ExtensionSyncData data; 1658 SyncChangeList sync_change_list(1);
1625 data.id = id; 1659 ExtensionSyncData extension_sync_data(extension,
1626 data.uninstalled = false; 1660 IsExtensionEnabled(extension.id()),
1627 data.enabled = IsExtensionEnabled(id); 1661 IsIncognitoEnabled(extension.id()));
1628 data.incognito_enabled = IsIncognitoEnabled(id); 1662
1629 data.version = *extension.version(); 1663 sync_change_list[0] = extension_sync_data.GetSyncChange(
1630 data.update_url = extension.update_url(); 1664 sync_bundle->HasExtensionId(extension.id()) ?
1631 data.name = extension.name(); 1665 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD);
1632 return data; 1666 sync_bundle->sync_processor->ProcessSyncChanges(
1633 } 1667 FROM_HERE, sync_change_list);
1634 1668 sync_bundle->synced_extensions.insert(extension.id());
1635 bool ExtensionService::GetSyncData( 1669 sync_bundle->pending_sync_data.erase(extension.id());
1636 const Extension& extension, 1670 }
1637 ExtensionFilter filter, 1671 }
1638 ExtensionSyncData* extension_sync_data) const { 1672
1639 if (!(*filter)(extension)) { 1673 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension(
1640 return false; 1674 const Extension& extension) {
1641 } 1675 if (app_sync_bundle_.filter(extension))
1642 *extension_sync_data = GetSyncDataHelper(extension); 1676 return &app_sync_bundle_;
1643 return true; 1677 else if (extension_sync_bundle_.filter(extension))
1678 return &extension_sync_bundle_;
1679 else
1680 return NULL;
1681 }
1682
1683 ExtensionService::SyncBundle*
1684 ExtensionService::GetSyncBundleForExtensionSyncData(
1685 const ExtensionSyncData& extension_sync_data) {
1686 switch (extension_sync_data.type()) {
1687 case Extension::SYNC_TYPE_APP:
1688 return &app_sync_bundle_;
1689 case Extension::SYNC_TYPE_EXTENSION:
1690 return &extension_sync_bundle_;
1691 default:
1692 NOTREACHED();
1693 return NULL;
1694 }
1695 }
1696
1697 const ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForModelType(
1698 syncable::ModelType type) const {
1699 switch (type) {
1700 case syncable::APPS:
1701 return &app_sync_bundle_;
1702 case syncable::EXTENSIONS:
1703 return &extension_sync_bundle_;
1704 default:
1705 NOTREACHED();
1706 return NULL;
1707 }
1708 }
1709
1710 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForModelType(
1711 syncable::ModelType type) {
1712 switch (type) {
1713 case syncable::APPS:
1714 return &app_sync_bundle_;
1715 case syncable::EXTENSIONS:
1716 return &extension_sync_bundle_;
1717 default:
1718 NOTREACHED();
1719 return NULL;
asargent_no_longer_on_chrome 2011/08/12 20:50:39 nit: Looks like these two have the same body. Mayb
1720 }
1721 }
1722
1723 SyncError ExtensionService::MergeDataAndStartSyncing(
1724 syncable::ModelType type,
1725 const SyncDataList& initial_sync_data,
1726 SyncChangeProcessor* sync_processor) {
1727
1728 SyncBundle* bundle = NULL;
1729
1730 switch (type) {
1731 case syncable::EXTENSIONS:
1732 bundle = &extension_sync_bundle_;
1733 bundle->filter = IsSyncableExtension;
1734 break;
1735
1736 case syncable::APPS:
1737 bundle = &app_sync_bundle_;
1738 bundle->filter = IsSyncableApp;
1739 break;
1740
1741 default:
1742 DLOG(ERROR) << "Got " << type << " ModelType";
1743 NOTREACHED();
akalin 2011/08/12 03:35:02 may as well just do NOTREACHED() << "Got " ...; Al
asargent_no_longer_on_chrome 2011/08/12 20:50:39 consider LOG(FATAL)
1744 }
1745
1746 bundle->sync_processor = sync_processor;
asargent_no_longer_on_chrome 2011/08/12 20:50:39 consider adding a CHECK(sync_processor) right abov
1747
1748 for (SyncDataList::const_iterator i = initial_sync_data.begin();
1749 i != initial_sync_data.end();
1750 ++i) {
1751 ExtensionSyncData extension_sync_data = ExtensionSyncData(*i);
1752 bundle->synced_extensions.insert(extension_sync_data.id());
1753 ProcessExtensionSyncData(extension_sync_data, *bundle);
1754 }
1755
1756 SyncDataList sync_data_list = GetAllSyncData(type);
1757 SyncChangeList sync_change_list;
1758 for (SyncDataList::const_iterator i = sync_data_list.begin();
1759 i != sync_data_list.end();
1760 ++i) {
1761 if (bundle->HasExtensionId(i->GetTag()))
1762 sync_change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, *i));
asargent_no_longer_on_chrome 2011/08/12 20:50:39 I was a bit surprised not to see you check here wh
Ben Olmstead 2011/08/15 20:20:12 According to Fred, yes it does. I considered the
1763 else
1764 sync_change_list.push_back(SyncChange(SyncChange::ACTION_ADD, *i));
1765 }
1766 bundle->sync_processor->ProcessSyncChanges(FROM_HERE, sync_change_list);
1767
1768 return SyncError();
1769 }
1770
1771 void ExtensionService::StopSyncing(syncable::ModelType type) {
1772 SyncBundle* bundle = GetSyncBundleForModelType(type);
1773 DCHECK(bundle);
akalin 2011/08/12 03:35:02 change to CHECK, since you're dereferencing in nex
1774 // This is the simplest way to clear out the bundle.
1775 *bundle = SyncBundle();
1776 }
1777
1778 SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const {
1779 const SyncBundle* bundle = GetSyncBundleForModelType(type);
1780 DCHECK(bundle);
akalin 2011/08/12 03:35:02 CHECK
1781 std::vector<ExtensionSyncData> extension_sync_data = GetSyncDataList(*bundle);
1782 SyncDataList rv(extension_sync_data.size());
asargent_no_longer_on_chrome 2011/08/12 20:50:39 naming nit: "rv" is too abbreviated - maybe use "r
1783 for (int i = 0; i < static_cast<int>(extension_sync_data.size()); ++i) {
akalin 2011/08/12 03:35:02 may as well use iterators here, too
1784 rv[i] = extension_sync_data[i].GetSyncData();
1785 }
1786 return rv;
1787 }
1788
1789 SyncError ExtensionService::ProcessSyncChanges(
1790 const tracked_objects::Location& from_here,
1791 const SyncChangeList& change_list) {
1792 for (SyncChangeList::const_iterator i = change_list.begin();
1793 i != change_list.end();
1794 ++i) {
1795 ExtensionSyncData extension_sync_data = ExtensionSyncData(*i);
1796 SyncBundle* bundle = GetSyncBundleForExtensionSyncData(extension_sync_data);
1797 DCHECK(bundle);
akalin 2011/08/12 03:35:02 CHECK
1798
1799 if (extension_sync_data.uninstalled())
1800 bundle->synced_extensions.erase(extension_sync_data.id());
1801 else
1802 bundle->synced_extensions.insert(extension_sync_data.id());
1803 ProcessExtensionSyncData(extension_sync_data, *bundle);
1804 }
1805
1806 return SyncError();
1644 } 1807 }
1645 1808
1646 void ExtensionService::GetSyncDataListHelper( 1809 void ExtensionService::GetSyncDataListHelper(
1647 const ExtensionList& extensions, 1810 const ExtensionList& extensions,
1648 ExtensionFilter filter, 1811 const SyncBundle& bundle,
1649 std::vector<ExtensionSyncData>* sync_data_list) const { 1812 std::vector<ExtensionSyncData>* sync_data_list) const {
1650 for (ExtensionList::const_iterator it = extensions.begin(); 1813 for (ExtensionList::const_iterator it = extensions.begin();
1651 it != extensions.end(); ++it) { 1814 it != extensions.end(); ++it) {
1652 const Extension& extension = **it; 1815 const Extension& extension = **it;
1653 if ((*filter)(extension)) { 1816 if (bundle.filter(extension) &&
1654 sync_data_list->push_back(GetSyncDataHelper(extension)); 1817 // If we have pending extension data for this extension, then this
1818 // version is out of date. We'll sync back the version we got from
1819 // sync.
1820 !bundle.HasPendingExtensionId(extension.id())) {
1821 sync_data_list->push_back(
1822 ExtensionSyncData(extension,
1823 IsExtensionEnabled(extension.id()),
1824 IsIncognitoEnabled(extension.id())));
1655 } 1825 }
1656 } 1826 }
1657 } 1827 }
1658 1828
1659 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( 1829 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList(
1660 ExtensionFilter filter) const { 1830 const SyncBundle& bundle) const {
1661 std::vector<ExtensionSyncData> sync_data_list; 1831 std::vector<ExtensionSyncData> extension_sync_list;
1662 GetSyncDataListHelper(extensions_, filter, &sync_data_list); 1832 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list);
1663 GetSyncDataListHelper(disabled_extensions_, filter, &sync_data_list); 1833 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list);
1664 GetSyncDataListHelper(terminated_extensions_, filter, &sync_data_list); 1834 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list);
1665 return sync_data_list; 1835
1666 } 1836 for (std::map<std::string, ExtensionSyncData>::const_iterator i =
1667 1837 bundle.pending_sync_data.begin();
1668 void ExtensionService::ProcessSyncData( 1838 i != bundle.pending_sync_data.end();
1839 ++i) {
1840 extension_sync_list.push_back(i->second);
1841 }
1842
1843 return extension_sync_list;
1844 }
1845
1846 void ExtensionService::ProcessExtensionSyncData(
1669 const ExtensionSyncData& extension_sync_data, 1847 const ExtensionSyncData& extension_sync_data,
1670 ExtensionFilter filter) { 1848 SyncBundle& bundle) {
1671 const std::string& id = extension_sync_data.id; 1849 const std::string& id = extension_sync_data.id();
1672 1850
1673 // Handle uninstalls first. 1851 // Handle uninstalls first.
1674 if (extension_sync_data.uninstalled) { 1852 if (extension_sync_data.uninstalled()) {
1675 std::string error; 1853 std::string error;
1676 if (!UninstallExtensionHelper(this, id)) { 1854 if (!UninstallExtensionHelper(this, id)) {
1677 LOG(WARNING) << "Could not uninstall extension " << id 1855 LOG(WARNING) << "Could not uninstall extension " << id
1678 << " for sync"; 1856 << " for sync";
1679 } 1857 }
1680 return; 1858 return;
1681 } 1859 }
1682 1860
1683 // Set user settings. 1861 // Set user settings.
1684 if (extension_sync_data.enabled) { 1862 if (extension_sync_data.enabled()) {
1685 EnableExtension(id); 1863 EnableExtension(id);
1686 } else { 1864 } else {
1687 DisableExtension(id); 1865 DisableExtension(id);
1688 } 1866 }
1689 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled); 1867 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
1690 1868
1691 const Extension* extension = GetInstalledExtension(id); 1869 const Extension* extension = GetInstalledExtension(id);
1692 if (extension) { 1870 if (extension) {
1693 // If the extension is already installed, check if it's outdated. 1871 // If the extension is already installed, check if it's outdated.
1694 int result = extension->version()->CompareTo(extension_sync_data.version); 1872 int result = extension->version()->CompareTo(extension_sync_data.version());
1695 if (result < 0) { 1873 if (result < 0) {
1696 // Extension is outdated. 1874 // Extension is outdated.
1875 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data;
1697 CheckForUpdatesSoon(); 1876 CheckForUpdatesSoon();
1698 } else if (result > 0) {
1699 // Sync version is outdated. Do nothing for now, as sync code
1700 // in other places will eventually update the sync data.
1701 //
1702 // TODO(akalin): Move that code here.
1703 } 1877 }
1704 } else { 1878 } else {
1705 // TODO(akalin): Replace silent update with a list of enabled 1879 // TODO(akalin): Replace silent update with a list of enabled
1706 // permissions. 1880 // permissions.
1881 //
1882 // TODO(bolms): Install disabled if it came in from sync disabled.
akalin 2011/08/12 03:35:02 i believe the DisableExtension(id) call above shou
Ben Olmstead 2011/08/15 20:20:12 You are correct--just verified.
1707 const bool kInstallSilently = true; 1883 const bool kInstallSilently = true;
1708 if (!pending_extension_manager()->AddFromSync( 1884 if (!pending_extension_manager()->AddFromSync(
1709 id, 1885 id,
1710 extension_sync_data.update_url, 1886 extension_sync_data.update_url(),
1711 filter, 1887 bundle.filter,
1712 kInstallSilently)) { 1888 kInstallSilently)) {
1713 LOG(WARNING) << "Could not add pending extension for " << id; 1889 LOG(WARNING) << "Could not add pending extension for " << id;
akalin 2011/08/12 03:35:02 From the comments re. when AddFromSync returns fal
Ben Olmstead 2011/08/15 20:20:12 Looking at the code, it looks like this can only h
1714 return; 1890 return;
1715 } 1891 }
1892 // Track pending extensions so that we can return them in GetAllSyncData().
1893 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data;
1716 CheckForUpdatesSoon(); 1894 CheckForUpdatesSoon();
1717 } 1895 }
1718 } 1896 }
1719 1897
1720 bool ExtensionService::IsIncognitoEnabled( 1898 bool ExtensionService::IsIncognitoEnabled(
1721 const std::string& extension_id) const { 1899 const std::string& extension_id) const {
1722 // If this is an existing component extension we always allow it to 1900 // If this is an existing component extension we always allow it to
1723 // work in incognito mode. 1901 // work in incognito mode.
1724 const Extension* extension = GetInstalledExtension(extension_id); 1902 const Extension* extension = GetInstalledExtension(extension_id);
1725 if (extension && extension->location() == Extension::COMPONENT) 1903 if (extension && extension->location() == Extension::COMPONENT)
(...skipping 21 matching lines...) Expand all
1747 1925
1748 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); 1926 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
1749 1927
1750 // If the extension is enabled (and not terminated), unload and 1928 // If the extension is enabled (and not terminated), unload and
1751 // reload it to update UI. 1929 // reload it to update UI.
1752 const Extension* enabled_extension = GetExtensionById(extension_id, false); 1930 const Extension* enabled_extension = GetExtensionById(extension_id, false);
1753 if (enabled_extension) { 1931 if (enabled_extension) {
1754 NotifyExtensionUnloaded(enabled_extension, UnloadedExtensionInfo::DISABLE); 1932 NotifyExtensionUnloaded(enabled_extension, UnloadedExtensionInfo::DISABLE);
1755 NotifyExtensionLoaded(enabled_extension); 1933 NotifyExtensionLoaded(enabled_extension);
1756 } 1934 }
1935
1936 if (extension)
1937 SyncExtensionUpdateIfNeeded(*extension);
1757 } 1938 }
1758 1939
1759 bool ExtensionService::CanCrossIncognito(const Extension* extension) { 1940 bool ExtensionService::CanCrossIncognito(const Extension* extension) {
1760 // We allow the extension to see events and data from another profile iff it 1941 // We allow the extension to see events and data from another profile iff it
1761 // uses "spanning" behavior and it has incognito access. "split" mode 1942 // uses "spanning" behavior and it has incognito access. "split" mode
1762 // extensions only see events for a matching profile. 1943 // extensions only see events for a matching profile.
1763 return IsIncognitoEnabled(extension->id()) && 1944 return IsIncognitoEnabled(extension->id()) &&
1764 !extension->incognito_split_mode(); 1945 !extension->incognito_split_mode();
1765 } 1946 }
1766 1947
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); 2197 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id());
2017 if (disabled) { 2198 if (disabled) {
2018 disabled_extensions_.push_back(scoped_extension); 2199 disabled_extensions_.push_back(scoped_extension);
2019 // TODO(aa): This seems dodgy. It seems that AddExtension() could get called 2200 // TODO(aa): This seems dodgy. It seems that AddExtension() could get called
2020 // with a disabled extension for other reasons other than that an update was 2201 // with a disabled extension for other reasons other than that an update was
2021 // disabled. 2202 // disabled.
2022 NotificationService::current()->Notify( 2203 NotificationService::current()->Notify(
2023 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 2204 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
2024 Source<Profile>(profile_), 2205 Source<Profile>(profile_),
2025 Details<const Extension>(extension)); 2206 Details<const Extension>(extension));
2207 SyncExtensionUpdateIfNeeded(*extension);
2026 return; 2208 return;
2027 } 2209 }
2028 2210
2029 extensions_.push_back(scoped_extension); 2211 extensions_.push_back(scoped_extension);
2212 SyncExtensionUpdateIfNeeded(*extension);
2030 NotifyExtensionLoaded(extension); 2213 NotifyExtensionLoaded(extension);
2031 } 2214 }
2032 2215
2033 void ExtensionService::InitializePermissions(const Extension* extension) { 2216 void ExtensionService::InitializePermissions(const Extension* extension) {
2034 // If the extension has used the optional permissions API, it will have a 2217 // If the extension has used the optional permissions API, it will have a
2035 // custom set of active permissions defined in the extension prefs. Here, 2218 // custom set of active permissions defined in the extension prefs. Here,
2036 // we update the extension's active permissions based on the prefs. 2219 // we update the extension's active permissions based on the prefs.
2037 scoped_refptr<ExtensionPermissionSet> active_permissions = 2220 scoped_refptr<ExtensionPermissionSet> active_permissions =
2038 extension_prefs()->GetActivePermissions(extension->id()); 2221 extension_prefs()->GetActivePermissions(extension->id());
2039 2222
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 2780
2598 ExtensionService::NaClModuleInfoList::iterator 2781 ExtensionService::NaClModuleInfoList::iterator
2599 ExtensionService::FindNaClModule(const GURL& url) { 2782 ExtensionService::FindNaClModule(const GURL& url) {
2600 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 2783 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2601 iter != nacl_module_list_.end(); ++iter) { 2784 iter != nacl_module_list_.end(); ++iter) {
2602 if (iter->url == url) 2785 if (iter->url == url)
2603 return iter; 2786 return iter;
2604 } 2787 }
2605 return nacl_module_list_.end(); 2788 return nacl_module_list_.end();
2606 } 2789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698