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

Unified Diff: chrome/browser/sync/glue/shared_change_processor.h

Issue 8065016: [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some comments addressed Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/shared_change_processor.h
diff --git a/chrome/browser/sync/glue/shared_change_processor.h b/chrome/browser/sync/glue/shared_change_processor.h
new file mode 100644
index 0000000000000000000000000000000000000000..705359f5b40ba246bcbb4f344486f9732248f757
--- /dev/null
+++ b/chrome/browser/sync/glue/shared_change_processor.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_
+#define CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
+#include "chrome/browser/sync/glue/generic_change_processor.h"
+#include "content/browser/browser_thread.h"
+
+class SyncData;
+class SyncableService;
+
+typedef std::vector<SyncData> SyncDataList;
+
+namespace browser_sync {
+
+
+// A ref-counted GenericChangeProcessor for use with datatypes that don't live
+// on the UI thread. We need to make it refcounted as the ownership transfer
+// from the DataTypeController is dependent on threading, and hence racy.
+// The SharedChangeProcessor should be created and destroyed on the UI thread,
+// but should only be connected and used on the same thread as the datatype it
+// interacts with. The only thread-safe method is Disconnect, which will
+// disconnect the change processor from the syncer, letting us shut down the
+// syncer/datatype without waiting for non-UI threads.
+class SharedChangeProcessor
+ : public GenericChangeProcessor,
+ public base::RefCountedThreadSafe<SharedChangeProcessor,
+ BrowserThread::DeleteOnUIThread> {
+ public:
+ // Create an uninitialized change processor (to be later connected).
+ explicit SharedChangeProcessor(UnrecoverableErrorHandler* error_handler);
+
+ // Connect to the syncer and the SyncableService specified. Should be called
+ // on the same thread the datatype resides.
+ virtual void Connect(SyncableService* local_service,
+ sync_api::UserShare* user_share);
+
+ // Disconnects from the syncer. May be called from any thread. After this, all
+ // attempts to interact with the change processor by |local_service_| are
+ // dropped and return errors. The syncer will be safe to shut down from the
+ // point of view of this datatype.
+ // Note: Once disconnected, you cannot reconnect without creating a new
+ // change processor.
+ virtual void Disconnect();
+
+ // GenericChangeProcessor implementation (with disconnect support).
+ // Should only be called on the same thread the datatype resides.
+ virtual SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const SyncChangeList& change_list) OVERRIDE;
+ virtual SyncError GetSyncDataForType(syncable::ModelType type,
+ SyncDataList* current_sync_data);
+ virtual bool SyncModelHasUserCreatedNodes(syncable::ModelType type,
+ bool* has_nodes);
+ virtual bool CryptoReadyIfNecessary(syncable::ModelType type);
+
+ protected:
+ friend class base::RefCountedThreadSafe<SharedChangeProcessor>;
+ friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
+ friend class DeleteTask<SharedChangeProcessor>;
+
+ virtual ~SharedChangeProcessor() OVERRIDE;
+
+ private:
+ // Monitor lock for this object. All methods that interact with the Syncer
+ // must aquire this lock and check whether we're disconnected or not. Once
+ // disconnected, all attempted changes to or loads from the syncer return
+ // errors. This enables us to shut down the syncer without having to wait
+ // for possibly non-UI thread datatypes to complete work.
+ base::Lock monitor_lock_;
+ bool disconnected_;
+
+ DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor);
+};
+
+} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_

Powered by Google App Engine
This is Rietveld 408576698