OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 InitializeBackend(!HasSyncSetupCompleted()); | 365 InitializeBackend(!HasSyncSetupCompleted()); |
366 | 366 |
367 if (!sync_global_error_.get()) { | 367 if (!sync_global_error_.get()) { |
368 sync_global_error_.reset(new SyncGlobalError(this)); | 368 sync_global_error_.reset(new SyncGlobalError(this)); |
369 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | 369 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( |
370 sync_global_error_.get()); | 370 sync_global_error_.get()); |
371 AddObserver(sync_global_error_.get()); | 371 AddObserver(sync_global_error_.get()); |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 void ProfileSyncService::Shutdown(bool sync_disabled) { | 375 void ProfileSyncService::Shutdown(bool delete_stale_data) { |
376 // First, we spin down the backend and wait for it to stop syncing completely | 376 // First, we spin down the backend and wait for it to stop syncing completely |
377 // before we Stop the data type manager. This is to avoid a late sync cycle | 377 // before we Stop the data type manager. This is to avoid a late sync cycle |
378 // applying changes to the sync db that wouldn't get applied via | 378 // applying changes to the sync db that wouldn't get applied via |
379 // ChangeProcessors, leading to back-from-the-dead bugs. | 379 // ChangeProcessors, leading to back-from-the-dead bugs. |
380 if (backend_.get()) | 380 if (backend_.get()) |
381 backend_->StopSyncingForShutdown(); | 381 backend_->StopSyncingForShutdown(); |
382 | 382 |
383 // Stop all data type controllers, if needed. Note that until Stop | 383 // Stop all data type controllers, if needed. Note that until Stop |
384 // completes, it is possible in theory to have a ChangeProcessor apply a | 384 // completes, it is possible in theory to have a ChangeProcessor apply a |
385 // change from a native model. In that case, it will get applied to the sync | 385 // change from a native model. In that case, it will get applied to the sync |
(...skipping 20 matching lines...) Expand all Loading... |
406 | 406 |
407 // Shutdown the migrator before the backend to ensure it doesn't pull a null | 407 // Shutdown the migrator before the backend to ensure it doesn't pull a null |
408 // snapshot. | 408 // snapshot. |
409 migrator_.reset(); | 409 migrator_.reset(); |
410 sync_js_controller_.AttachJsBackend(WeakHandle<JsBackend>()); | 410 sync_js_controller_.AttachJsBackend(WeakHandle<JsBackend>()); |
411 | 411 |
412 // Move aside the backend so nobody else tries to use it while we are | 412 // Move aside the backend so nobody else tries to use it while we are |
413 // shutting it down. | 413 // shutting it down. |
414 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); | 414 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); |
415 if (doomed_backend.get()) { | 415 if (doomed_backend.get()) { |
416 doomed_backend->Shutdown(sync_disabled); | 416 doomed_backend->Shutdown(delete_stale_data); |
417 | 417 |
418 doomed_backend.reset(); | 418 doomed_backend.reset(); |
419 } | 419 } |
420 | 420 |
421 scoped_runnable_method_factory_.RevokeAll(); | 421 scoped_runnable_method_factory_.RevokeAll(); |
422 | 422 |
423 // Clear various flags. | 423 // Clear various flags. |
424 expect_sync_configuration_aborted_ = false; | 424 expect_sync_configuration_aborted_ = false; |
425 is_auth_in_progress_ = false; | 425 is_auth_in_progress_ = false; |
426 backend_initialized_ = false; | 426 backend_initialized_ = false; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 549 |
550 // Shut all data types down. | 550 // Shut all data types down. |
551 MessageLoop::current()->PostTask(FROM_HERE, | 551 MessageLoop::current()->PostTask(FROM_HERE, |
552 scoped_runnable_method_factory_.NewRunnableMethod( | 552 scoped_runnable_method_factory_.NewRunnableMethod( |
553 &ProfileSyncService::Shutdown, true)); | 553 &ProfileSyncService::Shutdown, true)); |
554 } | 554 } |
555 | 555 |
556 void ProfileSyncService::OnBackendInitialized( | 556 void ProfileSyncService::OnBackendInitialized( |
557 const WeakHandle<JsBackend>& js_backend, bool success) { | 557 const WeakHandle<JsBackend>& js_backend, bool success) { |
558 if (!success) { | 558 if (!success) { |
559 // If backend initialization failed, abort. We only want to blow away | 559 // We may have gotten here because the sync database is corrupt. We |
560 // state (DBs, etc) if this was a first-time scenario that failed. | 560 // force its deletion, just in case. |
561 wizard_.Step(SyncSetupWizard::FATAL_ERROR); | 561 wizard_.Step(SyncSetupWizard::FATAL_ERROR); |
562 Shutdown(!HasSyncSetupCompleted()); | 562 Shutdown(true); |
563 return; | 563 return; |
564 } | 564 } |
565 | 565 |
566 backend_initialized_ = true; | 566 backend_initialized_ = true; |
567 | 567 |
568 sync_js_controller_.AttachJsBackend(js_backend); | 568 sync_js_controller_.AttachJsBackend(js_backend); |
569 | 569 |
570 // The very first time the backend initializes is effectively the first time | 570 // The very first time the backend initializes is effectively the first time |
571 // we can say we successfully "synced". last_synced_time_ will only be null | 571 // we can say we successfully "synced". last_synced_time_ will only be null |
572 // in this case, because the pref wasn't restored on StartUp. | 572 // in this case, because the pref wasn't restored on StartUp. |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 << "Unrecoverable error."; | 1559 << "Unrecoverable error."; |
1560 } else { | 1560 } else { |
1561 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1561 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1562 << "initialized"; | 1562 << "initialized"; |
1563 } | 1563 } |
1564 } | 1564 } |
1565 | 1565 |
1566 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1566 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1567 return failed_datatypes_handler_; | 1567 return failed_datatypes_handler_; |
1568 } | 1568 } |
OLD | NEW |