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

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

Issue 9749012: [Sync] Have SyncableService's take ownership of their SyncChangeProcessor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflict Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 } else { 1259 } else {
1260 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; 1260 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
1261 } 1261 }
1262 } 1262 }
1263 1263
1264 namespace { 1264 namespace {
1265 bool IsSyncableNone(const Extension& extension) { return false; } 1265 bool IsSyncableNone(const Extension& extension) { return false; }
1266 } // namespace 1266 } // namespace
1267 1267
1268 ExtensionService::SyncBundle::SyncBundle() 1268 ExtensionService::SyncBundle::SyncBundle()
1269 : filter(IsSyncableNone), 1269 : filter(IsSyncableNone) {
1270 sync_processor(NULL) {
1271 } 1270 }
1272 1271
1273 ExtensionService::SyncBundle::~SyncBundle() { 1272 ExtensionService::SyncBundle::~SyncBundle() {
1274 } 1273 }
1275 1274
1275 void ExtensionService::SyncBundle::Reset() {
1276 filter = IsSyncableNone;
1277 synced_extensions.clear();
1278 pending_sync_data.clear();
1279 sync_processor.reset();
1280 }
1281
1276 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { 1282 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const {
1277 return synced_extensions.find(id) != synced_extensions.end(); 1283 return synced_extensions.find(id) != synced_extensions.end();
1278 } 1284 }
1279 1285
1280 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) 1286 bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id)
1281 const { 1287 const {
1282 return pending_sync_data.find(id) != pending_sync_data.end(); 1288 return pending_sync_data.find(id) != pending_sync_data.end();
1283 } 1289 }
1284 1290
1285 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension( 1291 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForModelType( 1334 ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForModelType(
1329 syncable::ModelType type) { 1335 syncable::ModelType type) {
1330 GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY(); 1336 GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY();
1331 } 1337 }
1332 1338
1333 #undef GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY 1339 #undef GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY
1334 1340
1335 SyncError ExtensionService::MergeDataAndStartSyncing( 1341 SyncError ExtensionService::MergeDataAndStartSyncing(
1336 syncable::ModelType type, 1342 syncable::ModelType type,
1337 const SyncDataList& initial_sync_data, 1343 const SyncDataList& initial_sync_data,
1338 SyncChangeProcessor* sync_processor) { 1344 scoped_ptr<SyncChangeProcessor> sync_processor) {
1339 CHECK(sync_processor);
1340
1341 SyncBundle* bundle = NULL; 1345 SyncBundle* bundle = NULL;
1342 1346
1343 switch (type) { 1347 switch (type) {
1344 case syncable::EXTENSIONS: 1348 case syncable::EXTENSIONS:
1345 bundle = &extension_sync_bundle_; 1349 bundle = &extension_sync_bundle_;
1346 bundle->filter = IsSyncableExtension; 1350 bundle->filter = IsSyncableExtension;
1347 break; 1351 break;
1348 1352
1349 case syncable::APPS: 1353 case syncable::APPS:
1350 bundle = &app_sync_bundle_; 1354 bundle = &app_sync_bundle_;
1351 bundle->filter = IsSyncableApp; 1355 bundle->filter = IsSyncableApp;
1352 break; 1356 break;
1353 1357
1354 default: 1358 default:
1355 LOG(FATAL) << "Got " << type << " ModelType"; 1359 LOG(FATAL) << "Got " << type << " ModelType";
1356 } 1360 }
1357 1361 DCHECK(!bundle->sync_processor.get());
1358 bundle->sync_processor = sync_processor; 1362 DCHECK(sync_processor.get());
1363 bundle->sync_processor = sync_processor.Pass();
1359 1364
1360 // Process extensions from sync. 1365 // Process extensions from sync.
1361 for (SyncDataList::const_iterator i = initial_sync_data.begin(); 1366 for (SyncDataList::const_iterator i = initial_sync_data.begin();
1362 i != initial_sync_data.end(); 1367 i != initial_sync_data.end();
1363 ++i) { 1368 ++i) {
1364 ExtensionSyncData extension_sync_data = ExtensionSyncData(*i); 1369 ExtensionSyncData extension_sync_data = ExtensionSyncData(*i);
1365 bundle->synced_extensions.insert(extension_sync_data.id()); 1370 bundle->synced_extensions.insert(extension_sync_data.id());
1366 ProcessExtensionSyncData(extension_sync_data, *bundle); 1371 ProcessExtensionSyncData(extension_sync_data, *bundle);
1367 } 1372 }
1368 1373
(...skipping 15 matching lines...) Expand all
1384 bundle->sync_processor->ProcessSyncChanges(FROM_HERE, sync_change_list); 1389 bundle->sync_processor->ProcessSyncChanges(FROM_HERE, sync_change_list);
1385 1390
1386 extension_prefs_->extension_sorting()->FixNTPOrdinalCollisions(); 1391 extension_prefs_->extension_sorting()->FixNTPOrdinalCollisions();
1387 1392
1388 return SyncError(); 1393 return SyncError();
1389 } 1394 }
1390 1395
1391 void ExtensionService::StopSyncing(syncable::ModelType type) { 1396 void ExtensionService::StopSyncing(syncable::ModelType type) {
1392 SyncBundle* bundle = GetSyncBundleForModelType(type); 1397 SyncBundle* bundle = GetSyncBundleForModelType(type);
1393 CHECK(bundle); 1398 CHECK(bundle);
1394 // This is the simplest way to clear out the bundle. 1399 bundle->Reset();
1395 *bundle = SyncBundle();
1396 } 1400 }
1397 1401
1398 SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const { 1402 SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const {
1399 const SyncBundle* bundle = GetSyncBundleForModelTypeConst(type); 1403 const SyncBundle* bundle = GetSyncBundleForModelTypeConst(type);
1400 CHECK(bundle); 1404 CHECK(bundle);
1401 std::vector<ExtensionSyncData> extension_sync_data = GetSyncDataList(*bundle); 1405 std::vector<ExtensionSyncData> extension_sync_data = GetSyncDataList(*bundle);
1402 SyncDataList result(extension_sync_data.size()); 1406 SyncDataList result(extension_sync_data.size());
1403 for (int i = 0; i < static_cast<int>(extension_sync_data.size()); ++i) { 1407 for (int i = 0; i < static_cast<int>(extension_sync_data.size()); ++i) {
1404 result[i] = extension_sync_data[i].GetSyncData(); 1408 result[i] = extension_sync_data[i].GetSyncData();
1405 } 1409 }
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 return api_resource_controller_; 2641 return api_resource_controller_;
2638 } 2642 }
2639 2643
2640 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { 2644 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() {
2641 if (!rules_registry_service_.get()) { 2645 if (!rules_registry_service_.get()) {
2642 rules_registry_service_.reset( 2646 rules_registry_service_.reset(
2643 new extensions::RulesRegistryService(profile_)); 2647 new extensions::RulesRegistryService(profile_));
2644 } 2648 }
2645 return rules_registry_service_.get(); 2649 return rules_registry_service_.get();
2646 } 2650 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698