| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "chrome/browser/extensions/bookmark_app_helper.h" | 10 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 ExtensionSyncService::~ExtensionSyncService() {} | 107 ExtensionSyncService::~ExtensionSyncService() {} |
| 108 | 108 |
| 109 // static | 109 // static |
| 110 ExtensionSyncService* ExtensionSyncService::Get( | 110 ExtensionSyncService* ExtensionSyncService::Get( |
| 111 content::BrowserContext* context) { | 111 content::BrowserContext* context) { |
| 112 return ExtensionSyncServiceFactory::GetForBrowserContext(context); | 112 return ExtensionSyncServiceFactory::GetForBrowserContext(context); |
| 113 } | 113 } |
| 114 | 114 |
| 115 syncer::SyncData ExtensionSyncService::PrepareToSyncUninstallExtension( | 115 void ExtensionSyncService::SyncUninstallExtension( |
| 116 const Extension& extension) { | 116 const extensions::Extension& extension) { |
| 117 // Extract the data we need for sync now, but don't actually sync until we've | 117 if (!extensions::util::ShouldSync(&extension, profile_)) |
| 118 // completed the uninstallation. | 118 return; |
| 119 |
| 119 // TODO(tim): If we get here and IsSyncing is false, this will cause | 120 // TODO(tim): If we get here and IsSyncing is false, this will cause |
| 120 // "back from the dead" style bugs, because sync will add-back the extension | 121 // "back from the dead" style bugs, because sync will add-back the extension |
| 121 // that was uninstalled here when MergeDataAndStartSyncing is called. | 122 // that was uninstalled here when MergeDataAndStartSyncing is called. |
| 122 // See crbug.com/256795. | 123 // See crbug.com/256795. |
| 123 syncer::ModelType type = | 124 syncer::ModelType type = |
| 124 extension.is_app() ? syncer::APPS : syncer::EXTENSIONS; | 125 extension.is_app() ? syncer::APPS : syncer::EXTENSIONS; |
| 125 const SyncBundle* bundle = GetSyncBundle(type); | 126 SyncBundle* bundle = GetSyncBundle(type); |
| 126 if (extensions::util::ShouldSync(&extension, profile_)) { | 127 if (!bundle->IsSyncing()) { |
| 127 if (bundle->IsSyncing()) | |
| 128 return CreateSyncData(extension).GetSyncData(); | |
| 129 if (extension_service_->is_ready() && !flare_.is_null()) | 128 if (extension_service_->is_ready() && !flare_.is_null()) |
| 130 flare_.Run(type); // Tell sync to start ASAP. | 129 flare_.Run(type); // Tell sync to start ASAP. |
| 130 return; |
| 131 } | 131 } |
| 132 | 132 const std::string& id = extension.id(); |
| 133 return syncer::SyncData(); | 133 if (bundle->HasExtensionId(id)) |
| 134 } | 134 bundle->PushSyncDeletion(id, CreateSyncData(extension).GetSyncData()); |
| 135 | |
| 136 void ExtensionSyncService::ProcessSyncUninstallExtension( | |
| 137 const std::string& extension_id, | |
| 138 const syncer::SyncData& sync_data) { | |
| 139 SyncBundle* bundle = GetSyncBundle(sync_data.GetDataType()); | |
| 140 if (bundle->HasExtensionId(extension_id)) | |
| 141 bundle->PushSyncDeletion(extension_id, sync_data); | |
| 142 } | 135 } |
| 143 | 136 |
| 144 void ExtensionSyncService::SyncEnableExtension(const Extension& extension) { | 137 void ExtensionSyncService::SyncEnableExtension(const Extension& extension) { |
| 145 // Syncing may not have started yet, so handle pending enables. | 138 // Syncing may not have started yet, so handle pending enables. |
| 146 if (extensions::util::ShouldSync(&extension, profile_)) | 139 if (extensions::util::ShouldSync(&extension, profile_)) |
| 147 GetPendingEnables(extension.is_app())->Add(extension.id()); | 140 GetPendingEnables(extension.is_app())->Add(extension.id()); |
| 148 | 141 |
| 149 SyncExtensionChangeIfNeeded(extension); | 142 SyncExtensionChangeIfNeeded(extension); |
| 150 } | 143 } |
| 151 | 144 |
| 152 void ExtensionSyncService::SyncDisableExtension(const Extension& extension) { | 145 void ExtensionSyncService::SyncDisableExtension(const Extension& extension) { |
| 153 // Syncing may not have started yet, so handle pending enables. | 146 // Syncing may not have started yet, so handle pending enables. |
| 154 if (extensions::util::ShouldSync(&extension, profile_)) | 147 if (extensions::util::ShouldSync(&extension, profile_)) |
| 155 GetPendingEnables(extension.is_app())->Remove(extension.id()); | 148 GetPendingEnables(extension.is_app())->Remove(extension.id()); |
| 156 | 149 |
| 157 SyncExtensionChangeIfNeeded(extension); | 150 SyncExtensionChangeIfNeeded(extension); |
| 158 } | 151 } |
| 159 | 152 |
| 160 void ExtensionSyncService::SyncExtensionChangeIfNeeded( | 153 void ExtensionSyncService::SyncExtensionChangeIfNeeded( |
| 161 const Extension& extension) { | 154 const Extension& extension) { |
| 162 if (!extensions::util::ShouldSync(&extension, profile_)) | 155 if (!extensions::util::ShouldSync(&extension, profile_)) |
| 163 return; | 156 return; |
| 164 | 157 |
| 165 syncer::ModelType type = | 158 syncer::ModelType type = |
| 166 extension.is_app() ? syncer::APPS : syncer::EXTENSIONS; | 159 extension.is_app() ? syncer::APPS : syncer::EXTENSIONS; |
| 167 SyncBundle* bundle = GetSyncBundle(type); | 160 SyncBundle* bundle = GetSyncBundle(type); |
| 168 if (bundle->IsSyncing()) | 161 if (bundle->IsSyncing()) |
| 169 bundle->PushSyncChangeIfNeeded(extension); | 162 bundle->PushSyncAddOrUpdate(extension); |
| 170 else if (extension_service_->is_ready() && !flare_.is_null()) | 163 else if (extension_service_->is_ready() && !flare_.is_null()) |
| 171 flare_.Run(type); | 164 flare_.Run(type); |
| 172 } | 165 } |
| 173 | 166 |
| 174 syncer::SyncMergeResult ExtensionSyncService::MergeDataAndStartSyncing( | 167 syncer::SyncMergeResult ExtensionSyncService::MergeDataAndStartSyncing( |
| 175 syncer::ModelType type, | 168 syncer::ModelType type, |
| 176 const syncer::SyncDataList& initial_sync_data, | 169 const syncer::SyncDataList& initial_sync_data, |
| 177 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 170 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 178 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { | 171 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { |
| 179 CHECK(sync_processor.get()); | 172 CHECK(sync_processor.get()); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // non-INTERNAL location. Add to pending_sync_data, even though it will | 513 // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 521 // never be removed (we'll never install a syncable version of the | 514 // never be removed (we'll never install a syncable version of the |
| 522 // extension), so that GetAllSyncData() continues to send it. | 515 // extension), so that GetAllSyncData() continues to send it. |
| 523 } | 516 } |
| 524 // Track pending extensions so that we can return them in GetAllSyncData(). | 517 // Track pending extensions so that we can return them in GetAllSyncData(). |
| 525 return false; | 518 return false; |
| 526 } | 519 } |
| 527 | 520 |
| 528 return true; | 521 return true; |
| 529 } | 522 } |
| OLD | NEW |