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/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "chrome/browser/extensions/extension_cookies_api.h" | 31 #include "chrome/browser/extensions/extension_cookies_api.h" |
32 #include "chrome/browser/extensions/extension_data_deleter.h" | 32 #include "chrome/browser/extensions/extension_data_deleter.h" |
33 #include "chrome/browser/extensions/extension_error_reporter.h" | 33 #include "chrome/browser/extensions/extension_error_reporter.h" |
34 #include "chrome/browser/extensions/extension_history_api.h" | 34 #include "chrome/browser/extensions/extension_history_api.h" |
35 #include "chrome/browser/extensions/extension_host.h" | 35 #include "chrome/browser/extensions/extension_host.h" |
36 #include "chrome/browser/extensions/extension_management_api.h" | 36 #include "chrome/browser/extensions/extension_management_api.h" |
37 #include "chrome/browser/extensions/extension_preference_api.h" | 37 #include "chrome/browser/extensions/extension_preference_api.h" |
38 #include "chrome/browser/extensions/extension_process_manager.h" | 38 #include "chrome/browser/extensions/extension_process_manager.h" |
39 #include "chrome/browser/extensions/extension_processes_api.h" | 39 #include "chrome/browser/extensions/extension_processes_api.h" |
40 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 40 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
41 #include "chrome/browser/extensions/extension_sync_data.h" | |
41 #include "chrome/browser/extensions/extension_updater.h" | 42 #include "chrome/browser/extensions/extension_updater.h" |
42 #include "chrome/browser/extensions/extension_web_ui.h" | 43 #include "chrome/browser/extensions/extension_web_ui.h" |
43 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 44 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
44 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 45 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
45 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 46 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
46 #include "chrome/browser/extensions/pending_extension_manager.h" | 47 #include "chrome/browser/extensions/pending_extension_manager.h" |
47 #include "chrome/browser/net/chrome_url_request_context.h" | 48 #include "chrome/browser/net/chrome_url_request_context.h" |
48 #include "chrome/browser/prefs/pref_service.h" | 49 #include "chrome/browser/prefs/pref_service.h" |
49 #include "chrome/browser/profiles/profile.h" | 50 #include "chrome/browser/profiles/profile.h" |
50 #include "chrome/browser/search_engines/template_url_model.h" | 51 #include "chrome/browser/search_engines/template_url_model.h" |
52 // TODO(akalin): Remove dependency on this. | |
53 #include "chrome/browser/sync/glue/extension_util.h" | |
51 #include "chrome/browser/themes/theme_service.h" | 54 #include "chrome/browser/themes/theme_service.h" |
52 #include "chrome/browser/themes/theme_service_factory.h" | 55 #include "chrome/browser/themes/theme_service_factory.h" |
53 #include "chrome/browser/ui/webui/shown_sections_handler.h" | 56 #include "chrome/browser/ui/webui/shown_sections_handler.h" |
54 #include "chrome/common/child_process_logging.h" | 57 #include "chrome/common/child_process_logging.h" |
55 #include "chrome/common/chrome_switches.h" | 58 #include "chrome/common/chrome_switches.h" |
56 #include "chrome/common/extensions/extension.h" | 59 #include "chrome/common/extensions/extension.h" |
57 #include "chrome/common/extensions/extension_constants.h" | 60 #include "chrome/common/extensions/extension_constants.h" |
58 #include "chrome/common/extensions/extension_error_utils.h" | 61 #include "chrome/common/extensions/extension_error_utils.h" |
59 #include "chrome/common/extensions/extension_file_util.h" | 62 #include "chrome/common/extensions/extension_file_util.h" |
60 #include "chrome/common/extensions/extension_l10n_util.h" | 63 #include "chrome/common/extensions/extension_l10n_util.h" |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1181 } | 1184 } |
1182 | 1185 |
1183 void ExtensionService::CheckForUpdatesSoon() { | 1186 void ExtensionService::CheckForUpdatesSoon() { |
1184 if (updater()) { | 1187 if (updater()) { |
1185 updater()->CheckSoon(); | 1188 updater()->CheckSoon(); |
1186 } else { | 1189 } else { |
1187 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; | 1190 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
1188 } | 1191 } |
1189 } | 1192 } |
1190 | 1193 |
1194 namespace { | |
1195 | |
1196 bool ShouldAllowInstallFromSync(const Extension& extension) { | |
1197 return | |
1198 browser_sync::IsValidAndSyncableExtension(extension) || | |
1199 browser_sync::IsValidAndSyncableApp(extension); | |
asargent_no_longer_on_chrome
2011/04/14 23:32:14
I'm not crazy about seeing the ExtensionService us
akalin
2011/04/15 01:17:11
Done.
| |
1200 } | |
1201 | |
1202 } // namespace | |
1203 | |
1204 void ExtensionService::ProcessSyncData( | |
1205 const ExtensionSyncData& extension_sync_data) { | |
1206 const std::string& id = extension_sync_data.id; | |
1207 | |
1208 // Handle uninstalls first. | |
1209 if (extension_sync_data.uninstalled) { | |
1210 std::string error; | |
1211 if (!UninstallExtensionHelper(this, id)) { | |
1212 LOG(WARNING) << "Sync tried to uninstall nonexistent extension " << id; | |
asargent_no_longer_on_chrome
2011/04/14 23:32:14
Note that it's possible we couldn't uninstall beca
akalin
2011/04/15 01:17:11
Ah, okay. Fixed.
| |
1213 } | |
1214 return; | |
1215 } | |
1216 | |
1217 const Extension* extension = GetExtensionByIdInternal(id, true, true); | |
1218 // TODO(akalin): Figure out what to do with terminated extensions. | |
1219 | |
1220 // Handle already-installed extensions (just update settings). | |
1221 // | |
1222 // TODO(akalin): Ideally, we should be able to set prefs for an | |
1223 // extension regardless of whether or not it's installed (and have | |
1224 // it automatially apply on install). | |
1225 if (extension) { | |
1226 if (extension_sync_data.enabled) { | |
1227 EnableExtension(id); | |
1228 } else { | |
1229 DisableExtension(id); | |
1230 } | |
1231 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled); | |
1232 int result = extension->version()->CompareTo(extension_sync_data.version); | |
1233 if (result < 0) { | |
1234 // Extension is outdated. | |
1235 CheckForUpdatesSoon(); | |
1236 } else if (result > 0) { | |
1237 // Sync version is outdated. Do nothing for now, as sync code | |
1238 // in other places will eventually update the sync data. | |
1239 // | |
1240 // TODO(akalin): Move that code here. | |
1241 } | |
1242 return; | |
1243 } | |
1244 | |
1245 // Handle not-yet-installed extensions. | |
1246 // | |
1247 // TODO(akalin): Replace silent update with a list of enabled | |
1248 // permissions. | |
1249 // | |
1250 // TODO(akalin): Use a different install predicate once we split | |
1251 // this function into one for extension sync and one for app sync. | |
1252 pending_extension_manager()->AddFromSync( | |
1253 id, | |
1254 extension_sync_data.update_url, | |
1255 &ShouldAllowInstallFromSync, | |
1256 true, // install_silently | |
1257 extension_sync_data.enabled, | |
1258 extension_sync_data.incognito_enabled); | |
1259 CheckForUpdatesSoon(); | |
1260 } | |
1261 | |
1191 bool ExtensionService::IsIncognitoEnabled( | 1262 bool ExtensionService::IsIncognitoEnabled( |
1192 const std::string& extension_id) const { | 1263 const std::string& extension_id) const { |
1193 // If this is an existing component extension we always allow it to | 1264 // If this is an existing component extension we always allow it to |
1194 // work in incognito mode. | 1265 // work in incognito mode. |
1195 const Extension* extension = GetExtensionById(extension_id, true); | 1266 const Extension* extension = GetExtensionById(extension_id, true); |
1196 if (extension && extension->location() == Extension::COMPONENT) | 1267 if (extension && extension->location() == Extension::COMPONENT) |
1197 return true; | 1268 return true; |
1198 | 1269 |
1199 // Check the prefs. | 1270 // Check the prefs. |
1200 return extension_prefs_->IsIncognitoEnabled(extension_id); | 1271 return extension_prefs_->IsIncognitoEnabled(extension_id); |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1925 } | 1996 } |
1926 | 1997 |
1927 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 1998 void ExtensionService::SetBeingUpgraded(const Extension* extension, |
1928 bool value) { | 1999 bool value) { |
1929 extension_runtime_data_[extension->id()].being_upgraded = value; | 2000 extension_runtime_data_[extension->id()].being_upgraded = value; |
1930 } | 2001 } |
1931 | 2002 |
1932 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { | 2003 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
1933 return &extension_runtime_data_[extension->id()].property_bag; | 2004 return &extension_runtime_data_[extension->id()].property_bag; |
1934 } | 2005 } |
OLD | NEW |