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..1613c621206ac9967cf2efc8547a0e14185b46df |
--- /dev/null |
+++ b/chrome/browser/sync/glue/shared_change_processor.h |
@@ -0,0 +1,101 @@ |
+// 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/location.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/synchronization/lock.h" |
+#include "base/threading/non_thread_safe.h" |
+#include "chrome/browser/sync/api/sync_change_processor.h" |
+#include "chrome/browser/sync/api/sync_error.h" |
+#include "chrome/browser/sync/engine/model_safe_worker.h" |
+ |
+class ProfileSyncService; |
+class SyncData; |
+class SyncableService; |
+ |
+typedef std::vector<SyncData> SyncDataList; |
+ |
+namespace browser_sync { |
+ |
+class GenericChangeProcessor; |
+ |
+// A ref-counted wrapper around a 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 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 methods is Disconnect, which will disconnect from the |
akalin
2011/10/11 22:41:08
methods is -> method is
Nicolas Zea
2011/10/12 04:24:19
Done.
|
+// generic change processor, letting us shut down the syncer/datatype without |
+// waiting for non-UI threads. |
+// |
+// Note: since we control the work being done while holding the lock, we ensure |
+// no I/O or other intensive work is done while blocking the UI thread (all |
+// the work is in-memory sync interactions). |
+class SharedChangeProcessor |
+ : public base::RefCountedThreadSafe<SharedChangeProcessor>, |
+ public base::NonThreadSafe { |
akalin
2011/10/11 22:41:08
I don't think this class counts as NonThreadSafe.
Nicolas Zea
2011/10/12 04:24:19
Done.
|
+ public: |
+ // Create a blank SharedChangeProcessor (to be later connected). |
akalin
2011/10/11 22:41:08
blank -> disconnected?
Nicolas Zea
2011/10/12 04:24:19
No, once disconnected it can't be connected. This
|
+ SharedChangeProcessor(); |
+ |
+ // Connect to the GenericChangeProcessor provided. We take ownership of |
+ // |generic_change_processor_| and delete on when disconnected or destroyed. |
akalin
2011/10/11 22:41:08
on when -> when
Nicolas Zea
2011/10/12 04:24:19
Changed to take in the sync components and create
|
+ virtual void Connect(GenericChangeProcessor* generic_change_processor_); |
akalin
2011/10/11 22:41:08
do any of these methods have to be virtual? Ah, I
Nicolas Zea
2011/10/12 04:24:19
Done.
|
+ |
+ // Disconnects from the generic change processor. 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 |
+ // SharedChangeProcessor. |
+ virtual void Disconnect(); |
+ |
+ // GenericChangeProcessor stubs (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); |
+ 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); |
+ |
+ // Register |generic_change_processor_| as the change processor for |
+ // |model_type| with the |sync_service|. |
+ // Does nothing if |disconnected_| is true. |
+ virtual void ActivateDataType( |
+ ProfileSyncService* sync_service, |
+ syncable::ModelType model_type, |
+ browser_sync::ModelSafeGroup model_safe_group); |
+ |
+ protected: |
+ friend class base::RefCountedThreadSafe<SharedChangeProcessor>; |
+ virtual ~SharedChangeProcessor(); |
+ |
+ private: |
+ // Monitor lock for this object. All methods that interact with the change |
+ // processor must aquire this lock and check whether we're disconnected or |
+ // not. Once disconnected, all attempted changes to or loads from the change |
+ // processor return errors. This enables us to shut down the syncer without |
+ // having to wait for possibly non-UI thread datatypes to complete work. |
+ mutable base::Lock monitor_lock_; |
+ bool disconnected_; |
+ |
+ scoped_ptr<GenericChangeProcessor> generic_change_processor_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); |
+}; |
+ |
+} // namespace browser_sync |
+ |
+#endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ |