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

Side by Side Diff: components/sync/driver/frontend_data_type_controller.cc

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "components/sync/driver/frontend_data_type_controller.h" 5 #include "components/sync/driver/frontend_data_type_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/sync/api/data_type_error_handler_impl.h" 10 #include "components/sync/api/data_type_error_handler_impl.h"
11 #include "components/sync/api/sync_error.h" 11 #include "components/sync/api/sync_error.h"
12 #include "components/sync/api/sync_merge_result.h" 12 #include "components/sync/api/sync_merge_result.h"
13 #include "components/sync/base/data_type_histogram.h" 13 #include "components/sync/base/data_type_histogram.h"
14 #include "components/sync/base/model_type.h" 14 #include "components/sync/base/model_type.h"
15 #include "components/sync/driver/change_processor.h" 15 #include "components/sync/driver/change_processor.h"
16 #include "components/sync/driver/model_associator.h" 16 #include "components/sync/driver/model_associator.h"
17 #include "components/sync/driver/sync_client.h" 17 #include "components/sync/driver/sync_client.h"
18 #include "components/sync/driver/sync_service.h" 18 #include "components/sync/driver/sync_service.h"
19 19
20 namespace syncer { 20 namespace browser_sync {
21 21
22 FrontendDataTypeController::FrontendDataTypeController( 22 FrontendDataTypeController::FrontendDataTypeController(
23 ModelType type, 23 syncer::ModelType type,
24 const base::Closure& dump_stack, 24 const base::Closure& dump_stack,
25 SyncClient* sync_client) 25 sync_driver::SyncClient* sync_client)
26 : DirectoryDataTypeController(type, dump_stack, sync_client), 26 : DirectoryDataTypeController(type, dump_stack, sync_client),
27 state_(NOT_RUNNING) { 27 state_(NOT_RUNNING) {
28 DCHECK(CalledOnValidThread()); 28 DCHECK(CalledOnValidThread());
29 DCHECK(sync_client); 29 DCHECK(sync_client);
30 } 30 }
31 31
32 void FrontendDataTypeController::LoadModels( 32 void FrontendDataTypeController::LoadModels(
33 const ModelLoadCallback& model_load_callback) { 33 const ModelLoadCallback& model_load_callback) {
34 DCHECK(CalledOnValidThread()); 34 DCHECK(CalledOnValidThread());
35 model_load_callback_ = model_load_callback; 35 model_load_callback_ = model_load_callback;
36 36
37 if (state_ != NOT_RUNNING) { 37 if (state_ != NOT_RUNNING) {
38 model_load_callback.Run(type(), 38 model_load_callback.Run(
39 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, 39 type(), syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
40 "Model already running", type())); 40 "Model already running", type()));
41 return; 41 return;
42 } 42 }
43 43
44 state_ = MODEL_STARTING; 44 state_ = MODEL_STARTING;
45 if (!StartModels()) { 45 if (!StartModels()) {
46 // If we are waiting for some external service to load before associating 46 // If we are waiting for some external service to load before associating
47 // or we failed to start the models, we exit early. state_ will control 47 // or we failed to start the models, we exit early. state_ will control
48 // what we perform next. 48 // what we perform next.
49 DCHECK(state_ == NOT_RUNNING || state_ == MODEL_STARTING); 49 DCHECK(state_ == NOT_RUNNING || state_ == MODEL_STARTING);
50 return; 50 return;
51 } 51 }
52 52
53 OnModelLoaded(); 53 OnModelLoaded();
54 } 54 }
55 55
56 void FrontendDataTypeController::OnModelLoaded() { 56 void FrontendDataTypeController::OnModelLoaded() {
57 DCHECK(CalledOnValidThread()); 57 DCHECK(CalledOnValidThread());
58 DCHECK_EQ(state_, MODEL_STARTING); 58 DCHECK_EQ(state_, MODEL_STARTING);
59 59
60 state_ = MODEL_LOADED; 60 state_ = MODEL_LOADED;
61 model_load_callback_.Run(type(), SyncError()); 61 model_load_callback_.Run(type(), syncer::SyncError());
62 } 62 }
63 63
64 void FrontendDataTypeController::StartAssociating( 64 void FrontendDataTypeController::StartAssociating(
65 const StartCallback& start_callback) { 65 const StartCallback& start_callback) {
66 DCHECK(CalledOnValidThread()); 66 DCHECK(CalledOnValidThread());
67 DCHECK(!start_callback.is_null()); 67 DCHECK(!start_callback.is_null());
68 DCHECK_EQ(state_, MODEL_LOADED); 68 DCHECK_EQ(state_, MODEL_LOADED);
69 69
70 start_callback_ = start_callback; 70 start_callback_ = start_callback;
71 state_ = ASSOCIATING; 71 state_ = ASSOCIATING;
(...skipping 17 matching lines...) Expand all
89 if (prev_state == MODEL_STARTING) { 89 if (prev_state == MODEL_STARTING) {
90 AbortModelLoad(); 90 AbortModelLoad();
91 // We can just return here since we haven't performed association if we're 91 // We can just return here since we haven't performed association if we're
92 // still in MODEL_STARTING. 92 // still in MODEL_STARTING.
93 return; 93 return;
94 } 94 }
95 95
96 CleanUpState(); 96 CleanUpState();
97 97
98 if (model_associator()) { 98 if (model_associator()) {
99 SyncError error; // Not used. 99 syncer::SyncError error; // Not used.
100 error = model_associator()->DisassociateModels(); 100 error = model_associator()->DisassociateModels();
101 } 101 }
102 102
103 set_model_associator(NULL); 103 set_model_associator(NULL);
104 change_processor_.reset(); 104 change_processor_.reset();
105 105
106 state_ = NOT_RUNNING; 106 state_ = NOT_RUNNING;
107 } 107 }
108 108
109 ModelSafeGroup FrontendDataTypeController::model_safe_group() const { 109 syncer::ModelSafeGroup FrontendDataTypeController::model_safe_group() const {
110 return GROUP_UI; 110 return syncer::GROUP_UI;
111 } 111 }
112 112
113 std::string FrontendDataTypeController::name() const { 113 std::string FrontendDataTypeController::name() const {
114 // For logging only. 114 // For logging only.
115 return ModelTypeToString(type()); 115 return syncer::ModelTypeToString(type());
116 } 116 }
117 117
118 DataTypeController::State FrontendDataTypeController::state() const { 118 sync_driver::DataTypeController::State FrontendDataTypeController::state()
119 const {
119 return state_; 120 return state_;
120 } 121 }
121 122
122 FrontendDataTypeController::FrontendDataTypeController() 123 FrontendDataTypeController::FrontendDataTypeController()
123 : DirectoryDataTypeController(UNSPECIFIED, base::Closure(), nullptr), 124 : DirectoryDataTypeController(syncer::UNSPECIFIED,
125 base::Closure(),
126 nullptr),
124 state_(NOT_RUNNING) {} 127 state_(NOT_RUNNING) {}
125 128
126 FrontendDataTypeController::~FrontendDataTypeController() {} 129 FrontendDataTypeController::~FrontendDataTypeController() {}
127 130
128 bool FrontendDataTypeController::StartModels() { 131 bool FrontendDataTypeController::StartModels() {
129 DCHECK(CalledOnValidThread()); 132 DCHECK(CalledOnValidThread());
130 DCHECK_EQ(state_, MODEL_STARTING); 133 DCHECK_EQ(state_, MODEL_STARTING);
131 // By default, no additional services need to be started before we can proceed 134 // By default, no additional services need to be started before we can proceed
132 // with model association. 135 // with model association.
133 return true; 136 return true;
134 } 137 }
135 138
136 void FrontendDataTypeController::Associate() { 139 void FrontendDataTypeController::Associate() {
137 DCHECK(CalledOnValidThread()); 140 DCHECK(CalledOnValidThread());
138 if (state_ != ASSOCIATING) { 141 if (state_ != ASSOCIATING) {
139 // Stop() must have been called while Associate() task have been waiting. 142 // Stop() must have been called while Associate() task have been waiting.
140 DCHECK_EQ(state_, NOT_RUNNING); 143 DCHECK_EQ(state_, NOT_RUNNING);
141 return; 144 return;
142 } 145 }
143 146
144 SyncMergeResult local_merge_result(type()); 147 syncer::SyncMergeResult local_merge_result(type());
145 SyncMergeResult syncer_merge_result(type()); 148 syncer::SyncMergeResult syncer_merge_result(type());
146 CreateSyncComponents(); 149 CreateSyncComponents();
147 if (!model_associator()->CryptoReadyIfNecessary()) { 150 if (!model_associator()->CryptoReadyIfNecessary()) {
148 StartDone(NEEDS_CRYPTO, local_merge_result, syncer_merge_result); 151 StartDone(NEEDS_CRYPTO, local_merge_result, syncer_merge_result);
149 return; 152 return;
150 } 153 }
151 154
152 bool sync_has_nodes = false; 155 bool sync_has_nodes = false;
153 if (!model_associator()->SyncModelHasUserCreatedNodes(&sync_has_nodes)) { 156 if (!model_associator()->SyncModelHasUserCreatedNodes(&sync_has_nodes)) {
154 SyncError error(FROM_HERE, SyncError::UNRECOVERABLE_ERROR, 157 syncer::SyncError error(FROM_HERE, syncer::SyncError::UNRECOVERABLE_ERROR,
155 "Failed to load sync nodes", type()); 158 "Failed to load sync nodes", type());
156 local_merge_result.set_error(error); 159 local_merge_result.set_error(error);
157 StartDone(UNRECOVERABLE_ERROR, local_merge_result, syncer_merge_result); 160 StartDone(UNRECOVERABLE_ERROR, local_merge_result, syncer_merge_result);
158 return; 161 return;
159 } 162 }
160 163
161 // TODO(zea): Have AssociateModels fill the local and syncer merge results. 164 // TODO(zea): Have AssociateModels fill the local and syncer merge results.
162 base::TimeTicks start_time = base::TimeTicks::Now(); 165 base::TimeTicks start_time = base::TimeTicks::Now();
163 SyncError error; 166 syncer::SyncError error;
164 error = model_associator()->AssociateModels(&local_merge_result, 167 error = model_associator()->AssociateModels(&local_merge_result,
165 &syncer_merge_result); 168 &syncer_merge_result);
166 // TODO(lipalani): crbug.com/122690 - handle abort. 169 // TODO(lipalani): crbug.com/122690 - handle abort.
167 RecordAssociationTime(base::TimeTicks::Now() - start_time); 170 RecordAssociationTime(base::TimeTicks::Now() - start_time);
168 if (error.IsSet()) { 171 if (error.IsSet()) {
169 local_merge_result.set_error(error); 172 local_merge_result.set_error(error);
170 StartDone(ASSOCIATION_FAILED, local_merge_result, syncer_merge_result); 173 StartDone(ASSOCIATION_FAILED, local_merge_result, syncer_merge_result);
171 return; 174 return;
172 } 175 }
173 176
(...skipping 16 matching lines...) Expand all
190 } 193 }
191 194
192 void FrontendDataTypeController::AbortModelLoad() { 195 void FrontendDataTypeController::AbortModelLoad() {
193 DCHECK(CalledOnValidThread()); 196 DCHECK(CalledOnValidThread());
194 CleanUp(); 197 CleanUp();
195 state_ = NOT_RUNNING; 198 state_ = NOT_RUNNING;
196 } 199 }
197 200
198 void FrontendDataTypeController::StartDone( 201 void FrontendDataTypeController::StartDone(
199 ConfigureResult start_result, 202 ConfigureResult start_result,
200 const SyncMergeResult& local_merge_result, 203 const syncer::SyncMergeResult& local_merge_result,
201 const SyncMergeResult& syncer_merge_result) { 204 const syncer::SyncMergeResult& syncer_merge_result) {
202 DCHECK(CalledOnValidThread()); 205 DCHECK(CalledOnValidThread());
203 if (!IsSuccessfulResult(start_result)) { 206 if (!IsSuccessfulResult(start_result)) {
204 CleanUp(); 207 CleanUp();
205 if (start_result == ASSOCIATION_FAILED) { 208 if (start_result == ASSOCIATION_FAILED) {
206 state_ = DISABLED; 209 state_ = DISABLED;
207 } else { 210 } else {
208 state_ = NOT_RUNNING; 211 state_ = NOT_RUNNING;
209 } 212 }
210 RecordStartFailure(start_result); 213 RecordStartFailure(start_result);
211 } 214 }
212 215
213 start_callback_.Run(start_result, local_merge_result, syncer_merge_result); 216 start_callback_.Run(start_result, local_merge_result, syncer_merge_result);
214 } 217 }
215 218
216 std::unique_ptr<DataTypeErrorHandler> 219 std::unique_ptr<syncer::DataTypeErrorHandler>
217 FrontendDataTypeController::CreateErrorHandler() { 220 FrontendDataTypeController::CreateErrorHandler() {
218 return base::MakeUnique<DataTypeErrorHandlerImpl>( 221 return base::MakeUnique<syncer::DataTypeErrorHandlerImpl>(
219 base::ThreadTaskRunnerHandle::Get(), dump_stack_, 222 base::ThreadTaskRunnerHandle::Get(), dump_stack_,
220 base::Bind(&FrontendDataTypeController::OnUnrecoverableError, 223 base::Bind(&FrontendDataTypeController::OnUnrecoverableError,
221 base::AsWeakPtr(this))); 224 base::AsWeakPtr(this)));
222 } 225 }
223 226
224 void FrontendDataTypeController::OnUnrecoverableError(const SyncError& error) { 227 void FrontendDataTypeController::OnUnrecoverableError(
228 const syncer::SyncError& error) {
225 DCHECK(CalledOnValidThread()); 229 DCHECK(CalledOnValidThread());
226 DCHECK_EQ(type(), error.model_type()); 230 DCHECK_EQ(type(), error.model_type());
227 if (!model_load_callback_.is_null()) { 231 if (!model_load_callback_.is_null()) {
228 model_load_callback_.Run(type(), error); 232 model_load_callback_.Run(type(), error);
229 } 233 }
230 } 234 }
231 235
232 void FrontendDataTypeController::RecordAssociationTime(base::TimeDelta time) { 236 void FrontendDataTypeController::RecordAssociationTime(base::TimeDelta time) {
233 DCHECK(CalledOnValidThread()); 237 DCHECK(CalledOnValidThread());
234 #define PER_DATA_TYPE_MACRO(type_str) \ 238 #define PER_DATA_TYPE_MACRO(type_str) \
235 UMA_HISTOGRAM_TIMES("Sync." type_str "AssociationTime", time); 239 UMA_HISTOGRAM_TIMES("Sync." type_str "AssociationTime", time);
236 SYNC_DATA_TYPE_HISTOGRAM(type()); 240 SYNC_DATA_TYPE_HISTOGRAM(type());
237 #undef PER_DATA_TYPE_MACRO 241 #undef PER_DATA_TYPE_MACRO
238 } 242 }
239 243
240 void FrontendDataTypeController::RecordStartFailure(ConfigureResult result) { 244 void FrontendDataTypeController::RecordStartFailure(ConfigureResult result) {
241 DCHECK(CalledOnValidThread()); 245 DCHECK(CalledOnValidThread());
242 UMA_HISTOGRAM_ENUMERATION("Sync.DataTypeStartFailures", 246 UMA_HISTOGRAM_ENUMERATION("Sync.DataTypeStartFailures",
243 ModelTypeToHistogramInt(type()), MODEL_TYPE_COUNT); 247 ModelTypeToHistogramInt(type()),
248 syncer::MODEL_TYPE_COUNT);
244 #define PER_DATA_TYPE_MACRO(type_str) \ 249 #define PER_DATA_TYPE_MACRO(type_str) \
245 UMA_HISTOGRAM_ENUMERATION("Sync." type_str "ConfigureFailure", result, \ 250 UMA_HISTOGRAM_ENUMERATION("Sync." type_str "ConfigureFailure", result, \
246 MAX_CONFIGURE_RESULT); 251 MAX_CONFIGURE_RESULT);
247 SYNC_DATA_TYPE_HISTOGRAM(type()); 252 SYNC_DATA_TYPE_HISTOGRAM(type());
248 #undef PER_DATA_TYPE_MACRO 253 #undef PER_DATA_TYPE_MACRO
249 } 254 }
250 255
251 AssociatorInterface* FrontendDataTypeController::model_associator() const { 256 sync_driver::AssociatorInterface* FrontendDataTypeController::model_associator()
257 const {
252 return model_associator_.get(); 258 return model_associator_.get();
253 } 259 }
254 260
255 void FrontendDataTypeController::set_model_associator( 261 void FrontendDataTypeController::set_model_associator(
256 AssociatorInterface* model_associator) { 262 sync_driver::AssociatorInterface* model_associator) {
257 model_associator_.reset(model_associator); 263 model_associator_.reset(model_associator);
258 } 264 }
259 265
260 ChangeProcessor* FrontendDataTypeController::GetChangeProcessor() const { 266 sync_driver::ChangeProcessor* FrontendDataTypeController::GetChangeProcessor()
267 const {
261 return change_processor_.get(); 268 return change_processor_.get();
262 } 269 }
263 270
264 void FrontendDataTypeController::set_change_processor( 271 void FrontendDataTypeController::set_change_processor(
265 ChangeProcessor* change_processor) { 272 sync_driver::ChangeProcessor* change_processor) {
266 change_processor_.reset(change_processor); 273 change_processor_.reset(change_processor);
267 } 274 }
268 275
269 } // namespace syncer 276 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync/driver/frontend_data_type_controller.h ('k') | components/sync/driver/frontend_data_type_controller_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698