[Sync] Have SyncableService's take ownership of their SyncChangeProcessor.

The UIDataTypeController now uses a SharedChangeProcessor, and passes a ref
to the SyncableService's. Every SyncableService now owns its own change
processor. Additionally, we use the ScopedPtr::Pass semantics for passing
around SyncChangeProcessors to ensure SyncableServices properly take
ownership.

This, along with all the test updates it requires (most of the patch) fixes
several leaks introduced in the previous patch to remove the Syncable Service
Adapter. SyncableServiceMock is removed as it didn't play nice with
scoped_ptr parameters (and was hardly used).

BUG=117098,117538
TEST=unit_tests with valgrind/drmemory/heapcheck
[email protected]

Review URL: https://chromiumcodereview.appspot.com/9749012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128578 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 968b3fcc..070e378 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -1266,13 +1266,19 @@
 }  // namespace
 
 ExtensionService::SyncBundle::SyncBundle()
-  : filter(IsSyncableNone),
-    sync_processor(NULL) {
+  : filter(IsSyncableNone) {
 }
 
 ExtensionService::SyncBundle::~SyncBundle() {
 }
 
+void ExtensionService::SyncBundle::Reset() {
+  filter = IsSyncableNone;
+  synced_extensions.clear();
+  pending_sync_data.clear();
+  sync_processor.reset();
+}
+
 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const {
   return synced_extensions.find(id) != synced_extensions.end();
 }
@@ -1335,9 +1341,7 @@
 SyncError ExtensionService::MergeDataAndStartSyncing(
     syncable::ModelType type,
     const SyncDataList& initial_sync_data,
-    SyncChangeProcessor* sync_processor) {
-  CHECK(sync_processor);
-
+    scoped_ptr<SyncChangeProcessor> sync_processor) {
   SyncBundle* bundle = NULL;
 
   switch (type) {
@@ -1354,8 +1358,9 @@
     default:
       LOG(FATAL) << "Got " << type << " ModelType";
   }
-
-  bundle->sync_processor = sync_processor;
+  DCHECK(!bundle->sync_processor.get());
+  DCHECK(sync_processor.get());
+  bundle->sync_processor = sync_processor.Pass();
 
   // Process extensions from sync.
   for (SyncDataList::const_iterator i = initial_sync_data.begin();
@@ -1391,8 +1396,7 @@
 void ExtensionService::StopSyncing(syncable::ModelType type) {
   SyncBundle* bundle = GetSyncBundleForModelType(type);
   CHECK(bundle);
-  // This is the simplest way to clear out the bundle.
-  *bundle = SyncBundle();
+  bundle->Reset();
 }
 
 SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const {