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

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

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights 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 "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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 syncer::ConnectionStatus status) OVERRIDE; 91 syncer::ConnectionStatus status) OVERRIDE;
92 virtual void OnPassphraseRequired( 92 virtual void OnPassphraseRequired(
93 syncer::PassphraseRequiredReason reason, 93 syncer::PassphraseRequiredReason reason,
94 const sync_pb::EncryptedData& pending_keys) OVERRIDE; 94 const sync_pb::EncryptedData& pending_keys) OVERRIDE;
95 virtual void OnPassphraseAccepted() OVERRIDE; 95 virtual void OnPassphraseAccepted() OVERRIDE;
96 virtual void OnBootstrapTokenUpdated( 96 virtual void OnBootstrapTokenUpdated(
97 const std::string& bootstrap_token) OVERRIDE; 97 const std::string& bootstrap_token) OVERRIDE;
98 virtual void OnStopSyncingPermanently() OVERRIDE; 98 virtual void OnStopSyncingPermanently() OVERRIDE;
99 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; 99 virtual void OnUpdatedToken(const std::string& token) OVERRIDE;
100 virtual void OnEncryptedTypesChanged( 100 virtual void OnEncryptedTypesChanged(
101 syncable::ModelTypeSet encrypted_types, 101 syncer::ModelTypeSet encrypted_types,
102 bool encrypt_everything) OVERRIDE; 102 bool encrypt_everything) OVERRIDE;
103 virtual void OnEncryptionComplete() OVERRIDE; 103 virtual void OnEncryptionComplete() OVERRIDE;
104 virtual void OnActionableError( 104 virtual void OnActionableError(
105 const syncer::SyncProtocolError& sync_error) OVERRIDE; 105 const syncer::SyncProtocolError& sync_error) OVERRIDE;
106 106
107 // Note: 107 // Note:
108 // 108 //
109 // The Do* methods are the various entry points from our 109 // The Do* methods are the various entry points from our
110 // SyncBackendHost. They are all called on the sync thread to 110 // SyncBackendHost. They are all called on the sync thread to
111 // actually perform synchronous (and potentially blocking) syncapi 111 // actually perform synchronous (and potentially blocking) syncapi
112 // operations. 112 // operations.
113 // 113 //
114 // Called to perform initialization of the syncapi on behalf of 114 // Called to perform initialization of the syncapi on behalf of
115 // SyncBackendHost::Initialize. 115 // SyncBackendHost::Initialize.
116 void DoInitialize(const DoInitializeOptions& options); 116 void DoInitialize(const DoInitializeOptions& options);
117 117
118 // Called to perform credential update on behalf of 118 // Called to perform credential update on behalf of
119 // SyncBackendHost::UpdateCredentials 119 // SyncBackendHost::UpdateCredentials
120 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); 120 void DoUpdateCredentials(const syncer::SyncCredentials& credentials);
121 121
122 // Called when the user disables or enables a sync type. 122 // Called when the user disables or enables a sync type.
123 void DoUpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types); 123 void DoUpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types);
124 124
125 // Called to tell the syncapi to start syncing (generally after 125 // Called to tell the syncapi to start syncing (generally after
126 // initialization and authentication). 126 // initialization and authentication).
127 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); 127 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info);
128 128
129 // Called to cleanup disabled types. 129 // Called to cleanup disabled types.
130 void DoRequestCleanupDisabledTypes( 130 void DoRequestCleanupDisabledTypes(
131 const syncer::ModelSafeRoutingInfo& routing_info); 131 const syncer::ModelSafeRoutingInfo& routing_info);
132 132
133 // Called to set the passphrase for encryption. 133 // Called to set the passphrase for encryption.
(...skipping 20 matching lines...) Expand all
154 // to run and make use of cached pointers to various components 154 // to run and make use of cached pointers to various components
155 // owned implicitly by us. 155 // owned implicitly by us.
156 // 3) Destroy this Core. That will delete syncapi components in a 156 // 3) Destroy this Core. That will delete syncapi components in a
157 // safe order because the thread that was using them has exited 157 // safe order because the thread that was using them has exited
158 // (in step 2). 158 // (in step 2).
159 void DoStopSyncManagerForShutdown(const base::Closure& closure); 159 void DoStopSyncManagerForShutdown(const base::Closure& closure);
160 void DoShutdown(bool stopping_sync); 160 void DoShutdown(bool stopping_sync);
161 161
162 virtual void DoRequestConfig( 162 virtual void DoRequestConfig(
163 const syncer::ModelSafeRoutingInfo& routing_info, 163 const syncer::ModelSafeRoutingInfo& routing_info,
164 syncable::ModelTypeSet types_to_config, 164 syncer::ModelTypeSet types_to_config,
165 syncer::ConfigureReason reason); 165 syncer::ConfigureReason reason);
166 166
167 // Start the configuration mode. |callback| is called on the sync 167 // Start the configuration mode. |callback| is called on the sync
168 // thread. 168 // thread.
169 virtual void DoStartConfiguration(const base::Closure& callback); 169 virtual void DoStartConfiguration(const base::Closure& callback);
170 170
171 // Set the base request context to use when making HTTP calls. 171 // Set the base request context to use when making HTTP calls.
172 // This method will add a reference to the context to persist it 172 // This method will add a reference to the context to persist it
173 // on the IO thread. Must be removed from IO thread. 173 // on the IO thread. Must be removed from IO thread.
174 174
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 const scoped_refptr<net::URLRequestContextGetter>& getter) { 359 const scoped_refptr<net::URLRequestContextGetter>& getter) {
360 return new syncer::HttpBridgeFactory(getter, MakeUserAgentForSyncApi()); 360 return new syncer::HttpBridgeFactory(getter, MakeUserAgentForSyncApi());
361 } 361 }
362 362
363 } // namespace 363 } // namespace
364 364
365 void SyncBackendHost::Initialize( 365 void SyncBackendHost::Initialize(
366 SyncFrontend* frontend, 366 SyncFrontend* frontend,
367 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 367 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
368 const GURL& sync_service_url, 368 const GURL& sync_service_url,
369 syncable::ModelTypeSet initial_types, 369 syncer::ModelTypeSet initial_types,
370 const SyncCredentials& credentials, 370 const SyncCredentials& credentials,
371 bool delete_sync_data_folder, 371 bool delete_sync_data_folder,
372 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 372 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
373 syncer::ReportUnrecoverableErrorFunction 373 syncer::ReportUnrecoverableErrorFunction
374 report_unrecoverable_error_function) { 374 report_unrecoverable_error_function) {
375 if (!sync_thread_.Start()) 375 if (!sync_thread_.Start())
376 return; 376 return;
377 377
378 frontend_ = frontend; 378 frontend_ = frontend;
379 DCHECK(frontend); 379 DCHECK(frontend);
380 380
381 syncable::ModelTypeSet initial_types_with_nigori(initial_types); 381 syncer::ModelTypeSet initial_types_with_nigori(initial_types);
382 CHECK(sync_prefs_.get()); 382 CHECK(sync_prefs_.get());
383 if (sync_prefs_->HasSyncSetupCompleted()) { 383 if (sync_prefs_->HasSyncSetupCompleted()) {
384 initial_types_with_nigori.Put(syncable::NIGORI); 384 initial_types_with_nigori.Put(syncer::NIGORI);
385 } 385 }
386 386
387 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori, 387 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori,
388 name_, 388 name_,
389 profile_, 389 profile_,
390 sync_thread_.message_loop())); 390 sync_thread_.message_loop()));
391 syncer::ModelSafeRoutingInfo routing_info; 391 syncer::ModelSafeRoutingInfo routing_info;
392 std::vector<syncer::ModelSafeWorker*> workers; 392 std::vector<syncer::ModelSafeWorker*> workers;
393 registrar_->GetModelSafeRoutingInfo(&routing_info); 393 registrar_->GetModelSafeRoutingInfo(&routing_info);
394 registrar_->GetWorkers(&workers); 394 registrar_->GetWorkers(&workers);
(...skipping 21 matching lines...) Expand all
416 416
417 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { 417 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
418 sync_thread_.message_loop()->PostTask(FROM_HERE, 418 sync_thread_.message_loop()->PostTask(FROM_HERE,
419 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), 419 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(),
420 credentials)); 420 credentials));
421 } 421 }
422 422
423 void SyncBackendHost::StartSyncingWithServer() { 423 void SyncBackendHost::StartSyncingWithServer() {
424 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; 424 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called.";
425 425
426 syncer::ModelSafeRoutingInfo routing_info; 426 syncer::ModelSafeRoutingInfo routing_info;
427 registrar_->GetModelSafeRoutingInfo(&routing_info); 427 registrar_->GetModelSafeRoutingInfo(&routing_info);
428 428
429 sync_thread_.message_loop()->PostTask(FROM_HERE, 429 sync_thread_.message_loop()->PostTask(FROM_HERE,
430 base::Bind(&SyncBackendHost::Core::DoStartSyncing, 430 base::Bind(&SyncBackendHost::Core::DoStartSyncing,
431 core_.get(), routing_info)); 431 core_.get(), routing_info));
432 } 432 }
433 433
434 void SyncBackendHost::SetEncryptionPassphrase(const std::string& passphrase, 434 void SyncBackendHost::SetEncryptionPassphrase(const std::string& passphrase,
435 bool is_explicit) { 435 bool is_explicit) {
436 if (!IsNigoriEnabled()) { 436 if (!IsNigoriEnabled()) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", 579 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime",
580 stop_sync_thread_time); 580 stop_sync_thread_time);
581 581
582 registrar_.reset(); 582 registrar_.reset();
583 frontend_ = NULL; 583 frontend_ = NULL;
584 core_ = NULL; // Releases reference to core_. 584 core_ = NULL; // Releases reference to core_.
585 } 585 }
586 586
587 void SyncBackendHost::ConfigureDataTypes( 587 void SyncBackendHost::ConfigureDataTypes(
588 syncer::ConfigureReason reason, 588 syncer::ConfigureReason reason,
589 syncable::ModelTypeSet types_to_add, 589 syncer::ModelTypeSet types_to_add,
590 syncable::ModelTypeSet types_to_remove, 590 syncer::ModelTypeSet types_to_remove,
591 NigoriState nigori_state, 591 NigoriState nigori_state,
592 base::Callback<void(syncable::ModelTypeSet)> ready_task, 592 base::Callback<void(syncer::ModelTypeSet)> ready_task,
593 base::Callback<void()> retry_callback) { 593 base::Callback<void()> retry_callback) {
594 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add; 594 syncer::ModelTypeSet types_to_add_with_nigori = types_to_add;
595 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove; 595 syncer::ModelTypeSet types_to_remove_with_nigori = types_to_remove;
596 if (nigori_state == WITH_NIGORI) { 596 if (nigori_state == WITH_NIGORI) {
597 types_to_add_with_nigori.Put(syncable::NIGORI); 597 types_to_add_with_nigori.Put(syncer::NIGORI);
598 types_to_remove_with_nigori.Remove(syncable::NIGORI); 598 types_to_remove_with_nigori.Remove(syncer::NIGORI);
599 } else { 599 } else {
600 types_to_add_with_nigori.Remove(syncable::NIGORI); 600 types_to_add_with_nigori.Remove(syncer::NIGORI);
601 types_to_remove_with_nigori.Put(syncable::NIGORI); 601 types_to_remove_with_nigori.Put(syncer::NIGORI);
602 } 602 }
603 // Only one configure is allowed at a time. 603 // Only one configure is allowed at a time.
604 DCHECK(!pending_config_mode_state_.get()); 604 DCHECK(!pending_config_mode_state_.get());
605 DCHECK(!pending_download_state_.get()); 605 DCHECK(!pending_download_state_.get());
606 DCHECK_GT(initialization_state_, NOT_INITIALIZED); 606 DCHECK_GT(initialization_state_, NOT_INITIALIZED);
607 607
608 pending_config_mode_state_.reset(new PendingConfigureDataTypesState()); 608 pending_config_mode_state_.reset(new PendingConfigureDataTypesState());
609 pending_config_mode_state_->ready_task = ready_task; 609 pending_config_mode_state_->ready_task = ready_task;
610 pending_config_mode_state_->types_to_add = types_to_add_with_nigori; 610 pending_config_mode_state_->types_to_add = types_to_add_with_nigori;
611 pending_config_mode_state_->added_types = 611 pending_config_mode_state_->added_types =
612 registrar_->ConfigureDataTypes(types_to_add_with_nigori, 612 registrar_->ConfigureDataTypes(types_to_add_with_nigori,
613 types_to_remove_with_nigori); 613 types_to_remove_with_nigori);
614 pending_config_mode_state_->reason = reason; 614 pending_config_mode_state_->reason = reason;
615 pending_config_mode_state_->retry_callback = retry_callback; 615 pending_config_mode_state_->retry_callback = retry_callback;
616 616
617 // Cleanup disabled types before starting configuration so that 617 // Cleanup disabled types before starting configuration so that
618 // callers can assume that the data types are cleaned up once 618 // callers can assume that the data types are cleaned up once
619 // configuration is done. 619 // configuration is done.
620 if (!types_to_remove_with_nigori.Empty()) { 620 if (!types_to_remove_with_nigori.Empty()) {
621 syncer::ModelSafeRoutingInfo routing_info; 621 syncer::ModelSafeRoutingInfo routing_info;
622 registrar_->GetModelSafeRoutingInfo(&routing_info); 622 registrar_->GetModelSafeRoutingInfo(&routing_info);
623 sync_thread_.message_loop()->PostTask( 623 sync_thread_.message_loop()->PostTask(
624 FROM_HERE, 624 FROM_HERE,
625 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes, 625 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes,
626 core_.get(), 626 core_.get(),
627 routing_info)); 627 routing_info));
628 } 628 }
629 629
630 StartConfiguration( 630 StartConfiguration(
631 base::Bind(&SyncBackendHost::Core::FinishConfigureDataTypes, 631 base::Bind(&SyncBackendHost::Core::FinishConfigureDataTypes,
632 core_.get())); 632 core_.get()));
633 } 633 }
634 634
635 void SyncBackendHost::StartConfiguration(const base::Closure& callback) { 635 void SyncBackendHost::StartConfiguration(const base::Closure& callback) {
636 // Put syncer in the config mode. DTM will put us in normal mode once it is 636 // Put syncer in the config mode. DTM will put us in normal mode once it is
637 // done. This is to ensure we dont do a normal sync when we are doing model 637 // done. This is to ensure we dont do a normal sync when we are doing model
638 // association. 638 // association.
639 sync_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 639 sync_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
640 &SyncBackendHost::Core::DoStartConfiguration, core_.get(), callback)); 640 &SyncBackendHost::Core::DoStartConfiguration, core_.get(), callback));
641 } 641 }
642 642
643 void SyncBackendHost::EnableEncryptEverything() { 643 void SyncBackendHost::EnableEncryptEverything() {
644 sync_thread_.message_loop()->PostTask(FROM_HERE, 644 sync_thread_.message_loop()->PostTask(FROM_HERE,
645 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything, 645 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything,
646 core_.get())); 646 core_.get()));
647 } 647 }
648 648
649 void SyncBackendHost::ActivateDataType( 649 void SyncBackendHost::ActivateDataType(
650 syncable::ModelType type, syncer::ModelSafeGroup group, 650 syncer::ModelType type, syncer::ModelSafeGroup group,
651 ChangeProcessor* change_processor) { 651 ChangeProcessor* change_processor) {
652 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); 652 registrar_->ActivateDataType(type, group, change_processor, GetUserShare());
653 } 653 }
654 654
655 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) { 655 void SyncBackendHost::DeactivateDataType(syncer::ModelType type) {
656 registrar_->DeactivateDataType(type); 656 registrar_->DeactivateDataType(type);
657 } 657 }
658 658
659 syncer::UserShare* SyncBackendHost::GetUserShare() const { 659 syncer::UserShare* SyncBackendHost::GetUserShare() const {
660 DCHECK(initialized()); 660 DCHECK(initialized());
661 return core_->sync_manager()->GetUserShare(); 661 return core_->sync_manager()->GetUserShare();
662 } 662 }
663 663
664 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { 664 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() {
665 DCHECK(initialized()); 665 DCHECK(initialized());
(...skipping 21 matching lines...) Expand all
687 return IsNigoriEnabled() && 687 return IsNigoriEnabled() &&
688 core_->sync_manager()->IsUsingExplicitPassphrase(); 688 core_->sync_manager()->IsUsingExplicitPassphrase();
689 } 689 }
690 690
691 bool SyncBackendHost::IsCryptographerReady( 691 bool SyncBackendHost::IsCryptographerReady(
692 const syncer::BaseTransaction* trans) const { 692 const syncer::BaseTransaction* trans) const {
693 return initialized() && trans->GetCryptographer()->is_ready(); 693 return initialized() && trans->GetCryptographer()->is_ready();
694 } 694 }
695 695
696 void SyncBackendHost::GetModelSafeRoutingInfo( 696 void SyncBackendHost::GetModelSafeRoutingInfo(
697 syncer::ModelSafeRoutingInfo* out) const { 697 syncer::ModelSafeRoutingInfo* out) const {
698 if (initialized()) { 698 if (initialized()) {
699 CHECK(registrar_.get()); 699 CHECK(registrar_.get());
700 registrar_->GetModelSafeRoutingInfo(out); 700 registrar_->GetModelSafeRoutingInfo(out);
701 } else { 701 } else {
702 NOTREACHED(); 702 NOTREACHED();
703 } 703 }
704 } 704 }
705 705
706 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { 706 void SyncBackendHost::InitCore(const DoInitializeOptions& options) {
707 sync_thread_.message_loop()->PostTask(FROM_HERE, 707 sync_thread_.message_loop()->PostTask(FROM_HERE,
708 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); 708 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options));
709 } 709 }
710 710
711 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( 711 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop(
712 const SyncSessionSnapshot& snapshot) { 712 const SyncSessionSnapshot& snapshot) {
713 if (!frontend_) 713 if (!frontend_)
714 return; 714 return;
715 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 715 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
716 716
717 last_snapshot_ = snapshot; 717 last_snapshot_ = snapshot;
718 718
719 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); 719 SDVLOG(1) << "Got snapshot " << snapshot.ToString();
720 720
721 const syncable::ModelTypeSet to_migrate = 721 const syncer::ModelTypeSet to_migrate =
722 snapshot.model_neutral_state().types_needing_local_migration; 722 snapshot.model_neutral_state().types_needing_local_migration;
723 if (!to_migrate.Empty()) 723 if (!to_migrate.Empty())
724 frontend_->OnMigrationNeededForTypes(to_migrate); 724 frontend_->OnMigrationNeededForTypes(to_migrate);
725 725
726 // Process any changes to the datatypes we're syncing. 726 // Process any changes to the datatypes we're syncing.
727 // TODO(sync): add support for removing types. 727 // TODO(sync): add support for removing types.
728 if (initialized()) 728 if (initialized())
729 AddExperimentalTypes(); 729 AddExperimentalTypes();
730 730
731 // If we are waiting for a configuration change, check here to see 731 // If we are waiting for a configuration change, check here to see
732 // if this sync cycle has initialized all of the types we've been 732 // if this sync cycle has initialized all of the types we've been
733 // waiting for. 733 // waiting for.
734 if (pending_download_state_.get()) { 734 if (pending_download_state_.get()) {
735 const syncable::ModelTypeSet types_to_add = 735 const syncer::ModelTypeSet types_to_add =
736 pending_download_state_->types_to_add; 736 pending_download_state_->types_to_add;
737 const syncable::ModelTypeSet added_types = 737 const syncer::ModelTypeSet added_types =
738 pending_download_state_->added_types; 738 pending_download_state_->added_types;
739 DCHECK(types_to_add.HasAll(added_types)); 739 DCHECK(types_to_add.HasAll(added_types));
740 const syncable::ModelTypeSet initial_sync_ended = 740 const syncer::ModelTypeSet initial_sync_ended =
741 snapshot.initial_sync_ended(); 741 snapshot.initial_sync_ended();
742 const syncable::ModelTypeSet failed_configuration_types = 742 const syncer::ModelTypeSet failed_configuration_types =
743 Difference(added_types, initial_sync_ended); 743 Difference(added_types, initial_sync_ended);
744 SDVLOG(1) 744 SDVLOG(1)
745 << "Added types: " 745 << "Added types: "
746 << syncable::ModelTypeSetToString(added_types) 746 << syncer::ModelTypeSetToString(added_types)
747 << ", configured types: " 747 << ", configured types: "
748 << syncable::ModelTypeSetToString(initial_sync_ended) 748 << syncer::ModelTypeSetToString(initial_sync_ended)
749 << ", failed configuration types: " 749 << ", failed configuration types: "
750 << syncable::ModelTypeSetToString(failed_configuration_types); 750 << syncer::ModelTypeSetToString(failed_configuration_types);
751 751
752 if (!failed_configuration_types.Empty() && 752 if (!failed_configuration_types.Empty() &&
753 snapshot.retry_scheduled()) { 753 snapshot.retry_scheduled()) {
754 // Inform the caller that download failed but we are retrying. 754 // Inform the caller that download failed but we are retrying.
755 if (!pending_download_state_->retry_in_progress) { 755 if (!pending_download_state_->retry_in_progress) {
756 pending_download_state_->retry_callback.Run(); 756 pending_download_state_->retry_callback.Run();
757 pending_download_state_->retry_in_progress = true; 757 pending_download_state_->retry_in_progress = true;
758 } 758 }
759 // Nothing more to do. 759 // Nothing more to do.
760 return; 760 return;
(...skipping 22 matching lines...) Expand all
783 // 783 //
784 // In the case of additions, on the next sync cycle, the syncer should 784 // In the case of additions, on the next sync cycle, the syncer should
785 // notice that the routing info has changed and start the process of 785 // notice that the routing info has changed and start the process of
786 // downloading updates for newly added data types. Once this is 786 // downloading updates for newly added data types. Once this is
787 // complete, the configure_state_.ready_task_ is run via an 787 // complete, the configure_state_.ready_task_ is run via an
788 // OnInitializationComplete notification. 788 // OnInitializationComplete notification.
789 789
790 SDVLOG(1) << "Syncer in config mode. SBH executing " 790 SDVLOG(1) << "Syncer in config mode. SBH executing "
791 << "FinishConfigureDataTypesOnFrontendLoop"; 791 << "FinishConfigureDataTypesOnFrontendLoop";
792 792
793 793 syncer::ModelSafeRoutingInfo routing_info;
794 syncer::ModelSafeRoutingInfo routing_info;
795 registrar_->GetModelSafeRoutingInfo(&routing_info); 794 registrar_->GetModelSafeRoutingInfo(&routing_info);
796 const syncable::ModelTypeSet enabled_types = 795 const syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
797 GetRoutingInfoTypes(routing_info);
798 796
799 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has 797 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has
800 // to happen on the UI thread. 798 // to happen on the UI thread.
801 chrome_sync_notification_bridge_.UpdateEnabledTypes(enabled_types); 799 chrome_sync_notification_bridge_.UpdateEnabledTypes(enabled_types);
802 800
803 if (pending_config_mode_state_->added_types.Empty() && 801 if (pending_config_mode_state_->added_types.Empty() &&
804 !core_->sync_manager()->InitialSyncEndedTypes().HasAll(enabled_types)) { 802 !core_->sync_manager()->InitialSyncEndedTypes().HasAll(enabled_types)) {
805 803
806 // TODO(tim): Log / UMA / count this somehow? 804 // TODO(tim): Log / UMA / count this somehow?
807 // Add only the types with empty progress markers. Note: it is possible 805 // Add only the types with empty progress markers. Note: it is possible
808 // that some types have their initial_sync_ended be false but with non 806 // that some types have their initial_sync_ended be false but with non
809 // empty progress marker. Which is ok as the rest of the changes would 807 // empty progress marker. Which is ok as the rest of the changes would
810 // be downloaded on a regular nudge and initial_sync_ended should be set 808 // be downloaded on a regular nudge and initial_sync_ended should be set
811 // to true. However this is a very corner case. So it is not explicitly 809 // to true. However this is a very corner case. So it is not explicitly
812 // handled. 810 // handled.
813 pending_config_mode_state_->added_types = 811 pending_config_mode_state_->added_types =
814 syncer::GetTypesWithEmptyProgressMarkerToken(enabled_types, 812 syncer::GetTypesWithEmptyProgressMarkerToken(enabled_types,
815 GetUserShare()); 813 GetUserShare());
816 } 814 }
817 815
818 // If we've added types, we always want to request a nudge/config (even if 816 // If we've added types, we always want to request a nudge/config (even if
819 // the initial sync is ended), in case we could not decrypt the data. 817 // the initial sync is ended), in case we could not decrypt the data.
820 if (pending_config_mode_state_->added_types.Empty()) { 818 if (pending_config_mode_state_->added_types.Empty()) {
821 SDVLOG(1) << "No new types added; calling ready_task directly"; 819 SDVLOG(1) << "No new types added; calling ready_task directly";
822 // No new types - just notify the caller that the types are available. 820 // No new types - just notify the caller that the types are available.
823 const syncable::ModelTypeSet failed_configuration_types; 821 const syncer::ModelTypeSet failed_configuration_types;
824 pending_config_mode_state_->ready_task.Run(failed_configuration_types); 822 pending_config_mode_state_->ready_task.Run(failed_configuration_types);
825 } else { 823 } else {
826 pending_download_state_.reset(pending_config_mode_state_.release()); 824 pending_download_state_.reset(pending_config_mode_state_.release());
827 825
828 // Always configure nigori if it's enabled. 826 // Always configure nigori if it's enabled.
829 syncable::ModelTypeSet types_to_config = 827 syncer::ModelTypeSet types_to_config = pending_download_state_->added_types;
830 pending_download_state_->added_types;
831 if (IsNigoriEnabled()) { 828 if (IsNigoriEnabled()) {
832 // Note: Nigori is the only type that gets added with a nonempty 829 // Note: Nigori is the only type that gets added with a nonempty
833 // progress marker during config. If the server returns a migration 830 // progress marker during config. If the server returns a migration
834 // error then we will go into unrecoverable error. We dont handle it 831 // error then we will go into unrecoverable error. We dont handle it
835 // explicitly because server might help us out here by not sending a 832 // explicitly because server might help us out here by not sending a
836 // migraiton error for nigori during config. 833 // migraiton error for nigori during config.
837 types_to_config.Put(syncable::NIGORI); 834 types_to_config.Put(syncer::NIGORI);
838 } 835 }
839 SDVLOG(1) << "Types " 836 SDVLOG(1) << "Types "
840 << syncable::ModelTypeSetToString(types_to_config) 837 << syncer::ModelTypeSetToString(types_to_config)
841 << " added; calling DoRequestConfig"; 838 << " added; calling DoRequestConfig";
842 syncer::ModelSafeRoutingInfo routing_info; 839 syncer::ModelSafeRoutingInfo routing_info;
843 registrar_->GetModelSafeRoutingInfo(&routing_info); 840 registrar_->GetModelSafeRoutingInfo(&routing_info);
844 sync_thread_.message_loop()->PostTask(FROM_HERE, 841 sync_thread_.message_loop()->PostTask(FROM_HERE,
845 base::Bind(&SyncBackendHost::Core::DoRequestConfig, 842 base::Bind(&SyncBackendHost::Core::DoRequestConfig,
846 core_.get(), 843 core_.get(),
847 routing_info, 844 routing_info,
848 types_to_config, 845 types_to_config,
849 pending_download_state_->reason)); 846 pending_download_state_->reason));
850 } 847 }
851 848
852 pending_config_mode_state_.reset(); 849 pending_config_mode_state_.reset();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) { 1001 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) {
1005 if (!sync_loop_) 1002 if (!sync_loop_)
1006 return; 1003 return;
1007 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1004 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1008 host_.Call( 1005 host_.Call(
1009 FROM_HERE, 1006 FROM_HERE,
1010 &SyncBackendHost::NotifyUpdatedToken, token); 1007 &SyncBackendHost::NotifyUpdatedToken, token);
1011 } 1008 }
1012 1009
1013 void SyncBackendHost::Core::OnEncryptedTypesChanged( 1010 void SyncBackendHost::Core::OnEncryptedTypesChanged(
1014 syncable::ModelTypeSet encrypted_types, 1011 syncer::ModelTypeSet encrypted_types,
1015 bool encrypt_everything) { 1012 bool encrypt_everything) {
1016 if (!sync_loop_) 1013 if (!sync_loop_)
1017 return; 1014 return;
1018 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1015 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1019 // NOTE: We're in a transaction. 1016 // NOTE: We're in a transaction.
1020 host_.Call( 1017 host_.Call(
1021 FROM_HERE, 1018 FROM_HERE,
1022 &SyncBackendHost::NotifyEncryptedTypesChanged, 1019 &SyncBackendHost::NotifyEncryptedTypesChanged,
1023 encrypted_types, encrypt_everything); 1020 encrypted_types, encrypt_everything);
1024 } 1021 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 } 1098 }
1102 } 1099 }
1103 1100
1104 void SyncBackendHost::Core::DoUpdateCredentials( 1101 void SyncBackendHost::Core::DoUpdateCredentials(
1105 const SyncCredentials& credentials) { 1102 const SyncCredentials& credentials) {
1106 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1103 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1107 sync_manager_->UpdateCredentials(credentials); 1104 sync_manager_->UpdateCredentials(credentials);
1108 } 1105 }
1109 1106
1110 void SyncBackendHost::Core::DoUpdateEnabledTypes( 1107 void SyncBackendHost::Core::DoUpdateEnabledTypes(
1111 const syncable::ModelTypeSet& enabled_types) { 1108 const syncer::ModelTypeSet& enabled_types) {
1112 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1109 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1113 sync_manager_->UpdateEnabledTypes(enabled_types); 1110 sync_manager_->UpdateEnabledTypes(enabled_types);
1114 } 1111 }
1115 1112
1116 void SyncBackendHost::Core::DoStartSyncing( 1113 void SyncBackendHost::Core::DoStartSyncing(
1117 const syncer::ModelSafeRoutingInfo& routing_info) { 1114 const syncer::ModelSafeRoutingInfo& routing_info) {
1118 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1115 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1119 sync_manager_->StartSyncingNormally(routing_info); 1116 sync_manager_->StartSyncingNormally(routing_info);
1120 } 1117 }
1121 1118
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 if (sync_disabled) 1168 if (sync_disabled)
1172 DeleteSyncDataFolder(); 1169 DeleteSyncDataFolder();
1173 1170
1174 sync_loop_ = NULL; 1171 sync_loop_ = NULL;
1175 1172
1176 host_.Reset(); 1173 host_.Reset();
1177 } 1174 }
1178 1175
1179 void SyncBackendHost::Core::DoRequestConfig( 1176 void SyncBackendHost::Core::DoRequestConfig(
1180 const syncer::ModelSafeRoutingInfo& routing_info, 1177 const syncer::ModelSafeRoutingInfo& routing_info,
1181 syncable::ModelTypeSet types_to_config, 1178 syncer::ModelTypeSet types_to_config,
1182 syncer::ConfigureReason reason) { 1179 syncer::ConfigureReason reason) {
1183 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1180 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1184 sync_manager_->RequestConfig(routing_info, types_to_config, reason); 1181 sync_manager_->RequestConfig(routing_info, types_to_config, reason);
1185 } 1182 }
1186 1183
1187 void SyncBackendHost::Core::DoStartConfiguration( 1184 void SyncBackendHost::Core::DoStartConfiguration(
1188 const base::Closure& callback) { 1185 const base::Closure& callback) {
1189 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1186 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1190 sync_manager_->StartConfigurationMode(callback); 1187 sync_manager_->StartConfigurationMode(callback);
1191 } 1188 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 initialization_state_ < DOWNLOADING_NIGORI) { 1260 initialization_state_ < DOWNLOADING_NIGORI) {
1264 initialization_state_ = DOWNLOADING_NIGORI; 1261 initialization_state_ = DOWNLOADING_NIGORI;
1265 } 1262 }
1266 1263
1267 // Run initialization state machine. 1264 // Run initialization state machine.
1268 switch (initialization_state_) { 1265 switch (initialization_state_) {
1269 case NOT_INITIALIZED: 1266 case NOT_INITIALIZED:
1270 initialization_state_ = DOWNLOADING_NIGORI; 1267 initialization_state_ = DOWNLOADING_NIGORI;
1271 ConfigureDataTypes( 1268 ConfigureDataTypes(
1272 syncer::CONFIGURE_REASON_NEW_CLIENT, 1269 syncer::CONFIGURE_REASON_NEW_CLIENT,
1273 syncable::ModelTypeSet(), 1270 syncer::ModelTypeSet(),
1274 syncable::ModelTypeSet(), 1271 syncer::ModelTypeSet(),
1275 WITH_NIGORI, 1272 WITH_NIGORI,
1276 // Calls back into this function. 1273 // Calls back into this function.
1277 base::Bind( 1274 base::Bind(
1278 &SyncBackendHost:: 1275 &SyncBackendHost::
1279 HandleNigoriConfigurationCompletedOnFrontendLoop, 1276 HandleNigoriConfigurationCompletedOnFrontendLoop,
1280 weak_ptr_factory_.GetWeakPtr(), js_backend), 1277 weak_ptr_factory_.GetWeakPtr(), js_backend),
1281 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, 1278 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry,
1282 weak_ptr_factory_.GetWeakPtr())); 1279 weak_ptr_factory_.GetWeakPtr()));
1283 break; 1280 break;
1284 case DOWNLOADING_NIGORI: 1281 case DOWNLOADING_NIGORI:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 void SyncBackendHost::NotifyUpdatedToken(const std::string& token) { 1354 void SyncBackendHost::NotifyUpdatedToken(const std::string& token) {
1358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1359 TokenAvailableDetails details(GaiaConstants::kSyncService, token); 1356 TokenAvailableDetails details(GaiaConstants::kSyncService, token);
1360 content::NotificationService::current()->Notify( 1357 content::NotificationService::current()->Notify(
1361 chrome::NOTIFICATION_TOKEN_UPDATED, 1358 chrome::NOTIFICATION_TOKEN_UPDATED,
1362 content::Source<Profile>(profile_), 1359 content::Source<Profile>(profile_),
1363 content::Details<const TokenAvailableDetails>(&details)); 1360 content::Details<const TokenAvailableDetails>(&details));
1364 } 1361 }
1365 1362
1366 void SyncBackendHost::NotifyEncryptedTypesChanged( 1363 void SyncBackendHost::NotifyEncryptedTypesChanged(
1367 syncable::ModelTypeSet encrypted_types, 1364 syncer::ModelTypeSet encrypted_types,
1368 bool encrypt_everything) { 1365 bool encrypt_everything) {
1369 if (!frontend_) 1366 if (!frontend_)
1370 return; 1367 return;
1371 1368
1372 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1369 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1373 frontend_->OnEncryptedTypesChanged( 1370 frontend_->OnEncryptedTypesChanged(
1374 encrypted_types, encrypt_everything); 1371 encrypted_types, encrypt_everything);
1375 } 1372 }
1376 1373
1377 void SyncBackendHost::NotifyEncryptionComplete() { 1374 void SyncBackendHost::NotifyEncryptionComplete() {
(...skipping 15 matching lines...) Expand all
1393 if (!frontend_) 1390 if (!frontend_)
1394 return; 1391 return;
1395 1392
1396 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1393 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1397 1394
1398 frontend_->OnConnectionStatusChange(status); 1395 frontend_->OnConnectionStatusChange(status);
1399 } 1396 }
1400 1397
1401 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( 1398 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop(
1402 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 1399 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
1403 const syncable::ModelTypeSet failed_configuration_types) { 1400 const syncer::ModelTypeSet failed_configuration_types) {
1404 HandleInitializationCompletedOnFrontendLoop( 1401 HandleInitializationCompletedOnFrontendLoop(
1405 js_backend, failed_configuration_types.Empty()); 1402 js_backend, failed_configuration_types.Empty());
1406 } 1403 }
1407 1404
1408 namespace { 1405 namespace {
1409 1406
1410 // Needed because MessageLoop::PostTask is overloaded. 1407 // Needed because MessageLoop::PostTask is overloaded.
1411 void PostClosure(MessageLoop* message_loop, 1408 void PostClosure(MessageLoop* message_loop,
1412 const tracked_objects::Location& from_here, 1409 const tracked_objects::Location& from_here,
1413 const base::Closure& callback) { 1410 const base::Closure& callback) {
(...skipping 11 matching lines...) Expand all
1425 FROM_HERE, 1422 FROM_HERE,
1426 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, 1423 base::Bind(&SyncBackendHost::Core::DoRefreshNigori,
1427 core_.get(), sync_thread_done_callback)); 1424 core_.get(), sync_thread_done_callback));
1428 } 1425 }
1429 1426
1430 #undef SDVLOG 1427 #undef SDVLOG
1431 1428
1432 #undef SLOG 1429 #undef SLOG
1433 1430
1434 } // namespace browser_sync 1431 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/glue/sync_backend_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698