| OLD | NEW |
| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } | 899 } |
| 900 return false; | 900 return false; |
| 901 } | 901 } |
| 902 | 902 |
| 903 // Extract the data we need for sync now, but don't actually sync until we've | 903 // Extract the data we need for sync now, but don't actually sync until we've |
| 904 // completed the uninstallation. | 904 // completed the uninstallation. |
| 905 SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); | 905 SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); |
| 906 | 906 |
| 907 SyncChange sync_change; | 907 SyncChange sync_change; |
| 908 if (sync_bundle) { | 908 if (sync_bundle) { |
| 909 ExtensionSyncData extension_sync_data(*extension, | 909 ExtensionSyncData extension_sync_data( |
| 910 IsExtensionEnabled(extension_id), | 910 *extension, |
| 911 IsIncognitoEnabled(extension_id)); | 911 IsExtensionEnabled(extension_id), |
| 912 IsIncognitoEnabled(extension_id), |
| 913 extension_prefs_->IsAppNotificationSetupDone(extension_id), |
| 914 extension_prefs_->IsAppNotificationDisabled(extension_id)); |
| 912 sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); | 915 sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); |
| 913 } | 916 } |
| 914 | 917 |
| 915 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", | 918 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
| 916 extension->GetType(), 100); | 919 extension->GetType(), 100); |
| 917 RecordPermissionMessagesHistogram( | 920 RecordPermissionMessagesHistogram( |
| 918 extension, "Extensions.Permissions_Uninstall"); | 921 extension, "Extensions.Permissions_Uninstall"); |
| 919 | 922 |
| 920 TemplateURLService* url_service = | 923 TemplateURLService* url_service = |
| 921 TemplateURLServiceFactory::GetForProfile(profile_); | 924 TemplateURLServiceFactory::GetForProfile(profile_); |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 } | 1743 } |
| 1741 | 1744 |
| 1742 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) | 1745 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) |
| 1743 const { | 1746 const { |
| 1744 return pending_sync_data.find(id) != pending_sync_data.end(); | 1747 return pending_sync_data.find(id) != pending_sync_data.end(); |
| 1745 } | 1748 } |
| 1746 | 1749 |
| 1747 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { | 1750 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { |
| 1748 SyncBundle* sync_bundle = GetSyncBundleForExtension(extension); | 1751 SyncBundle* sync_bundle = GetSyncBundleForExtension(extension); |
| 1749 if (sync_bundle) { | 1752 if (sync_bundle) { |
| 1750 ExtensionSyncData extension_sync_data(extension, | 1753 ExtensionSyncData extension_sync_data( |
| 1751 IsExtensionEnabled(extension.id()), | 1754 extension, |
| 1752 IsIncognitoEnabled(extension.id())); | 1755 IsExtensionEnabled(extension.id()), |
| 1756 IsIncognitoEnabled(extension.id()), |
| 1757 extension_prefs_->IsAppNotificationSetupDone(extension.id()), |
| 1758 extension_prefs_->IsAppNotificationDisabled(extension.id())); |
| 1753 | 1759 |
| 1754 SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange( | 1760 SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange( |
| 1755 sync_bundle->HasExtensionId(extension.id()) ? | 1761 sync_bundle->HasExtensionId(extension.id()) ? |
| 1756 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); | 1762 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); |
| 1757 sync_bundle->sync_processor->ProcessSyncChanges( | 1763 sync_bundle->sync_processor->ProcessSyncChanges( |
| 1758 FROM_HERE, sync_change_list); | 1764 FROM_HERE, sync_change_list); |
| 1759 sync_bundle->synced_extensions.insert(extension.id()); | 1765 sync_bundle->synced_extensions.insert(extension.id()); |
| 1760 sync_bundle->pending_sync_data.erase(extension.id()); | 1766 sync_bundle->pending_sync_data.erase(extension.id()); |
| 1761 } | 1767 } |
| 1762 } | 1768 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 const SyncBundle& bundle, | 1908 const SyncBundle& bundle, |
| 1903 std::vector<ExtensionSyncData>* sync_data_list) const { | 1909 std::vector<ExtensionSyncData>* sync_data_list) const { |
| 1904 for (ExtensionList::const_iterator it = extensions.begin(); | 1910 for (ExtensionList::const_iterator it = extensions.begin(); |
| 1905 it != extensions.end(); ++it) { | 1911 it != extensions.end(); ++it) { |
| 1906 const Extension& extension = **it; | 1912 const Extension& extension = **it; |
| 1907 if (bundle.filter(extension) && | 1913 if (bundle.filter(extension) && |
| 1908 // If we have pending extension data for this extension, then this | 1914 // If we have pending extension data for this extension, then this |
| 1909 // version is out of date. We'll sync back the version we got from | 1915 // version is out of date. We'll sync back the version we got from |
| 1910 // sync. | 1916 // sync. |
| 1911 !bundle.HasPendingExtensionId(extension.id())) { | 1917 !bundle.HasPendingExtensionId(extension.id())) { |
| 1912 sync_data_list->push_back( | 1918 sync_data_list->push_back(ExtensionSyncData( |
| 1913 ExtensionSyncData(extension, | 1919 extension, |
| 1914 IsExtensionEnabled(extension.id()), | 1920 IsExtensionEnabled(extension.id()), |
| 1915 IsIncognitoEnabled(extension.id()))); | 1921 IsIncognitoEnabled(extension.id()), |
| 1922 extension_prefs_->IsAppNotificationSetupDone(extension.id()), |
| 1923 extension_prefs_->IsAppNotificationDisabled(extension.id()))); |
| 1916 } | 1924 } |
| 1917 } | 1925 } |
| 1918 } | 1926 } |
| 1919 | 1927 |
| 1920 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( | 1928 std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( |
| 1921 const SyncBundle& bundle) const { | 1929 const SyncBundle& bundle) const { |
| 1922 std::vector<ExtensionSyncData> extension_sync_list; | 1930 std::vector<ExtensionSyncData> extension_sync_list; |
| 1923 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); | 1931 GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); |
| 1924 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); | 1932 GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); |
| 1925 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); | 1933 GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2029 if (enabled_extension) { | 2037 if (enabled_extension) { |
| 2030 NotifyExtensionUnloaded( | 2038 NotifyExtensionUnloaded( |
| 2031 enabled_extension, extension_misc::UNLOAD_REASON_DISABLE); | 2039 enabled_extension, extension_misc::UNLOAD_REASON_DISABLE); |
| 2032 NotifyExtensionLoaded(enabled_extension); | 2040 NotifyExtensionLoaded(enabled_extension); |
| 2033 } | 2041 } |
| 2034 | 2042 |
| 2035 if (extension) | 2043 if (extension) |
| 2036 SyncExtensionChangeIfNeeded(*extension); | 2044 SyncExtensionChangeIfNeeded(*extension); |
| 2037 } | 2045 } |
| 2038 | 2046 |
| 2047 void ExtensionService::SetAppNotificationSetupDone( |
| 2048 const std::string& extension_id, |
| 2049 bool value) { |
| 2050 const Extension* extension = GetInstalledExtension(extension_id); |
| 2051 // This method is called when the user sets up app notifications. |
| 2052 // So it is not expected to be called until the extension is installed. |
| 2053 if (!extension) { |
| 2054 NOTREACHED(); |
| 2055 return; |
| 2056 } |
| 2057 extension_prefs_->SetAppNotificationSetupDone(extension_id, value); |
| 2058 SyncExtensionChangeIfNeeded(*extension); |
| 2059 } |
| 2060 |
| 2061 void ExtensionService::SetAppNotificationDisabled( |
| 2062 const std::string& extension_id, |
| 2063 bool value) { |
| 2064 const Extension* extension = GetInstalledExtension(extension_id); |
| 2065 // This method is called when the user enables/disables app notifications. |
| 2066 // So it is not expected to be called until the extension is installed. |
| 2067 if (!extension) { |
| 2068 NOTREACHED(); |
| 2069 return; |
| 2070 } |
| 2071 |
| 2072 extension_prefs_->SetAppNotificationDisabled(extension_id, value); |
| 2073 SyncExtensionChangeIfNeeded(*extension); |
| 2074 } |
| 2075 |
| 2039 bool ExtensionService::CanCrossIncognito(const Extension* extension) { | 2076 bool ExtensionService::CanCrossIncognito(const Extension* extension) { |
| 2040 // We allow the extension to see events and data from another profile iff it | 2077 // We allow the extension to see events and data from another profile iff it |
| 2041 // uses "spanning" behavior and it has incognito access. "split" mode | 2078 // uses "spanning" behavior and it has incognito access. "split" mode |
| 2042 // extensions only see events for a matching profile. | 2079 // extensions only see events for a matching profile. |
| 2043 CHECK(extension); | 2080 CHECK(extension); |
| 2044 return IsIncognitoEnabled(extension->id()) && | 2081 return IsIncognitoEnabled(extension->id()) && |
| 2045 !extension->incognito_split_mode(); | 2082 !extension->incognito_split_mode(); |
| 2046 } | 2083 } |
| 2047 | 2084 |
| 2048 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { | 2085 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3026 | 3063 |
| 3027 ExtensionService::NaClModuleInfoList::iterator | 3064 ExtensionService::NaClModuleInfoList::iterator |
| 3028 ExtensionService::FindNaClModule(const GURL& url) { | 3065 ExtensionService::FindNaClModule(const GURL& url) { |
| 3029 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 3066 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 3030 iter != nacl_module_list_.end(); ++iter) { | 3067 iter != nacl_module_list_.end(); ++iter) { |
| 3031 if (iter->url == url) | 3068 if (iter->url == url) |
| 3032 return iter; | 3069 return iter; |
| 3033 } | 3070 } |
| 3034 return nacl_module_list_.end(); | 3071 return nacl_module_list_.end(); |
| 3035 } | 3072 } |
| OLD | NEW |