| 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 "sync/internal_api/public/sync_manager.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "net/base/network_change_notifier.h" | 20 #include "net/base/network_change_notifier.h" |
| 21 #include "sync/engine/all_status.h" | 21 #include "sync/engine/all_status.h" |
| 22 #include "sync/engine/net/server_connection_manager.h" | 22 #include "sync/engine/net/server_connection_manager.h" |
| 23 #include "sync/engine/sync_scheduler.h" | 23 #include "sync/engine/sync_scheduler.h" |
| 24 #include "sync/engine/syncer_types.h" | 24 #include "sync/engine/syncer_types.h" |
| 25 #include "sync/engine/throttled_data_type_tracker.h" | 25 #include "sync/engine/throttled_data_type_tracker.h" |
| 26 #include "sync/internal_api/change_reorder_buffer.h" | 26 #include "sync/internal_api/change_reorder_buffer.h" |
| 27 #include "sync/internal_api/debug_info_event_listener.h" | 27 #include "sync/internal_api/debug_info_event_listener.h" |
| 28 #include "sync/internal_api/js_mutation_event_observer.h" | 28 #include "sync/internal_api/js_mutation_event_observer.h" |
| 29 #include "sync/internal_api/js_sync_manager_observer.h" | 29 #include "sync/internal_api/js_sync_manager_observer.h" |
| 30 #include "sync/internal_api/public/base/model_type.h" | 30 #include "sync/internal_api/public/base/model_type.h" |
| 31 #include "sync/internal_api/public/base/model_type_payload_map.h" | 31 #include "sync/internal_api/public/base/model_type_payload_map.h" |
| 32 #include "sync/internal_api/public/base_node.h" | 32 #include "sync/internal_api/public/base_node.h" |
| 33 #include "sync/internal_api/public/configure_reason.h" | 33 #include "sync/internal_api/public/configure_reason.h" |
| 34 #include "sync/internal_api/public/engine/polling_constants.h" | 34 #include "sync/internal_api/public/engine/polling_constants.h" |
| 35 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 35 #include "sync/internal_api/public/read_node.h" | 36 #include "sync/internal_api/public/read_node.h" |
| 36 #include "sync/internal_api/public/read_transaction.h" | 37 #include "sync/internal_api/public/read_transaction.h" |
| 37 #include "sync/internal_api/public/user_share.h" | 38 #include "sync/internal_api/public/user_share.h" |
| 38 #include "sync/internal_api/public/util/experiments.h" | 39 #include "sync/internal_api/public/util/experiments.h" |
| 39 #include "sync/internal_api/public/write_node.h" | 40 #include "sync/internal_api/public/write_node.h" |
| 40 #include "sync/internal_api/public/write_transaction.h" | 41 #include "sync/internal_api/public/write_transaction.h" |
| 41 #include "sync/internal_api/syncapi_internal.h" | 42 #include "sync/internal_api/syncapi_internal.h" |
| 42 #include "sync/internal_api/syncapi_server_connection_manager.h" | 43 #include "sync/internal_api/syncapi_server_connection_manager.h" |
| 43 #include "sync/js/js_arg_list.h" | 44 #include "sync/js/js_arg_list.h" |
| 44 #include "sync/js/js_backend.h" | 45 #include "sync/js/js_backend.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 #include "sync/util/cryptographer.h" | 61 #include "sync/util/cryptographer.h" |
| 61 #include "sync/util/get_session_name.h" | 62 #include "sync/util/get_session_name.h" |
| 62 #include "sync/util/time.h" | 63 #include "sync/util/time.h" |
| 63 | 64 |
| 64 using base::TimeDelta; | 65 using base::TimeDelta; |
| 65 using sync_pb::GetUpdatesCallerInfo; | 66 using sync_pb::GetUpdatesCallerInfo; |
| 66 | 67 |
| 67 namespace { | 68 namespace { |
| 68 | 69 |
| 69 // Delays for syncer nudges. | 70 // Delays for syncer nudges. |
| 71 static const int kDefaultNudgeDelayMilliseconds = 200; |
| 72 static const int kPreferencesNudgeDelayMilliseconds = 2000; |
| 70 static const int kSyncRefreshDelayMsec = 500; | 73 static const int kSyncRefreshDelayMsec = 500; |
| 71 static const int kSyncSchedulerDelayMsec = 250; | 74 static const int kSyncSchedulerDelayMsec = 250; |
| 72 | 75 |
| 73 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( | 76 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( |
| 74 syncer::ConfigureReason reason) { | 77 syncer::ConfigureReason reason) { |
| 75 switch (reason) { | 78 switch (reason) { |
| 76 case syncer::CONFIGURE_REASON_RECONFIGURATION: | 79 case syncer::CONFIGURE_REASON_RECONFIGURATION: |
| 77 return GetUpdatesCallerInfo::RECONFIGURATION; | 80 return GetUpdatesCallerInfo::RECONFIGURATION; |
| 78 case syncer::CONFIGURE_REASON_MIGRATION: | 81 case syncer::CONFIGURE_REASON_MIGRATION: |
| 79 return GetUpdatesCallerInfo::MIGRATION; | 82 return GetUpdatesCallerInfo::MIGRATION; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 93 static const int kNigoriOverwriteLimit = 10; | 96 static const int kNigoriOverwriteLimit = 10; |
| 94 | 97 |
| 95 } // namespace | 98 } // namespace |
| 96 | 99 |
| 97 namespace syncer { | 100 namespace syncer { |
| 98 | 101 |
| 99 using sessions::SyncSessionContext; | 102 using sessions::SyncSessionContext; |
| 100 using syncable::ImmutableWriteTransactionInfo; | 103 using syncable::ImmutableWriteTransactionInfo; |
| 101 using syncable::SPECIFICS; | 104 using syncable::SPECIFICS; |
| 102 | 105 |
| 103 const int SyncManager::kDefaultNudgeDelayMilliseconds = 200; | |
| 104 const int SyncManager::kPreferencesNudgeDelayMilliseconds = 2000; | |
| 105 | |
| 106 // Maximum count and size for traffic recorder. | 106 // Maximum count and size for traffic recorder. |
| 107 const unsigned int kMaxMessagesToRecord = 10; | 107 const unsigned int kMaxMessagesToRecord = 10; |
| 108 const unsigned int kMaxMessageSizeToRecord = 5 * 1024; | 108 const unsigned int kMaxMessageSizeToRecord = 5 * 1024; |
| 109 | 109 |
| 110 ////////////////////////////////////////////////////////////////////////// | 110 ////////////////////////////////////////////////////////////////////////// |
| 111 // SyncManager's implementation: SyncManager::SyncInternal | 111 // SyncManagerImpl's implementation: SyncManagerImpl::SyncInternal |
| 112 class SyncManager::SyncInternal | 112 class SyncManagerImpl::SyncInternal |
| 113 : public net::NetworkChangeNotifier::IPAddressObserver, | 113 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 114 public syncer::Cryptographer::Observer, | 114 public syncer::Cryptographer::Observer, |
| 115 public syncer::SyncNotifierObserver, | 115 public syncer::SyncNotifierObserver, |
| 116 public JsBackend, | 116 public JsBackend, |
| 117 public SyncEngineEventListener, | 117 public SyncEngineEventListener, |
| 118 public ServerConnectionEventListener, | 118 public ServerConnectionEventListener, |
| 119 public syncable::DirectoryChangeDelegate { | 119 public syncable::DirectoryChangeDelegate { |
| 120 public: | 120 public: |
| 121 explicit SyncInternal(const std::string& name) | 121 explicit SyncInternal(const std::string& name) |
| 122 : name_(name), | 122 : name_(name), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 135 // Pre-fill |notification_info_map_|. | 135 // Pre-fill |notification_info_map_|. |
| 136 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | 136 for (int i = syncer::FIRST_REAL_MODEL_TYPE; |
| 137 i < syncer::MODEL_TYPE_COUNT; ++i) { | 137 i < syncer::MODEL_TYPE_COUNT; ++i) { |
| 138 notification_info_map_.insert( | 138 notification_info_map_.insert( |
| 139 std::make_pair(syncer::ModelTypeFromInt(i), NotificationInfo())); | 139 std::make_pair(syncer::ModelTypeFromInt(i), NotificationInfo())); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Bind message handlers. | 142 // Bind message handlers. |
| 143 BindJsMessageHandler( | 143 BindJsMessageHandler( |
| 144 "getNotificationState", | 144 "getNotificationState", |
| 145 &SyncManager::SyncInternal::GetNotificationState); | 145 &SyncManagerImpl::SyncInternal::GetNotificationState); |
| 146 BindJsMessageHandler( | 146 BindJsMessageHandler( |
| 147 "getNotificationInfo", | 147 "getNotificationInfo", |
| 148 &SyncManager::SyncInternal::GetNotificationInfo); | 148 &SyncManagerImpl::SyncInternal::GetNotificationInfo); |
| 149 BindJsMessageHandler( | 149 BindJsMessageHandler( |
| 150 "getRootNodeDetails", | 150 "getRootNodeDetails", |
| 151 &SyncManager::SyncInternal::GetRootNodeDetails); | 151 &SyncManagerImpl::SyncInternal::GetRootNodeDetails); |
| 152 BindJsMessageHandler( | 152 BindJsMessageHandler( |
| 153 "getNodeSummariesById", | 153 "getNodeSummariesById", |
| 154 &SyncManager::SyncInternal::GetNodeSummariesById); | 154 &SyncManagerImpl::SyncInternal::GetNodeSummariesById); |
| 155 BindJsMessageHandler( | 155 BindJsMessageHandler( |
| 156 "getNodeDetailsById", | 156 "getNodeDetailsById", |
| 157 &SyncManager::SyncInternal::GetNodeDetailsById); | 157 &SyncManagerImpl::SyncInternal::GetNodeDetailsById); |
| 158 BindJsMessageHandler( | 158 BindJsMessageHandler( |
| 159 "getAllNodes", | 159 "getAllNodes", |
| 160 &SyncManager::SyncInternal::GetAllNodes); | 160 &SyncManagerImpl::SyncInternal::GetAllNodes); |
| 161 BindJsMessageHandler( | 161 BindJsMessageHandler( |
| 162 "getChildNodeIds", | 162 "getChildNodeIds", |
| 163 &SyncManager::SyncInternal::GetChildNodeIds); | 163 &SyncManagerImpl::SyncInternal::GetChildNodeIds); |
| 164 BindJsMessageHandler( | 164 BindJsMessageHandler( |
| 165 "getClientServerTraffic", | 165 "getClientServerTraffic", |
| 166 &SyncManager::SyncInternal::GetClientServerTraffic); | 166 &SyncManagerImpl::SyncInternal::GetClientServerTraffic); |
| 167 } | 167 } |
| 168 | 168 |
| 169 virtual ~SyncInternal() { | 169 virtual ~SyncInternal() { |
| 170 CHECK(!initialized_); | 170 CHECK(!initialized_); |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool Init(const FilePath& database_location, | 173 bool Init(const FilePath& database_location, |
| 174 const WeakHandle<JsEventHandler>& event_handler, | 174 const WeakHandle<JsEventHandler>& event_handler, |
| 175 const std::string& sync_server_and_path, | 175 const std::string& sync_server_and_path, |
| 176 int port, | 176 int port, |
| 177 bool use_ssl, | 177 bool use_ssl, |
| 178 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 178 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 179 HttpPostProviderFactory* post_factory, | 179 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 180 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | 180 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, |
| 181 const std::vector<syncer::ModelSafeWorker*>& workers, | 181 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 182 syncer::ExtensionsActivityMonitor* | 182 syncer::ExtensionsActivityMonitor* |
| 183 extensions_activity_monitor, | 183 extensions_activity_monitor, |
| 184 ChangeDelegate* change_delegate, | 184 SyncManager::ChangeDelegate* change_delegate, |
| 185 const SyncCredentials& credentials, | 185 const SyncCredentials& credentials, |
| 186 syncer::SyncNotifier* sync_notifier, | 186 scoped_ptr<syncer::SyncNotifier> sync_notifier, |
| 187 const std::string& restored_key_for_bootstrapping, | 187 const std::string& restored_key_for_bootstrapping, |
| 188 TestingMode testing_mode, | 188 SyncManager::TestingMode testing_mode, |
| 189 Encryptor* encryptor, | 189 Encryptor* encryptor, |
| 190 UnrecoverableErrorHandler* unrecoverable_error_handler, | 190 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 191 ReportUnrecoverableErrorFunction | 191 ReportUnrecoverableErrorFunction |
| 192 report_unrecoverable_error_function); | 192 report_unrecoverable_error_function); |
| 193 | 193 |
| 194 // Sign into sync with given credentials. | 194 // Sign into sync with given credentials. |
| 195 // We do not verify the tokens given. After this call, the tokens are set | 195 // We do not verify the tokens given. After this call, the tokens are set |
| 196 // and the sync DB is open. True if successful, false if something | 196 // and the sync DB is open. True if successful, false if something |
| 197 // went wrong. | 197 // went wrong. |
| 198 bool SignIn(const SyncCredentials& credentials); | 198 bool SignIn(const SyncCredentials& credentials); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 DictionaryValue* ToValue() const { | 411 DictionaryValue* ToValue() const { |
| 412 DictionaryValue* value = new DictionaryValue(); | 412 DictionaryValue* value = new DictionaryValue(); |
| 413 value->SetInteger("totalCount", total_count); | 413 value->SetInteger("totalCount", total_count); |
| 414 value->SetString("payload", payload); | 414 value->SetString("payload", payload); |
| 415 return value; | 415 return value; |
| 416 } | 416 } |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 typedef std::map<syncer::ModelType, NotificationInfo> NotificationInfoMap; | 419 typedef std::map<syncer::ModelType, NotificationInfo> NotificationInfoMap; |
| 420 typedef JsArgList | 420 typedef JsArgList |
| 421 (SyncManager::SyncInternal::*UnboundJsMessageHandler)(const JsArgList&); | 421 (SyncManagerImpl::SyncInternal::*UnboundJsMessageHandler)( |
| 422 const JsArgList&); |
| 422 typedef base::Callback<JsArgList(const JsArgList&)> JsMessageHandler; | 423 typedef base::Callback<JsArgList(const JsArgList&)> JsMessageHandler; |
| 423 typedef std::map<std::string, JsMessageHandler> JsMessageHandlerMap; | 424 typedef std::map<std::string, JsMessageHandler> JsMessageHandlerMap; |
| 424 | 425 |
| 425 // Internal callback of UpdateCryptographerAndNigoriCallback. | 426 // Internal callback of UpdateCryptographerAndNigoriCallback. |
| 426 void UpdateCryptographerAndNigoriCallback( | 427 void UpdateCryptographerAndNigoriCallback( |
| 427 const std::string& chrome_version, | 428 const std::string& chrome_version, |
| 428 const base::Closure& done_callback, | 429 const base::Closure& done_callback, |
| 429 const std::string& session_name); | 430 const std::string& session_name); |
| 430 | 431 |
| 431 // Determine if the parents or predecessors differ between the old and new | 432 // Determine if the parents or predecessors differ between the old and new |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 | 585 |
| 585 SyncManager::ChangeDelegate* change_delegate_; | 586 SyncManager::ChangeDelegate* change_delegate_; |
| 586 | 587 |
| 587 // Set to true once Init has been called. | 588 // Set to true once Init has been called. |
| 588 bool initialized_; | 589 bool initialized_; |
| 589 | 590 |
| 590 // Controls the disabling of certain SyncManager features. | 591 // Controls the disabling of certain SyncManager features. |
| 591 // Can be used to disable communication with the server and the use of an | 592 // Can be used to disable communication with the server and the use of an |
| 592 // on-disk file for maintaining syncer state. | 593 // on-disk file for maintaining syncer state. |
| 593 // TODO(117836): Clean up implementation of SyncManager unit tests. | 594 // TODO(117836): Clean up implementation of SyncManager unit tests. |
| 594 TestingMode testing_mode_; | 595 SyncManager::TestingMode testing_mode_; |
| 595 | 596 |
| 596 bool observing_ip_address_changes_; | 597 bool observing_ip_address_changes_; |
| 597 | 598 |
| 598 // Map used to store the notification info to be displayed in | 599 // Map used to store the notification info to be displayed in |
| 599 // about:sync page. | 600 // about:sync page. |
| 600 NotificationInfoMap notification_info_map_; | 601 NotificationInfoMap notification_info_map_; |
| 601 | 602 |
| 602 // These are for interacting with chrome://sync-internals. | 603 // These are for interacting with chrome://sync-internals. |
| 603 JsMessageHandlerMap js_message_handlers_; | 604 JsMessageHandlerMap js_message_handlers_; |
| 604 WeakHandle<JsEventHandler> js_event_handler_; | 605 WeakHandle<JsEventHandler> js_event_handler_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 621 // The number of times we've automatically (i.e. not via SetPassphrase or | 622 // The number of times we've automatically (i.e. not via SetPassphrase or |
| 622 // conflict resolver) updated the nigori's encryption keys in this chrome | 623 // conflict resolver) updated the nigori's encryption keys in this chrome |
| 623 // instantiation. | 624 // instantiation. |
| 624 int nigori_overwrite_count_; | 625 int nigori_overwrite_count_; |
| 625 }; | 626 }; |
| 626 | 627 |
| 627 // A class to calculate nudge delays for types. | 628 // A class to calculate nudge delays for types. |
| 628 class NudgeStrategy { | 629 class NudgeStrategy { |
| 629 public: | 630 public: |
| 630 static TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type, | 631 static TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type, |
| 631 SyncManager::SyncInternal* core) { | 632 SyncManagerImpl::SyncInternal* core) { |
| 632 NudgeDelayStrategy delay_type = GetNudgeDelayStrategy(model_type); | 633 NudgeDelayStrategy delay_type = GetNudgeDelayStrategy(model_type); |
| 633 return GetNudgeDelayTimeDeltaFromType(delay_type, | 634 return GetNudgeDelayTimeDeltaFromType(delay_type, |
| 634 model_type, | 635 model_type, |
| 635 core); | 636 core); |
| 636 } | 637 } |
| 637 | 638 |
| 638 private: | 639 private: |
| 639 // Possible types of nudge delay for datatypes. | 640 // Possible types of nudge delay for datatypes. |
| 640 // Note: These are just hints. If a sync happens then all dirty entries | 641 // Note: These are just hints. If a sync happens then all dirty entries |
| 641 // would be committed as part of the sync. | 642 // would be committed as part of the sync. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 658 case syncer::PREFERENCES: | 659 case syncer::PREFERENCES: |
| 659 case syncer::SESSIONS: | 660 case syncer::SESSIONS: |
| 660 return CUSTOM; | 661 return CUSTOM; |
| 661 default: | 662 default: |
| 662 return IMMEDIATE; | 663 return IMMEDIATE; |
| 663 } | 664 } |
| 664 } | 665 } |
| 665 | 666 |
| 666 static TimeDelta GetNudgeDelayTimeDeltaFromType( | 667 static TimeDelta GetNudgeDelayTimeDeltaFromType( |
| 667 const NudgeDelayStrategy& delay_type, const ModelType& model_type, | 668 const NudgeDelayStrategy& delay_type, const ModelType& model_type, |
| 668 const SyncManager::SyncInternal* core) { | 669 const SyncManagerImpl::SyncInternal* core) { |
| 669 CHECK(core); | 670 CHECK(core); |
| 670 TimeDelta delay = TimeDelta::FromMilliseconds( | 671 TimeDelta delay = TimeDelta::FromMilliseconds( |
| 671 SyncManager::kDefaultNudgeDelayMilliseconds); | 672 kDefaultNudgeDelayMilliseconds); |
| 672 switch (delay_type) { | 673 switch (delay_type) { |
| 673 case IMMEDIATE: | 674 case IMMEDIATE: |
| 674 delay = TimeDelta::FromMilliseconds( | 675 delay = TimeDelta::FromMilliseconds( |
| 675 SyncManager::kDefaultNudgeDelayMilliseconds); | 676 kDefaultNudgeDelayMilliseconds); |
| 676 break; | 677 break; |
| 677 case ACCOMPANY_ONLY: | 678 case ACCOMPANY_ONLY: |
| 678 delay = TimeDelta::FromSeconds( | 679 delay = TimeDelta::FromSeconds( |
| 679 syncer::kDefaultShortPollIntervalSeconds); | 680 syncer::kDefaultShortPollIntervalSeconds); |
| 680 break; | 681 break; |
| 681 case CUSTOM: | 682 case CUSTOM: |
| 682 switch (model_type) { | 683 switch (model_type) { |
| 683 case syncer::PREFERENCES: | 684 case syncer::PREFERENCES: |
| 684 delay = TimeDelta::FromMilliseconds( | 685 delay = TimeDelta::FromMilliseconds( |
| 685 SyncManager::kPreferencesNudgeDelayMilliseconds); | 686 kPreferencesNudgeDelayMilliseconds); |
| 686 break; | 687 break; |
| 687 case syncer::SESSIONS: | 688 case syncer::SESSIONS: |
| 688 delay = core->scheduler()->sessions_commit_delay(); | 689 delay = core->scheduler()->sessions_commit_delay(); |
| 689 break; | 690 break; |
| 690 default: | 691 default: |
| 691 NOTREACHED(); | 692 NOTREACHED(); |
| 692 } | 693 } |
| 693 break; | 694 break; |
| 694 default: | 695 default: |
| 695 NOTREACHED(); | 696 NOTREACHED(); |
| 696 } | 697 } |
| 697 return delay; | 698 return delay; |
| 698 } | 699 } |
| 699 }; | 700 }; |
| 700 | 701 |
| 701 SyncManager::ChangeDelegate::~ChangeDelegate() {} | 702 SyncManagerImpl::SyncManagerImpl(const std::string& name) |
| 702 | |
| 703 SyncManager::ChangeObserver::~ChangeObserver() {} | |
| 704 | |
| 705 SyncManager::Observer::~Observer() {} | |
| 706 | |
| 707 SyncManager::SyncManager(const std::string& name) | |
| 708 : data_(new SyncInternal(name)) {} | 703 : data_(new SyncInternal(name)) {} |
| 709 | 704 |
| 710 bool SyncManager::Init( | 705 bool SyncManagerImpl::Init( |
| 711 const FilePath& database_location, | 706 const FilePath& database_location, |
| 712 const WeakHandle<JsEventHandler>& event_handler, | 707 const WeakHandle<JsEventHandler>& event_handler, |
| 713 const std::string& sync_server_and_path, | 708 const std::string& sync_server_and_path, |
| 714 int sync_server_port, | 709 int sync_server_port, |
| 715 bool use_ssl, | 710 bool use_ssl, |
| 716 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 711 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 717 HttpPostProviderFactory* post_factory, | 712 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 718 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | 713 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, |
| 719 const std::vector<syncer::ModelSafeWorker*>& workers, | 714 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 720 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 715 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
| 721 ChangeDelegate* change_delegate, | 716 SyncManager::ChangeDelegate* change_delegate, |
| 722 const SyncCredentials& credentials, | 717 const SyncCredentials& credentials, |
| 723 syncer::SyncNotifier* sync_notifier, | 718 scoped_ptr<syncer::SyncNotifier> sync_notifier, |
| 724 const std::string& restored_key_for_bootstrapping, | 719 const std::string& restored_key_for_bootstrapping, |
| 725 TestingMode testing_mode, | 720 SyncManager::TestingMode testing_mode, |
| 726 Encryptor* encryptor, | 721 Encryptor* encryptor, |
| 727 UnrecoverableErrorHandler* unrecoverable_error_handler, | 722 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 728 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 723 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
| 729 DCHECK(thread_checker_.CalledOnValidThread()); | 724 DCHECK(thread_checker_.CalledOnValidThread()); |
| 730 DCHECK(post_factory); | 725 DCHECK(post_factory.get()); |
| 731 DVLOG(1) << "SyncManager starting Init..."; | 726 DVLOG(1) << "SyncManager starting Init..."; |
| 732 std::string server_string(sync_server_and_path); | 727 std::string server_string(sync_server_and_path); |
| 733 return data_->Init(database_location, | 728 return data_->Init(database_location, |
| 734 event_handler, | 729 event_handler, |
| 735 server_string, | 730 server_string, |
| 736 sync_server_port, | 731 sync_server_port, |
| 737 use_ssl, | 732 use_ssl, |
| 738 blocking_task_runner, | 733 blocking_task_runner, |
| 739 post_factory, | 734 post_factory.Pass(), |
| 740 model_safe_routing_info, | 735 model_safe_routing_info, |
| 741 workers, | 736 workers, |
| 742 extensions_activity_monitor, | 737 extensions_activity_monitor, |
| 743 change_delegate, | 738 change_delegate, |
| 744 credentials, | 739 credentials, |
| 745 sync_notifier, | 740 sync_notifier.Pass(), |
| 746 restored_key_for_bootstrapping, | 741 restored_key_for_bootstrapping, |
| 747 testing_mode, | 742 testing_mode, |
| 748 encryptor, | 743 encryptor, |
| 749 unrecoverable_error_handler, | 744 unrecoverable_error_handler, |
| 750 report_unrecoverable_error_function); | 745 report_unrecoverable_error_function); |
| 751 } | 746 } |
| 752 | 747 |
| 753 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 748 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { |
| 754 DCHECK(thread_checker_.CalledOnValidThread()); | 749 DCHECK(thread_checker_.CalledOnValidThread()); |
| 755 data_->UpdateCredentials(credentials); | 750 data_->UpdateCredentials(credentials); |
| 756 } | 751 } |
| 757 | 752 |
| 758 void SyncManager::UpdateEnabledTypes(const ModelTypeSet& enabled_types) { | 753 void SyncManagerImpl::UpdateEnabledTypes(const ModelTypeSet& enabled_types) { |
| 759 DCHECK(thread_checker_.CalledOnValidThread()); | 754 DCHECK(thread_checker_.CalledOnValidThread()); |
| 760 data_->UpdateEnabledTypes(enabled_types); | 755 data_->UpdateEnabledTypes(enabled_types); |
| 761 } | 756 } |
| 762 | 757 |
| 763 void SyncManager::ThrowUnrecoverableError() { | 758 void SyncManagerImpl::ThrowUnrecoverableError() { |
| 764 DCHECK(thread_checker_.CalledOnValidThread()); | 759 DCHECK(thread_checker_.CalledOnValidThread()); |
| 765 ReadTransaction trans(FROM_HERE, GetUserShare()); | 760 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 766 trans.GetWrappedTrans()->OnUnrecoverableError( | 761 trans.GetWrappedTrans()->OnUnrecoverableError( |
| 767 FROM_HERE, "Simulating unrecoverable error for testing purposes."); | 762 FROM_HERE, "Simulating unrecoverable error for testing purposes."); |
| 768 } | 763 } |
| 769 | 764 |
| 770 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() { | 765 syncer::ModelTypeSet SyncManagerImpl::InitialSyncEndedTypes() { |
| 771 return data_->InitialSyncEndedTypes(); | 766 return data_->InitialSyncEndedTypes(); |
| 772 } | 767 } |
| 773 | 768 |
| 774 syncer::ModelTypeSet SyncManager::GetTypesWithEmptyProgressMarkerToken( | 769 syncer::ModelTypeSet SyncManagerImpl::GetTypesWithEmptyProgressMarkerToken( |
| 775 syncer::ModelTypeSet types) { | 770 syncer::ModelTypeSet types) { |
| 776 return data_->GetTypesWithEmptyProgressMarkerToken(types); | 771 return data_->GetTypesWithEmptyProgressMarkerToken(types); |
| 777 } | 772 } |
| 778 | 773 |
| 779 bool SyncManager::PurgePartiallySyncedTypes() { | 774 bool SyncManagerImpl::PurgePartiallySyncedTypes() { |
| 780 return data_->PurgePartiallySyncedTypes(); | 775 return data_->PurgePartiallySyncedTypes(); |
| 781 } | 776 } |
| 782 | 777 |
| 783 void SyncManager::StartSyncingNormally( | 778 void SyncManagerImpl::StartSyncingNormally( |
| 784 const syncer::ModelSafeRoutingInfo& routing_info) { | 779 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 785 DCHECK(thread_checker_.CalledOnValidThread()); | 780 DCHECK(thread_checker_.CalledOnValidThread()); |
| 786 data_->StartSyncingNormally(routing_info); | 781 data_->StartSyncingNormally(routing_info); |
| 787 } | 782 } |
| 788 | 783 |
| 789 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase, | 784 void SyncManagerImpl::SetEncryptionPassphrase(const std::string& passphrase, |
| 790 bool is_explicit) { | 785 bool is_explicit) { |
| 791 DCHECK(thread_checker_.CalledOnValidThread()); | 786 DCHECK(thread_checker_.CalledOnValidThread()); |
| 792 data_->SetEncryptionPassphrase(passphrase, is_explicit); | 787 data_->SetEncryptionPassphrase(passphrase, is_explicit); |
| 793 } | 788 } |
| 794 | 789 |
| 795 void SyncManager::SetDecryptionPassphrase(const std::string& passphrase) { | 790 void SyncManagerImpl::SetDecryptionPassphrase(const std::string& passphrase) { |
| 796 DCHECK(thread_checker_.CalledOnValidThread()); | 791 DCHECK(thread_checker_.CalledOnValidThread()); |
| 797 data_->SetDecryptionPassphrase(passphrase); | 792 data_->SetDecryptionPassphrase(passphrase); |
| 798 } | 793 } |
| 799 | 794 |
| 800 void SyncManager::EnableEncryptEverything() { | 795 void SyncManagerImpl::EnableEncryptEverything() { |
| 801 DCHECK(thread_checker_.CalledOnValidThread()); | 796 DCHECK(thread_checker_.CalledOnValidThread()); |
| 802 { | 797 { |
| 803 // Update the cryptographer to know we're now encrypting everything. | 798 // Update the cryptographer to know we're now encrypting everything. |
| 804 WriteTransaction trans(FROM_HERE, GetUserShare()); | 799 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 805 Cryptographer* cryptographer = trans.GetCryptographer(); | 800 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 806 // Only set encrypt everything if we know we can encrypt. This allows the | 801 // Only set encrypt everything if we know we can encrypt. This allows the |
| 807 // user to cancel encryption if they have forgotten their passphrase. | 802 // user to cancel encryption if they have forgotten their passphrase. |
| 808 if (cryptographer->is_ready()) | 803 if (cryptographer->is_ready()) |
| 809 cryptographer->set_encrypt_everything(); | 804 cryptographer->set_encrypt_everything(); |
| 810 } | 805 } |
| 811 | 806 |
| 812 // Reads from cryptographer so will automatically encrypt all | 807 // Reads from cryptographer so will automatically encrypt all |
| 813 // datatypes and update the nigori node as necessary. Will trigger | 808 // datatypes and update the nigori node as necessary. Will trigger |
| 814 // OnPassphraseRequired if necessary. | 809 // OnPassphraseRequired if necessary. |
| 815 data_->RefreshEncryption(); | 810 data_->RefreshEncryption(); |
| 816 } | 811 } |
| 817 | 812 |
| 818 bool SyncManager::EncryptEverythingEnabledForTest() const { | 813 bool SyncManagerImpl::EncryptEverythingEnabledForTest() const { |
| 819 ReadTransaction trans(FROM_HERE, GetUserShare()); | 814 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 820 return trans.GetCryptographer()->encrypt_everything(); | 815 return trans.GetCryptographer()->encrypt_everything(); |
| 821 } | 816 } |
| 822 | 817 |
| 823 bool SyncManager::IsUsingExplicitPassphrase() { | 818 bool SyncManagerImpl::IsUsingExplicitPassphrase() { |
| 824 return data_ && data_->IsUsingExplicitPassphrase(); | 819 return data_ && data_->IsUsingExplicitPassphrase(); |
| 825 } | 820 } |
| 826 | 821 |
| 827 void SyncManager::ConfigureSyncer( | 822 void SyncManagerImpl::ConfigureSyncer( |
| 828 ConfigureReason reason, | 823 ConfigureReason reason, |
| 829 const syncer::ModelTypeSet& types_to_config, | 824 const syncer::ModelTypeSet& types_to_config, |
| 830 const syncer::ModelSafeRoutingInfo& new_routing_info, | 825 const syncer::ModelSafeRoutingInfo& new_routing_info, |
| 831 const base::Closure& ready_task, | 826 const base::Closure& ready_task, |
| 832 const base::Closure& retry_task) { | 827 const base::Closure& retry_task) { |
| 833 DCHECK(thread_checker_.CalledOnValidThread()); | 828 DCHECK(thread_checker_.CalledOnValidThread()); |
| 834 DCHECK(!ready_task.is_null()); | 829 DCHECK(!ready_task.is_null()); |
| 835 DCHECK(!retry_task.is_null()); | 830 DCHECK(!retry_task.is_null()); |
| 836 | 831 |
| 837 // TODO(zea): set this based on whether cryptographer has keystore | 832 // TODO(zea): set this based on whether cryptographer has keystore |
| 838 // encryption key or not (requires opening a transaction). crbug.com/129665. | 833 // encryption key or not (requires opening a transaction). crbug.com/129665. |
| 839 ConfigurationParams::KeystoreKeyStatus keystore_key_status = | 834 ConfigurationParams::KeystoreKeyStatus keystore_key_status = |
| 840 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; | 835 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; |
| 841 | 836 |
| 842 ConfigurationParams params(GetSourceFromReason(reason), | 837 ConfigurationParams params(GetSourceFromReason(reason), |
| 843 types_to_config, | 838 types_to_config, |
| 844 new_routing_info, | 839 new_routing_info, |
| 845 keystore_key_status, | 840 keystore_key_status, |
| 846 ready_task); | 841 ready_task); |
| 847 | 842 |
| 848 if (!data_->scheduler()) { | 843 if (!data_->scheduler()) { |
| 849 LOG(INFO) | 844 LOG(INFO) |
| 850 << "SyncManager::ConfigureSyncer: could not configure because " | 845 << "SyncManagerImpl::ConfigureSyncer: could not configure because " |
| 851 << "scheduler is null"; | 846 << "scheduler is null"; |
| 852 params.ready_task.Run(); | 847 params.ready_task.Run(); |
| 853 return; | 848 return; |
| 854 } | 849 } |
| 855 | 850 |
| 856 data_->scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); | 851 data_->scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); |
| 857 if (!data_->scheduler()->ScheduleConfiguration(params)) | 852 if (!data_->scheduler()->ScheduleConfiguration(params)) |
| 858 retry_task.Run(); | 853 retry_task.Run(); |
| 859 | 854 |
| 860 } | 855 } |
| 861 | 856 |
| 862 bool SyncManager::SyncInternal::Init( | 857 bool SyncManagerImpl::SyncInternal::Init( |
| 863 const FilePath& database_location, | 858 const FilePath& database_location, |
| 864 const WeakHandle<JsEventHandler>& event_handler, | 859 const WeakHandle<JsEventHandler>& event_handler, |
| 865 const std::string& sync_server_and_path, | 860 const std::string& sync_server_and_path, |
| 866 int port, | 861 int port, |
| 867 bool use_ssl, | 862 bool use_ssl, |
| 868 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 863 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 869 HttpPostProviderFactory* post_factory, | 864 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 870 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | 865 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, |
| 871 const std::vector<syncer::ModelSafeWorker*>& workers, | 866 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 872 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 867 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
| 873 ChangeDelegate* change_delegate, | 868 SyncManager::ChangeDelegate* change_delegate, |
| 874 const SyncCredentials& credentials, | 869 const SyncCredentials& credentials, |
| 875 syncer::SyncNotifier* sync_notifier, | 870 scoped_ptr<syncer::SyncNotifier> sync_notifier, |
| 876 const std::string& restored_key_for_bootstrapping, | 871 const std::string& restored_key_for_bootstrapping, |
| 877 TestingMode testing_mode, | 872 SyncManager::TestingMode testing_mode, |
| 878 Encryptor* encryptor, | 873 Encryptor* encryptor, |
| 879 UnrecoverableErrorHandler* unrecoverable_error_handler, | 874 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 880 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 875 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
| 881 CHECK(!initialized_); | 876 CHECK(!initialized_); |
| 882 | 877 |
| 883 DCHECK(thread_checker_.CalledOnValidThread()); | 878 DCHECK(thread_checker_.CalledOnValidThread()); |
| 884 | 879 |
| 885 DVLOG(1) << "Starting SyncInternal initialization."; | 880 DVLOG(1) << "Starting SyncInternal initialization."; |
| 886 | 881 |
| 887 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 882 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
| 888 | 883 |
| 889 blocking_task_runner_ = blocking_task_runner; | 884 blocking_task_runner_ = blocking_task_runner; |
| 890 | 885 |
| 891 change_delegate_ = change_delegate; | 886 change_delegate_ = change_delegate; |
| 892 testing_mode_ = testing_mode; | 887 testing_mode_ = testing_mode; |
| 893 | 888 |
| 894 sync_notifier_.reset(sync_notifier); | 889 sync_notifier_ = sync_notifier.Pass(); |
| 895 | 890 |
| 896 AddObserver(&js_sync_manager_observer_); | 891 AddObserver(&js_sync_manager_observer_); |
| 897 SetJsEventHandler(event_handler); | 892 SetJsEventHandler(event_handler); |
| 898 | 893 |
| 899 AddObserver(&debug_info_event_listener_); | 894 AddObserver(&debug_info_event_listener_); |
| 900 | 895 |
| 901 database_path_ = database_location.Append( | 896 database_path_ = database_location.Append( |
| 902 syncable::Directory::kSyncDatabaseFilename); | 897 syncable::Directory::kSyncDatabaseFilename); |
| 903 encryptor_ = encryptor; | 898 encryptor_ = encryptor; |
| 904 unrecoverable_error_handler_ = unrecoverable_error_handler; | 899 unrecoverable_error_handler_ = unrecoverable_error_handler; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 918 } | 913 } |
| 919 | 914 |
| 920 DCHECK(backing_store); | 915 DCHECK(backing_store); |
| 921 share_.directory.reset( | 916 share_.directory.reset( |
| 922 new syncable::Directory(encryptor_, | 917 new syncable::Directory(encryptor_, |
| 923 unrecoverable_error_handler_, | 918 unrecoverable_error_handler_, |
| 924 report_unrecoverable_error_function_, | 919 report_unrecoverable_error_function_, |
| 925 backing_store)); | 920 backing_store)); |
| 926 | 921 |
| 927 connection_manager_.reset(new SyncAPIServerConnectionManager( | 922 connection_manager_.reset(new SyncAPIServerConnectionManager( |
| 928 sync_server_and_path, port, use_ssl, post_factory)); | 923 sync_server_and_path, port, use_ssl, post_factory.release())); |
| 929 | 924 |
| 930 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 925 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 931 observing_ip_address_changes_ = true; | 926 observing_ip_address_changes_ = true; |
| 932 | 927 |
| 933 connection_manager()->AddListener(this); | 928 connection_manager()->AddListener(this); |
| 934 | 929 |
| 935 // Test mode does not use a syncer context or syncer thread. | 930 // Test mode does not use a syncer context or syncer thread. |
| 936 if (testing_mode_ == NON_TEST) { | 931 if (testing_mode_ == NON_TEST) { |
| 937 // Build a SyncSessionContext and store the worker in it. | 932 // Build a SyncSessionContext and store the worker in it. |
| 938 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | 933 DVLOG(1) << "Sync is bringing up SyncSessionContext."; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 success)); | 991 success)); |
| 997 | 992 |
| 998 if (!success && testing_mode_ == NON_TEST) | 993 if (!success && testing_mode_ == NON_TEST) |
| 999 return false; | 994 return false; |
| 1000 | 995 |
| 1001 sync_notifier_->AddObserver(this); | 996 sync_notifier_->AddObserver(this); |
| 1002 | 997 |
| 1003 return success; | 998 return success; |
| 1004 } | 999 } |
| 1005 | 1000 |
| 1006 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( | 1001 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( |
| 1007 const std::string& chrome_version, | 1002 const std::string& chrome_version, |
| 1008 const base::Closure& done_callback) { | 1003 const base::Closure& done_callback) { |
| 1009 DCHECK(initialized_); | 1004 DCHECK(initialized_); |
| 1010 syncer::GetSessionName( | 1005 syncer::GetSessionName( |
| 1011 blocking_task_runner_, | 1006 blocking_task_runner_, |
| 1012 base::Bind( | 1007 base::Bind( |
| 1013 &SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback, | 1008 &SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback, |
| 1014 weak_ptr_factory_.GetWeakPtr(), | 1009 weak_ptr_factory_.GetWeakPtr(), |
| 1015 chrome_version, | 1010 chrome_version, |
| 1016 done_callback)); | 1011 done_callback)); |
| 1017 } | 1012 } |
| 1018 | 1013 |
| 1019 void SyncManager::SyncInternal::UpdateNigoriEncryptionState( | 1014 void SyncManagerImpl::SyncInternal::UpdateNigoriEncryptionState( |
| 1020 Cryptographer* cryptographer, | 1015 Cryptographer* cryptographer, |
| 1021 WriteNode* nigori_node) { | 1016 WriteNode* nigori_node) { |
| 1022 DCHECK(nigori_node); | 1017 DCHECK(nigori_node); |
| 1023 sync_pb::NigoriSpecifics nigori = nigori_node->GetNigoriSpecifics(); | 1018 sync_pb::NigoriSpecifics nigori = nigori_node->GetNigoriSpecifics(); |
| 1024 | 1019 |
| 1025 if (cryptographer->is_ready() && | 1020 if (cryptographer->is_ready() && |
| 1026 nigori_overwrite_count_ < kNigoriOverwriteLimit) { | 1021 nigori_overwrite_count_ < kNigoriOverwriteLimit) { |
| 1027 // Does not modify the encrypted blob if the unencrypted data already | 1022 // Does not modify the encrypted blob if the unencrypted data already |
| 1028 // matches what is about to be written. | 1023 // matches what is about to be written. |
| 1029 sync_pb::EncryptedData original_keys = nigori.encrypted(); | 1024 sync_pb::EncryptedData original_keys = nigori.encrypted(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1043 // Note: we don't try to set using_explicit_passphrase here since if that | 1038 // Note: we don't try to set using_explicit_passphrase here since if that |
| 1044 // is lost the user can always set it again. The main point is to preserve | 1039 // is lost the user can always set it again. The main point is to preserve |
| 1045 // the encryption keys so all data remains decryptable. | 1040 // the encryption keys so all data remains decryptable. |
| 1046 } | 1041 } |
| 1047 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); | 1042 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); |
| 1048 | 1043 |
| 1049 // If nothing has changed, this is a no-op. | 1044 // If nothing has changed, this is a no-op. |
| 1050 nigori_node->SetNigoriSpecifics(nigori); | 1045 nigori_node->SetNigoriSpecifics(nigori); |
| 1051 } | 1046 } |
| 1052 | 1047 |
| 1053 void SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback( | 1048 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback( |
| 1054 const std::string& chrome_version, | 1049 const std::string& chrome_version, |
| 1055 const base::Closure& done_callback, | 1050 const base::Closure& done_callback, |
| 1056 const std::string& session_name) { | 1051 const std::string& session_name) { |
| 1057 if (!directory()->initial_sync_ended_for_type(syncer::NIGORI)) { | 1052 if (!directory()->initial_sync_ended_for_type(syncer::NIGORI)) { |
| 1058 done_callback.Run(); // Should only happen during first time sync. | 1053 done_callback.Run(); // Should only happen during first time sync. |
| 1059 return; | 1054 return; |
| 1060 } | 1055 } |
| 1061 | 1056 |
| 1062 bool success = false; | 1057 bool success = false; |
| 1063 { | 1058 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 } else { | 1119 } else { |
| 1125 NOTREACHED(); | 1120 NOTREACHED(); |
| 1126 } | 1121 } |
| 1127 } | 1122 } |
| 1128 | 1123 |
| 1129 if (success) | 1124 if (success) |
| 1130 RefreshEncryption(); | 1125 RefreshEncryption(); |
| 1131 done_callback.Run(); | 1126 done_callback.Run(); |
| 1132 } | 1127 } |
| 1133 | 1128 |
| 1134 void SyncManager::SyncInternal::NotifyCryptographerState( | 1129 void SyncManagerImpl::SyncInternal::NotifyCryptographerState( |
| 1135 Cryptographer * cryptographer) { | 1130 Cryptographer * cryptographer) { |
| 1136 // TODO(lipalani): Explore the possibility of hooking this up to | 1131 // TODO(lipalani): Explore the possibility of hooking this up to |
| 1137 // SyncManager::Observer and making |AllStatus| a listener for that. | 1132 // SyncManager::Observer and making |AllStatus| a listener for that. |
| 1138 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 1133 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
| 1139 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 1134 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
| 1140 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); | 1135 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); |
| 1141 debug_info_event_listener_.SetCrytographerHasPendingKeys( | 1136 debug_info_event_listener_.SetCrytographerHasPendingKeys( |
| 1142 cryptographer->has_pending_keys()); | 1137 cryptographer->has_pending_keys()); |
| 1143 } | 1138 } |
| 1144 | 1139 |
| 1145 void SyncManager::SyncInternal::StartSyncingNormally( | 1140 void SyncManagerImpl::SyncInternal::StartSyncingNormally( |
| 1146 const syncer::ModelSafeRoutingInfo& routing_info) { | 1141 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 1147 // Start the sync scheduler. | 1142 // Start the sync scheduler. |
| 1148 if (scheduler()) { // NULL during certain unittests. | 1143 if (scheduler()) { // NULL during certain unittests. |
| 1149 // TODO(sync): We always want the newest set of routes when we switch back | 1144 // TODO(sync): We always want the newest set of routes when we switch back |
| 1150 // to normal mode. Figure out how to enforce set_routing_info is always | 1145 // to normal mode. Figure out how to enforce set_routing_info is always |
| 1151 // appropriately set and that it's only modified when switching to normal | 1146 // appropriately set and that it's only modified when switching to normal |
| 1152 // mode. | 1147 // mode. |
| 1153 session_context()->set_routing_info(routing_info); | 1148 session_context()->set_routing_info(routing_info); |
| 1154 scheduler()->Start(SyncScheduler::NORMAL_MODE); | 1149 scheduler()->Start(SyncScheduler::NORMAL_MODE); |
| 1155 } | 1150 } |
| 1156 } | 1151 } |
| 1157 | 1152 |
| 1158 bool SyncManager::SyncInternal::OpenDirectory() { | 1153 bool SyncManagerImpl::SyncInternal::OpenDirectory() { |
| 1159 DCHECK(!initialized_) << "Should only happen once"; | 1154 DCHECK(!initialized_) << "Should only happen once"; |
| 1160 | 1155 |
| 1161 // Set before Open(). | 1156 // Set before Open(). |
| 1162 change_observer_ = | 1157 change_observer_ = |
| 1163 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); | 1158 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); |
| 1164 WeakHandle<syncable::TransactionObserver> transaction_observer( | 1159 WeakHandle<syncable::TransactionObserver> transaction_observer( |
| 1165 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); | 1160 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); |
| 1166 | 1161 |
| 1167 syncable::DirOpenResult open_result = syncable::NOT_INITIALIZED; | 1162 syncable::DirOpenResult open_result = syncable::NOT_INITIALIZED; |
| 1168 open_result = directory()->Open(username_for_share(), this, | 1163 open_result = directory()->Open(username_for_share(), this, |
| 1169 transaction_observer); | 1164 transaction_observer); |
| 1170 if (open_result != syncable::OPENED) { | 1165 if (open_result != syncable::OPENED) { |
| 1171 LOG(ERROR) << "Could not open share for:" << username_for_share(); | 1166 LOG(ERROR) << "Could not open share for:" << username_for_share(); |
| 1172 return false; | 1167 return false; |
| 1173 } | 1168 } |
| 1174 | 1169 |
| 1175 connection_manager()->set_client_id(directory()->cache_guid()); | 1170 connection_manager()->set_client_id(directory()->cache_guid()); |
| 1176 return true; | 1171 return true; |
| 1177 } | 1172 } |
| 1178 | 1173 |
| 1179 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { | 1174 bool SyncManagerImpl::SyncInternal::SignIn(const SyncCredentials& credentials) { |
| 1180 DCHECK(thread_checker_.CalledOnValidThread()); | 1175 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1181 DCHECK(share_.name.empty()); | 1176 DCHECK(share_.name.empty()); |
| 1182 share_.name = credentials.email; | 1177 share_.name = credentials.email; |
| 1183 | 1178 |
| 1184 DVLOG(1) << "Signing in user: " << username_for_share(); | 1179 DVLOG(1) << "Signing in user: " << username_for_share(); |
| 1185 if (!OpenDirectory()) | 1180 if (!OpenDirectory()) |
| 1186 return false; | 1181 return false; |
| 1187 | 1182 |
| 1188 // Retrieve and set the sync notifier state. This should be done | 1183 // Retrieve and set the sync notifier state. This should be done |
| 1189 // only after OpenDirectory is called. | 1184 // only after OpenDirectory is called. |
| 1190 std::string unique_id = directory()->cache_guid(); | 1185 std::string unique_id = directory()->cache_guid(); |
| 1191 std::string state = directory()->GetNotificationState(); | 1186 std::string state = directory()->GetNotificationState(); |
| 1192 DVLOG(1) << "Read notification unique ID: " << unique_id; | 1187 DVLOG(1) << "Read notification unique ID: " << unique_id; |
| 1193 if (VLOG_IS_ON(1)) { | 1188 if (VLOG_IS_ON(1)) { |
| 1194 std::string encoded_state; | 1189 std::string encoded_state; |
| 1195 base::Base64Encode(state, &encoded_state); | 1190 base::Base64Encode(state, &encoded_state); |
| 1196 DVLOG(1) << "Read notification state: " << encoded_state; | 1191 DVLOG(1) << "Read notification state: " << encoded_state; |
| 1197 } | 1192 } |
| 1198 allstatus_.SetUniqueId(unique_id); | 1193 allstatus_.SetUniqueId(unique_id); |
| 1199 sync_notifier_->SetUniqueId(unique_id); | 1194 sync_notifier_->SetUniqueId(unique_id); |
| 1200 // TODO(tim): Remove once invalidation state has been migrated to new | 1195 // TODO(tim): Remove once invalidation state has been migrated to new |
| 1201 // InvalidationStateTracker store. Bug 124140. | 1196 // InvalidationStateTracker store. Bug 124140. |
| 1202 sync_notifier_->SetStateDeprecated(state); | 1197 sync_notifier_->SetStateDeprecated(state); |
| 1203 | 1198 |
| 1204 UpdateCredentials(credentials); | 1199 UpdateCredentials(credentials); |
| 1205 return true; | 1200 return true; |
| 1206 } | 1201 } |
| 1207 | 1202 |
| 1208 bool SyncManager::SyncInternal::PurgePartiallySyncedTypes() { | 1203 bool SyncManagerImpl::SyncInternal::PurgePartiallySyncedTypes() { |
| 1209 syncer::ModelTypeSet partially_synced_types = | 1204 syncer::ModelTypeSet partially_synced_types = |
| 1210 syncer::ModelTypeSet::All(); | 1205 syncer::ModelTypeSet::All(); |
| 1211 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); | 1206 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); |
| 1212 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( | 1207 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( |
| 1213 syncer::ModelTypeSet::All())); | 1208 syncer::ModelTypeSet::All())); |
| 1214 | 1209 |
| 1215 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", | 1210 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", |
| 1216 partially_synced_types.Size()); | 1211 partially_synced_types.Size()); |
| 1217 if (partially_synced_types.Empty()) | 1212 if (partially_synced_types.Empty()) |
| 1218 return true; | 1213 return true; |
| 1219 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); | 1214 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); |
| 1220 } | 1215 } |
| 1221 | 1216 |
| 1222 void SyncManager::SyncInternal::UpdateCredentials( | 1217 void SyncManagerImpl::SyncInternal::UpdateCredentials( |
| 1223 const SyncCredentials& credentials) { | 1218 const SyncCredentials& credentials) { |
| 1224 DCHECK(thread_checker_.CalledOnValidThread()); | 1219 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1225 DCHECK_EQ(credentials.email, share_.name); | 1220 DCHECK_EQ(credentials.email, share_.name); |
| 1226 DCHECK(!credentials.email.empty()); | 1221 DCHECK(!credentials.email.empty()); |
| 1227 DCHECK(!credentials.sync_token.empty()); | 1222 DCHECK(!credentials.sync_token.empty()); |
| 1228 | 1223 |
| 1229 observing_ip_address_changes_ = true; | 1224 observing_ip_address_changes_ = true; |
| 1230 if (connection_manager()->set_auth_token(credentials.sync_token)) { | 1225 if (connection_manager()->set_auth_token(credentials.sync_token)) { |
| 1231 sync_notifier_->UpdateCredentials( | 1226 sync_notifier_->UpdateCredentials( |
| 1232 credentials.email, credentials.sync_token); | 1227 credentials.email, credentials.sync_token); |
| 1233 if (initialized_ && scheduler()) { | 1228 if (initialized_ && scheduler()) { |
| 1234 scheduler()->OnCredentialsUpdated(); | 1229 scheduler()->OnCredentialsUpdated(); |
| 1235 } | 1230 } |
| 1236 } | 1231 } |
| 1237 } | 1232 } |
| 1238 | 1233 |
| 1239 void SyncManager::SyncInternal::UpdateEnabledTypes( | 1234 void SyncManagerImpl::SyncInternal::UpdateEnabledTypes( |
| 1240 const ModelTypeSet& enabled_types) { | 1235 const ModelTypeSet& enabled_types) { |
| 1241 DCHECK(thread_checker_.CalledOnValidThread()); | 1236 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1242 sync_notifier_->UpdateEnabledTypes(enabled_types); | 1237 sync_notifier_->UpdateEnabledTypes(enabled_types); |
| 1243 } | 1238 } |
| 1244 | 1239 |
| 1245 void SyncManager::SyncInternal::SetEncryptionPassphrase( | 1240 void SyncManagerImpl::SyncInternal::SetEncryptionPassphrase( |
| 1246 const std::string& passphrase, | 1241 const std::string& passphrase, |
| 1247 bool is_explicit) { | 1242 bool is_explicit) { |
| 1248 // We do not accept empty passphrases. | 1243 // We do not accept empty passphrases. |
| 1249 if (passphrase.empty()) { | 1244 if (passphrase.empty()) { |
| 1250 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 1245 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 1251 return; | 1246 return; |
| 1252 } | 1247 } |
| 1253 | 1248 |
| 1254 // All accesses to the cryptographer are protected by a transaction. | 1249 // All accesses to the cryptographer are protected by a transaction. |
| 1255 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1250 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 DVLOG_IF(1, !success) | 1345 DVLOG_IF(1, !success) |
| 1351 << "Failure in SetEncryptionPassphrase; notifying and returning."; | 1346 << "Failure in SetEncryptionPassphrase; notifying and returning."; |
| 1352 DVLOG_IF(1, success) | 1347 DVLOG_IF(1, success) |
| 1353 << "Successfully set encryption passphrase; updating nigori and " | 1348 << "Successfully set encryption passphrase; updating nigori and " |
| 1354 "reencrypting."; | 1349 "reencrypting."; |
| 1355 | 1350 |
| 1356 FinishSetPassphrase( | 1351 FinishSetPassphrase( |
| 1357 success, bootstrap_token, is_explicit, &trans, &node); | 1352 success, bootstrap_token, is_explicit, &trans, &node); |
| 1358 } | 1353 } |
| 1359 | 1354 |
| 1360 void SyncManager::SyncInternal::SetDecryptionPassphrase( | 1355 void SyncManagerImpl::SyncInternal::SetDecryptionPassphrase( |
| 1361 const std::string& passphrase) { | 1356 const std::string& passphrase) { |
| 1362 // We do not accept empty passphrases. | 1357 // We do not accept empty passphrases. |
| 1363 if (passphrase.empty()) { | 1358 if (passphrase.empty()) { |
| 1364 NOTREACHED() << "Cannot decrypt with an empty passphrase."; | 1359 NOTREACHED() << "Cannot decrypt with an empty passphrase."; |
| 1365 return; | 1360 return; |
| 1366 } | 1361 } |
| 1367 | 1362 |
| 1368 // All accesses to the cryptographer are protected by a transaction. | 1363 // All accesses to the cryptographer are protected by a transaction. |
| 1369 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1364 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1370 Cryptographer* cryptographer = trans.GetCryptographer(); | 1365 Cryptographer* cryptographer = trans.GetCryptographer(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 << "Successfully set decryption passphrase; updating nigori and " | 1487 << "Successfully set decryption passphrase; updating nigori and " |
| 1493 "reencrypting."; | 1488 "reencrypting."; |
| 1494 | 1489 |
| 1495 FinishSetPassphrase(success, | 1490 FinishSetPassphrase(success, |
| 1496 bootstrap_token, | 1491 bootstrap_token, |
| 1497 nigori_has_explicit_passphrase, | 1492 nigori_has_explicit_passphrase, |
| 1498 &trans, | 1493 &trans, |
| 1499 &node); | 1494 &node); |
| 1500 } | 1495 } |
| 1501 | 1496 |
| 1502 void SyncManager::SyncInternal::FinishSetPassphrase( | 1497 void SyncManagerImpl::SyncInternal::FinishSetPassphrase( |
| 1503 bool success, | 1498 bool success, |
| 1504 const std::string& bootstrap_token, | 1499 const std::string& bootstrap_token, |
| 1505 bool is_explicit, | 1500 bool is_explicit, |
| 1506 WriteTransaction* trans, | 1501 WriteTransaction* trans, |
| 1507 WriteNode* nigori_node) { | 1502 WriteNode* nigori_node) { |
| 1508 Cryptographer* cryptographer = trans->GetCryptographer(); | 1503 Cryptographer* cryptographer = trans->GetCryptographer(); |
| 1509 NotifyCryptographerState(cryptographer); | 1504 NotifyCryptographerState(cryptographer); |
| 1510 | 1505 |
| 1511 // It's possible we need to change the bootstrap token even if we failed to | 1506 // It's possible we need to change the bootstrap token even if we failed to |
| 1512 // set the passphrase (for example if we need to preserve the new GAIA | 1507 // set the passphrase (for example if we need to preserve the new GAIA |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 return; | 1544 return; |
| 1550 } | 1545 } |
| 1551 specifics.set_using_explicit_passphrase(is_explicit); | 1546 specifics.set_using_explicit_passphrase(is_explicit); |
| 1552 nigori_node->SetNigoriSpecifics(specifics); | 1547 nigori_node->SetNigoriSpecifics(specifics); |
| 1553 | 1548 |
| 1554 // Does nothing if everything is already encrypted or the cryptographer has | 1549 // Does nothing if everything is already encrypted or the cryptographer has |
| 1555 // pending keys. | 1550 // pending keys. |
| 1556 ReEncryptEverything(trans); | 1551 ReEncryptEverything(trans); |
| 1557 } | 1552 } |
| 1558 | 1553 |
| 1559 bool SyncManager::SyncInternal::IsUsingExplicitPassphrase() { | 1554 bool SyncManagerImpl::SyncInternal::IsUsingExplicitPassphrase() { |
| 1560 ReadTransaction trans(FROM_HERE, &share_); | 1555 ReadTransaction trans(FROM_HERE, &share_); |
| 1561 ReadNode node(&trans); | 1556 ReadNode node(&trans); |
| 1562 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1557 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { |
| 1563 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 1558 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 1564 NOTREACHED(); | 1559 NOTREACHED(); |
| 1565 return false; | 1560 return false; |
| 1566 } | 1561 } |
| 1567 | 1562 |
| 1568 return node.GetNigoriSpecifics().using_explicit_passphrase(); | 1563 return node.GetNigoriSpecifics().using_explicit_passphrase(); |
| 1569 } | 1564 } |
| 1570 | 1565 |
| 1571 void SyncManager::SyncInternal::RefreshEncryption() { | 1566 void SyncManagerImpl::SyncInternal::RefreshEncryption() { |
| 1572 DCHECK(initialized_); | 1567 DCHECK(initialized_); |
| 1573 | 1568 |
| 1574 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1569 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1575 WriteNode node(&trans); | 1570 WriteNode node(&trans); |
| 1576 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1571 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { |
| 1577 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " | 1572 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " |
| 1578 << "found."; | 1573 << "found."; |
| 1579 return; | 1574 return; |
| 1580 } | 1575 } |
| 1581 | 1576 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1601 | 1596 |
| 1602 // We reencrypt everything regardless of whether the set of encrypted | 1597 // We reencrypt everything regardless of whether the set of encrypted |
| 1603 // types changed to ensure that any stray unencrypted entries are overwritten. | 1598 // types changed to ensure that any stray unencrypted entries are overwritten. |
| 1604 ReEncryptEverything(&trans); | 1599 ReEncryptEverything(&trans); |
| 1605 } | 1600 } |
| 1606 | 1601 |
| 1607 // This function iterates over all encrypted types. There are many scenarios in | 1602 // This function iterates over all encrypted types. There are many scenarios in |
| 1608 // which data for some or all types is not currently available. In that case, | 1603 // which data for some or all types is not currently available. In that case, |
| 1609 // the lookup of the root node will fail and we will skip encryption for that | 1604 // the lookup of the root node will fail and we will skip encryption for that |
| 1610 // type. | 1605 // type. |
| 1611 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { | 1606 void SyncManagerImpl::SyncInternal::ReEncryptEverything( |
| 1607 WriteTransaction* trans) { |
| 1612 Cryptographer* cryptographer = trans->GetCryptographer(); | 1608 Cryptographer* cryptographer = trans->GetCryptographer(); |
| 1613 if (!cryptographer || !cryptographer->is_ready()) | 1609 if (!cryptographer || !cryptographer->is_ready()) |
| 1614 return; | 1610 return; |
| 1615 syncer::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); | 1611 syncer::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); |
| 1616 for (syncer::ModelTypeSet::Iterator iter = encrypted_types.First(); | 1612 for (syncer::ModelTypeSet::Iterator iter = encrypted_types.First(); |
| 1617 iter.Good(); iter.Inc()) { | 1613 iter.Good(); iter.Inc()) { |
| 1618 if (iter.Get() == syncer::PASSWORDS || iter.Get() == syncer::NIGORI) | 1614 if (iter.Get() == syncer::PASSWORDS || iter.Get() == syncer::NIGORI) |
| 1619 continue; // These types handle encryption differently. | 1615 continue; // These types handle encryption differently. |
| 1620 | 1616 |
| 1621 ReadNode type_root(trans); | 1617 ReadNode type_root(trans); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) { | 1658 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) { |
| 1663 NOTREACHED(); | 1659 NOTREACHED(); |
| 1664 return; | 1660 return; |
| 1665 } | 1661 } |
| 1666 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); | 1662 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); |
| 1667 child_id = child.GetSuccessorId(); | 1663 child_id = child.GetSuccessorId(); |
| 1668 } | 1664 } |
| 1669 } | 1665 } |
| 1670 | 1666 |
| 1671 // NOTE: We notify from within a transaction. | 1667 // NOTE: We notify from within a transaction. |
| 1672 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, OnEncryptionComplete()); | 1668 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1669 OnEncryptionComplete()); |
| 1673 } | 1670 } |
| 1674 | 1671 |
| 1675 SyncManager::~SyncManager() { | 1672 SyncManagerImpl::~SyncManagerImpl() { |
| 1676 DCHECK(thread_checker_.CalledOnValidThread()); | 1673 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1677 delete data_; | 1674 delete data_; |
| 1678 } | 1675 } |
| 1679 | 1676 |
| 1680 void SyncManager::AddObserver(Observer* observer) { | 1677 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { |
| 1681 DCHECK(thread_checker_.CalledOnValidThread()); | 1678 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1682 data_->AddObserver(observer); | 1679 data_->AddObserver(observer); |
| 1683 } | 1680 } |
| 1684 | 1681 |
| 1685 void SyncManager::RemoveObserver(Observer* observer) { | 1682 void SyncManagerImpl::RemoveObserver(SyncManager::Observer* observer) { |
| 1686 DCHECK(thread_checker_.CalledOnValidThread()); | 1683 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1687 data_->RemoveObserver(observer); | 1684 data_->RemoveObserver(observer); |
| 1688 } | 1685 } |
| 1689 | 1686 |
| 1690 void SyncManager::StopSyncingForShutdown(const base::Closure& callback) { | 1687 void SyncManagerImpl::StopSyncingForShutdown(const base::Closure& callback) { |
| 1691 data_->StopSyncingForShutdown(callback); | 1688 data_->StopSyncingForShutdown(callback); |
| 1692 } | 1689 } |
| 1693 | 1690 |
| 1694 void SyncManager::SyncInternal::StopSyncingForShutdown( | 1691 void SyncManagerImpl::SyncInternal::StopSyncingForShutdown( |
| 1695 const base::Closure& callback) { | 1692 const base::Closure& callback) { |
| 1696 DVLOG(2) << "StopSyncingForShutdown"; | 1693 DVLOG(2) << "StopSyncingForShutdown"; |
| 1697 if (scheduler()) // May be null in tests. | 1694 if (scheduler()) // May be null in tests. |
| 1698 scheduler()->RequestStop(callback); | 1695 scheduler()->RequestStop(callback); |
| 1699 else | 1696 else |
| 1700 created_on_loop_->PostTask(FROM_HERE, callback); | 1697 created_on_loop_->PostTask(FROM_HERE, callback); |
| 1701 | 1698 |
| 1702 if (connection_manager_.get()) | 1699 if (connection_manager_.get()) |
| 1703 connection_manager_->TerminateAllIO(); | 1700 connection_manager_->TerminateAllIO(); |
| 1704 } | 1701 } |
| 1705 | 1702 |
| 1706 void SyncManager::ShutdownOnSyncThread() { | 1703 void SyncManagerImpl::ShutdownOnSyncThread() { |
| 1707 DCHECK(thread_checker_.CalledOnValidThread()); | 1704 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1708 data_->ShutdownOnSyncThread(); | 1705 data_->ShutdownOnSyncThread(); |
| 1709 } | 1706 } |
| 1710 | 1707 |
| 1711 void SyncManager::SyncInternal::ShutdownOnSyncThread() { | 1708 void SyncManagerImpl::SyncInternal::ShutdownOnSyncThread() { |
| 1712 DCHECK(thread_checker_.CalledOnValidThread()); | 1709 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1713 | 1710 |
| 1714 // Prevent any in-flight method calls from running. Also | 1711 // Prevent any in-flight method calls from running. Also |
| 1715 // invalidates |weak_handle_this_| and |change_observer_|. | 1712 // invalidates |weak_handle_this_| and |change_observer_|. |
| 1716 weak_ptr_factory_.InvalidateWeakPtrs(); | 1713 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 1717 js_mutation_event_observer_.InvalidateWeakPtrs(); | 1714 js_mutation_event_observer_.InvalidateWeakPtrs(); |
| 1718 | 1715 |
| 1719 scheduler_.reset(); | 1716 scheduler_.reset(); |
| 1720 session_context_.reset(); | 1717 session_context_.reset(); |
| 1721 | 1718 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1752 change_delegate_ = NULL; | 1749 change_delegate_ = NULL; |
| 1753 | 1750 |
| 1754 initialized_ = false; | 1751 initialized_ = false; |
| 1755 | 1752 |
| 1756 // We reset these here, since only now we know they will not be | 1753 // We reset these here, since only now we know they will not be |
| 1757 // accessed from other threads (since we shut down everything). | 1754 // accessed from other threads (since we shut down everything). |
| 1758 change_observer_.Reset(); | 1755 change_observer_.Reset(); |
| 1759 weak_handle_this_.Reset(); | 1756 weak_handle_this_.Reset(); |
| 1760 } | 1757 } |
| 1761 | 1758 |
| 1762 void SyncManager::SyncInternal::OnIPAddressChanged() { | 1759 void SyncManagerImpl::SyncInternal::OnIPAddressChanged() { |
| 1763 DVLOG(1) << "IP address change detected"; | 1760 DVLOG(1) << "IP address change detected"; |
| 1764 if (!observing_ip_address_changes_) { | 1761 if (!observing_ip_address_changes_) { |
| 1765 DVLOG(1) << "IP address change dropped."; | 1762 DVLOG(1) << "IP address change dropped."; |
| 1766 return; | 1763 return; |
| 1767 } | 1764 } |
| 1768 | 1765 |
| 1769 OnIPAddressChangedImpl(); | 1766 OnIPAddressChangedImpl(); |
| 1770 } | 1767 } |
| 1771 | 1768 |
| 1772 void SyncManager::SyncInternal::OnIPAddressChangedImpl() { | 1769 void SyncManagerImpl::SyncInternal::OnIPAddressChangedImpl() { |
| 1773 DCHECK(thread_checker_.CalledOnValidThread()); | 1770 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1774 if (scheduler()) | 1771 if (scheduler()) |
| 1775 scheduler()->OnConnectionStatusChange(); | 1772 scheduler()->OnConnectionStatusChange(); |
| 1776 } | 1773 } |
| 1777 | 1774 |
| 1778 void SyncManager::SyncInternal::OnServerConnectionEvent( | 1775 void SyncManagerImpl::SyncInternal::OnServerConnectionEvent( |
| 1779 const ServerConnectionEvent& event) { | 1776 const ServerConnectionEvent& event) { |
| 1780 DCHECK(thread_checker_.CalledOnValidThread()); | 1777 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1781 if (event.connection_code == | 1778 if (event.connection_code == |
| 1782 syncer::HttpResponse::SERVER_CONNECTION_OK) { | 1779 syncer::HttpResponse::SERVER_CONNECTION_OK) { |
| 1783 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1780 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1784 OnConnectionStatusChange(CONNECTION_OK)); | 1781 OnConnectionStatusChange(CONNECTION_OK)); |
| 1785 } | 1782 } |
| 1786 | 1783 |
| 1787 if (event.connection_code == syncer::HttpResponse::SYNC_AUTH_ERROR) { | 1784 if (event.connection_code == syncer::HttpResponse::SYNC_AUTH_ERROR) { |
| 1788 observing_ip_address_changes_ = false; | 1785 observing_ip_address_changes_ = false; |
| 1789 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1786 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1790 OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); | 1787 OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); |
| 1791 } | 1788 } |
| 1792 | 1789 |
| 1793 if (event.connection_code == | 1790 if (event.connection_code == |
| 1794 syncer::HttpResponse::SYNC_SERVER_ERROR) { | 1791 syncer::HttpResponse::SYNC_SERVER_ERROR) { |
| 1795 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1792 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1796 OnConnectionStatusChange(CONNECTION_SERVER_ERROR)); | 1793 OnConnectionStatusChange(CONNECTION_SERVER_ERROR)); |
| 1797 } | 1794 } |
| 1798 } | 1795 } |
| 1799 | 1796 |
| 1800 void SyncManager::SyncInternal::HandleTransactionCompleteChangeEvent( | 1797 void SyncManagerImpl::SyncInternal::HandleTransactionCompleteChangeEvent( |
| 1801 ModelTypeSet models_with_changes) { | 1798 ModelTypeSet models_with_changes) { |
| 1802 // This notification happens immediately after the transaction mutex is | 1799 // This notification happens immediately after the transaction mutex is |
| 1803 // released. This allows work to be performed without blocking other threads | 1800 // released. This allows work to be performed without blocking other threads |
| 1804 // from acquiring a transaction. | 1801 // from acquiring a transaction. |
| 1805 if (!change_delegate_) | 1802 if (!change_delegate_) |
| 1806 return; | 1803 return; |
| 1807 | 1804 |
| 1808 // Call commit. | 1805 // Call commit. |
| 1809 for (ModelTypeSet::Iterator it = models_with_changes.First(); | 1806 for (ModelTypeSet::Iterator it = models_with_changes.First(); |
| 1810 it.Good(); it.Inc()) { | 1807 it.Good(); it.Inc()) { |
| 1811 change_delegate_->OnChangesComplete(it.Get()); | 1808 change_delegate_->OnChangesComplete(it.Get()); |
| 1812 change_observer_.Call( | 1809 change_observer_.Call( |
| 1813 FROM_HERE, &SyncManager::ChangeObserver::OnChangesComplete, it.Get()); | 1810 FROM_HERE, |
| 1811 &SyncManager::ChangeObserver::OnChangesComplete, |
| 1812 it.Get()); |
| 1814 } | 1813 } |
| 1815 } | 1814 } |
| 1816 | 1815 |
| 1817 ModelTypeSet | 1816 ModelTypeSet |
| 1818 SyncManager::SyncInternal::HandleTransactionEndingChangeEvent( | 1817 SyncManagerImpl::SyncInternal::HandleTransactionEndingChangeEvent( |
| 1819 const ImmutableWriteTransactionInfo& write_transaction_info, | 1818 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 1820 syncable::BaseTransaction* trans) { | 1819 syncable::BaseTransaction* trans) { |
| 1821 // This notification happens immediately before a syncable WriteTransaction | 1820 // This notification happens immediately before a syncable WriteTransaction |
| 1822 // falls out of scope. It happens while the channel mutex is still held, | 1821 // falls out of scope. It happens while the channel mutex is still held, |
| 1823 // and while the transaction mutex is held, so it cannot be re-entrant. | 1822 // and while the transaction mutex is held, so it cannot be re-entrant. |
| 1824 if (!change_delegate_ || ChangeBuffersAreEmpty()) | 1823 if (!change_delegate_ || ChangeBuffersAreEmpty()) |
| 1825 return ModelTypeSet(); | 1824 return ModelTypeSet(); |
| 1826 | 1825 |
| 1827 // This will continue the WriteTransaction using a read only wrapper. | 1826 // This will continue the WriteTransaction using a read only wrapper. |
| 1828 // This is the last chance for read to occur in the WriteTransaction | 1827 // This is the last chance for read to occur in the WriteTransaction |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1848 change_observer_.Call(FROM_HERE, | 1847 change_observer_.Call(FROM_HERE, |
| 1849 &SyncManager::ChangeObserver::OnChangesApplied, | 1848 &SyncManager::ChangeObserver::OnChangesApplied, |
| 1850 type, write_transaction_info.Get().id, ordered_changes); | 1849 type, write_transaction_info.Get().id, ordered_changes); |
| 1851 models_with_changes.Put(type); | 1850 models_with_changes.Put(type); |
| 1852 } | 1851 } |
| 1853 change_buffers_[i].Clear(); | 1852 change_buffers_[i].Clear(); |
| 1854 } | 1853 } |
| 1855 return models_with_changes; | 1854 return models_with_changes; |
| 1856 } | 1855 } |
| 1857 | 1856 |
| 1858 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi( | 1857 void SyncManagerImpl::SyncInternal:: |
| 1858 HandleCalculateChangesChangeEventFromSyncApi( |
| 1859 const ImmutableWriteTransactionInfo& write_transaction_info, | 1859 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 1860 syncable::BaseTransaction* trans) { | 1860 syncable::BaseTransaction* trans) { |
| 1861 if (!scheduler()) { | 1861 if (!scheduler()) { |
| 1862 return; | 1862 return; |
| 1863 } | 1863 } |
| 1864 | 1864 |
| 1865 // We have been notified about a user action changing a sync model. | 1865 // We have been notified about a user action changing a sync model. |
| 1866 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << | 1866 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << |
| 1867 "CALCULATE_CHANGES called with unapplied old changes."; | 1867 "CALCULATE_CHANGES called with unapplied old changes."; |
| 1868 | 1868 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1897 weak_handle_this_.Call(FROM_HERE, | 1897 weak_handle_this_.Call(FROM_HERE, |
| 1898 &SyncInternal::RequestNudgeForDataTypes, | 1898 &SyncInternal::RequestNudgeForDataTypes, |
| 1899 FROM_HERE, | 1899 FROM_HERE, |
| 1900 mutated_model_types); | 1900 mutated_model_types); |
| 1901 } else { | 1901 } else { |
| 1902 NOTREACHED(); | 1902 NOTREACHED(); |
| 1903 } | 1903 } |
| 1904 } | 1904 } |
| 1905 } | 1905 } |
| 1906 | 1906 |
| 1907 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id, | 1907 void SyncManagerImpl::SyncInternal::SetExtraChangeRecordData(int64 id, |
| 1908 syncer::ModelType type, ChangeReorderBuffer* buffer, | 1908 syncer::ModelType type, ChangeReorderBuffer* buffer, |
| 1909 Cryptographer* cryptographer, const syncable::EntryKernel& original, | 1909 Cryptographer* cryptographer, const syncable::EntryKernel& original, |
| 1910 bool existed_before, bool exists_now) { | 1910 bool existed_before, bool exists_now) { |
| 1911 // If this is a deletion and the datatype was encrypted, we need to decrypt it | 1911 // If this is a deletion and the datatype was encrypted, we need to decrypt it |
| 1912 // and attach it to the buffer. | 1912 // and attach it to the buffer. |
| 1913 if (!exists_now && existed_before) { | 1913 if (!exists_now && existed_before) { |
| 1914 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); | 1914 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); |
| 1915 if (type == syncer::PASSWORDS) { | 1915 if (type == syncer::PASSWORDS) { |
| 1916 // Passwords must use their own legacy ExtraPasswordChangeRecordData. | 1916 // Passwords must use their own legacy ExtraPasswordChangeRecordData. |
| 1917 scoped_ptr<sync_pb::PasswordSpecificsData> data( | 1917 scoped_ptr<sync_pb::PasswordSpecificsData> data( |
| 1918 DecryptPasswordSpecifics(original_specifics, cryptographer)); | 1918 DecryptPasswordSpecifics(original_specifics, cryptographer)); |
| 1919 if (!data.get()) { | 1919 if (!data.get()) { |
| 1920 NOTREACHED(); | 1920 NOTREACHED(); |
| 1921 return; | 1921 return; |
| 1922 } | 1922 } |
| 1923 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); | 1923 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); |
| 1924 } else if (original_specifics.has_encrypted()) { | 1924 } else if (original_specifics.has_encrypted()) { |
| 1925 // All other datatypes can just create a new unencrypted specifics and | 1925 // All other datatypes can just create a new unencrypted specifics and |
| 1926 // attach it. | 1926 // attach it. |
| 1927 const sync_pb::EncryptedData& encrypted = original_specifics.encrypted(); | 1927 const sync_pb::EncryptedData& encrypted = original_specifics.encrypted(); |
| 1928 if (!cryptographer->Decrypt(encrypted, &original_specifics)) { | 1928 if (!cryptographer->Decrypt(encrypted, &original_specifics)) { |
| 1929 NOTREACHED(); | 1929 NOTREACHED(); |
| 1930 return; | 1930 return; |
| 1931 } | 1931 } |
| 1932 } | 1932 } |
| 1933 buffer->SetSpecificsForId(id, original_specifics); | 1933 buffer->SetSpecificsForId(id, original_specifics); |
| 1934 } | 1934 } |
| 1935 } | 1935 } |
| 1936 | 1936 |
| 1937 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncer( | 1937 void SyncManagerImpl::SyncInternal::HandleCalculateChangesChangeEventFromSyncer( |
| 1938 const ImmutableWriteTransactionInfo& write_transaction_info, | 1938 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 1939 syncable::BaseTransaction* trans) { | 1939 syncable::BaseTransaction* trans) { |
| 1940 // We only expect one notification per sync step, so change_buffers_ should | 1940 // We only expect one notification per sync step, so change_buffers_ should |
| 1941 // contain no pending entries. | 1941 // contain no pending entries. |
| 1942 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << | 1942 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << |
| 1943 "CALCULATE_CHANGES called with unapplied old changes."; | 1943 "CALCULATE_CHANGES called with unapplied old changes."; |
| 1944 | 1944 |
| 1945 Cryptographer* crypto = directory()->GetCryptographer(trans); | 1945 Cryptographer* crypto = directory()->GetCryptographer(trans); |
| 1946 const syncable::ImmutableEntryKernelMutationMap& mutations = | 1946 const syncable::ImmutableEntryKernelMutationMap& mutations = |
| 1947 write_transaction_info.Get().mutations; | 1947 write_transaction_info.Get().mutations; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1966 VisiblePropertiesDiffer(it->second, crypto)) { | 1966 VisiblePropertiesDiffer(it->second, crypto)) { |
| 1967 change_buffers_[type].PushUpdatedItem( | 1967 change_buffers_[type].PushUpdatedItem( |
| 1968 handle, VisiblePositionsDiffer(it->second)); | 1968 handle, VisiblePositionsDiffer(it->second)); |
| 1969 } | 1969 } |
| 1970 | 1970 |
| 1971 SetExtraChangeRecordData(handle, type, &change_buffers_[type], crypto, | 1971 SetExtraChangeRecordData(handle, type, &change_buffers_[type], crypto, |
| 1972 it->second.original, existed_before, exists_now); | 1972 it->second.original, existed_before, exists_now); |
| 1973 } | 1973 } |
| 1974 } | 1974 } |
| 1975 | 1975 |
| 1976 SyncStatus SyncManager::SyncInternal::GetStatus() { | 1976 SyncStatus SyncManagerImpl::SyncInternal::GetStatus() { |
| 1977 return allstatus_.status(); | 1977 return allstatus_.status(); |
| 1978 } | 1978 } |
| 1979 | 1979 |
| 1980 void SyncManager::SyncInternal::RequestNudge( | 1980 void SyncManagerImpl::SyncInternal::RequestNudge( |
| 1981 const tracked_objects::Location& location) { | 1981 const tracked_objects::Location& location) { |
| 1982 if (scheduler()) { | 1982 if (scheduler()) { |
| 1983 scheduler()->ScheduleNudgeAsync( | 1983 scheduler()->ScheduleNudgeAsync( |
| 1984 TimeDelta::FromMilliseconds(0), syncer::NUDGE_SOURCE_LOCAL, | 1984 TimeDelta::FromMilliseconds(0), syncer::NUDGE_SOURCE_LOCAL, |
| 1985 ModelTypeSet(), location); | 1985 ModelTypeSet(), location); |
| 1986 } | 1986 } |
| 1987 } | 1987 } |
| 1988 | 1988 |
| 1989 TimeDelta SyncManager::SyncInternal::GetNudgeDelayTimeDelta( | 1989 TimeDelta SyncManagerImpl::SyncInternal::GetNudgeDelayTimeDelta( |
| 1990 const ModelType& model_type) { | 1990 const ModelType& model_type) { |
| 1991 return NudgeStrategy::GetNudgeDelayTimeDelta(model_type, this); | 1991 return NudgeStrategy::GetNudgeDelayTimeDelta(model_type, this); |
| 1992 } | 1992 } |
| 1993 | 1993 |
| 1994 void SyncManager::SyncInternal::RequestNudgeForDataTypes( | 1994 void SyncManagerImpl::SyncInternal::RequestNudgeForDataTypes( |
| 1995 const tracked_objects::Location& nudge_location, | 1995 const tracked_objects::Location& nudge_location, |
| 1996 ModelTypeSet types) { | 1996 ModelTypeSet types) { |
| 1997 if (!scheduler()) { | 1997 if (!scheduler()) { |
| 1998 NOTREACHED(); | 1998 NOTREACHED(); |
| 1999 return; | 1999 return; |
| 2000 } | 2000 } |
| 2001 | 2001 |
| 2002 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); | 2002 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); |
| 2003 | 2003 |
| 2004 // TODO(lipalani) : Calculate the nudge delay based on all types. | 2004 // TODO(lipalani) : Calculate the nudge delay based on all types. |
| 2005 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( | 2005 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( |
| 2006 types.First().Get(), | 2006 types.First().Get(), |
| 2007 this); | 2007 this); |
| 2008 scheduler()->ScheduleNudgeAsync(nudge_delay, | 2008 scheduler()->ScheduleNudgeAsync(nudge_delay, |
| 2009 syncer::NUDGE_SOURCE_LOCAL, | 2009 syncer::NUDGE_SOURCE_LOCAL, |
| 2010 types, | 2010 types, |
| 2011 nudge_location); | 2011 nudge_location); |
| 2012 } | 2012 } |
| 2013 | 2013 |
| 2014 void SyncManager::SyncInternal::OnSyncEngineEvent( | 2014 void SyncManagerImpl::SyncInternal::OnSyncEngineEvent( |
| 2015 const SyncEngineEvent& event) { | 2015 const SyncEngineEvent& event) { |
| 2016 DCHECK(thread_checker_.CalledOnValidThread()); | 2016 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2017 // Only send an event if this is due to a cycle ending and this cycle | 2017 // Only send an event if this is due to a cycle ending and this cycle |
| 2018 // concludes a canonical "sync" process; that is, based on what is known | 2018 // concludes a canonical "sync" process; that is, based on what is known |
| 2019 // locally we are "all happy" and up-to-date. There may be new changes on | 2019 // locally we are "all happy" and up-to-date. There may be new changes on |
| 2020 // the server, but we'll get them on a subsequent sync. | 2020 // the server, but we'll get them on a subsequent sync. |
| 2021 // | 2021 // |
| 2022 // Notifications are sent at the end of every sync cycle, regardless of | 2022 // Notifications are sent at the end of every sync cycle, regardless of |
| 2023 // whether we should sync again. | 2023 // whether we should sync again. |
| 2024 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 2024 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2103 if (event.what_happened == SyncEngineEvent::ACTIONABLE_ERROR) { | 2103 if (event.what_happened == SyncEngineEvent::ACTIONABLE_ERROR) { |
| 2104 FOR_EACH_OBSERVER( | 2104 FOR_EACH_OBSERVER( |
| 2105 SyncManager::Observer, observers_, | 2105 SyncManager::Observer, observers_, |
| 2106 OnActionableError( | 2106 OnActionableError( |
| 2107 event.snapshot.model_neutral_state().sync_protocol_error)); | 2107 event.snapshot.model_neutral_state().sync_protocol_error)); |
| 2108 return; | 2108 return; |
| 2109 } | 2109 } |
| 2110 | 2110 |
| 2111 } | 2111 } |
| 2112 | 2112 |
| 2113 void SyncManager::SyncInternal::SetJsEventHandler( | 2113 void SyncManagerImpl::SyncInternal::SetJsEventHandler( |
| 2114 const WeakHandle<JsEventHandler>& event_handler) { | 2114 const WeakHandle<JsEventHandler>& event_handler) { |
| 2115 js_event_handler_ = event_handler; | 2115 js_event_handler_ = event_handler; |
| 2116 js_sync_manager_observer_.SetJsEventHandler(js_event_handler_); | 2116 js_sync_manager_observer_.SetJsEventHandler(js_event_handler_); |
| 2117 js_mutation_event_observer_.SetJsEventHandler(js_event_handler_); | 2117 js_mutation_event_observer_.SetJsEventHandler(js_event_handler_); |
| 2118 } | 2118 } |
| 2119 | 2119 |
| 2120 void SyncManager::SyncInternal::ProcessJsMessage( | 2120 void SyncManagerImpl::SyncInternal::ProcessJsMessage( |
| 2121 const std::string& name, const JsArgList& args, | 2121 const std::string& name, const JsArgList& args, |
| 2122 const WeakHandle<JsReplyHandler>& reply_handler) { | 2122 const WeakHandle<JsReplyHandler>& reply_handler) { |
| 2123 if (!initialized_) { | 2123 if (!initialized_) { |
| 2124 NOTREACHED(); | 2124 NOTREACHED(); |
| 2125 return; | 2125 return; |
| 2126 } | 2126 } |
| 2127 | 2127 |
| 2128 if (!reply_handler.IsInitialized()) { | 2128 if (!reply_handler.IsInitialized()) { |
| 2129 DVLOG(1) << "Uninitialized reply handler; dropping unknown message " | 2129 DVLOG(1) << "Uninitialized reply handler; dropping unknown message " |
| 2130 << name << " with args " << args.ToString(); | 2130 << name << " with args " << args.ToString(); |
| 2131 return; | 2131 return; |
| 2132 } | 2132 } |
| 2133 | 2133 |
| 2134 JsMessageHandler js_message_handler = js_message_handlers_[name]; | 2134 JsMessageHandler js_message_handler = js_message_handlers_[name]; |
| 2135 if (js_message_handler.is_null()) { | 2135 if (js_message_handler.is_null()) { |
| 2136 DVLOG(1) << "Dropping unknown message " << name | 2136 DVLOG(1) << "Dropping unknown message " << name |
| 2137 << " with args " << args.ToString(); | 2137 << " with args " << args.ToString(); |
| 2138 return; | 2138 return; |
| 2139 } | 2139 } |
| 2140 | 2140 |
| 2141 reply_handler.Call(FROM_HERE, | 2141 reply_handler.Call(FROM_HERE, |
| 2142 &JsReplyHandler::HandleJsReply, | 2142 &JsReplyHandler::HandleJsReply, |
| 2143 name, js_message_handler.Run(args)); | 2143 name, js_message_handler.Run(args)); |
| 2144 } | 2144 } |
| 2145 | 2145 |
| 2146 void SyncManager::SyncInternal::BindJsMessageHandler( | 2146 void SyncManagerImpl::SyncInternal::BindJsMessageHandler( |
| 2147 const std::string& name, | 2147 const std::string& name, |
| 2148 UnboundJsMessageHandler unbound_message_handler) { | 2148 UnboundJsMessageHandler unbound_message_handler) { |
| 2149 js_message_handlers_[name] = | 2149 js_message_handlers_[name] = |
| 2150 base::Bind(unbound_message_handler, base::Unretained(this)); | 2150 base::Bind(unbound_message_handler, base::Unretained(this)); |
| 2151 } | 2151 } |
| 2152 | 2152 |
| 2153 DictionaryValue* SyncManager::SyncInternal::NotificationInfoToValue( | 2153 DictionaryValue* SyncManagerImpl::SyncInternal::NotificationInfoToValue( |
| 2154 const NotificationInfoMap& notification_info) { | 2154 const NotificationInfoMap& notification_info) { |
| 2155 DictionaryValue* value = new DictionaryValue(); | 2155 DictionaryValue* value = new DictionaryValue(); |
| 2156 | 2156 |
| 2157 for (NotificationInfoMap::const_iterator it = notification_info.begin(); | 2157 for (NotificationInfoMap::const_iterator it = notification_info.begin(); |
| 2158 it != notification_info.end(); ++it) { | 2158 it != notification_info.end(); ++it) { |
| 2159 const std::string& model_type_str = | 2159 const std::string& model_type_str = |
| 2160 syncer::ModelTypeToString(it->first); | 2160 syncer::ModelTypeToString(it->first); |
| 2161 value->Set(model_type_str, it->second.ToValue()); | 2161 value->Set(model_type_str, it->second.ToValue()); |
| 2162 } | 2162 } |
| 2163 | 2163 |
| 2164 return value; | 2164 return value; |
| 2165 } | 2165 } |
| 2166 | 2166 |
| 2167 JsArgList SyncManager::SyncInternal::GetNotificationState( | 2167 JsArgList SyncManagerImpl::SyncInternal::GetNotificationState( |
| 2168 const JsArgList& args) { | 2168 const JsArgList& args) { |
| 2169 bool notifications_enabled = allstatus_.status().notifications_enabled; | 2169 bool notifications_enabled = allstatus_.status().notifications_enabled; |
| 2170 ListValue return_args; | 2170 ListValue return_args; |
| 2171 return_args.Append(Value::CreateBooleanValue(notifications_enabled)); | 2171 return_args.Append(Value::CreateBooleanValue(notifications_enabled)); |
| 2172 return JsArgList(&return_args); | 2172 return JsArgList(&return_args); |
| 2173 } | 2173 } |
| 2174 | 2174 |
| 2175 JsArgList SyncManager::SyncInternal::GetNotificationInfo( | 2175 JsArgList SyncManagerImpl::SyncInternal::GetNotificationInfo( |
| 2176 const JsArgList& args) { | 2176 const JsArgList& args) { |
| 2177 ListValue return_args; | 2177 ListValue return_args; |
| 2178 return_args.Append(NotificationInfoToValue(notification_info_map_)); | 2178 return_args.Append(NotificationInfoToValue(notification_info_map_)); |
| 2179 return JsArgList(&return_args); | 2179 return JsArgList(&return_args); |
| 2180 } | 2180 } |
| 2181 | 2181 |
| 2182 JsArgList SyncManager::SyncInternal::GetRootNodeDetails( | 2182 JsArgList SyncManagerImpl::SyncInternal::GetRootNodeDetails( |
| 2183 const JsArgList& args) { | 2183 const JsArgList& args) { |
| 2184 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2184 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2185 ReadNode root(&trans); | 2185 ReadNode root(&trans); |
| 2186 root.InitByRootLookup(); | 2186 root.InitByRootLookup(); |
| 2187 ListValue return_args; | 2187 ListValue return_args; |
| 2188 return_args.Append(root.GetDetailsAsValue()); | 2188 return_args.Append(root.GetDetailsAsValue()); |
| 2189 return JsArgList(&return_args); | 2189 return JsArgList(&return_args); |
| 2190 } | 2190 } |
| 2191 | 2191 |
| 2192 JsArgList SyncManager::SyncInternal::GetClientServerTraffic( | 2192 JsArgList SyncManagerImpl::SyncInternal::GetClientServerTraffic( |
| 2193 const JsArgList& args) { | 2193 const JsArgList& args) { |
| 2194 ListValue return_args; | 2194 ListValue return_args; |
| 2195 ListValue* value = traffic_recorder_.ToValue(); | 2195 ListValue* value = traffic_recorder_.ToValue(); |
| 2196 if (value != NULL) | 2196 if (value != NULL) |
| 2197 return_args.Append(value); | 2197 return_args.Append(value); |
| 2198 return JsArgList(&return_args); | 2198 return JsArgList(&return_args); |
| 2199 } | 2199 } |
| 2200 | 2200 |
| 2201 namespace { | 2201 namespace { |
| 2202 | 2202 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2233 continue; | 2233 continue; |
| 2234 } | 2234 } |
| 2235 node_summaries->Append((node.*info_getter)()); | 2235 node_summaries->Append((node.*info_getter)()); |
| 2236 } | 2236 } |
| 2237 } | 2237 } |
| 2238 return JsArgList(&return_args); | 2238 return JsArgList(&return_args); |
| 2239 } | 2239 } |
| 2240 | 2240 |
| 2241 } // namespace | 2241 } // namespace |
| 2242 | 2242 |
| 2243 JsArgList SyncManager::SyncInternal::GetNodeSummariesById( | 2243 JsArgList SyncManagerImpl::SyncInternal::GetNodeSummariesById( |
| 2244 const JsArgList& args) { | 2244 const JsArgList& args) { |
| 2245 return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetSummaryAsValue); | 2245 return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetSummaryAsValue); |
| 2246 } | 2246 } |
| 2247 | 2247 |
| 2248 JsArgList SyncManager::SyncInternal::GetNodeDetailsById( | 2248 JsArgList SyncManagerImpl::SyncInternal::GetNodeDetailsById( |
| 2249 const JsArgList& args) { | 2249 const JsArgList& args) { |
| 2250 return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetDetailsAsValue); | 2250 return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetDetailsAsValue); |
| 2251 } | 2251 } |
| 2252 | 2252 |
| 2253 JsArgList SyncManager::SyncInternal::GetAllNodes( | 2253 JsArgList SyncManagerImpl::SyncInternal::GetAllNodes( |
| 2254 const JsArgList& args) { | 2254 const JsArgList& args) { |
| 2255 ListValue return_args; | 2255 ListValue return_args; |
| 2256 ListValue* result = new ListValue(); | 2256 ListValue* result = new ListValue(); |
| 2257 return_args.Append(result); | 2257 return_args.Append(result); |
| 2258 | 2258 |
| 2259 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2259 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2260 std::vector<const syncable::EntryKernel*> entry_kernels; | 2260 std::vector<const syncable::EntryKernel*> entry_kernels; |
| 2261 trans.GetDirectory()->GetAllEntryKernels(trans.GetWrappedTrans(), | 2261 trans.GetDirectory()->GetAllEntryKernels(trans.GetWrappedTrans(), |
| 2262 &entry_kernels); | 2262 &entry_kernels); |
| 2263 | 2263 |
| 2264 for (std::vector<const syncable::EntryKernel*>::const_iterator it = | 2264 for (std::vector<const syncable::EntryKernel*>::const_iterator it = |
| 2265 entry_kernels.begin(); it != entry_kernels.end(); ++it) { | 2265 entry_kernels.begin(); it != entry_kernels.end(); ++it) { |
| 2266 result->Append((*it)->ToValue()); | 2266 result->Append((*it)->ToValue()); |
| 2267 } | 2267 } |
| 2268 | 2268 |
| 2269 return JsArgList(&return_args); | 2269 return JsArgList(&return_args); |
| 2270 } | 2270 } |
| 2271 | 2271 |
| 2272 JsArgList SyncManager::SyncInternal::GetChildNodeIds( | 2272 JsArgList SyncManagerImpl::SyncInternal::GetChildNodeIds( |
| 2273 const JsArgList& args) { | 2273 const JsArgList& args) { |
| 2274 ListValue return_args; | 2274 ListValue return_args; |
| 2275 ListValue* child_ids = new ListValue(); | 2275 ListValue* child_ids = new ListValue(); |
| 2276 return_args.Append(child_ids); | 2276 return_args.Append(child_ids); |
| 2277 int64 id = GetId(args.Get(), 0); | 2277 int64 id = GetId(args.Get(), 0); |
| 2278 if (id != kInvalidId) { | 2278 if (id != kInvalidId) { |
| 2279 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2279 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2280 syncable::Directory::ChildHandles child_handles; | 2280 syncable::Directory::ChildHandles child_handles; |
| 2281 trans.GetDirectory()->GetChildHandlesByHandle(trans.GetWrappedTrans(), | 2281 trans.GetDirectory()->GetChildHandlesByHandle(trans.GetWrappedTrans(), |
| 2282 id, &child_handles); | 2282 id, &child_handles); |
| 2283 for (syncable::Directory::ChildHandles::const_iterator it = | 2283 for (syncable::Directory::ChildHandles::const_iterator it = |
| 2284 child_handles.begin(); it != child_handles.end(); ++it) { | 2284 child_handles.begin(); it != child_handles.end(); ++it) { |
| 2285 child_ids->Append(Value::CreateStringValue( | 2285 child_ids->Append(Value::CreateStringValue( |
| 2286 base::Int64ToString(*it))); | 2286 base::Int64ToString(*it))); |
| 2287 } | 2287 } |
| 2288 } | 2288 } |
| 2289 return JsArgList(&return_args); | 2289 return JsArgList(&return_args); |
| 2290 } | 2290 } |
| 2291 | 2291 |
| 2292 void SyncManager::SyncInternal::OnEncryptedTypesChanged( | 2292 void SyncManagerImpl::SyncInternal::OnEncryptedTypesChanged( |
| 2293 syncer::ModelTypeSet encrypted_types, | 2293 syncer::ModelTypeSet encrypted_types, |
| 2294 bool encrypt_everything) { | 2294 bool encrypt_everything) { |
| 2295 // NOTE: We're in a transaction. | 2295 // NOTE: We're in a transaction. |
| 2296 FOR_EACH_OBSERVER( | 2296 FOR_EACH_OBSERVER( |
| 2297 SyncManager::Observer, observers_, | 2297 SyncManager::Observer, observers_, |
| 2298 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); | 2298 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); |
| 2299 } | 2299 } |
| 2300 | 2300 |
| 2301 void SyncManager::SyncInternal::UpdateNotificationInfo( | 2301 void SyncManagerImpl::SyncInternal::UpdateNotificationInfo( |
| 2302 const syncer::ModelTypePayloadMap& type_payloads) { | 2302 const syncer::ModelTypePayloadMap& type_payloads) { |
| 2303 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); | 2303 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
| 2304 it != type_payloads.end(); ++it) { | 2304 it != type_payloads.end(); ++it) { |
| 2305 NotificationInfo* info = ¬ification_info_map_[it->first]; | 2305 NotificationInfo* info = ¬ification_info_map_[it->first]; |
| 2306 info->total_count++; | 2306 info->total_count++; |
| 2307 info->payload = it->second; | 2307 info->payload = it->second; |
| 2308 } | 2308 } |
| 2309 } | 2309 } |
| 2310 | 2310 |
| 2311 void SyncManager::SyncInternal::OnNotificationsEnabled() { | 2311 void SyncManagerImpl::SyncInternal::OnNotificationsEnabled() { |
| 2312 DVLOG(1) << "Notifications enabled"; | 2312 DVLOG(1) << "Notifications enabled"; |
| 2313 allstatus_.SetNotificationsEnabled(true); | 2313 allstatus_.SetNotificationsEnabled(true); |
| 2314 if (scheduler()) { | 2314 if (scheduler()) { |
| 2315 scheduler()->set_notifications_enabled(true); | 2315 scheduler()->set_notifications_enabled(true); |
| 2316 } | 2316 } |
| 2317 // TODO(akalin): Separate onNotificationStateChange into | 2317 // TODO(akalin): Separate onNotificationStateChange into |
| 2318 // enabled/disabled events. | 2318 // enabled/disabled events. |
| 2319 if (js_event_handler_.IsInitialized()) { | 2319 if (js_event_handler_.IsInitialized()) { |
| 2320 DictionaryValue details; | 2320 DictionaryValue details; |
| 2321 details.Set("enabled", Value::CreateBooleanValue(true)); | 2321 details.Set("enabled", Value::CreateBooleanValue(true)); |
| 2322 js_event_handler_.Call(FROM_HERE, | 2322 js_event_handler_.Call(FROM_HERE, |
| 2323 &JsEventHandler::HandleJsEvent, | 2323 &JsEventHandler::HandleJsEvent, |
| 2324 "onNotificationStateChange", | 2324 "onNotificationStateChange", |
| 2325 JsEventDetails(&details)); | 2325 JsEventDetails(&details)); |
| 2326 } | 2326 } |
| 2327 } | 2327 } |
| 2328 | 2328 |
| 2329 void SyncManager::SyncInternal::OnNotificationsDisabled( | 2329 void SyncManagerImpl::SyncInternal::OnNotificationsDisabled( |
| 2330 syncer::NotificationsDisabledReason reason) { | 2330 syncer::NotificationsDisabledReason reason) { |
| 2331 DVLOG(1) << "Notifications disabled with reason " | 2331 DVLOG(1) << "Notifications disabled with reason " |
| 2332 << syncer::NotificationsDisabledReasonToString(reason); | 2332 << syncer::NotificationsDisabledReasonToString(reason); |
| 2333 allstatus_.SetNotificationsEnabled(false); | 2333 allstatus_.SetNotificationsEnabled(false); |
| 2334 if (scheduler()) { | 2334 if (scheduler()) { |
| 2335 scheduler()->set_notifications_enabled(false); | 2335 scheduler()->set_notifications_enabled(false); |
| 2336 } | 2336 } |
| 2337 if (js_event_handler_.IsInitialized()) { | 2337 if (js_event_handler_.IsInitialized()) { |
| 2338 DictionaryValue details; | 2338 DictionaryValue details; |
| 2339 details.Set("enabled", Value::CreateBooleanValue(false)); | 2339 details.Set("enabled", Value::CreateBooleanValue(false)); |
| 2340 js_event_handler_.Call(FROM_HERE, | 2340 js_event_handler_.Call(FROM_HERE, |
| 2341 &JsEventHandler::HandleJsEvent, | 2341 &JsEventHandler::HandleJsEvent, |
| 2342 "onNotificationStateChange", | 2342 "onNotificationStateChange", |
| 2343 JsEventDetails(&details)); | 2343 JsEventDetails(&details)); |
| 2344 } | 2344 } |
| 2345 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 2345 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
| 2346 // error. | 2346 // error. |
| 2347 } | 2347 } |
| 2348 | 2348 |
| 2349 void SyncManager::SyncInternal::OnIncomingNotification( | 2349 void SyncManagerImpl::SyncInternal::OnIncomingNotification( |
| 2350 const syncer::ModelTypePayloadMap& type_payloads, | 2350 const syncer::ModelTypePayloadMap& type_payloads, |
| 2351 syncer::IncomingNotificationSource source) { | 2351 syncer::IncomingNotificationSource source) { |
| 2352 DCHECK(thread_checker_.CalledOnValidThread()); | 2352 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2353 if (source == syncer::LOCAL_NOTIFICATION) { | 2353 if (source == syncer::LOCAL_NOTIFICATION) { |
| 2354 if (scheduler()) { | 2354 if (scheduler()) { |
| 2355 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2355 scheduler()->ScheduleNudgeWithPayloadsAsync( |
| 2356 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 2356 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 2357 syncer::NUDGE_SOURCE_LOCAL_REFRESH, | 2357 syncer::NUDGE_SOURCE_LOCAL_REFRESH, |
| 2358 type_payloads, FROM_HERE); | 2358 type_payloads, FROM_HERE); |
| 2359 } | 2359 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2384 } | 2384 } |
| 2385 details.SetString("source", (source == syncer::LOCAL_NOTIFICATION) ? | 2385 details.SetString("source", (source == syncer::LOCAL_NOTIFICATION) ? |
| 2386 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); | 2386 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); |
| 2387 js_event_handler_.Call(FROM_HERE, | 2387 js_event_handler_.Call(FROM_HERE, |
| 2388 &JsEventHandler::HandleJsEvent, | 2388 &JsEventHandler::HandleJsEvent, |
| 2389 "onIncomingNotification", | 2389 "onIncomingNotification", |
| 2390 JsEventDetails(&details)); | 2390 JsEventDetails(&details)); |
| 2391 } | 2391 } |
| 2392 } | 2392 } |
| 2393 | 2393 |
| 2394 void SyncManager::SyncInternal::AddObserver( | 2394 void SyncManagerImpl::SyncInternal::AddObserver( |
| 2395 SyncManager::Observer* observer) { | 2395 SyncManager::Observer* observer) { |
| 2396 observers_.AddObserver(observer); | 2396 observers_.AddObserver(observer); |
| 2397 } | 2397 } |
| 2398 | 2398 |
| 2399 void SyncManager::SyncInternal::RemoveObserver( | 2399 void SyncManagerImpl::SyncInternal::RemoveObserver( |
| 2400 SyncManager::Observer* observer) { | 2400 SyncManager::Observer* observer) { |
| 2401 observers_.RemoveObserver(observer); | 2401 observers_.RemoveObserver(observer); |
| 2402 } | 2402 } |
| 2403 | 2403 |
| 2404 void SyncManager::SyncInternal::SetSyncSchedulerForTest( | 2404 void SyncManagerImpl::SyncInternal::SetSyncSchedulerForTest( |
| 2405 scoped_ptr<SyncScheduler> sync_scheduler) { | 2405 scoped_ptr<SyncScheduler> sync_scheduler) { |
| 2406 scheduler_ = sync_scheduler.Pass(); | 2406 scheduler_ = sync_scheduler.Pass(); |
| 2407 } | 2407 } |
| 2408 | 2408 |
| 2409 SyncStatus SyncManager::GetDetailedStatus() const { | 2409 SyncStatus SyncManagerImpl::GetDetailedStatus() const { |
| 2410 return data_->GetStatus(); | 2410 return data_->GetStatus(); |
| 2411 } | 2411 } |
| 2412 | 2412 |
| 2413 void SyncManager::SaveChanges() { | 2413 void SyncManagerImpl::SaveChanges() { |
| 2414 DCHECK(thread_checker_.CalledOnValidThread()); | 2414 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2415 data_->SaveChanges(); | 2415 data_->SaveChanges(); |
| 2416 } | 2416 } |
| 2417 | 2417 |
| 2418 void SyncManager::SyncInternal::SaveChanges() { | 2418 void SyncManagerImpl::SyncInternal::SaveChanges() { |
| 2419 directory()->SaveChanges(); | 2419 directory()->SaveChanges(); |
| 2420 } | 2420 } |
| 2421 | 2421 |
| 2422 UserShare* SyncManager::GetUserShare() const { | 2422 UserShare* SyncManagerImpl::GetUserShare() const { |
| 2423 return data_->GetUserShare(); | 2423 return data_->GetUserShare(); |
| 2424 } | 2424 } |
| 2425 | 2425 |
| 2426 void SyncManager::RefreshNigori(const std::string& chrome_version, | 2426 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
| 2427 const base::Closure& done_callback) { | 2427 const base::Closure& done_callback) { |
| 2428 DCHECK(thread_checker_.CalledOnValidThread()); | 2428 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2429 data_->UpdateCryptographerAndNigori( | 2429 data_->UpdateCryptographerAndNigori( |
| 2430 chrome_version, | 2430 chrome_version, |
| 2431 done_callback); | 2431 done_callback); |
| 2432 } | 2432 } |
| 2433 | 2433 |
| 2434 TimeDelta SyncManager::GetNudgeDelayTimeDelta( | 2434 TimeDelta SyncManagerImpl::GetNudgeDelayTimeDelta( |
| 2435 const ModelType& model_type) { | 2435 const ModelType& model_type) { |
| 2436 return data_->GetNudgeDelayTimeDelta(model_type); | 2436 return data_->GetNudgeDelayTimeDelta(model_type); |
| 2437 } | 2437 } |
| 2438 | 2438 |
| 2439 void SyncManager::SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler) { | 2439 void SyncManagerImpl::SetSyncSchedulerForTest( |
| 2440 scoped_ptr<SyncScheduler> scheduler) { |
| 2440 data_->SetSyncSchedulerForTest(scheduler.Pass()); | 2441 data_->SetSyncSchedulerForTest(scheduler.Pass()); |
| 2441 } | 2442 } |
| 2442 | 2443 |
| 2443 syncer::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { | 2444 syncer::ModelTypeSet SyncManagerImpl::GetEncryptedDataTypesForTest() const { |
| 2444 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2445 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2445 return GetEncryptedTypes(&trans); | 2446 return GetEncryptedTypes(&trans); |
| 2446 } | 2447 } |
| 2447 | 2448 |
| 2448 bool SyncManager::ReceivedExperiment(syncer::Experiments* experiments) | 2449 bool SyncManagerImpl::ReceivedExperiment( |
| 2449 const { | 2450 syncer::Experiments* experiments) const { |
| 2450 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2451 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2451 ReadNode node(&trans); | 2452 ReadNode node(&trans); |
| 2452 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 2453 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { |
| 2453 DVLOG(1) << "Couldn't find Nigori node."; | 2454 DVLOG(1) << "Couldn't find Nigori node."; |
| 2454 return false; | 2455 return false; |
| 2455 } | 2456 } |
| 2456 bool found_experiment = false; | 2457 bool found_experiment = false; |
| 2457 if (node.GetNigoriSpecifics().sync_tab_favicons()) { | 2458 if (node.GetNigoriSpecifics().sync_tab_favicons()) { |
| 2458 experiments->sync_tab_favicons = true; | 2459 experiments->sync_tab_favicons = true; |
| 2459 found_experiment = true; | 2460 found_experiment = true; |
| 2460 } | 2461 } |
| 2461 return found_experiment; | 2462 return found_experiment; |
| 2462 } | 2463 } |
| 2463 | 2464 |
| 2464 bool SyncManager::HasUnsyncedItems() const { | 2465 bool SyncManagerImpl::HasUnsyncedItems() const { |
| 2465 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); | 2466 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2466 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2467 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
| 2467 } | 2468 } |
| 2468 | 2469 |
| 2469 void SyncManager::SimulateEnableNotificationsForTest() { | 2470 void SyncManagerImpl::SimulateEnableNotificationsForTest() { |
| 2470 DCHECK(thread_checker_.CalledOnValidThread()); | 2471 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2471 data_->OnNotificationsEnabled(); | 2472 data_->OnNotificationsEnabled(); |
| 2472 } | 2473 } |
| 2473 | 2474 |
| 2474 void SyncManager::SimulateDisableNotificationsForTest(int reason) { | 2475 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { |
| 2475 DCHECK(thread_checker_.CalledOnValidThread()); | 2476 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2476 data_->OnNotificationsDisabled( | 2477 data_->OnNotificationsDisabled( |
| 2477 static_cast<syncer::NotificationsDisabledReason>(reason)); | 2478 static_cast<syncer::NotificationsDisabledReason>(reason)); |
| 2478 } | 2479 } |
| 2479 | 2480 |
| 2480 void SyncManager::TriggerOnIncomingNotificationForTest( | 2481 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( |
| 2481 ModelTypeSet model_types) { | 2482 ModelTypeSet model_types) { |
| 2482 DCHECK(thread_checker_.CalledOnValidThread()); | 2483 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2483 syncer::ModelTypePayloadMap model_types_with_payloads = | 2484 syncer::ModelTypePayloadMap model_types_with_payloads = |
| 2484 syncer::ModelTypePayloadMapFromEnumSet(model_types, | 2485 syncer::ModelTypePayloadMapFromEnumSet(model_types, |
| 2485 std::string()); | 2486 std::string()); |
| 2486 | 2487 |
| 2487 data_->OnIncomingNotification(model_types_with_payloads, | 2488 data_->OnIncomingNotification(model_types_with_payloads, |
| 2488 syncer::REMOTE_NOTIFICATION); | 2489 syncer::REMOTE_NOTIFICATION); |
| 2489 } | 2490 } |
| 2490 | 2491 |
| 2491 const char* ConnectionStatusToString(ConnectionStatus status) { | 2492 // static. |
| 2492 switch (status) { | 2493 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 2493 case CONNECTION_OK: | 2494 return kDefaultNudgeDelayMilliseconds; |
| 2494 return "CONNECTION_OK"; | |
| 2495 case CONNECTION_AUTH_ERROR: | |
| 2496 return "CONNECTION_AUTH_ERROR"; | |
| 2497 case CONNECTION_SERVER_ERROR: | |
| 2498 return "CONNECTION_SERVER_ERROR"; | |
| 2499 default: | |
| 2500 NOTREACHED(); | |
| 2501 return "INVALID_CONNECTION_STATUS"; | |
| 2502 } | |
| 2503 } | 2495 } |
| 2504 | 2496 |
| 2505 // Helper function that converts a PassphraseRequiredReason value to a string. | 2497 // static. |
| 2506 const char* PassphraseRequiredReasonToString( | 2498 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 2507 PassphraseRequiredReason reason) { | 2499 return kPreferencesNudgeDelayMilliseconds; |
| 2508 switch (reason) { | |
| 2509 case REASON_PASSPHRASE_NOT_REQUIRED: | |
| 2510 return "REASON_PASSPHRASE_NOT_REQUIRED"; | |
| 2511 case REASON_ENCRYPTION: | |
| 2512 return "REASON_ENCRYPTION"; | |
| 2513 case REASON_DECRYPTION: | |
| 2514 return "REASON_DECRYPTION"; | |
| 2515 default: | |
| 2516 NOTREACHED(); | |
| 2517 return "INVALID_REASON"; | |
| 2518 } | |
| 2519 } | |
| 2520 | |
| 2521 // Helper function to determine if initial sync had ended for types. | |
| 2522 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, | |
| 2523 syncer::UserShare* share) { | |
| 2524 for (syncer::ModelTypeSet::Iterator i = types.First(); | |
| 2525 i.Good(); i.Inc()) { | |
| 2526 if (!share->directory->initial_sync_ended_for_type(i.Get())) | |
| 2527 return false; | |
| 2528 } | |
| 2529 return true; | |
| 2530 } | 2500 } |
| 2531 | 2501 |
| 2532 } // namespace syncer | 2502 } // namespace syncer |
| OLD | NEW |