[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_sync_service.h" |
| 6 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 7 | #include "base/basictypes.h" |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 8 | #include "base/strings/utf_string_conversions.h" |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 9 | #include "chrome/browser/extensions/bookmark_app_helper.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_sync_data.h" |
| 12 | #include "chrome/browser/extensions/extension_sync_service_factory.h" |
| 13 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | a9f74a6 | 2014-01-10 06:48:36 | [diff] [blame] | 14 | #include "chrome/browser/extensions/launch_util.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 15 | #include "chrome/browser/profiles/profile.h" |
| 16 | #include "chrome/browser/sync/glue/sync_start_util.h" |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 17 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 18 | #include "chrome/common/extensions/sync_helper.h" |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 19 | #include "chrome/common/web_application_info.h" |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 20 | #include "extensions/browser/app_sorting.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 21 | #include "extensions/browser/extension_prefs.h" |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 22 | #include "extensions/browser/extension_registry.h" |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 23 | #include "extensions/browser/extension_system.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 24 | #include "extensions/browser/extension_util.h" |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 25 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 26 | #include "extensions/common/extension.h" |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 27 | #include "extensions/common/extension_set.h" |
benwells | d4b64a7 | 2014-12-11 12:38:27 | [diff] [blame] | 28 | #include "extensions/common/image_util.h" |
treib | 8668a30 | 2015-10-05 16:21:53 | [diff] [blame] | 29 | #include "extensions/common/permissions/permission_message_provider.h" |
| 30 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 31 | #include "sync/api/sync_change.h" |
| 32 | #include "sync/api/sync_error_factory.h" |
| 33 | |
treib | 40d3ad9 | 2015-10-20 18:15:42 | [diff] [blame^] | 34 | #if defined(ENABLE_SUPERVISED_USERS) |
| 35 | #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 36 | #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 37 | #endif |
| 38 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 39 | using extensions::AppSorting; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 40 | using extensions::Extension; |
| 41 | using extensions::ExtensionPrefs; |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 42 | using extensions::ExtensionRegistry; |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 43 | using extensions::ExtensionSet; |
rdevlin.cronin | d1aa852 | 2015-02-13 00:25:57 | [diff] [blame] | 44 | using extensions::ExtensionSyncData; |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 45 | using extensions::ExtensionSystem; |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 46 | using extensions::SyncBundle; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 47 | |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 48 | namespace { |
| 49 | |
| 50 | void OnWebApplicationInfoLoaded( |
| 51 | WebApplicationInfo synced_info, |
| 52 | base::WeakPtr<ExtensionService> extension_service, |
| 53 | const WebApplicationInfo& loaded_info) { |
| 54 | DCHECK_EQ(synced_info.app_url, loaded_info.app_url); |
| 55 | |
| 56 | if (!extension_service) |
| 57 | return; |
| 58 | |
| 59 | // Use the old icons if they exist. |
| 60 | synced_info.icons = loaded_info.icons; |
benwells | d4b64a7 | 2014-12-11 12:38:27 | [diff] [blame] | 61 | CreateOrUpdateBookmarkApp(extension_service.get(), &synced_info); |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 62 | } |
| 63 | |
rdevlin.cronin | d1aa852 | 2015-02-13 00:25:57 | [diff] [blame] | 64 | // Returns the pref value for "all urls enabled" for the given extension id. |
| 65 | ExtensionSyncData::OptionalBoolean GetAllowedOnAllUrlsOptionalBoolean( |
| 66 | const std::string& extension_id, |
| 67 | content::BrowserContext* context) { |
| 68 | bool allowed_on_all_urls = |
| 69 | extensions::util::AllowedScriptingOnAllUrls(extension_id, context); |
| 70 | // If the extension is not allowed on all urls (which is not the default), |
| 71 | // then we have to sync the preference. |
| 72 | if (!allowed_on_all_urls) |
| 73 | return ExtensionSyncData::BOOLEAN_FALSE; |
| 74 | |
| 75 | // If the user has explicitly set a value, then we sync it. |
| 76 | if (extensions::util::HasSetAllowedScriptingOnAllUrls(extension_id, context)) |
| 77 | return ExtensionSyncData::BOOLEAN_TRUE; |
| 78 | |
| 79 | // Otherwise, unset. |
| 80 | return ExtensionSyncData::BOOLEAN_UNSET; |
| 81 | } |
| 82 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 83 | // Returns true if the sync type of |extension| matches |type|. |
| 84 | bool IsCorrectSyncType(const Extension& extension, syncer::ModelType type) { |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 85 | return (type == syncer::EXTENSIONS && extension.is_extension()) || |
| 86 | (type == syncer::APPS && extension.is_app()); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 87 | } |
| 88 | |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 89 | syncer::SyncDataList ToSyncerSyncDataList( |
| 90 | const std::vector<ExtensionSyncData>& data) { |
| 91 | syncer::SyncDataList result; |
| 92 | result.reserve(data.size()); |
| 93 | for (const ExtensionSyncData& item : data) |
| 94 | result.push_back(item.GetSyncData()); |
| 95 | return result; |
| 96 | } |
| 97 | |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 98 | } // namespace |
| 99 | |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 100 | struct ExtensionSyncService::PendingUpdate { |
| 101 | PendingUpdate() : grant_permissions_and_reenable(false) {} |
| 102 | PendingUpdate(const base::Version& version, |
| 103 | bool grant_permissions_and_reenable) |
| 104 | : version(version), |
| 105 | grant_permissions_and_reenable(grant_permissions_and_reenable) {} |
| 106 | |
| 107 | base::Version version; |
| 108 | bool grant_permissions_and_reenable; |
| 109 | }; |
| 110 | |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 111 | ExtensionSyncService::ExtensionSyncService(Profile* profile) |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 112 | : profile_(profile), |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 113 | registry_observer_(this), |
| 114 | prefs_observer_(this), |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 115 | flare_(sync_start_util::GetFlareForSyncableService(profile->GetPath())) { |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 116 | registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 117 | prefs_observer_.Add(ExtensionPrefs::Get(profile_)); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 118 | } |
| 119 | |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 120 | ExtensionSyncService::~ExtensionSyncService() { |
| 121 | } |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 122 | |
| 123 | // static |
macourteau | 86b29d8 | 2015-01-23 13:24:45 | [diff] [blame] | 124 | ExtensionSyncService* ExtensionSyncService::Get( |
| 125 | content::BrowserContext* context) { |
| 126 | return ExtensionSyncServiceFactory::GetForBrowserContext(context); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 127 | } |
| 128 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 129 | void ExtensionSyncService::SyncExtensionChangeIfNeeded( |
| 130 | const Extension& extension) { |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 131 | if (!extensions::util::ShouldSync(&extension, profile_)) |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 132 | return; |
| 133 | |
| 134 | syncer::ModelType type = |
| 135 | extension.is_app() ? syncer::APPS : syncer::EXTENSIONS; |
| 136 | SyncBundle* bundle = GetSyncBundle(type); |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 137 | if (bundle->IsSyncing()) { |
| 138 | bundle->PushSyncAddOrUpdate(extension.id(), |
| 139 | CreateSyncData(extension).GetSyncData()); |
| 140 | DCHECK(!ExtensionPrefs::Get(profile_)->NeedsSync(extension.id())); |
| 141 | } else { |
| 142 | ExtensionPrefs::Get(profile_)->SetNeedsSync(extension.id(), true); |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 143 | if (extension_service()->is_ready() && !flare_.is_null()) |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 144 | flare_.Run(type); // Tell sync to start ASAP. |
| 145 | } |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 146 | } |
| 147 | |
treib | 40d3ad9 | 2015-10-20 18:15:42 | [diff] [blame^] | 148 | bool ExtensionSyncService::HasPendingReenable( |
| 149 | const std::string& id, |
| 150 | const base::Version& version) const { |
| 151 | auto it = pending_updates_.find(id); |
| 152 | if (it == pending_updates_.end()) |
| 153 | return false; |
| 154 | const PendingUpdate& pending = it->second; |
| 155 | return pending.version.Equals(version) && |
| 156 | pending.grant_permissions_and_reenable; |
| 157 | } |
| 158 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 159 | syncer::SyncMergeResult ExtensionSyncService::MergeDataAndStartSyncing( |
| 160 | syncer::ModelType type, |
| 161 | const syncer::SyncDataList& initial_sync_data, |
| 162 | scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 163 | scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { |
| 164 | CHECK(sync_processor.get()); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 165 | LOG_IF(FATAL, type != syncer::EXTENSIONS && type != syncer::APPS) |
| 166 | << "Got " << type << " ModelType"; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 167 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 168 | SyncBundle* bundle = GetSyncBundle(type); |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 169 | bundle->StartSyncing(sync_processor.Pass()); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 170 | |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 171 | // Apply the initial sync data, filtering out any items where we have more |
| 172 | // recent local changes. Also tell the SyncBundle the extension IDs. |
| 173 | for (const syncer::SyncData& sync_data : initial_sync_data) { |
| 174 | scoped_ptr<ExtensionSyncData> extension_sync_data( |
| 175 | ExtensionSyncData::CreateFromSyncData(sync_data)); |
| 176 | // If the extension has local state that needs to be synced, ignore this |
| 177 | // change (we assume the local state is more recent). |
| 178 | if (extension_sync_data && |
| 179 | !ExtensionPrefs::Get(profile_)->NeedsSync(extension_sync_data->id())) { |
| 180 | ApplySyncData(*extension_sync_data); |
| 181 | } |
| 182 | } |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 183 | |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 184 | // Now push those local changes to sync. |
| 185 | // TODO(treib,kalman): We should only have to send out changes for extensions |
| 186 | // which have NeedsSync set (i.e. |GetLocalSyncDataList(type, false)|). That |
| 187 | // makes some sync_integration_tests fail though - figure out why and fix it! |
| 188 | std::vector<ExtensionSyncData> data_list = GetLocalSyncDataList(type, true); |
| 189 | bundle->PushSyncDataList(ToSyncerSyncDataList(data_list)); |
| 190 | for (const ExtensionSyncData& data : data_list) |
| 191 | ExtensionPrefs::Get(profile_)->SetNeedsSync(data.id(), false); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 192 | |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 193 | if (type == syncer::APPS) |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 194 | ExtensionSystem::Get(profile_)->app_sorting()->FixNTPOrdinalCollisions(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 195 | |
| 196 | return syncer::SyncMergeResult(type); |
| 197 | } |
| 198 | |
| 199 | void ExtensionSyncService::StopSyncing(syncer::ModelType type) { |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 200 | GetSyncBundle(type)->Reset(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | syncer::SyncDataList ExtensionSyncService::GetAllSyncData( |
| 204 | syncer::ModelType type) const { |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 205 | const SyncBundle* bundle = GetSyncBundle(type); |
| 206 | if (!bundle->IsSyncing()) |
| 207 | return syncer::SyncDataList(); |
| 208 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 209 | std::vector<ExtensionSyncData> sync_data_list = |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 210 | GetLocalSyncDataList(type, true); |
| 211 | |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 212 | // Add pending data (where the local extension is not installed yet). |
| 213 | std::vector<ExtensionSyncData> pending_extensions = |
| 214 | bundle->GetPendingExtensionData(); |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 215 | sync_data_list.insert(sync_data_list.begin(), |
| 216 | pending_extensions.begin(), |
| 217 | pending_extensions.end()); |
| 218 | |
| 219 | return ToSyncerSyncDataList(sync_data_list); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | syncer::SyncError ExtensionSyncService::ProcessSyncChanges( |
| 223 | const tracked_objects::Location& from_here, |
| 224 | const syncer::SyncChangeList& change_list) { |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 225 | for (const syncer::SyncChange& sync_change : change_list) { |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 226 | scoped_ptr<ExtensionSyncData> extension_sync_data( |
| 227 | ExtensionSyncData::CreateFromSyncChange(sync_change)); |
| 228 | if (extension_sync_data) |
| 229 | ApplySyncData(*extension_sync_data); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 230 | } |
| 231 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 232 | ExtensionSystem::Get(profile_)->app_sorting()->FixNTPOrdinalCollisions(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 233 | |
| 234 | return syncer::SyncError(); |
| 235 | } |
| 236 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 237 | ExtensionSyncData ExtensionSyncService::CreateSyncData( |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 238 | const Extension& extension) const { |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 239 | const ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 240 | // Query the enabled state from ExtensionPrefs rather than |
| 241 | // ExtensionService::IsExtensionEnabled - the latter uses ExtensionRegistry |
| 242 | // which might not have been updated yet (ExtensionPrefs are updated first, |
| 243 | // and we're listening for changes to these). |
| 244 | bool enabled = !extension_prefs->IsExtensionDisabled(extension.id()); |
| 245 | enabled = enabled && |
| 246 | !extension_prefs->IsExternalExtensionUninstalled(extension.id()); |
| 247 | // Blacklisted extensions are not marked as disabled in ExtensionPrefs. |
| 248 | enabled = enabled && |
| 249 | extension_prefs->GetExtensionBlacklistState(extension.id()) == |
| 250 | extensions::NOT_BLACKLISTED; |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 251 | int disable_reasons = extension_prefs->GetDisableReasons(extension.id()); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 252 | bool incognito_enabled = extensions::util::IsIncognitoEnabled(extension.id(), |
| 253 | profile_); |
| 254 | bool remote_install = |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 255 | extension_prefs->HasDisableReason(extension.id(), |
| 256 | Extension::DISABLE_REMOTE_INSTALL); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 257 | ExtensionSyncData::OptionalBoolean allowed_on_all_url = |
| 258 | GetAllowedOnAllUrlsOptionalBoolean(extension.id(), profile_); |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 259 | AppSorting* app_sorting = ExtensionSystem::Get(profile_)->app_sorting(); |
| 260 | |
| 261 | ExtensionSyncData result = extension.is_app() |
| 262 | ? ExtensionSyncData( |
| 263 | extension, enabled, disable_reasons, incognito_enabled, |
| 264 | remote_install, allowed_on_all_url, |
| 265 | app_sorting->GetAppLaunchOrdinal(extension.id()), |
| 266 | app_sorting->GetPageOrdinal(extension.id()), |
| 267 | extensions::GetLaunchTypePrefValue(extension_prefs, |
| 268 | extension.id())) |
| 269 | : ExtensionSyncData( |
| 270 | extension, enabled, disable_reasons, incognito_enabled, |
| 271 | remote_install, allowed_on_all_url); |
| 272 | |
| 273 | // If there's a pending update, send the new version to sync instead of the |
| 274 | // installed one. |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 275 | auto it = pending_updates_.find(extension.id()); |
| 276 | if (it != pending_updates_.end()) { |
| 277 | const base::Version& version = it->second.version; |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 278 | // If we have a pending version, it should be newer than the installed one. |
| 279 | DCHECK_EQ(-1, extension.version()->CompareTo(version)); |
| 280 | result.set_version(version); |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 281 | // If we'll re-enable the extension once it's updated, also send that back |
| 282 | // to sync. |
| 283 | if (it->second.grant_permissions_and_reenable) |
| 284 | result.set_enabled(true); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 285 | } |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 286 | return result; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 287 | } |
| 288 | |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 289 | void ExtensionSyncService::ApplySyncData( |
rdevlin.cronin | d1aa852 | 2015-02-13 00:25:57 | [diff] [blame] | 290 | const ExtensionSyncData& extension_sync_data) { |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 291 | syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS |
| 292 | : syncer::EXTENSIONS; |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 293 | const std::string& id = extension_sync_data.id(); |
| 294 | // Note: |extension| may be null if it hasn't been installed yet. |
| 295 | const Extension* extension = |
| 296 | ExtensionRegistry::Get(profile_)->GetInstalledExtension(id); |
| 297 | // TODO(bolms): we should really handle this better. The particularly bad |
| 298 | // case is where an app becomes an extension or vice versa, and we end up with |
| 299 | // a zombie extension that won't go away. |
| 300 | // TODO(treib): Is this still true? |
| 301 | if (extension && !IsCorrectSyncType(*extension, type)) |
| 302 | return; |
| 303 | |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 304 | SyncBundle* bundle = GetSyncBundle(type); |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 305 | // Forward to the bundle. This will just update the list of synced extensions. |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 306 | bundle->ApplySyncData(extension_sync_data); |
| 307 | |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 308 | // Handle uninstalls first. |
| 309 | if (extension_sync_data.uninstalled()) { |
| 310 | if (!ExtensionService::UninstallExtensionHelper( |
| 311 | extension_service(), id, extensions::UNINSTALL_REASON_SYNC)) { |
| 312 | LOG(WARNING) << "Could not uninstall extension " << id << " for sync"; |
| 313 | } |
| 314 | return; |
| 315 | } |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 316 | |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 317 | // Extension from sync was uninstalled by the user as an external extension. |
| 318 | // Honor user choice and skip installation/enabling. |
| 319 | // TODO(treib): Should we still apply pref changes? |
treib | 8668a30 | 2015-10-05 16:21:53 | [diff] [blame] | 320 | ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); |
| 321 | if (extension_prefs->IsExternalExtensionUninstalled(id)) { |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 322 | LOG(WARNING) << "Extension with id " << id |
| 323 | << " from sync was uninstalled as external extension"; |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | int version_compare_result = extension ? |
| 328 | extension->version()->CompareTo(extension_sync_data.version()) : 0; |
| 329 | |
| 330 | // Enable/disable the extension. |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 331 | bool reenable_after_update = false; |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 332 | if (extension_sync_data.enabled()) { |
| 333 | DCHECK(!extension_sync_data.disable_reasons()); |
| 334 | |
treib | 8668a30 | 2015-10-05 16:21:53 | [diff] [blame] | 335 | if (extension) { |
| 336 | // Only grant permissions if the sync data explicitly sets the disable |
| 337 | // reasons to Extension::DISABLE_NONE (as opposed to the legacy (<M45) |
| 338 | // case where they're not set at all), and if the version from sync |
| 339 | // matches our local one. |
| 340 | bool grant_permissions = extension_sync_data.supports_disable_reasons() && |
| 341 | (version_compare_result == 0); |
| 342 | if (grant_permissions) { |
| 343 | extension_service()->GrantPermissionsAndEnableExtension(extension); |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 344 | } else if (!extension_service()->IsExtensionEnabled(extension->id())) { |
treib | 8668a30 | 2015-10-05 16:21:53 | [diff] [blame] | 345 | // Only enable if the extension already has all required permissions. |
| 346 | scoped_ptr<const extensions::PermissionSet> granted_permissions = |
| 347 | extension_prefs->GetGrantedPermissions(extension->id()); |
| 348 | DCHECK(granted_permissions.get()); |
| 349 | bool is_privilege_increase = |
| 350 | extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease( |
| 351 | *granted_permissions, |
| 352 | extension->permissions_data()->active_permissions(), |
| 353 | extension->GetType()); |
| 354 | if (!is_privilege_increase) |
| 355 | extension_service()->EnableExtension(id); |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 356 | else if (extension_sync_data.supports_disable_reasons()) |
| 357 | reenable_after_update = true; |
treib | 40d3ad9 | 2015-10-20 18:15:42 | [diff] [blame^] | 358 | |
| 359 | #if defined(ENABLE_SUPERVISED_USERS) |
| 360 | if (is_privilege_increase && version_compare_result > 0 && |
| 361 | extensions::util::IsExtensionSupervised(extension, profile_)) { |
| 362 | SupervisedUserServiceFactory::GetForProfile(profile_) |
| 363 | ->AddExtensionUpdateRequest(id, *extension->version()); |
| 364 | } |
| 365 | #endif |
treib | 8668a30 | 2015-10-05 16:21:53 | [diff] [blame] | 366 | } |
| 367 | } else { |
| 368 | // The extension is not installed yet. Set it to enabled; we'll check for |
| 369 | // permission increase when it's actually installed. |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 370 | extension_service()->EnableExtension(id); |
treib | 8668a30 | 2015-10-05 16:21:53 | [diff] [blame] | 371 | } |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 372 | } else { |
| 373 | int disable_reasons = extension_sync_data.disable_reasons(); |
| 374 | if (extension_sync_data.remote_install()) { |
| 375 | if (!(disable_reasons & Extension::DISABLE_REMOTE_INSTALL)) { |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 376 | // Since disabled reasons are synced since M45, DISABLE_REMOTE_INSTALL |
| 377 | // should be among them already. |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 378 | DCHECK(!extension_sync_data.supports_disable_reasons()); |
| 379 | disable_reasons |= Extension::DISABLE_REMOTE_INSTALL; |
| 380 | } |
| 381 | } else if (!extension_sync_data.supports_disable_reasons()) { |
| 382 | // Legacy case (<M45), from before we synced disable reasons (see |
| 383 | // crbug.com/484214). |
| 384 | disable_reasons = Extension::DISABLE_UNKNOWN_FROM_SYNC; |
| 385 | } |
| 386 | |
| 387 | // In the non-legacy case (>=M45), clear any existing disable reasons first. |
| 388 | // Otherwise sync can't remove just some of them. |
| 389 | if (extension_sync_data.supports_disable_reasons()) |
treib | 8668a30 | 2015-10-05 16:21:53 | [diff] [blame] | 390 | extension_prefs->ClearDisableReasons(id); |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 391 | |
| 392 | extension_service()->DisableExtension(id, disable_reasons); |
| 393 | } |
| 394 | |
| 395 | // If the target extension has already been installed ephemerally, it can |
| 396 | // be promoted to a regular installed extension and downloading from the Web |
| 397 | // Store is not necessary. |
| 398 | if (extension && extensions::util::IsEphemeralApp(id, profile_)) |
| 399 | extension_service()->PromoteEphemeralApp(extension, true); |
| 400 | |
| 401 | // Cache whether the extension was already installed because setting the |
| 402 | // incognito flag invalidates the |extension| pointer (it reloads the |
| 403 | // extension). |
| 404 | bool extension_installed = (extension != nullptr); |
| 405 | |
| 406 | // Update the incognito flag. |
| 407 | extensions::util::SetIsIncognitoEnabled( |
| 408 | id, profile_, extension_sync_data.incognito_enabled()); |
| 409 | extension = nullptr; // No longer safe to use. |
| 410 | |
| 411 | // Update the all urls flag. |
| 412 | if (extension_sync_data.all_urls_enabled() != |
| 413 | ExtensionSyncData::BOOLEAN_UNSET) { |
| 414 | bool allowed = extension_sync_data.all_urls_enabled() == |
| 415 | ExtensionSyncData::BOOLEAN_TRUE; |
| 416 | extensions::util::SetAllowedScriptingOnAllUrls(id, profile_, allowed); |
| 417 | } |
| 418 | |
| 419 | // Set app-specific data. |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 420 | if (extension_sync_data.is_app()) { |
| 421 | if (extension_sync_data.app_launch_ordinal().IsValid() && |
| 422 | extension_sync_data.page_ordinal().IsValid()) { |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 423 | AppSorting* app_sorting = ExtensionSystem::Get(profile_)->app_sorting(); |
| 424 | app_sorting->SetAppLaunchOrdinal( |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 425 | id, |
| 426 | extension_sync_data.app_launch_ordinal()); |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 427 | app_sorting->SetPageOrdinal(id, extension_sync_data.page_ordinal()); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 428 | } |
| 429 | |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 430 | // The corresponding validation of this value during ExtensionSyncData |
| 431 | // population is in ExtensionSyncData::ToAppSpecifics. |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 432 | if (extension_sync_data.launch_type() >= extensions::LAUNCH_TYPE_FIRST && |
| 433 | extension_sync_data.launch_type() < extensions::NUM_LAUNCH_TYPES) { |
| 434 | extensions::SetLaunchType( |
| 435 | profile_, id, extension_sync_data.launch_type()); |
| 436 | } |
| 437 | |
| 438 | if (!extension_sync_data.bookmark_app_url().empty()) |
| 439 | ApplyBookmarkAppSyncData(extension_sync_data); |
| 440 | } |
| 441 | |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 442 | // Finally, trigger installation/update as required. |
| 443 | bool check_for_updates = false; |
| 444 | if (extension_installed) { |
| 445 | // If the extension is installed but outdated, store the new version. |
| 446 | if (version_compare_result < 0) { |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 447 | pending_updates_[id] = PendingUpdate(extension_sync_data.version(), |
| 448 | reenable_after_update); |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 449 | check_for_updates = true; |
| 450 | } |
| 451 | } else { |
| 452 | if (!extension_service()->pending_extension_manager()->AddFromSync( |
| 453 | id, |
| 454 | extension_sync_data.update_url(), |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 455 | extension_sync_data.version(), |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 456 | extensions::sync_helper::IsSyncable, |
| 457 | extension_sync_data.remote_install(), |
| 458 | extension_sync_data.installed_by_custodian())) { |
| 459 | LOG(WARNING) << "Could not add pending extension for " << id; |
| 460 | // This means that the extension is already pending installation, with a |
| 461 | // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 462 | // never be removed (we'll never install a syncable version of the |
| 463 | // extension), so that GetAllSyncData() continues to send it. |
| 464 | } |
| 465 | // Track pending extensions so that we can return them in GetAllSyncData(). |
| 466 | bundle->AddPendingExtensionData(id, extension_sync_data); |
| 467 | check_for_updates = true; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 468 | } |
| 469 | |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 470 | if (check_for_updates) |
| 471 | extension_service()->CheckForUpdatesSoon(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 472 | } |
| 473 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 474 | void ExtensionSyncService::ApplyBookmarkAppSyncData( |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 475 | const ExtensionSyncData& extension_sync_data) { |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 476 | DCHECK(extension_sync_data.is_app()); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 477 | |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 478 | // Process bookmark app sync if necessary. |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 479 | GURL bookmark_app_url(extension_sync_data.bookmark_app_url()); |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 480 | if (!bookmark_app_url.is_valid() || |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 481 | extension_sync_data.uninstalled()) { |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 482 | return; |
| 483 | } |
| 484 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 485 | const Extension* extension = |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 486 | extension_service()->GetInstalledExtension(extension_sync_data.id()); |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 487 | |
| 488 | // Return if there are no bookmark app details that need updating. |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 489 | if (extension && |
| 490 | extension->non_localized_name() == extension_sync_data.name() && |
| 491 | extension->description() == |
| 492 | extension_sync_data.bookmark_app_description()) { |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 493 | return; |
| 494 | } |
| 495 | |
| 496 | WebApplicationInfo web_app_info; |
| 497 | web_app_info.app_url = bookmark_app_url; |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 498 | web_app_info.title = base::UTF8ToUTF16(extension_sync_data.name()); |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 499 | web_app_info.description = |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 500 | base::UTF8ToUTF16(extension_sync_data.bookmark_app_description()); |
| 501 | if (!extension_sync_data.bookmark_app_icon_color().empty()) { |
benwells | d4b64a7 | 2014-12-11 12:38:27 | [diff] [blame] | 502 | extensions::image_util::ParseCSSColorString( |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 503 | extension_sync_data.bookmark_app_icon_color(), |
benwells | d4b64a7 | 2014-12-11 12:38:27 | [diff] [blame] | 504 | &web_app_info.generated_icon_color); |
| 505 | } |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 506 | for (const auto& icon : extension_sync_data.linked_icons()) { |
benwells | ed75d1b5 | 2015-04-29 02:39:19 | [diff] [blame] | 507 | WebApplicationInfo::IconInfo icon_info; |
| 508 | icon_info.url = icon.url; |
| 509 | icon_info.width = icon.size; |
| 510 | icon_info.height = icon.size; |
| 511 | web_app_info.icons.push_back(icon_info); |
| 512 | } |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 513 | |
| 514 | // If the bookmark app already exists, keep the old icons. |
| 515 | if (!extension) { |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 516 | CreateOrUpdateBookmarkApp(extension_service(), &web_app_info); |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 517 | } else { |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 518 | GetWebApplicationInfoFromApp(profile_, |
| 519 | extension, |
| 520 | base::Bind(&OnWebApplicationInfoLoaded, |
| 521 | web_app_info, |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 522 | extension_service()->AsWeakPtr())); |
[email protected] | d93fcd513 | 2014-04-24 08:42:45 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 526 | void ExtensionSyncService::SetSyncStartFlareForTesting( |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 527 | const syncer::SyncableService::StartSyncFlare& flare) { |
| 528 | flare_ = flare; |
| 529 | } |
| 530 | |
treib | 35f9ed0 | 2015-08-10 10:38:44 | [diff] [blame] | 531 | ExtensionService* ExtensionSyncService::extension_service() const { |
| 532 | return ExtensionSystem::Get(profile_)->extension_service(); |
| 533 | } |
| 534 | |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 535 | void ExtensionSyncService::OnExtensionInstalled( |
| 536 | content::BrowserContext* browser_context, |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 537 | const Extension* extension, |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 538 | bool is_update) { |
| 539 | DCHECK_EQ(profile_, browser_context); |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 540 | // Clear pending version if the installed one has caught up. |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 541 | auto it = pending_updates_.find(extension->id()); |
| 542 | if (it != pending_updates_.end()) { |
| 543 | int compare_result = extension->version()->CompareTo(it->second.version); |
| 544 | if (compare_result == 0 && it->second.grant_permissions_and_reenable) |
| 545 | extension_service()->GrantPermissionsAndEnableExtension(extension); |
| 546 | if (compare_result >= 0) |
| 547 | pending_updates_.erase(it); |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 548 | } |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 549 | SyncExtensionChangeIfNeeded(*extension); |
| 550 | } |
| 551 | |
| 552 | void ExtensionSyncService::OnExtensionUninstalled( |
| 553 | content::BrowserContext* browser_context, |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 554 | const Extension* extension, |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 555 | extensions::UninstallReason reason) { |
| 556 | DCHECK_EQ(profile_, browser_context); |
| 557 | // Don't bother syncing if the extension will be re-installed momentarily. |
| 558 | if (reason == extensions::UNINSTALL_REASON_REINSTALL || |
| 559 | !extensions::util::ShouldSync(extension, profile_)) |
| 560 | return; |
| 561 | |
| 562 | // TODO(tim): If we get here and IsSyncing is false, this will cause |
| 563 | // "back from the dead" style bugs, because sync will add-back the extension |
| 564 | // that was uninstalled here when MergeDataAndStartSyncing is called. |
| 565 | // See crbug.com/256795. |
| 566 | // Possible fix: Set NeedsSync here, then in MergeDataAndStartSyncing, if |
| 567 | // NeedsSync is set but the extension isn't installed, send a sync deletion. |
| 568 | syncer::ModelType type = |
| 569 | extension->is_app() ? syncer::APPS : syncer::EXTENSIONS; |
| 570 | SyncBundle* bundle = GetSyncBundle(type); |
| 571 | if (bundle->IsSyncing()) { |
| 572 | bundle->PushSyncDeletion(extension->id(), |
| 573 | CreateSyncData(*extension).GetSyncData()); |
| 574 | } else if (extension_service()->is_ready() && !flare_.is_null()) { |
| 575 | flare_.Run(type); // Tell sync to start ASAP. |
| 576 | } |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 577 | |
treib | 95e800c | 2015-10-13 15:48:31 | [diff] [blame] | 578 | pending_updates_.erase(extension->id()); |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | void ExtensionSyncService::OnExtensionStateChanged( |
| 582 | const std::string& extension_id, |
| 583 | bool state) { |
| 584 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| 585 | const Extension* extension = registry->GetInstalledExtension(extension_id); |
| 586 | // We can get pref change notifications for extensions that aren't installed |
| 587 | // (yet). In that case, we'll pick up the change later via ExtensionRegistry |
| 588 | // observation (in OnExtensionInstalled). |
| 589 | if (extension) |
| 590 | SyncExtensionChangeIfNeeded(*extension); |
| 591 | } |
| 592 | |
| 593 | void ExtensionSyncService::OnExtensionDisableReasonsChanged( |
| 594 | const std::string& extension_id, |
| 595 | int disabled_reasons) { |
| 596 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| 597 | const Extension* extension = registry->GetInstalledExtension(extension_id); |
| 598 | // We can get pref change notifications for extensions that aren't installed |
| 599 | // (yet). In that case, we'll pick up the change later via ExtensionRegistry |
| 600 | // observation (in OnExtensionInstalled). |
| 601 | if (extension) |
| 602 | SyncExtensionChangeIfNeeded(*extension); |
| 603 | } |
| 604 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 605 | SyncBundle* ExtensionSyncService::GetSyncBundle(syncer::ModelType type) { |
| 606 | return const_cast<SyncBundle*>( |
| 607 | const_cast<const ExtensionSyncService&>(*this).GetSyncBundle(type)); |
| 608 | } |
| 609 | |
| 610 | const SyncBundle* ExtensionSyncService::GetSyncBundle( |
| 611 | syncer::ModelType type) const { |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 612 | return (type == syncer::APPS) ? &app_sync_bundle_ : &extension_sync_bundle_; |
| 613 | } |
| 614 | |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 615 | std::vector<ExtensionSyncData> ExtensionSyncService::GetLocalSyncDataList( |
| 616 | syncer::ModelType type, |
| 617 | bool include_everything) const { |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 618 | // Collect the local state. |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 619 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 620 | std::vector<ExtensionSyncData> data; |
| 621 | // TODO(treib, kalman): Should we be including blacklisted/blocked extensions |
| 622 | // here? I.e. just calling registry->GeneratedInstalledExtensionsSet()? |
| 623 | // It would be more consistent, but the danger is that the black/blocklist |
| 624 | // hasn't been updated on all clients by the time sync has kicked in - |
| 625 | // so it's safest not to. Take care to add any other extension lists here |
| 626 | // in the future if they are added. |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 627 | FillSyncDataList( |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 628 | registry->enabled_extensions(), type, include_everything, &data); |
| 629 | FillSyncDataList( |
| 630 | registry->disabled_extensions(), type, include_everything, &data); |
| 631 | FillSyncDataList( |
| 632 | registry->terminated_extensions(), type, include_everything, &data); |
| 633 | return data; |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | void ExtensionSyncService::FillSyncDataList( |
| 637 | const ExtensionSet& extensions, |
| 638 | syncer::ModelType type, |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 639 | bool include_everything, |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 640 | std::vector<ExtensionSyncData>* sync_data_list) const { |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 641 | for (const scoped_refptr<const Extension>& extension : extensions) { |
| 642 | if (IsCorrectSyncType(*extension, type) && |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 643 | extensions::util::ShouldSync(extension.get(), profile_) && |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 644 | (include_everything || |
| 645 | ExtensionPrefs::Get(profile_)->NeedsSync(extension->id()))) { |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 646 | // We should never have pending data for an installed extension. |
| 647 | DCHECK(!GetSyncBundle(type)->HasPendingExtensionData(extension->id())); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 648 | sync_data_list->push_back(CreateSyncData(*extension)); |
| 649 | } |
| 650 | } |
| 651 | } |