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

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

Issue 8496002: Sync: Improve handling of database load failures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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) 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/sync/glue/sync_backend_host.h" 7 #include "chrome/browser/sync/glue/sync_backend_host.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 registrar_->StopOnUIThread(); 210 registrar_->StopOnUIThread();
211 } else { 211 } else {
212 // If the sync thread isn't running, then the syncer is effectively 212 // If the sync thread isn't running, then the syncer is effectively
213 // stopped. Moreover, it implies that we never attempted initialization, 213 // stopped. Moreover, it implies that we never attempted initialization,
214 // so the registrar won't need stopping either. 214 // so the registrar won't need stopping either.
215 DCHECK_EQ(NOT_ATTEMPTED, initialization_state_); 215 DCHECK_EQ(NOT_ATTEMPTED, initialization_state_);
216 DCHECK(!registrar_.get()); 216 DCHECK(!registrar_.get());
217 } 217 }
218 } 218 }
219 219
220 void SyncBackendHost::Shutdown(bool sync_disabled) { 220 void SyncBackendHost::Shutdown(bool delete_stale_data) {
221 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. 221 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice.
222 if (sync_thread_.IsRunning()) { 222 if (sync_thread_.IsRunning()) {
223 sync_thread_.message_loop()->PostTask(FROM_HERE, 223 sync_thread_.message_loop()->PostTask(FROM_HERE,
224 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), 224 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(),
225 sync_disabled)); 225 delete_stale_data));
226 } 226 }
227 227
228 // Stop will return once the thread exits, which will be after DoShutdown 228 // Stop will return once the thread exits, which will be after DoShutdown
229 // runs. DoShutdown needs to run from sync_thread_ because the sync backend 229 // runs. DoShutdown needs to run from sync_thread_ because the sync backend
230 // requires any thread that opened sqlite handles to relinquish them 230 // requires any thread that opened sqlite handles to relinquish them
231 // personally. We need to join threads, because otherwise the main Chrome 231 // personally. We need to join threads, because otherwise the main Chrome
232 // thread (ui loop) can exit before DoShutdown finishes, at which point 232 // thread (ui loop) can exit before DoShutdown finishes, at which point
233 // virtually anything the sync backend does (or the post-back to 233 // virtually anything the sync backend does (or the post-back to
234 // frontend_loop_ by our Core) will epically fail because the CRT won't be 234 // frontend_loop_ by our Core) will epically fail because the CRT won't be
235 // initialized. 235 // initialized.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 413
414 void SyncBackendHost::Core::OnInitializationComplete( 414 void SyncBackendHost::Core::OnInitializationComplete(
415 const WeakHandle<JsBackend>& js_backend, 415 const WeakHandle<JsBackend>& js_backend,
416 bool success) { 416 bool success) {
417 DCHECK_EQ(MessageLoop::current(), sync_loop_); 417 DCHECK_EQ(MessageLoop::current(), sync_loop_);
418 418
419 host_->frontend_loop_->PostTask(FROM_HERE, 419 host_->frontend_loop_->PostTask(FROM_HERE,
420 base::Bind(&Core::HandleInitializationCompletedOnFrontendLoop, this, 420 base::Bind(&Core::HandleInitializationCompletedOnFrontendLoop, this,
421 js_backend, success)); 421 js_backend, success));
422 422
423 // Initialization is complete, so we can schedule recurring SaveChanges. 423 if (success) {
424 sync_loop_->PostTask(FROM_HERE, base::Bind(&Core::StartSavingChanges, this)); 424 // Initialization is complete, so we can schedule recurring SaveChanges.
425 sync_loop_->PostTask(FROM_HERE,
426 base::Bind(&Core::StartSavingChanges, this));
427 }
425 } 428 }
426 429
427 void SyncBackendHost::Core::OnAuthError(const AuthError& auth_error) { 430 void SyncBackendHost::Core::OnAuthError(const AuthError& auth_error) {
428 if (!sync_loop_) 431 if (!sync_loop_)
429 return; 432 return;
430 DCHECK_EQ(MessageLoop::current(), sync_loop_); 433 DCHECK_EQ(MessageLoop::current(), sync_loop_);
431 // Post to our core loop so we can modify state. Could be on another thread. 434 // Post to our core loop so we can modify state. Could be on another thread.
432 host_->frontend_loop_->PostTask(FROM_HERE, 435 host_->frontend_loop_->PostTask(FROM_HERE,
433 base::Bind(&Core::HandleAuthErrorEventOnFrontendLoop, this, auth_error)); 436 base::Bind(&Core::HandleAuthErrorEventOnFrontendLoop, this, auth_error));
434 } 437 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 options.service_url.EffectiveIntPort(), 604 options.service_url.EffectiveIntPort(),
602 options.service_url.SchemeIsSecure(), 605 options.service_url.SchemeIsSecure(),
603 host_->MakeHttpBridgeFactory(options.request_context_getter), 606 host_->MakeHttpBridgeFactory(options.request_context_getter),
604 options.registrar /* as ModelSafeWorkerRegistrar */, 607 options.registrar /* as ModelSafeWorkerRegistrar */,
605 options.registrar /* as SyncManager::ChangeDelegate */, 608 options.registrar /* as SyncManager::ChangeDelegate */,
606 MakeUserAgentForSyncApi(), 609 MakeUserAgentForSyncApi(),
607 options.credentials, 610 options.credentials,
608 host_->sync_notifier_factory_.CreateSyncNotifier(), 611 host_->sync_notifier_factory_.CreateSyncNotifier(),
609 options.restored_key_for_bootstrapping, 612 options.restored_key_for_bootstrapping,
610 options.setup_for_test_mode); 613 options.setup_for_test_mode);
611 DCHECK(success) << "Syncapi initialization failed!";
Nicolas Zea 2011/11/08 22:12:18 LOG_IF(ERROR, !success) would still be useful I th
rlarocque 2011/11/11 22:24:56 Done.
612 } 614 }
613 615
614 void SyncBackendHost::Core::DoCheckServerReachable() { 616 void SyncBackendHost::Core::DoCheckServerReachable() {
615 DCHECK_EQ(MessageLoop::current(), sync_loop_); 617 DCHECK_EQ(MessageLoop::current(), sync_loop_);
616 sync_manager_->CheckServerReachable(); 618 sync_manager_->CheckServerReachable();
617 } 619 }
618 620
619 void SyncBackendHost::Core::DoUpdateCredentials( 621 void SyncBackendHost::Core::DoUpdateCredentials(
620 const SyncCredentials& credentials) { 622 const SyncCredentials& credentials) {
621 DCHECK_EQ(MessageLoop::current(), sync_loop_); 623 DCHECK_EQ(MessageLoop::current(), sync_loop_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 sync_manager_->RefreshEncryption(); 661 sync_manager_->RefreshEncryption();
660 done_callback.Run(); 662 done_callback.Run();
661 } 663 }
662 664
663 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( 665 void SyncBackendHost::Core::DoStopSyncManagerForShutdown(
664 const base::Closure& closure) { 666 const base::Closure& closure) {
665 DCHECK(sync_manager_.get()); 667 DCHECK(sync_manager_.get());
666 sync_manager_->StopSyncingForShutdown(closure); 668 sync_manager_->StopSyncingForShutdown(closure);
667 } 669 }
668 670
669 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { 671 void SyncBackendHost::Core::DoShutdown(bool delete_stale_data) {
670 DCHECK_EQ(MessageLoop::current(), sync_loop_); 672 DCHECK_EQ(MessageLoop::current(), sync_loop_);
671 if (!sync_manager_.get()) 673 if (!sync_manager_.get())
672 return; 674 return;
673 675
674 save_changes_timer_.Stop(); 676 save_changes_timer_.Stop();
675 sync_manager_->ShutdownOnSyncThread(); 677 sync_manager_->ShutdownOnSyncThread();
676 sync_manager_->RemoveObserver(this); 678 sync_manager_->RemoveObserver(this);
677 sync_manager_.reset(); 679 sync_manager_.reset();
678 registrar_ = NULL; 680 registrar_ = NULL;
679 681
680 if (sync_disabled) 682 if (delete_stale_data)
681 DeleteSyncDataFolder(); 683 DeleteSyncDataFolder();
682 684
683 sync_loop_ = NULL; 685 sync_loop_ = NULL;
684 686
685 host_ = NULL; 687 host_ = NULL;
686 } 688 }
687 689
688 void SyncBackendHost::Core::DoRequestConfig( 690 void SyncBackendHost::Core::DoRequestConfig(
689 const syncable::ModelTypeBitSet& types_to_config, 691 const syncable::ModelTypeBitSet& types_to_config,
690 sync_api::ConfigureReason reason) { 692 sync_api::ConfigureReason reason) {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 FROM_HERE, 1047 FROM_HERE,
1046 base::Bind(&SyncBackendHost::Core::DoRefreshEncryption, 1048 base::Bind(&SyncBackendHost::Core::DoRefreshEncryption,
1047 core_.get(), sync_thread_done_callback)); 1049 core_.get(), sync_thread_done_callback));
1048 } 1050 }
1049 1051
1050 #undef SVLOG 1052 #undef SVLOG
1051 1053
1052 #undef SLOG 1054 #undef SLOG
1053 1055
1054 } // namespace browser_sync 1056 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698