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

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

Issue 2923013006: [Extensions Sync] Don't apply sync data for unsyncable extensions (Closed)
Patch Set: lazyboy's Created 3 years, 6 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
« no previous file with comments | « chrome/browser/extensions/extension_service_sync_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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_sync_service.h" 5 #include "chrome/browser/extensions/extension_sync_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // If we'll re-enable the extension once it's updated, also send that back 310 // If we'll re-enable the extension once it's updated, also send that back
311 // to sync. 311 // to sync.
312 if (it->second.grant_permissions_and_reenable) 312 if (it->second.grant_permissions_and_reenable)
313 result.set_enabled(true); 313 result.set_enabled(true);
314 } 314 }
315 return result; 315 return result;
316 } 316 }
317 317
318 void ExtensionSyncService::ApplySyncData( 318 void ExtensionSyncService::ApplySyncData(
319 const ExtensionSyncData& extension_sync_data) { 319 const ExtensionSyncData& extension_sync_data) {
320 const std::string& id = extension_sync_data.id();
321 // Note: |extension| may be null if it hasn't been installed yet.
322 const Extension* extension =
323 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id);
324 // If there is an existing extension that shouldn't be sync'd, don't
325 // apply this sync data. This can happen if the local version of an
326 // extension is default-installed, but the sync server has data from another
327 // (non-default-installed) installation. We can't apply the sync data because
328 // it would always override the local state (which would never get sync'd).
329 // See crbug.com/731824.
330 if (extension && !ShouldSync(*extension))
331 return;
332
320 // Ignore any pref change notifications etc. while we're applying incoming 333 // Ignore any pref change notifications etc. while we're applying incoming
321 // sync data, so that we don't end up notifying ourselves. 334 // sync data, so that we don't end up notifying ourselves.
322 base::AutoReset<bool> ignore_updates(&ignore_updates_, true); 335 base::AutoReset<bool> ignore_updates(&ignore_updates_, true);
323 336
324 // Note: this may cause an existing version of the extension to be reloaded. 337 // Note: this may cause an existing version of the extension to be reloaded.
325 extensions::util::SetWasInstalledByCustodian( 338 extensions::util::SetWasInstalledByCustodian(
326 extension_sync_data.id(), profile_, 339 extension_sync_data.id(), profile_,
327 extension_sync_data.installed_by_custodian()); 340 extension_sync_data.installed_by_custodian());
328 341
329 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS 342 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS
330 : syncer::EXTENSIONS; 343 : syncer::EXTENSIONS;
331 const std::string& id = extension_sync_data.id();
332 SyncBundle* bundle = GetSyncBundle(type); 344 SyncBundle* bundle = GetSyncBundle(type);
333 DCHECK(bundle->IsSyncing()); 345 DCHECK(bundle->IsSyncing());
334 // Note: |extension| may be null if it hasn't been installed yet.
335 const Extension* extension =
336 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id);
337 if (extension && !IsCorrectSyncType(*extension, type)) { 346 if (extension && !IsCorrectSyncType(*extension, type)) {
338 // The installed item isn't the same type as the sync data item, so we need 347 // The installed item isn't the same type as the sync data item, so we need
339 // to remove the sync data item; otherwise it will be a zombie that will 348 // to remove the sync data item; otherwise it will be a zombie that will
340 // keep coming back even if the installed item with this id is uninstalled. 349 // keep coming back even if the installed item with this id is uninstalled.
341 // First tell the bundle about the extension, so that it won't just ignore 350 // First tell the bundle about the extension, so that it won't just ignore
342 // the deletion, then push the deletion. 351 // the deletion, then push the deletion.
343 bundle->ApplySyncData(extension_sync_data); 352 bundle->ApplySyncData(extension_sync_data);
344 bundle->PushSyncDeletion(id, extension_sync_data.GetSyncData()); 353 bundle->PushSyncDeletion(id, extension_sync_data.GetSyncData());
345 return; 354 return;
346 } 355 }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 sync_data_list->push_back(CreateSyncData(*extension)); 723 sync_data_list->push_back(CreateSyncData(*extension));
715 } 724 }
716 } 725 }
717 } 726 }
718 727
719 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { 728 bool ExtensionSyncService::ShouldSync(const Extension& extension) const {
720 // Themes are handled by the ThemeSyncableService. 729 // Themes are handled by the ThemeSyncableService.
721 return extensions::util::ShouldSync(&extension, profile_) && 730 return extensions::util::ShouldSync(&extension, profile_) &&
722 !extension.is_theme(); 731 !extension.is_theme();
723 } 732 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_sync_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698