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

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

Issue 1778923003: Fix extensions sync in cases where items change type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback Created 4 years, 9 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
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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 void ExtensionSyncService::ApplySyncData( 312 void ExtensionSyncService::ApplySyncData(
313 const ExtensionSyncData& extension_sync_data) { 313 const ExtensionSyncData& extension_sync_data) {
314 // Ignore any pref change notifications etc. while we're applying incoming 314 // Ignore any pref change notifications etc. while we're applying incoming
315 // sync data, so that we don't end up notifying ourselves. 315 // sync data, so that we don't end up notifying ourselves.
316 base::AutoReset<bool> ignore_updates(&ignore_updates_, true); 316 base::AutoReset<bool> ignore_updates(&ignore_updates_, true);
317 317
318 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS 318 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS
319 : syncer::EXTENSIONS; 319 : syncer::EXTENSIONS;
320 const std::string& id = extension_sync_data.id(); 320 const std::string& id = extension_sync_data.id();
321 SyncBundle* bundle = GetSyncBundle(type); 321 SyncBundle* bundle = GetSyncBundle(type);
322 DCHECK(bundle->IsSyncing());
322 // Note: |extension| may be null if it hasn't been installed yet. 323 // Note: |extension| may be null if it hasn't been installed yet.
323 const Extension* extension = 324 const Extension* extension =
324 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id); 325 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id);
325 // TODO(bolms): we should really handle this better. The particularly bad
326 // case is where an app becomes an extension or vice versa, and we end up with
327 // a zombie extension that won't go away.
328 // TODO(treib): Is this still true?
329 if (extension && !IsCorrectSyncType(*extension, type)) { 326 if (extension && !IsCorrectSyncType(*extension, type)) {
330 // Special hack: There was a bug where themes incorrectly ended up in the 327 // The installed item isn't the same type as the sync data item, so we need
331 // syncer::EXTENSIONS type. If we get incoming sync data for a theme, clean 328 // to remove the sync data item; otherwise it will be a zombie that will
332 // it up. crbug.com/558299 329 // keep coming back even if the installed item with this id is uninstalled.
333 // TODO(treib,devlin): Remove this after M52 or so. 330 // First tell the bundle about the extension, so that it won't just ignore
334 if (extension->is_theme()) { 331 // the deletion, then push the deletion.
335 // First tell the bundle about the extension, so that it won't just ignore 332 bundle->ApplySyncData(extension_sync_data);
336 // the deletion. 333 bundle->PushSyncDeletion(id, extension_sync_data.GetSyncData());
337 bundle->ApplySyncData(extension_sync_data);
338 bundle->PushSyncDeletion(id, extension_sync_data.GetSyncData());
339 }
340 return; 334 return;
341 } 335 }
342 336
343 // Forward to the bundle. This will just update the list of synced extensions. 337 // Forward to the bundle. This will just update the list of synced extensions.
344 bundle->ApplySyncData(extension_sync_data); 338 bundle->ApplySyncData(extension_sync_data);
345 339
346 // Handle uninstalls first. 340 // Handle uninstalls first.
347 if (extension_sync_data.uninstalled()) { 341 if (extension_sync_data.uninstalled()) {
348 if (!ExtensionService::UninstallExtensionHelper( 342 if (!ExtensionService::UninstallExtensionHelper(
349 extension_service(), id, extensions::UNINSTALL_REASON_SYNC)) { 343 extension_service(), id, extensions::UNINSTALL_REASON_SYNC)) {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 589
596 void ExtensionSyncService::OnExtensionInstalled( 590 void ExtensionSyncService::OnExtensionInstalled(
597 content::BrowserContext* browser_context, 591 content::BrowserContext* browser_context,
598 const Extension* extension, 592 const Extension* extension,
599 bool is_update) { 593 bool is_update) {
600 DCHECK_EQ(profile_, browser_context); 594 DCHECK_EQ(profile_, browser_context);
601 // Clear pending version if the installed one has caught up. 595 // Clear pending version if the installed one has caught up.
602 auto it = pending_updates_.find(extension->id()); 596 auto it = pending_updates_.find(extension->id());
603 if (it != pending_updates_.end()) { 597 if (it != pending_updates_.end()) {
604 int compare_result = extension->version()->CompareTo(it->second.version); 598 int compare_result = extension->version()->CompareTo(it->second.version);
605 if (compare_result == 0 && it->second.grant_permissions_and_reenable) 599 if (compare_result == 0 && it->second.grant_permissions_and_reenable) {
600 // The call to SyncExtensionChangeIfNeeded below will take care of syncing
601 // changes to this extension, so we don't want to trigger sync activity
602 // from the call to GrantPermissionsAndEnableExtension.
603 base::AutoReset<bool> ignore_updates(&ignore_updates_, true);
606 extension_service()->GrantPermissionsAndEnableExtension(extension); 604 extension_service()->GrantPermissionsAndEnableExtension(extension);
605 }
607 if (compare_result >= 0) 606 if (compare_result >= 0)
608 pending_updates_.erase(it); 607 pending_updates_.erase(it);
609 } 608 }
610 SyncExtensionChangeIfNeeded(*extension); 609 SyncExtensionChangeIfNeeded(*extension);
611 } 610 }
612 611
613 void ExtensionSyncService::OnExtensionUninstalled( 612 void ExtensionSyncService::OnExtensionUninstalled(
614 content::BrowserContext* browser_context, 613 content::BrowserContext* browser_context,
615 const Extension* extension, 614 const Extension* extension,
616 extensions::UninstallReason reason) { 615 extensions::UninstallReason reason) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 sync_data_list->push_back(CreateSyncData(*extension)); 703 sync_data_list->push_back(CreateSyncData(*extension));
705 } 704 }
706 } 705 }
707 } 706 }
708 707
709 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { 708 bool ExtensionSyncService::ShouldSync(const Extension& extension) const {
710 // Themes are handled by the ThemeSyncableService. 709 // Themes are handled by the ThemeSyncableService.
711 return extensions::util::ShouldSync(&extension, profile_) && 710 return extensions::util::ShouldSync(&extension, profile_) &&
712 !extension.is_theme(); 711 !extension.is_theme();
713 } 712 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_sync_unittest.cc ('k') | chrome/test/data/extensions/sync_datatypes/key.pem » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698