| 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 "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 27 matching lines...) Expand all Loading... |
| 38 #include "jingle/notifier/base/notification_method.h" | 38 #include "jingle/notifier/base/notification_method.h" |
| 39 #include "jingle/notifier/base/notifier_options.h" | 39 #include "jingle/notifier/base/notifier_options.h" |
| 40 #include "net/base/host_port_pair.h" | 40 #include "net/base/host_port_pair.h" |
| 41 #include "net/url_request/url_request_context_getter.h" | 41 #include "net/url_request/url_request_context_getter.h" |
| 42 #include "sync/engine/model_safe_worker.h" | 42 #include "sync/engine/model_safe_worker.h" |
| 43 #include "sync/internal_api/base_transaction.h" | 43 #include "sync/internal_api/base_transaction.h" |
| 44 #include "sync/internal_api/read_transaction.h" | 44 #include "sync/internal_api/read_transaction.h" |
| 45 #include "sync/notifier/sync_notifier.h" | 45 #include "sync/notifier/sync_notifier.h" |
| 46 #include "sync/protocol/encryption.pb.h" | 46 #include "sync/protocol/encryption.pb.h" |
| 47 #include "sync/protocol/sync.pb.h" | 47 #include "sync/protocol/sync.pb.h" |
| 48 #include "sync/sessions/session_state.h" | |
| 49 #include "sync/util/nigori.h" | 48 #include "sync/util/nigori.h" |
| 50 | 49 |
| 51 static const int kSaveChangesIntervalSeconds = 10; | 50 static const int kSaveChangesIntervalSeconds = 10; |
| 52 static const FilePath::CharType kSyncDataFolderName[] = | 51 static const FilePath::CharType kSyncDataFolderName[] = |
| 53 FILE_PATH_LITERAL("Sync Data"); | 52 FILE_PATH_LITERAL("Sync Data"); |
| 54 | 53 |
| 55 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; | 54 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; |
| 56 | 55 |
| 57 typedef GoogleServiceAuthError AuthError; | 56 typedef GoogleServiceAuthError AuthError; |
| 58 | 57 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 public sync_api::SyncManager::Observer { | 73 public sync_api::SyncManager::Observer { |
| 75 public: | 74 public: |
| 76 Core(const std::string& name, | 75 Core(const std::string& name, |
| 77 const FilePath& sync_data_folder_path, | 76 const FilePath& sync_data_folder_path, |
| 78 const base::WeakPtr<SyncBackendHost>& backend); | 77 const base::WeakPtr<SyncBackendHost>& backend); |
| 79 | 78 |
| 80 // SyncManager::Observer implementation. The Core just acts like an air | 79 // SyncManager::Observer implementation. The Core just acts like an air |
| 81 // traffic controller here, forwarding incoming messages to appropriate | 80 // traffic controller here, forwarding incoming messages to appropriate |
| 82 // landing threads. | 81 // landing threads. |
| 83 virtual void OnSyncCycleCompleted( | 82 virtual void OnSyncCycleCompleted( |
| 84 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; | 83 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
| 85 virtual void OnInitializationComplete( | 84 virtual void OnInitializationComplete( |
| 86 const WeakHandle<JsBackend>& js_backend, | 85 const WeakHandle<JsBackend>& js_backend, |
| 87 bool success) OVERRIDE; | 86 bool success) OVERRIDE; |
| 88 virtual void OnConnectionStatusChange( | 87 virtual void OnConnectionStatusChange( |
| 89 sync_api::ConnectionStatus status) OVERRIDE; | 88 sync_api::ConnectionStatus status) OVERRIDE; |
| 90 virtual void OnPassphraseRequired( | 89 virtual void OnPassphraseRequired( |
| 91 sync_api::PassphraseRequiredReason reason, | 90 sync_api::PassphraseRequiredReason reason, |
| 92 const sync_pb::EncryptedData& pending_keys) OVERRIDE; | 91 const sync_pb::EncryptedData& pending_keys) OVERRIDE; |
| 93 virtual void OnPassphraseAccepted() OVERRIDE; | 92 virtual void OnPassphraseAccepted() OVERRIDE; |
| 94 virtual void OnBootstrapTokenUpdated( | 93 virtual void OnBootstrapTokenUpdated( |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 sync_api::UserShare* SyncBackendHost::GetUserShare() const { | 606 sync_api::UserShare* SyncBackendHost::GetUserShare() const { |
| 608 DCHECK(initialized()); | 607 DCHECK(initialized()); |
| 609 return core_->sync_manager()->GetUserShare(); | 608 return core_->sync_manager()->GetUserShare(); |
| 610 } | 609 } |
| 611 | 610 |
| 612 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { | 611 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { |
| 613 DCHECK(initialized()); | 612 DCHECK(initialized()); |
| 614 return core_->sync_manager()->GetDetailedStatus(); | 613 return core_->sync_manager()->GetDetailedStatus(); |
| 615 } | 614 } |
| 616 | 615 |
| 617 const SyncSessionSnapshot* SyncBackendHost::GetLastSessionSnapshot() const { | 616 SyncSessionSnapshot SyncBackendHost::GetLastSessionSnapshot() const { |
| 618 return last_snapshot_.get(); | 617 return last_snapshot_; |
| 619 } | 618 } |
| 620 | 619 |
| 621 bool SyncBackendHost::HasUnsyncedItems() const { | 620 bool SyncBackendHost::HasUnsyncedItems() const { |
| 622 DCHECK(initialized()); | 621 DCHECK(initialized()); |
| 623 return core_->sync_manager()->HasUnsyncedItems(); | 622 return core_->sync_manager()->HasUnsyncedItems(); |
| 624 } | 623 } |
| 625 | 624 |
| 626 bool SyncBackendHost::IsNigoriEnabled() const { | 625 bool SyncBackendHost::IsNigoriEnabled() const { |
| 627 return registrar_.get() && registrar_->IsNigoriEnabled(); | 626 return registrar_.get() && registrar_->IsNigoriEnabled(); |
| 628 } | 627 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 650 NOTREACHED(); | 649 NOTREACHED(); |
| 651 } | 650 } |
| 652 } | 651 } |
| 653 | 652 |
| 654 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { | 653 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { |
| 655 sync_thread_.message_loop()->PostTask(FROM_HERE, | 654 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 656 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); | 655 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); |
| 657 } | 656 } |
| 658 | 657 |
| 659 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( | 658 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( |
| 660 SyncSessionSnapshot* snapshot) { | 659 const SyncSessionSnapshot& snapshot) { |
| 661 if (!frontend_) | 660 if (!frontend_) |
| 662 return; | 661 return; |
| 663 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 662 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 664 | 663 |
| 665 last_snapshot_.reset(snapshot); | 664 last_snapshot_ = snapshot; |
| 666 | 665 |
| 667 SDVLOG(1) << "Got snapshot " << snapshot->ToString(); | 666 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); |
| 668 | 667 |
| 669 const syncable::ModelTypeSet to_migrate = | 668 const syncable::ModelTypeSet to_migrate = |
| 670 snapshot->syncer_status.types_needing_local_migration; | 669 snapshot.syncer_status().types_needing_local_migration; |
| 671 if (!to_migrate.Empty()) | 670 if (!to_migrate.Empty()) |
| 672 frontend_->OnMigrationNeededForTypes(to_migrate); | 671 frontend_->OnMigrationNeededForTypes(to_migrate); |
| 673 | 672 |
| 674 // Process any changes to the datatypes we're syncing. | 673 // Process any changes to the datatypes we're syncing. |
| 675 // TODO(sync): add support for removing types. | 674 // TODO(sync): add support for removing types. |
| 676 if (initialized()) | 675 if (initialized()) |
| 677 AddExperimentalTypes(); | 676 AddExperimentalTypes(); |
| 678 | 677 |
| 679 // If we are waiting for a configuration change, check here to see | 678 // If we are waiting for a configuration change, check here to see |
| 680 // if this sync cycle has initialized all of the types we've been | 679 // if this sync cycle has initialized all of the types we've been |
| 681 // waiting for. | 680 // waiting for. |
| 682 if (pending_download_state_.get()) { | 681 if (pending_download_state_.get()) { |
| 683 const syncable::ModelTypeSet types_to_add = | 682 const syncable::ModelTypeSet types_to_add = |
| 684 pending_download_state_->types_to_add; | 683 pending_download_state_->types_to_add; |
| 685 const syncable::ModelTypeSet added_types = | 684 const syncable::ModelTypeSet added_types = |
| 686 pending_download_state_->added_types; | 685 pending_download_state_->added_types; |
| 687 DCHECK(types_to_add.HasAll(added_types)); | 686 DCHECK(types_to_add.HasAll(added_types)); |
| 688 const syncable::ModelTypeSet initial_sync_ended = | 687 const syncable::ModelTypeSet initial_sync_ended = |
| 689 snapshot->initial_sync_ended; | 688 snapshot.initial_sync_ended(); |
| 690 const syncable::ModelTypeSet failed_configuration_types = | 689 const syncable::ModelTypeSet failed_configuration_types = |
| 691 Difference(added_types, initial_sync_ended); | 690 Difference(added_types, initial_sync_ended); |
| 692 SDVLOG(1) | 691 SDVLOG(1) |
| 693 << "Added types: " | 692 << "Added types: " |
| 694 << syncable::ModelTypeSetToString(added_types) | 693 << syncable::ModelTypeSetToString(added_types) |
| 695 << ", configured types: " | 694 << ", configured types: " |
| 696 << syncable::ModelTypeSetToString(initial_sync_ended) | 695 << syncable::ModelTypeSetToString(initial_sync_ended) |
| 697 << ", failed configuration types: " | 696 << ", failed configuration types: " |
| 698 << syncable::ModelTypeSetToString(failed_configuration_types); | 697 << syncable::ModelTypeSetToString(failed_configuration_types); |
| 699 | 698 |
| 700 if (!failed_configuration_types.Empty() && | 699 if (!failed_configuration_types.Empty() && |
| 701 snapshot->retry_scheduled) { | 700 snapshot.retry_scheduled()) { |
| 702 // Inform the caller that download failed but we are retrying. | 701 // Inform the caller that download failed but we are retrying. |
| 703 if (!pending_download_state_->retry_in_progress) { | 702 if (!pending_download_state_->retry_in_progress) { |
| 704 pending_download_state_->retry_callback.Run(); | 703 pending_download_state_->retry_callback.Run(); |
| 705 pending_download_state_->retry_in_progress = true; | 704 pending_download_state_->retry_in_progress = true; |
| 706 } | 705 } |
| 707 // Nothing more to do. | 706 // Nothing more to do. |
| 708 return; | 707 return; |
| 709 } | 708 } |
| 710 | 709 |
| 711 scoped_ptr<PendingConfigureDataTypesState> state( | 710 scoped_ptr<PendingConfigureDataTypesState> state( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 | 856 |
| 858 SyncBackendHost::PendingConfigureDataTypesState:: | 857 SyncBackendHost::PendingConfigureDataTypesState:: |
| 859 PendingConfigureDataTypesState() | 858 PendingConfigureDataTypesState() |
| 860 : reason(sync_api::CONFIGURE_REASON_UNKNOWN), | 859 : reason(sync_api::CONFIGURE_REASON_UNKNOWN), |
| 861 retry_in_progress(false) {} | 860 retry_in_progress(false) {} |
| 862 | 861 |
| 863 SyncBackendHost::PendingConfigureDataTypesState:: | 862 SyncBackendHost::PendingConfigureDataTypesState:: |
| 864 ~PendingConfigureDataTypesState() {} | 863 ~PendingConfigureDataTypesState() {} |
| 865 | 864 |
| 866 void SyncBackendHost::Core::OnSyncCycleCompleted( | 865 void SyncBackendHost::Core::OnSyncCycleCompleted( |
| 867 const SyncSessionSnapshot* snapshot) { | 866 const SyncSessionSnapshot& snapshot) { |
| 868 if (!sync_loop_) | 867 if (!sync_loop_) |
| 869 return; | 868 return; |
| 870 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 869 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 871 host_.Call( | 870 host_.Call( |
| 872 FROM_HERE, | 871 FROM_HERE, |
| 873 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, | 872 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, |
| 874 new SyncSessionSnapshot(*snapshot)); | 873 snapshot); |
| 875 } | 874 } |
| 876 | 875 |
| 877 | 876 |
| 878 void SyncBackendHost::Core::OnInitializationComplete( | 877 void SyncBackendHost::Core::OnInitializationComplete( |
| 879 const WeakHandle<JsBackend>& js_backend, | 878 const WeakHandle<JsBackend>& js_backend, |
| 880 bool success) { | 879 bool success) { |
| 881 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 880 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 882 host_.Call( | 881 host_.Call( |
| 883 FROM_HERE, | 882 FROM_HERE, |
| 884 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, | 883 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 FROM_HERE, | 1424 FROM_HERE, |
| 1426 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1425 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| 1427 core_.get(), sync_thread_done_callback)); | 1426 core_.get(), sync_thread_done_callback)); |
| 1428 } | 1427 } |
| 1429 | 1428 |
| 1430 #undef SDVLOG | 1429 #undef SDVLOG |
| 1431 | 1430 |
| 1432 #undef SLOG | 1431 #undef SLOG |
| 1433 | 1432 |
| 1434 } // namespace browser_sync | 1433 } // namespace browser_sync |
| OLD | NEW |