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

Side by Side Diff: components/sync/driver/shared_change_processor.h

Issue 2257523003: [Sync] Move StartAssociation from NonUIDataTypeController to SharedChangeProcessor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move local_service_ WeakPtr to SharedChangeProcessor. Created 4 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ 5 #ifndef COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_
6 #define COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ 6 #define COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "components/sync/api/sync_change_processor.h" 16 #include "components/sync/api/sync_change_processor.h"
17 #include "components/sync/api/sync_data.h" 17 #include "components/sync/api/sync_data.h"
18 #include "components/sync/api/sync_error.h" 18 #include "components/sync/api/sync_error.h"
19 #include "components/sync/api/sync_error_factory.h" 19 #include "components/sync/api/sync_error_factory.h"
20 #include "components/sync/api/sync_merge_result.h" 20 #include "components/sync/api/sync_merge_result.h"
21 #include "components/sync/driver/data_type_controller.h"
21 #include "components/sync/engine/model_safe_worker.h" 22 #include "components/sync/engine/model_safe_worker.h"
22 23
23 namespace syncer { 24 namespace syncer {
24 class DataTypeErrorHandler; 25 class DataTypeErrorHandler;
25 class SyncableService; 26 class SyncableService;
26 struct UserShare; 27 struct UserShare;
27 } // namespace syncer 28 } // namespace syncer
28 29
29 namespace sync_driver { 30 namespace sync_driver {
30 31
(...skipping 15 matching lines...) Expand all
46 // waiting for non-UI threads. 47 // waiting for non-UI threads.
47 // 48 //
48 // Note: since we control the work being done while holding the lock, we ensure 49 // Note: since we control the work being done while holding the lock, we ensure
49 // no I/O or other intensive work is done while blocking the UI thread (all 50 // no I/O or other intensive work is done while blocking the UI thread (all
50 // the work is in-memory sync interactions). 51 // the work is in-memory sync interactions).
51 // 52 //
52 // We use virtual methods so that we can use mock's in testing. 53 // We use virtual methods so that we can use mock's in testing.
53 class SharedChangeProcessor 54 class SharedChangeProcessor
54 : public base::RefCountedThreadSafe<SharedChangeProcessor> { 55 : public base::RefCountedThreadSafe<SharedChangeProcessor> {
55 public: 56 public:
57 typedef base::Callback<void(
58 DataTypeController::ConfigureResult start_result,
59 const syncer::SyncMergeResult& local_merge_result,
60 const syncer::SyncMergeResult& syncer_merge_result)>
61 StartDoneCallback;
62
56 // Create an uninitialized SharedChangeProcessor. 63 // Create an uninitialized SharedChangeProcessor.
57 SharedChangeProcessor(); 64 explicit SharedChangeProcessor(syncer::ModelType type);
65
66 void StartAssociation(StartDoneCallback start_done,
67 SyncClient* const sync_client,
68 syncer::UserShare* user_share,
69 syncer::DataTypeErrorHandler* error_handler);
58 70
59 // Connect to the Syncer and prepare to handle changes for |type|. Will 71 // Connect to the Syncer and prepare to handle changes for |type|. Will
60 // create and store a new GenericChangeProcessor and return a weak pointer to 72 // create and store a new GenericChangeProcessor and return a weak pointer to
61 // the syncer::SyncableService associated with |type|. 73 // the syncer::SyncableService associated with |type|.
62 // Note: If this SharedChangeProcessor has been disconnected, or the 74 // Note: If this SharedChangeProcessor has been disconnected, or the
63 // syncer::SyncableService was not alive, will return a null weak pointer. 75 // syncer::SyncableService was not alive, will return a null weak pointer.
64 virtual base::WeakPtr<syncer::SyncableService> Connect( 76 virtual base::WeakPtr<syncer::SyncableService> Connect(
65 SyncClient* sync_client, 77 SyncClient* sync_client,
66 GenericChangeProcessorFactory* processor_factory, 78 GenericChangeProcessorFactory* processor_factory,
67 syncer::UserShare* user_share, 79 syncer::UserShare* user_share,
68 syncer::DataTypeErrorHandler* error_handler, 80 syncer::DataTypeErrorHandler* error_handler,
69 syncer::ModelType type,
70 const base::WeakPtr<syncer::SyncMergeResult>& merge_result); 81 const base::WeakPtr<syncer::SyncMergeResult>& merge_result);
71 82
72 // Disconnects from the generic change processor. May be called from any 83 // Disconnects from the generic change processor. May be called from any
73 // thread. After this, all attempts to interact with the change processor by 84 // thread. After this, all attempts to interact with the change processor by
74 // |local_service_| are dropped and return errors. The syncer will be safe to 85 // |local_service_| are dropped and return errors. The syncer will be safe to
75 // shut down from the point of view of this datatype. 86 // shut down from the point of view of this datatype.
76 // Note: Once disconnected, you cannot reconnect without creating a new 87 // Note: Once disconnected, you cannot reconnect without creating a new
77 // SharedChangeProcessor. 88 // SharedChangeProcessor.
78 // Returns: true if we were previously succesfully connected, false if we were 89 // Returns: true if we were previously succesfully connected, false if we were
79 // already disconnected. 90 // already disconnected.
(...skipping 18 matching lines...) Expand all
98 109
99 // If a datatype context associated with the current type exists, fills 110 // If a datatype context associated with the current type exists, fills
100 // |context| and returns true. Otheriwse, if there has not been a context 111 // |context| and returns true. Otheriwse, if there has not been a context
101 // set, returns false. 112 // set, returns false.
102 virtual bool GetDataTypeContext(std::string* context) const; 113 virtual bool GetDataTypeContext(std::string* context) const;
103 114
104 virtual syncer::SyncError CreateAndUploadError( 115 virtual syncer::SyncError CreateAndUploadError(
105 const tracked_objects::Location& location, 116 const tracked_objects::Location& location,
106 const std::string& message); 117 const std::string& message);
107 118
119 // Calls local_service_->StopSyncing() and releases our reference to it.
120 void StopLocalService();
121
108 ChangeProcessor* generic_change_processor(); 122 ChangeProcessor* generic_change_processor();
109 123
110 protected: 124 protected:
111 friend class base::RefCountedThreadSafe<SharedChangeProcessor>; 125 friend class base::RefCountedThreadSafe<SharedChangeProcessor>;
112 virtual ~SharedChangeProcessor(); 126 virtual ~SharedChangeProcessor();
113 127
114 private: 128 private:
129 // Record association time.
130 virtual void RecordAssociationTime(base::TimeDelta time);
131
115 // Monitor lock for this object. All methods that interact with the change 132 // Monitor lock for this object. All methods that interact with the change
116 // processor must aquire this lock and check whether we're disconnected or 133 // processor must aquire this lock and check whether we're disconnected or
117 // not. Once disconnected, all attempted changes to or loads from the change 134 // not. Once disconnected, all attempted changes to or loads from the change
118 // processor return errors. This enables us to shut down the syncer without 135 // processor return errors. This enables us to shut down the syncer without
119 // having to wait for possibly non-UI thread datatypes to complete work. 136 // having to wait for possibly non-UI thread datatypes to complete work.
120 mutable base::Lock monitor_lock_; 137 mutable base::Lock monitor_lock_;
121 bool disconnected_; 138 bool disconnected_;
122 139
123 // The sync datatype we were last connected to. 140 // The sync datatype we process changes for.
124 syncer::ModelType type_; 141 const syncer::ModelType type_;
125 142
126 // The frontend / UI MessageLoop this object is constructed on. May also be 143 // The frontend / UI MessageLoop this object is constructed on. May also be
127 // destructed and/or disconnected on this loop, see ~SharedChangeProcessor. 144 // destructed and/or disconnected on this loop, see ~SharedChangeProcessor.
128 const scoped_refptr<const base::SingleThreadTaskRunner> frontend_task_runner_; 145 const scoped_refptr<const base::SingleThreadTaskRunner> frontend_task_runner_;
129 146
130 // The loop that all methods except the constructor, destructor, and 147 // The loop that all methods except the constructor, destructor, and
131 // Disconnect() should be called on. Set in Connect(). 148 // Disconnect() should be called on. Set in Connect().
132 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_; 149 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_;
133 150
134 // Used only on |backend_loop_|. 151 // Used only on |backend_loop_|.
135 GenericChangeProcessor* generic_change_processor_; 152 GenericChangeProcessor* generic_change_processor_;
136 153
137 syncer::DataTypeErrorHandler* error_handler_; 154 syncer::DataTypeErrorHandler* error_handler_;
138 155
156 // The local service for this type. Only set if the DTC for the type uses
157 // SharedChangeProcessor::StartAssociation().
158 base::WeakPtr<syncer::SyncableService> local_service_;
159
139 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); 160 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor);
140 }; 161 };
141 162
142 } // namespace sync_driver 163 } // namespace sync_driver
143 164
144 #endif // COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ 165 #endif // COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_
OLDNEW
« no previous file with comments | « components/sync/driver/non_ui_data_type_controller_unittest.cc ('k') | components/sync/driver/shared_change_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698