Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ | |
| 6 #define CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 11 #include "chrome/browser/sync/glue/generic_change_processor.h" | |
| 12 #include "content/browser/browser_thread.h" | |
| 13 | |
| 14 class SyncData; | |
| 15 class SyncableService; | |
| 16 | |
| 17 typedef std::vector<SyncData> SyncDataList; | |
| 18 | |
| 19 namespace browser_sync { | |
| 20 | |
| 21 | |
| 22 // A ref-counted GenericChangeProcessor for use with datatypes that don't live | |
| 23 // on the UI thread. We need to make it refcounted as the ownership transfer | |
| 24 // from the DataTypeController is dependent on threading, and hence racy. | |
| 25 // The SharedChangeProcessor should be created and destroyed on the UI thread, | |
| 26 // but should only be connected and used on the same thread as the datatype it | |
| 27 // interacts with. The only thread-safe method is Disconnect, which will | |
| 28 // disconnect the change processor from the syncer, letting us shut down the | |
| 29 // syncer/datatype without waiting for non-UI threads. | |
| 30 class SharedChangeProcessor | |
| 31 : public GenericChangeProcessor, | |
|
akalin
2011/10/07 20:51:16
I think this shouldn't inherit from GenericChangeP
Nicolas Zea
2011/10/07 22:05:52
My main reason was that we want to access protecte
akalin
2011/10/07 22:18:28
What protected methods do you need? I only see th
| |
| 32 public base::RefCountedThreadSafe<SharedChangeProcessor, | |
| 33 BrowserThread::DeleteOnUIThread> { | |
|
akalin
2011/10/07 20:51:16
any reason why this is DeleteOnUIThread?
Nicolas Zea
2011/10/07 22:05:52
So that we have some determinism as to which threa
akalin
2011/10/07 22:18:28
The problem is that DeleteOnUIThread is a guarante
| |
| 34 public: | |
| 35 // Create an uninitialized change processor (to be later connected). | |
| 36 explicit SharedChangeProcessor(UnrecoverableErrorHandler* error_handler); | |
| 37 | |
| 38 // Connect to the syncer and the SyncableService specified. Should be called | |
| 39 // on the same thread the datatype resides. | |
| 40 virtual void Connect(SyncableService* local_service, | |
| 41 sync_api::UserShare* user_share); | |
| 42 | |
| 43 // Disconnects from the syncer. May be called from any thread. After this, all | |
| 44 // attempts to interact with the change processor by |local_service_| are | |
| 45 // dropped and return errors. The syncer will be safe to shut down from the | |
| 46 // point of view of this datatype. | |
| 47 // Note: Once disconnected, you cannot reconnect without creating a new | |
|
akalin
2011/10/07 20:51:16
can we provide a stronger guarantee? Will this be
Nicolas Zea
2011/10/07 22:05:52
Yes, this will be called on the UI thread. What gu
akalin
2011/10/07 22:18:28
Ah, right. I'm not sure I like the lock that much
| |
| 48 // change processor. | |
| 49 virtual void Disconnect(); | |
| 50 | |
| 51 // GenericChangeProcessor implementation (with disconnect support). | |
| 52 // Should only be called on the same thread the datatype resides. | |
| 53 virtual SyncError ProcessSyncChanges( | |
| 54 const tracked_objects::Location& from_here, | |
| 55 const SyncChangeList& change_list) OVERRIDE; | |
| 56 virtual SyncError GetSyncDataForType(syncable::ModelType type, | |
| 57 SyncDataList* current_sync_data); | |
| 58 virtual bool SyncModelHasUserCreatedNodes(syncable::ModelType type, | |
| 59 bool* has_nodes); | |
| 60 virtual bool CryptoReadyIfNecessary(syncable::ModelType type); | |
| 61 | |
| 62 protected: | |
| 63 friend class base::RefCountedThreadSafe<SharedChangeProcessor>; | |
| 64 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | |
| 65 friend class DeleteTask<SharedChangeProcessor>; | |
| 66 | |
| 67 virtual ~SharedChangeProcessor() OVERRIDE; | |
| 68 | |
| 69 private: | |
| 70 // Monitor lock for this object. All methods that interact with the Syncer | |
| 71 // must aquire this lock and check whether we're disconnected or not. Once | |
| 72 // disconnected, all attempted changes to or loads from the syncer return | |
| 73 // errors. This enables us to shut down the syncer without having to wait | |
| 74 // for possibly non-UI thread datatypes to complete work. | |
| 75 base::Lock monitor_lock_; | |
| 76 bool disconnected_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); | |
| 79 }; | |
| 80 | |
| 81 } // namespace browser_sync | |
| 82 | |
| 83 #endif // CHROME_BROWSER_SYNC_GLUE_SHARED_CHANGE_PROCESSOR_H_ | |
| OLD | NEW |