OLD | NEW |
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/ui_data_type_controller.h" | 5 #include "chrome/browser/sync/glue/ui_data_type_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sync/glue/shared_change_processor_ref.h" | 10 #include "chrome/browser/sync/glue/shared_change_processor_ref.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 state_ = RUNNING; | 194 state_ = RUNNING; |
195 StartDone(sync_has_nodes ? OK : OK_FIRST_RUN, | 195 StartDone(sync_has_nodes ? OK : OK_FIRST_RUN, |
196 local_merge_result, | 196 local_merge_result, |
197 syncer_merge_result); | 197 syncer_merge_result); |
198 } | 198 } |
199 | 199 |
200 void UIDataTypeController::AbortModelLoad() { | 200 void UIDataTypeController::AbortModelLoad() { |
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
202 state_ = NOT_RUNNING; | 202 state_ = NOT_RUNNING; |
203 | 203 |
204 if (shared_change_processor_) { | 204 if (shared_change_processor_.get()) { |
205 shared_change_processor_ = NULL; | 205 shared_change_processor_ = NULL; |
206 } | 206 } |
207 | 207 |
208 ModelLoadCallback model_load_callback = model_load_callback_; | 208 ModelLoadCallback model_load_callback = model_load_callback_; |
209 model_load_callback_.Reset(); | 209 model_load_callback_.Reset(); |
210 model_load_callback.Run(type(), syncer::SyncError(FROM_HERE, | 210 model_load_callback.Run(type(), syncer::SyncError(FROM_HERE, |
211 "Aborted", | 211 "Aborted", |
212 type())); | 212 type())); |
213 } | 213 } |
214 | 214 |
215 void UIDataTypeController::StartDone( | 215 void UIDataTypeController::StartDone( |
216 StartResult start_result, | 216 StartResult start_result, |
217 const syncer::SyncMergeResult& local_merge_result, | 217 const syncer::SyncMergeResult& local_merge_result, |
218 const syncer::SyncMergeResult& syncer_merge_result) { | 218 const syncer::SyncMergeResult& syncer_merge_result) { |
219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
220 | 220 |
221 if (!IsSuccessfulResult(start_result)) { | 221 if (!IsSuccessfulResult(start_result)) { |
222 if (IsUnrecoverableResult(start_result)) | 222 if (IsUnrecoverableResult(start_result)) |
223 RecordUnrecoverableError(FROM_HERE, "StartFailed"); | 223 RecordUnrecoverableError(FROM_HERE, "StartFailed"); |
224 | 224 |
225 StopModels(); | 225 StopModels(); |
226 if (start_result == ASSOCIATION_FAILED) { | 226 if (start_result == ASSOCIATION_FAILED) { |
227 state_ = DISABLED; | 227 state_ = DISABLED; |
228 } else { | 228 } else { |
229 state_ = NOT_RUNNING; | 229 state_ = NOT_RUNNING; |
230 } | 230 } |
231 RecordStartFailure(start_result); | 231 RecordStartFailure(start_result); |
232 | 232 |
233 if (shared_change_processor_) { | 233 if (shared_change_processor_.get()) { |
234 shared_change_processor_->Disconnect(); | 234 shared_change_processor_->Disconnect(); |
235 shared_change_processor_ = NULL; | 235 shared_change_processor_ = NULL; |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 // We have to release the callback before we call it, since it's possible | 239 // We have to release the callback before we call it, since it's possible |
240 // invoking the callback will trigger a call to Stop(), which will get | 240 // invoking the callback will trigger a call to Stop(), which will get |
241 // confused by the non-NULL start_callback_. | 241 // confused by the non-NULL start_callback_. |
242 StartCallback callback = start_callback_; | 242 StartCallback callback = start_callback_; |
243 start_callback_.Reset(); | 243 start_callback_.Reset(); |
244 callback.Run(start_result, local_merge_result, syncer_merge_result); | 244 callback.Run(start_result, local_merge_result, syncer_merge_result); |
245 } | 245 } |
246 | 246 |
247 void UIDataTypeController::Stop() { | 247 void UIDataTypeController::Stop() { |
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
249 DCHECK(syncer::IsRealDataType(type_)); | 249 DCHECK(syncer::IsRealDataType(type_)); |
250 | 250 |
251 State prev_state = state_; | 251 State prev_state = state_; |
252 state_ = STOPPING; | 252 state_ = STOPPING; |
253 | 253 |
254 if (shared_change_processor_) { | 254 if (shared_change_processor_.get()) { |
255 shared_change_processor_->Disconnect(); | 255 shared_change_processor_->Disconnect(); |
256 shared_change_processor_ = NULL; | 256 shared_change_processor_ = NULL; |
257 } | 257 } |
258 | 258 |
259 // If Stop() is called while Start() is waiting for the datatype model to | 259 // If Stop() is called while Start() is waiting for the datatype model to |
260 // load, abort the start. | 260 // load, abort the start. |
261 if (prev_state == MODEL_STARTING) { | 261 if (prev_state == MODEL_STARTING) { |
262 AbortModelLoad(); | 262 AbortModelLoad(); |
263 // We can just return here since we haven't performed association if we're | 263 // We can just return here since we haven't performed association if we're |
264 // still in MODEL_STARTING. | 264 // still in MODEL_STARTING. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 ModelTypeToHistogramInt(type()), | 320 ModelTypeToHistogramInt(type()), |
321 syncer::MODEL_TYPE_COUNT); | 321 syncer::MODEL_TYPE_COUNT); |
322 #define PER_DATA_TYPE_MACRO(type_str) \ | 322 #define PER_DATA_TYPE_MACRO(type_str) \ |
323 UMA_HISTOGRAM_ENUMERATION("Sync." type_str "StartFailure", result, \ | 323 UMA_HISTOGRAM_ENUMERATION("Sync." type_str "StartFailure", result, \ |
324 MAX_START_RESULT); | 324 MAX_START_RESULT); |
325 SYNC_DATA_TYPE_HISTOGRAM(type()); | 325 SYNC_DATA_TYPE_HISTOGRAM(type()); |
326 #undef PER_DATA_TYPE_MACRO | 326 #undef PER_DATA_TYPE_MACRO |
327 } | 327 } |
328 | 328 |
329 } // namespace browser_sync | 329 } // namespace browser_sync |
OLD | NEW |