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

Side by Side Diff: chrome/browser/sync/glue/frontend_data_type_controller.cc

Issue 10662035: [Sync] Put everything in sync/api into csync namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 8 years, 5 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 | Annotate | Revision Log
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 "chrome/browser/sync/glue/frontend_data_type_controller.h" 5 #include "chrome/browser/sync/glue/frontend_data_type_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/glue/change_processor.h" 9 #include "chrome/browser/sync/glue/change_processor.h"
10 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" 10 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
(...skipping 22 matching lines...) Expand all
33 DCHECK(profile); 33 DCHECK(profile);
34 DCHECK(sync_service); 34 DCHECK(sync_service);
35 } 35 }
36 36
37 void FrontendDataTypeController::LoadModels( 37 void FrontendDataTypeController::LoadModels(
38 const ModelLoadCallback& model_load_callback) { 38 const ModelLoadCallback& model_load_callback) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 DCHECK(!model_load_callback.is_null()); 40 DCHECK(!model_load_callback.is_null());
41 41
42 if (state_ != NOT_RUNNING) { 42 if (state_ != NOT_RUNNING) {
43 model_load_callback.Run(type(), SyncError(FROM_HERE, 43 model_load_callback.Run(type(), csync::SyncError(FROM_HERE,
44 "Model already running", 44 "Model already running",
45 type())); 45 type()));
46 return; 46 return;
47 } 47 }
48 48
49 DCHECK(model_load_callback_.is_null()); 49 DCHECK(model_load_callback_.is_null());
50 50
51 model_load_callback_ = model_load_callback; 51 model_load_callback_ = model_load_callback;
52 state_ = MODEL_STARTING; 52 state_ = MODEL_STARTING;
53 if (!StartModels()) { 53 if (!StartModels()) {
54 // If we are waiting for some external service to load before associating 54 // If we are waiting for some external service to load before associating
55 // or we failed to start the models, we exit early. state_ will control 55 // or we failed to start the models, we exit early. state_ will control
56 // what we perform next. 56 // what we perform next.
57 DCHECK(state_ == NOT_RUNNING || state_ == MODEL_STARTING); 57 DCHECK(state_ == NOT_RUNNING || state_ == MODEL_STARTING);
58 return; 58 return;
59 } 59 }
60 60
61 OnModelLoaded(); 61 OnModelLoaded();
62 } 62 }
63 63
64 void FrontendDataTypeController::OnModelLoaded() { 64 void FrontendDataTypeController::OnModelLoaded() {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 DCHECK(!model_load_callback_.is_null()); 66 DCHECK(!model_load_callback_.is_null());
67 DCHECK_EQ(state_, MODEL_STARTING); 67 DCHECK_EQ(state_, MODEL_STARTING);
68 68
69 state_ = MODEL_LOADED; 69 state_ = MODEL_LOADED;
70 ModelLoadCallback model_load_callback = model_load_callback_; 70 ModelLoadCallback model_load_callback = model_load_callback_;
71 model_load_callback_.Reset(); 71 model_load_callback_.Reset();
72 model_load_callback.Run(type(), SyncError()); 72 model_load_callback.Run(type(), csync::SyncError());
73 } 73 }
74 74
75 void FrontendDataTypeController::StartAssociating( 75 void FrontendDataTypeController::StartAssociating(
76 const StartCallback& start_callback) { 76 const StartCallback& start_callback) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 DCHECK(!start_callback.is_null()); 78 DCHECK(!start_callback.is_null());
79 DCHECK(start_callback_.is_null()); 79 DCHECK(start_callback_.is_null());
80 DCHECK_EQ(state_, MODEL_LOADED); 80 DCHECK_EQ(state_, MODEL_LOADED);
81 81
82 start_callback_ = start_callback; 82 start_callback_ = start_callback;
(...skipping 20 matching lines...) Expand all
103 // still in MODEL_STARTING. 103 // still in MODEL_STARTING.
104 return; 104 return;
105 } 105 }
106 DCHECK(start_callback_.is_null()); 106 DCHECK(start_callback_.is_null());
107 107
108 CleanUpState(); 108 CleanUpState();
109 109
110 sync_service_->DeactivateDataType(type()); 110 sync_service_->DeactivateDataType(type());
111 111
112 if (model_associator()) { 112 if (model_associator()) {
113 SyncError error; // Not used. 113 csync::SyncError error; // Not used.
114 error = model_associator()->DisassociateModels(); 114 error = model_associator()->DisassociateModels();
115 } 115 }
116 116
117 set_model_associator(NULL); 117 set_model_associator(NULL);
118 change_processor_.reset(); 118 change_processor_.reset();
119 119
120 state_ = NOT_RUNNING; 120 state_ = NOT_RUNNING;
121 } 121 }
122 122
123 csync::ModelSafeGroup FrontendDataTypeController::model_safe_group() 123 csync::ModelSafeGroup FrontendDataTypeController::model_safe_group()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 DCHECK_EQ(state_, MODEL_STARTING); 155 DCHECK_EQ(state_, MODEL_STARTING);
156 // By default, no additional services need to be started before we can proceed 156 // By default, no additional services need to be started before we can proceed
157 // with model association. 157 // with model association.
158 return true; 158 return true;
159 } 159 }
160 160
161 bool FrontendDataTypeController::Associate() { 161 bool FrontendDataTypeController::Associate() {
162 DCHECK_EQ(state_, ASSOCIATING); 162 DCHECK_EQ(state_, ASSOCIATING);
163 CreateSyncComponents(); 163 CreateSyncComponents();
164 if (!model_associator()->CryptoReadyIfNecessary()) { 164 if (!model_associator()->CryptoReadyIfNecessary()) {
165 StartFailed(NEEDS_CRYPTO, SyncError()); 165 StartFailed(NEEDS_CRYPTO, csync::SyncError());
166 return false; 166 return false;
167 } 167 }
168 168
169 bool sync_has_nodes = false; 169 bool sync_has_nodes = false;
170 if (!model_associator()->SyncModelHasUserCreatedNodes(&sync_has_nodes)) { 170 if (!model_associator()->SyncModelHasUserCreatedNodes(&sync_has_nodes)) {
171 SyncError error(FROM_HERE, "Failed to load sync nodes", type()); 171 csync::SyncError error(FROM_HERE, "Failed to load sync nodes", type());
172 StartFailed(UNRECOVERABLE_ERROR, error); 172 StartFailed(UNRECOVERABLE_ERROR, error);
173 return false; 173 return false;
174 } 174 }
175 175
176 base::TimeTicks start_time = base::TimeTicks::Now(); 176 base::TimeTicks start_time = base::TimeTicks::Now();
177 SyncError error; 177 csync::SyncError error;
178 error = model_associator()->AssociateModels(); 178 error = model_associator()->AssociateModels();
179 // TODO(lipalani): crbug.com/122690 - handle abort. 179 // TODO(lipalani): crbug.com/122690 - handle abort.
180 RecordAssociationTime(base::TimeTicks::Now() - start_time); 180 RecordAssociationTime(base::TimeTicks::Now() - start_time);
181 if (error.IsSet()) { 181 if (error.IsSet()) {
182 StartFailed(ASSOCIATION_FAILED, error); 182 StartFailed(ASSOCIATION_FAILED, error);
183 return false; 183 return false;
184 } 184 }
185 185
186 sync_service_->ActivateDataType(type(), model_safe_group(), 186 sync_service_->ActivateDataType(type(), model_safe_group(),
187 change_processor()); 187 change_processor());
(...skipping 14 matching lines...) Expand all
202 // Do nothing by default. 202 // Do nothing by default.
203 } 203 }
204 204
205 void FrontendDataTypeController::CleanUp() { 205 void FrontendDataTypeController::CleanUp() {
206 CleanUpState(); 206 CleanUpState();
207 set_model_associator(NULL); 207 set_model_associator(NULL);
208 change_processor_.reset(); 208 change_processor_.reset();
209 } 209 }
210 210
211 void FrontendDataTypeController::StartFailed(StartResult result, 211 void FrontendDataTypeController::StartFailed(StartResult result,
212 const SyncError& error) { 212 const csync::SyncError& error) {
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
214 214
215 if (IsUnrecoverableResult(result)) 215 if (IsUnrecoverableResult(result))
216 RecordUnrecoverableError(FROM_HERE, "StartFailed"); 216 RecordUnrecoverableError(FROM_HERE, "StartFailed");
217 217
218 CleanUp(); 218 CleanUp();
219 if (result == ASSOCIATION_FAILED) { 219 if (result == ASSOCIATION_FAILED) {
220 state_ = DISABLED; 220 state_ = DISABLED;
221 } else { 221 } else {
222 state_ = NOT_RUNNING; 222 state_ = NOT_RUNNING;
223 } 223 }
224 RecordStartFailure(result); 224 RecordStartFailure(result);
225 225
226 // We have to release the callback before we call it, since it's possible 226 // We have to release the callback before we call it, since it's possible
227 // invoking the callback will trigger a call to STOP(), which will get 227 // invoking the callback will trigger a call to STOP(), which will get
228 // confused by the non-NULL start_callback_. 228 // confused by the non-NULL start_callback_.
229 StartCallback callback = start_callback_; 229 StartCallback callback = start_callback_;
230 start_callback_.Reset(); 230 start_callback_.Reset();
231 callback.Run(result, error); 231 callback.Run(result, error);
232 } 232 }
233 233
234 void FrontendDataTypeController::AbortModelLoad() { 234 void FrontendDataTypeController::AbortModelLoad() {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236 CleanUp(); 236 CleanUp();
237 state_ = NOT_RUNNING; 237 state_ = NOT_RUNNING;
238 ModelLoadCallback model_load_callback = model_load_callback_; 238 ModelLoadCallback model_load_callback = model_load_callback_;
239 model_load_callback_.Reset(); 239 model_load_callback_.Reset();
240 model_load_callback.Run(type(), SyncError(FROM_HERE, 240 model_load_callback.Run(type(), csync::SyncError(FROM_HERE,
241 "Aborted", 241 "Aborted",
242 type())); 242 type()));
243 } 243 }
244 244
245 void FrontendDataTypeController::FinishStart(StartResult result) { 245 void FrontendDataTypeController::FinishStart(StartResult result) {
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
247 247
248 // We have to release the callback before we call it, since it's possible 248 // We have to release the callback before we call it, since it's possible
249 // invoking the callback will trigger a call to STOP(), which will get 249 // invoking the callback will trigger a call to STOP(), which will get
250 // confused by the non-NULL start_callback_. 250 // confused by the non-NULL start_callback_.
251 StartCallback callback = start_callback_; 251 StartCallback callback = start_callback_;
252 start_callback_.Reset(); 252 start_callback_.Reset();
253 callback.Run(result, SyncError()); 253 callback.Run(result, csync::SyncError());
254 } 254 }
255 255
256 void FrontendDataTypeController::RecordAssociationTime(base::TimeDelta time) { 256 void FrontendDataTypeController::RecordAssociationTime(base::TimeDelta time) {
257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
258 #define PER_DATA_TYPE_MACRO(type_str) \ 258 #define PER_DATA_TYPE_MACRO(type_str) \
259 UMA_HISTOGRAM_TIMES("Sync." type_str "AssociationTime", time); 259 UMA_HISTOGRAM_TIMES("Sync." type_str "AssociationTime", time);
260 SYNC_DATA_TYPE_HISTOGRAM(type()); 260 SYNC_DATA_TYPE_HISTOGRAM(type());
261 #undef PER_DATA_TYPE_MACRO 261 #undef PER_DATA_TYPE_MACRO
262 } 262 }
263 263
(...skipping 20 matching lines...) Expand all
284 ChangeProcessor* FrontendDataTypeController::change_processor() const { 284 ChangeProcessor* FrontendDataTypeController::change_processor() const {
285 return change_processor_.get(); 285 return change_processor_.get();
286 } 286 }
287 287
288 void FrontendDataTypeController::set_change_processor( 288 void FrontendDataTypeController::set_change_processor(
289 ChangeProcessor* change_processor) { 289 ChangeProcessor* change_processor) {
290 change_processor_.reset(change_processor); 290 change_processor_.reset(change_processor);
291 } 291 }
292 292
293 } // namespace browser_sync 293 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698