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

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

Issue 7926001: [Sync] Move change-related methods out of SyncManager::Observer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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) 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 syncable::ModelTypeSet initial_types_with_nigori(initial_types); 108 syncable::ModelTypeSet initial_types_with_nigori(initial_types);
109 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) 109 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted))
110 initial_types_with_nigori.insert(syncable::NIGORI); 110 initial_types_with_nigori.insert(syncable::NIGORI);
111 111
112 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori, 112 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori,
113 name_, 113 name_,
114 profile_, 114 profile_,
115 sync_thread_.message_loop())); 115 sync_thread_.message_loop()));
116 116
117 InitCore(Core::DoInitializeOptions( 117 InitCore(Core::DoInitializeOptions(
118 sync_thread_.message_loop(),
118 registrar_.get(), 119 registrar_.get(),
119 event_handler, 120 event_handler,
120 sync_service_url, 121 sync_service_url,
121 profile_->GetRequestContext(), 122 profile_->GetRequestContext(),
122 credentials, 123 credentials,
123 delete_sync_data_folder, 124 delete_sync_data_folder,
124 RestoreEncryptionBootstrapToken(), 125 RestoreEncryptionBootstrapToken(),
125 false)); 126 false));
126 } 127 }
127 128
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 string16 SyncBackendHost::GetAuthenticatedUsername() const { 319 string16 SyncBackendHost::GetAuthenticatedUsername() const {
319 DCHECK(initialized()); 320 DCHECK(initialized());
320 return UTF8ToUTF16(core_->sync_manager()->GetAuthenticatedUsername()); 321 return UTF8ToUTF16(core_->sync_manager()->GetAuthenticatedUsername());
321 } 322 }
322 323
323 bool SyncBackendHost::HasUnsyncedItems() const { 324 bool SyncBackendHost::HasUnsyncedItems() const {
324 DCHECK(initialized()); 325 DCHECK(initialized());
325 return core_->sync_manager()->HasUnsyncedItems(); 326 return core_->sync_manager()->HasUnsyncedItems();
326 } 327 }
327 328
328 void SyncBackendHost::LogUnsyncedItems(int level) const {
329 DCHECK(initialized());
330 return core_->sync_manager()->LogUnsyncedItems(level);
331 }
332
333 bool SyncBackendHost::IsNigoriEnabled() const { 329 bool SyncBackendHost::IsNigoriEnabled() const {
334 return registrar_.get() && registrar_->IsNigoriEnabled(); 330 return registrar_.get() && registrar_->IsNigoriEnabled();
335 } 331 }
336 332
337 bool SyncBackendHost::IsUsingExplicitPassphrase() { 333 bool SyncBackendHost::IsUsingExplicitPassphrase() {
338 return initialized() && IsNigoriEnabled() && 334 return initialized() && IsNigoriEnabled() &&
339 core_->sync_manager()->InitialSyncEndedForAllEnabledTypes() && 335 core_->sync_manager()->InitialSyncEndedForAllEnabledTypes() &&
340 core_->sync_manager()->IsUsingExplicitPassphrase(); 336 core_->sync_manager()->IsUsingExplicitPassphrase();
341 } 337 }
342 338
343 bool SyncBackendHost::IsCryptographerReady( 339 bool SyncBackendHost::IsCryptographerReady(
344 const sync_api::BaseTransaction* trans) const { 340 const sync_api::BaseTransaction* trans) const {
345 return initialized() && trans->GetCryptographer()->is_ready(); 341 return initialized() && trans->GetCryptographer()->is_ready();
346 } 342 }
347 343
348 void SyncBackendHost::GetModelSafeRoutingInfo( 344 void SyncBackendHost::GetModelSafeRoutingInfo(
349 ModelSafeRoutingInfo* out) const { 345 ModelSafeRoutingInfo* out) const {
350 if (initialized()) { 346 if (initialized()) {
351 CHECK(registrar_.get()); 347 CHECK(registrar_.get());
352 registrar_->GetModelSafeRoutingInfo(out); 348 registrar_->GetModelSafeRoutingInfo(out);
353 } else { 349 } else {
354 NOTREACHED(); 350 NOTREACHED();
355 } 351 }
356 } 352 }
357 353
358 SyncBackendHost::Core::Core(const std::string& name, 354 SyncBackendHost::Core::Core(const std::string& name,
359 SyncBackendHost* backend) 355 SyncBackendHost* backend)
360 : name_(name), 356 : name_(name),
361 host_(backend), 357 host_(backend),
358 sync_loop_(NULL),
362 registrar_(NULL) { 359 registrar_(NULL) {
363 DCHECK(host_); 360 DCHECK(host_);
364 } 361 }
365 362
366 SyncBackendHost::Core::~Core() { 363 SyncBackendHost::Core::~Core() {
367 DCHECK(!sync_manager_.get()); 364 DCHECK(!sync_manager_.get());
368 } 365 DCHECK(!sync_loop_);
369
370 void SyncBackendHost::Core::OnChangesApplied(
371 syncable::ModelType model_type,
372 const sync_api::BaseTransaction* trans,
373 const sync_api::ImmutableChangeRecordList& changes) {
374 if (!host_ || !host_->frontend_) {
375 DCHECK(false) << "OnChangesApplied called after Shutdown?";
376 return;
377 }
378 ChangeProcessor* processor = registrar_->GetProcessor(model_type);
379 if (!processor)
380 return;
381
382 processor->ApplyChangesFromSyncModel(trans, changes);
383 }
384
385 void SyncBackendHost::Core::OnChangesComplete(
386 syncable::ModelType model_type) {
387 if (!host_ || !host_->frontend_) {
388 DCHECK(false) << "OnChangesComplete called after Shutdown?";
389 return;
390 }
391
392 ChangeProcessor* processor = registrar_->GetProcessor(model_type);
393 if (!processor)
394 return;
395
396 // This call just notifies the processor that it can commit, it already
397 // buffered any changes it plans to makes so needs no further information.
398 processor->CommitChangesFromSyncModel();
399 } 366 }
400 367
401 void SyncBackendHost::Core::OnSyncCycleCompleted( 368 void SyncBackendHost::Core::OnSyncCycleCompleted(
402 const SyncSessionSnapshot* snapshot) { 369 const SyncSessionSnapshot* snapshot) {
370 if (!sync_loop_)
371 return;
372 DCHECK_EQ(MessageLoop::current(), sync_loop_);
403 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 373 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
404 &Core::HandleSyncCycleCompletedOnFrontendLoop, 374 &Core::HandleSyncCycleCompletedOnFrontendLoop,
405 new SyncSessionSnapshot(*snapshot))); 375 new SyncSessionSnapshot(*snapshot)));
406 } 376 }
407 377
408 378
409 void SyncBackendHost::Core::OnInitializationComplete( 379 void SyncBackendHost::Core::OnInitializationComplete(
410 const WeakHandle<JsBackend>& js_backend, 380 const WeakHandle<JsBackend>& js_backend,
411 bool success) { 381 bool success) {
412 if (!host_ || !host_->frontend_) 382 if (!sync_loop_)
413 return; // We may have been told to Shutdown before initialization 383 return; // We may have been told to Shutdown before initialization
414 // completed. 384 // completed.
385 DCHECK_EQ(MessageLoop::current(), sync_loop_);
415 386
416 // We could be on some random sync backend thread, so MessageLoop::current() 387 // We could be on some random sync backend thread, so MessageLoop::current()
417 // can definitely be null in here. 388 // can definitely be null in here.
418 host_->frontend_loop_->PostTask(FROM_HERE, 389 host_->frontend_loop_->PostTask(FROM_HERE,
419 NewRunnableMethod(this, 390 NewRunnableMethod(this,
420 &Core::HandleInitializationCompletedOnFrontendLoop, 391 &Core::HandleInitializationCompletedOnFrontendLoop,
421 js_backend, success)); 392 js_backend, success));
422 393
423 // Initialization is complete, so we can schedule recurring SaveChanges. 394 // Initialization is complete, so we can schedule recurring SaveChanges.
424 host_->sync_thread_.message_loop()->PostTask(FROM_HERE, 395 sync_loop_->PostTask(FROM_HERE,
425 NewRunnableMethod(this, &Core::StartSavingChanges)); 396 NewRunnableMethod(this, &Core::StartSavingChanges));
426 } 397 }
427 398
428 void SyncBackendHost::Core::OnAuthError(const AuthError& auth_error) { 399 void SyncBackendHost::Core::OnAuthError(const AuthError& auth_error) {
400 if (!sync_loop_)
401 return;
402 DCHECK_EQ(MessageLoop::current(), sync_loop_);
429 // Post to our core loop so we can modify state. Could be on another thread. 403 // Post to our core loop so we can modify state. Could be on another thread.
430 host_->frontend_loop_->PostTask(FROM_HERE, 404 host_->frontend_loop_->PostTask(FROM_HERE,
431 NewRunnableMethod(this, &Core::HandleAuthErrorEventOnFrontendLoop, 405 NewRunnableMethod(this, &Core::HandleAuthErrorEventOnFrontendLoop,
432 auth_error)); 406 auth_error));
433 } 407 }
434 408
435 void SyncBackendHost::Core::OnPassphraseRequired( 409 void SyncBackendHost::Core::OnPassphraseRequired(
436 sync_api::PassphraseRequiredReason reason) { 410 sync_api::PassphraseRequiredReason reason) {
411 if (!sync_loop_)
412 return;
413 DCHECK_EQ(MessageLoop::current(), sync_loop_);
437 host_->frontend_loop_->PostTask(FROM_HERE, 414 host_->frontend_loop_->PostTask(FROM_HERE,
438 NewRunnableMethod(this, &Core::NotifyPassphraseRequired, reason)); 415 NewRunnableMethod(this, &Core::NotifyPassphraseRequired, reason));
439 } 416 }
440 417
441 void SyncBackendHost::Core::OnPassphraseAccepted( 418 void SyncBackendHost::Core::OnPassphraseAccepted(
442 const std::string& bootstrap_token) { 419 const std::string& bootstrap_token) {
420 if (!sync_loop_)
421 return;
422 DCHECK_EQ(MessageLoop::current(), sync_loop_);
443 host_->frontend_loop_->PostTask(FROM_HERE, 423 host_->frontend_loop_->PostTask(FROM_HERE,
444 NewRunnableMethod(this, &Core::NotifyPassphraseAccepted, 424 NewRunnableMethod(this, &Core::NotifyPassphraseAccepted,
445 bootstrap_token)); 425 bootstrap_token));
446 } 426 }
447 427
448 void SyncBackendHost::Core::OnStopSyncingPermanently() { 428 void SyncBackendHost::Core::OnStopSyncingPermanently() {
429 if (!sync_loop_)
430 return;
431 DCHECK_EQ(MessageLoop::current(), sync_loop_);
449 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 432 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
450 &Core::HandleStopSyncingPermanentlyOnFrontendLoop)); 433 &Core::HandleStopSyncingPermanentlyOnFrontendLoop));
451 } 434 }
452 435
453 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) { 436 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) {
437 if (!sync_loop_)
438 return;
439 DCHECK_EQ(MessageLoop::current(), sync_loop_);
454 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 440 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
455 &Core::NotifyUpdatedToken, token)); 441 &Core::NotifyUpdatedToken, token));
456 } 442 }
457 443
458 void SyncBackendHost::Core::OnClearServerDataFailed() { 444 void SyncBackendHost::Core::OnClearServerDataFailed() {
445 if (!sync_loop_)
446 return;
447 DCHECK_EQ(MessageLoop::current(), sync_loop_);
459 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 448 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
460 &Core::HandleClearServerDataFailedOnFrontendLoop)); 449 &Core::HandleClearServerDataFailedOnFrontendLoop));
461 } 450 }
462 451
463 void SyncBackendHost::Core::OnClearServerDataSucceeded() { 452 void SyncBackendHost::Core::OnClearServerDataSucceeded() {
453 if (!sync_loop_)
454 return;
455 DCHECK_EQ(MessageLoop::current(), sync_loop_);
464 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 456 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
465 &Core::HandleClearServerDataSucceededOnFrontendLoop)); 457 &Core::HandleClearServerDataSucceededOnFrontendLoop));
466 } 458 }
467 459
468 void SyncBackendHost::Core::OnEncryptionComplete( 460 void SyncBackendHost::Core::OnEncryptionComplete(
469 const syncable::ModelTypeSet& encrypted_types) { 461 const syncable::ModelTypeSet& encrypted_types) {
462 if (!sync_loop_)
463 return;
464 DCHECK_EQ(MessageLoop::current(), sync_loop_);
470 host_->frontend_loop_->PostTask( 465 host_->frontend_loop_->PostTask(
471 FROM_HERE, 466 FROM_HERE,
472 NewRunnableMethod(this, &Core::NotifyEncryptionComplete, 467 NewRunnableMethod(this, &Core::NotifyEncryptionComplete,
473 encrypted_types)); 468 encrypted_types));
474 } 469 }
475 470
476 void SyncBackendHost::Core::OnActionableError( 471 void SyncBackendHost::Core::OnActionableError(
477 const browser_sync::SyncProtocolError& sync_error) { 472 const browser_sync::SyncProtocolError& sync_error) {
478 if (!host_ || !host_->frontend_) 473 if (!sync_loop_)
479 return; 474 return;
475 DCHECK_EQ(MessageLoop::current(), sync_loop_);
480 host_->frontend_loop_->PostTask( 476 host_->frontend_loop_->PostTask(
481 FROM_HERE, 477 FROM_HERE,
482 NewRunnableMethod(this, &Core::HandleActionableErrorEventOnFrontendLoop, 478 NewRunnableMethod(this, &Core::HandleActionableErrorEventOnFrontendLoop,
483 sync_error)); 479 sync_error));
484 } 480 }
485 481
486 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( 482 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions(
483 MessageLoop* sync_loop,
487 SyncBackendRegistrar* registrar, 484 SyncBackendRegistrar* registrar,
488 const WeakHandle<JsEventHandler>& event_handler, 485 const WeakHandle<JsEventHandler>& event_handler,
489 const GURL& service_url, 486 const GURL& service_url,
490 const scoped_refptr<net::URLRequestContextGetter>& 487 const scoped_refptr<net::URLRequestContextGetter>&
491 request_context_getter, 488 request_context_getter,
492 const sync_api::SyncCredentials& credentials, 489 const sync_api::SyncCredentials& credentials,
493 bool delete_sync_data_folder, 490 bool delete_sync_data_folder,
494 const std::string& restored_key_for_bootstrapping, 491 const std::string& restored_key_for_bootstrapping,
495 bool setup_for_test_mode) 492 bool setup_for_test_mode)
496 : registrar(registrar), 493 : sync_loop(sync_loop),
494 registrar(registrar),
497 event_handler(event_handler), 495 event_handler(event_handler),
498 service_url(service_url), 496 service_url(service_url),
499 request_context_getter(request_context_getter), 497 request_context_getter(request_context_getter),
500 credentials(credentials), 498 credentials(credentials),
501 delete_sync_data_folder(delete_sync_data_folder), 499 delete_sync_data_folder(delete_sync_data_folder),
502 restored_key_for_bootstrapping(restored_key_for_bootstrapping), 500 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
503 setup_for_test_mode(setup_for_test_mode) { 501 setup_for_test_mode(setup_for_test_mode) {
504 } 502 }
505 503
506 SyncBackendHost::Core::DoInitializeOptions::~DoInitializeOptions() {} 504 SyncBackendHost::Core::DoInitializeOptions::~DoInitializeOptions() {}
(...skipping 22 matching lines...) Expand all
529 } 527 }
530 528
531 user_agent += version_info.Version(); 529 user_agent += version_info.Version();
532 user_agent += " (" + version_info.LastChange() + ")"; 530 user_agent += " (" + version_info.LastChange() + ")";
533 if (!version_info.IsOfficialBuild()) 531 if (!version_info.IsOfficialBuild())
534 user_agent += "-devel"; 532 user_agent += "-devel";
535 return user_agent; 533 return user_agent;
536 } 534 }
537 535
538 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { 536 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
539 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); 537 DCHECK(!sync_loop_);
538 sync_loop_ = options.sync_loop;
539 DCHECK(sync_loop_);
540 540
541 // Blow away the partial or corrupt sync data folder before doing any more 541 // Blow away the partial or corrupt sync data folder before doing any more
542 // initialization, if necessary. 542 // initialization, if necessary.
543 if (options.delete_sync_data_folder) { 543 if (options.delete_sync_data_folder) {
544 DeleteSyncDataFolder(); 544 DeleteSyncDataFolder();
545 } 545 }
546 546
547 // Make sure that the directory exists before initializing the backend. 547 // Make sure that the directory exists before initializing the backend.
548 // If it already exists, this will do no harm. 548 // If it already exists, this will do no harm.
549 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); 549 bool success = file_util::CreateDirectory(host_->sync_data_folder_path());
550 DCHECK(success); 550 DCHECK(success);
551 551
552 DCHECK(!registrar_); 552 DCHECK(!registrar_);
553 registrar_ = options.registrar; 553 registrar_ = options.registrar;
554 DCHECK(registrar_); 554 DCHECK(registrar_);
555 555
556 sync_manager_.reset(new sync_api::SyncManager(name_)); 556 sync_manager_.reset(new sync_api::SyncManager(name_));
557 sync_manager_->AddObserver(this); 557 sync_manager_->AddObserver(this);
558 const FilePath& path_str = host_->sync_data_folder_path(); 558 const FilePath& path_str = host_->sync_data_folder_path();
559 success = sync_manager_->Init( 559 success = sync_manager_->Init(
560 path_str, 560 path_str,
561 options.event_handler, 561 options.event_handler,
562 options.service_url.host() + options.service_url.path(), 562 options.service_url.host() + options.service_url.path(),
563 options.service_url.EffectiveIntPort(), 563 options.service_url.EffectiveIntPort(),
564 options.service_url.SchemeIsSecure(), 564 options.service_url.SchemeIsSecure(),
565 host_->MakeHttpBridgeFactory(options.request_context_getter), 565 host_->MakeHttpBridgeFactory(options.request_context_getter),
566 options.registrar, 566 options.registrar /* as ModelSafeWorkerRegistrar */,
567 options.registrar /* as SyncManager::ChangeDelegate */,
567 MakeUserAgentForSyncApi(), 568 MakeUserAgentForSyncApi(),
568 options.credentials, 569 options.credentials,
569 host_->sync_notifier_factory_.CreateSyncNotifier(), 570 host_->sync_notifier_factory_.CreateSyncNotifier(),
570 options.restored_key_for_bootstrapping, 571 options.restored_key_for_bootstrapping,
571 options.setup_for_test_mode); 572 options.setup_for_test_mode);
572 DCHECK(success) << "Syncapi initialization failed!"; 573 DCHECK(success) << "Syncapi initialization failed!";
573 } 574 }
574 575
575 void SyncBackendHost::Core::DoUpdateCredentials( 576 void SyncBackendHost::Core::DoUpdateCredentials(
576 const SyncCredentials& credentials) { 577 const SyncCredentials& credentials) {
577 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); 578 DCHECK_EQ(MessageLoop::current(), sync_loop_);
578 sync_manager_->UpdateCredentials(credentials); 579 sync_manager_->UpdateCredentials(credentials);
579 } 580 }
580 581
581 void SyncBackendHost::Core::DoUpdateEnabledTypes() { 582 void SyncBackendHost::Core::DoUpdateEnabledTypes() {
582 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); 583 DCHECK_EQ(MessageLoop::current(), sync_loop_);
583 sync_manager_->UpdateEnabledTypes(); 584 sync_manager_->UpdateEnabledTypes();
584 } 585 }
585 586
586 void SyncBackendHost::Core::DoStartSyncing() { 587 void SyncBackendHost::Core::DoStartSyncing() {
587 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); 588 DCHECK_EQ(MessageLoop::current(), sync_loop_);
588 sync_manager_->StartSyncingNormally(); 589 sync_manager_->StartSyncingNormally();
589 } 590 }
590 591
591 void SyncBackendHost::Core::DoRequestClearServerData() { 592 void SyncBackendHost::Core::DoRequestClearServerData() {
593 DCHECK_EQ(MessageLoop::current(), sync_loop_);
592 sync_manager_->RequestClearServerData(); 594 sync_manager_->RequestClearServerData();
593 } 595 }
594 596
595 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes() { 597 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes() {
598 DCHECK_EQ(MessageLoop::current(), sync_loop_);
596 sync_manager_->RequestCleanupDisabledTypes(); 599 sync_manager_->RequestCleanupDisabledTypes();
597 } 600 }
598 601
599 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, 602 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase,
600 bool is_explicit) { 603 bool is_explicit) {
601 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); 604 DCHECK_EQ(MessageLoop::current(), sync_loop_);
602 sync_manager_->SetPassphrase(passphrase, is_explicit); 605 sync_manager_->SetPassphrase(passphrase, is_explicit);
603 } 606 }
604 607
605 void SyncBackendHost::Core::DoEnableEncryptEverything() { 608 void SyncBackendHost::Core::DoEnableEncryptEverything() {
606 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); 609 DCHECK_EQ(MessageLoop::current(), sync_loop_);
607 sync_manager_->EnableEncryptEverything(); 610 sync_manager_->EnableEncryptEverything();
608 } 611 }
609 612
610 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { 613 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) {
611 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); 614 DCHECK_EQ(MessageLoop::current(), sync_loop_);
612 615
613 save_changes_timer_.Stop(); 616 save_changes_timer_.Stop();
614 sync_manager_->Shutdown(); // Stops the SyncerThread. 617 sync_manager_->Shutdown(); // Stops the SyncerThread.
615 sync_manager_->RemoveObserver(this); 618 sync_manager_->RemoveObserver(this);
616 sync_manager_.reset(); 619 sync_manager_.reset();
617 registrar_->OnSyncerShutdownComplete(); 620 registrar_->OnSyncerShutdownComplete();
618 registrar_ = NULL; 621 registrar_ = NULL;
619 622
620 if (sync_disabled) 623 if (sync_disabled)
621 DeleteSyncDataFolder(); 624 DeleteSyncDataFolder();
622 625
626 sync_loop_ = NULL;
627
623 host_ = NULL; 628 host_ = NULL;
624 } 629 }
625 630
626 void SyncBackendHost::Core::DoRequestConfig( 631 void SyncBackendHost::Core::DoRequestConfig(
627 const syncable::ModelTypeBitSet& types_to_config, 632 const syncable::ModelTypeBitSet& types_to_config,
628 sync_api::ConfigureReason reason) { 633 sync_api::ConfigureReason reason) {
634 DCHECK_EQ(MessageLoop::current(), sync_loop_);
629 sync_manager_->RequestConfig(types_to_config, reason); 635 sync_manager_->RequestConfig(types_to_config, reason);
630 } 636 }
631 637
632 void SyncBackendHost::Core::DoStartConfiguration(Callback0::Type* callback) { 638 void SyncBackendHost::Core::DoStartConfiguration(Callback0::Type* callback) {
639 DCHECK_EQ(MessageLoop::current(), sync_loop_);
633 sync_manager_->StartConfigurationMode(callback); 640 sync_manager_->StartConfigurationMode(callback);
634 } 641 }
635 642
636 void SyncBackendHost::Core::DeleteSyncDataFolder() { 643 void SyncBackendHost::Core::DeleteSyncDataFolder() {
644 DCHECK_EQ(MessageLoop::current(), sync_loop_);
637 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { 645 if (file_util::DirectoryExists(host_->sync_data_folder_path())) {
638 if (!file_util::Delete(host_->sync_data_folder_path(), true)) 646 if (!file_util::Delete(host_->sync_data_folder_path(), true))
639 SLOG(DFATAL) << "Could not delete the Sync Data folder."; 647 SLOG(DFATAL) << "Could not delete the Sync Data folder.";
640 } 648 }
641 } 649 }
642 650
643 void SyncBackendHost::Core::FinishConfigureDataTypes() { 651 void SyncBackendHost::Core::FinishConfigureDataTypes() {
652 DCHECK_EQ(MessageLoop::current(), sync_loop_);
644 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 653 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
645 &SyncBackendHost::Core::FinishConfigureDataTypesOnFrontendLoop)); 654 &SyncBackendHost::Core::FinishConfigureDataTypesOnFrontendLoop));
646 } 655 }
647 656
648 void SyncBackendHost::Core::HandleInitializationCompletedOnFrontendLoop( 657 void SyncBackendHost::Core::HandleInitializationCompletedOnFrontendLoop(
649 const WeakHandle<JsBackend>& js_backend, 658 const WeakHandle<JsBackend>& js_backend,
650 bool success) { 659 bool success) {
651 if (!host_) 660 if (!host_)
652 return; 661 return;
653 host_->HandleInitializationCompletedOnFrontendLoop(js_backend, success); 662 host_->HandleInitializationCompletedOnFrontendLoop(js_backend, success);
654 } 663 }
655 664
656 void SyncBackendHost::Core::StartSavingChanges() { 665 void SyncBackendHost::Core::StartSavingChanges() {
666 // We may already be shut down.
667 if (!sync_loop_)
668 return;
669 DCHECK_EQ(MessageLoop::current(), sync_loop_);
657 save_changes_timer_.Start(FROM_HERE, 670 save_changes_timer_.Start(FROM_HERE,
658 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 671 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
659 this, &Core::SaveChanges); 672 this, &Core::SaveChanges);
660 } 673 }
661 674
662 void SyncBackendHost::Core::SaveChanges() { 675 void SyncBackendHost::Core::SaveChanges() {
676 DCHECK_EQ(MessageLoop::current(), sync_loop_);
663 sync_manager_->SaveChanges(); 677 sync_manager_->SaveChanges();
664 } 678 }
665 679
666 void SyncBackendHost::Core::HandleActionableErrorEventOnFrontendLoop( 680 void SyncBackendHost::Core::HandleActionableErrorEventOnFrontendLoop(
667 const browser_sync::SyncProtocolError& sync_error) { 681 const browser_sync::SyncProtocolError& sync_error) {
668 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
669 if (!host_ || !host_->frontend_) 682 if (!host_ || !host_->frontend_)
670 return; 683 return;
684 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
671 host_->frontend_->OnActionableError(sync_error); 685 host_->frontend_->OnActionableError(sync_error);
672 } 686 }
673 687
674 void SyncBackendHost::Core::HandleAuthErrorEventOnFrontendLoop( 688 void SyncBackendHost::Core::HandleAuthErrorEventOnFrontendLoop(
675 const GoogleServiceAuthError& new_auth_error) { 689 const GoogleServiceAuthError& new_auth_error) {
676 if (!host_ || !host_->frontend_) 690 if (!host_ || !host_->frontend_)
677 return; 691 return;
678 692
679 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 693 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
680 694
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 : reason(sync_api::CONFIGURE_REASON_UNKNOWN) {} 926 : reason(sync_api::CONFIGURE_REASON_UNKNOWN) {}
913 927
914 SyncBackendHost::PendingConfigureDataTypesState:: 928 SyncBackendHost::PendingConfigureDataTypesState::
915 ~PendingConfigureDataTypesState() {} 929 ~PendingConfigureDataTypesState() {}
916 930
917 #undef SVLOG 931 #undef SVLOG
918 932
919 #undef SLOG 933 #undef SLOG
920 934
921 } // namespace browser_sync 935 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698