| OLD | NEW |
| 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 <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 DCHECK_EQ(synced_info.app_url, loaded_info.app_url); | 51 DCHECK_EQ(synced_info.app_url, loaded_info.app_url); |
| 52 | 52 |
| 53 if (!extension_service) | 53 if (!extension_service) |
| 54 return; | 54 return; |
| 55 | 55 |
| 56 // Use the old icons if they exist. | 56 // Use the old icons if they exist. |
| 57 synced_info.icons = loaded_info.icons; | 57 synced_info.icons = loaded_info.icons; |
| 58 CreateOrUpdateBookmarkApp(extension_service.get(), synced_info); | 58 CreateOrUpdateBookmarkApp(extension_service.get(), synced_info); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool ShouldSyncApp(const Extension* extension, Profile* profile) { | |
| 62 return extensions::sync_helper::IsSyncableApp(extension) && | |
| 63 !extensions::util::IsEphemeralApp(extension->id(), profile); | |
| 64 } | |
| 65 | |
| 66 } // namespace | 61 } // namespace |
| 67 | 62 |
| 68 ExtensionSyncService::ExtensionSyncService(Profile* profile, | 63 ExtensionSyncService::ExtensionSyncService(Profile* profile, |
| 69 ExtensionPrefs* extension_prefs, | 64 ExtensionPrefs* extension_prefs, |
| 70 ExtensionService* extension_service) | 65 ExtensionService* extension_service) |
| 71 : profile_(profile), | 66 : profile_(profile), |
| 72 extension_prefs_(extension_prefs), | 67 extension_prefs_(extension_prefs), |
| 73 extension_service_(extension_service), | 68 extension_service_(extension_service), |
| 74 app_sync_bundle_(this), | 69 app_sync_bundle_(this), |
| 75 extension_sync_bundle_(this), | 70 extension_sync_bundle_(this), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 } | 91 } |
| 97 | 92 |
| 98 syncer::SyncChange ExtensionSyncService::PrepareToSyncUninstallExtension( | 93 syncer::SyncChange ExtensionSyncService::PrepareToSyncUninstallExtension( |
| 99 const extensions::Extension* extension, bool extensions_ready) { | 94 const extensions::Extension* extension, bool extensions_ready) { |
| 100 // Extract the data we need for sync now, but don't actually sync until we've | 95 // Extract the data we need for sync now, but don't actually sync until we've |
| 101 // completed the uninstallation. | 96 // completed the uninstallation. |
| 102 // TODO(tim): If we get here and IsSyncing is false, this will cause | 97 // TODO(tim): If we get here and IsSyncing is false, this will cause |
| 103 // "back from the dead" style bugs, because sync will add-back the extension | 98 // "back from the dead" style bugs, because sync will add-back the extension |
| 104 // that was uninstalled here when MergeDataAndStartSyncing is called. | 99 // that was uninstalled here when MergeDataAndStartSyncing is called. |
| 105 // See crbug.com/256795. | 100 // See crbug.com/256795. |
| 106 if (ShouldSyncApp(extension, profile_)) { | 101 if (extensions::util::ShouldSyncApp(extension, profile_)) { |
| 107 if (app_sync_bundle_.IsSyncing()) | 102 if (app_sync_bundle_.IsSyncing()) |
| 108 return app_sync_bundle_.CreateSyncChangeToDelete(extension); | 103 return app_sync_bundle_.CreateSyncChangeToDelete(extension); |
| 109 else if (extensions_ready && !flare_.is_null()) | 104 else if (extensions_ready && !flare_.is_null()) |
| 110 flare_.Run(syncer::APPS); // Tell sync to start ASAP. | 105 flare_.Run(syncer::APPS); // Tell sync to start ASAP. |
| 111 } else if (extensions::sync_helper::IsSyncableExtension(extension)) { | 106 } else if (extensions::sync_helper::IsSyncableExtension(extension)) { |
| 112 if (extension_sync_bundle_.IsSyncing()) | 107 if (extension_sync_bundle_.IsSyncing()) |
| 113 return extension_sync_bundle_.CreateSyncChangeToDelete(extension); | 108 return extension_sync_bundle_.CreateSyncChangeToDelete(extension); |
| 114 else if (extensions_ready && !flare_.is_null()) | 109 else if (extensions_ready && !flare_.is_null()) |
| 115 flare_.Run(syncer::EXTENSIONS); // Tell sync to start ASAP. | 110 flare_.Run(syncer::EXTENSIONS); // Tell sync to start ASAP. |
| 116 } | 111 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 127 } else if (extension_sync_bundle_.HasExtensionId(extension_id) && | 122 } else if (extension_sync_bundle_.HasExtensionId(extension_id) && |
| 128 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) { | 123 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) { |
| 129 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change); | 124 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change); |
| 130 } | 125 } |
| 131 } | 126 } |
| 132 | 127 |
| 133 void ExtensionSyncService::SyncEnableExtension( | 128 void ExtensionSyncService::SyncEnableExtension( |
| 134 const extensions::Extension& extension) { | 129 const extensions::Extension& extension) { |
| 135 | 130 |
| 136 // Syncing may not have started yet, so handle pending enables. | 131 // Syncing may not have started yet, so handle pending enables. |
| 137 if (ShouldSyncApp(&extension, profile_)) | 132 if (extensions::util::ShouldSyncApp(&extension, profile_)) |
| 138 pending_app_enables_.OnExtensionEnabled(extension.id()); | 133 pending_app_enables_.OnExtensionEnabled(extension.id()); |
| 139 | 134 |
| 140 if (extensions::sync_helper::IsSyncableExtension(&extension)) | 135 if (extensions::sync_helper::IsSyncableExtension(&extension)) |
| 141 pending_extension_enables_.OnExtensionEnabled(extension.id()); | 136 pending_extension_enables_.OnExtensionEnabled(extension.id()); |
| 142 | 137 |
| 143 SyncExtensionChangeIfNeeded(extension); | 138 SyncExtensionChangeIfNeeded(extension); |
| 144 } | 139 } |
| 145 | 140 |
| 146 void ExtensionSyncService::SyncDisableExtension( | 141 void ExtensionSyncService::SyncDisableExtension( |
| 147 const extensions::Extension& extension) { | 142 const extensions::Extension& extension) { |
| 148 | 143 |
| 149 // Syncing may not have started yet, so handle pending enables. | 144 // Syncing may not have started yet, so handle pending enables. |
| 150 if (ShouldSyncApp(&extension, profile_)) | 145 if (extensions::util::ShouldSyncApp(&extension, profile_)) |
| 151 pending_app_enables_.OnExtensionDisabled(extension.id()); | 146 pending_app_enables_.OnExtensionDisabled(extension.id()); |
| 152 | 147 |
| 153 if (extensions::sync_helper::IsSyncableExtension(&extension)) | 148 if (extensions::sync_helper::IsSyncableExtension(&extension)) |
| 154 pending_extension_enables_.OnExtensionDisabled(extension.id()); | 149 pending_extension_enables_.OnExtensionDisabled(extension.id()); |
| 155 | 150 |
| 156 SyncExtensionChangeIfNeeded(extension); | 151 SyncExtensionChangeIfNeeded(extension); |
| 157 } | 152 } |
| 158 | 153 |
| 159 syncer::SyncMergeResult ExtensionSyncService::MergeDataAndStartSyncing( | 154 syncer::SyncMergeResult ExtensionSyncService::MergeDataAndStartSyncing( |
| 160 syncer::ModelType type, | 155 syncer::ModelType type, |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 } | 526 } |
| 532 // Track pending extensions so that we can return them in GetAllSyncData(). | 527 // Track pending extensions so that we can return them in GetAllSyncData(). |
| 533 return false; | 528 return false; |
| 534 } | 529 } |
| 535 | 530 |
| 536 return true; | 531 return true; |
| 537 } | 532 } |
| 538 | 533 |
| 539 void ExtensionSyncService::SyncExtensionChangeIfNeeded( | 534 void ExtensionSyncService::SyncExtensionChangeIfNeeded( |
| 540 const Extension& extension) { | 535 const Extension& extension) { |
| 541 if (ShouldSyncApp(&extension, profile_)) { | 536 if (extensions::util::ShouldSyncApp(&extension, profile_)) { |
| 542 if (app_sync_bundle_.IsSyncing()) | 537 if (app_sync_bundle_.IsSyncing()) |
| 543 app_sync_bundle_.SyncChangeIfNeeded(extension); | 538 app_sync_bundle_.SyncChangeIfNeeded(extension); |
| 544 else if (extension_service_->is_ready() && !flare_.is_null()) | 539 else if (extension_service_->is_ready() && !flare_.is_null()) |
| 545 flare_.Run(syncer::APPS); | 540 flare_.Run(syncer::APPS); |
| 546 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { | 541 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { |
| 547 if (extension_sync_bundle_.IsSyncing()) | 542 if (extension_sync_bundle_.IsSyncing()) |
| 548 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 543 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
| 549 else if (extension_service_->is_ready() && !flare_.is_null()) | 544 else if (extension_service_->is_ready() && !flare_.is_null()) |
| 550 flare_.Run(syncer::EXTENSIONS); | 545 flare_.Run(syncer::EXTENSIONS); |
| 551 } | 546 } |
| 552 } | 547 } |
| OLD | NEW |