| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "chrome/common/net/gaia/gaia_constants.h" | 36 #include "chrome/common/net/gaia/gaia_constants.h" |
| 37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/common/content_client.h" | 39 #include "content/public/common/content_client.h" |
| 40 #include "jingle/notifier/base/notification_method.h" | 40 #include "jingle/notifier/base/notification_method.h" |
| 41 #include "jingle/notifier/base/notifier_options.h" | 41 #include "jingle/notifier/base/notifier_options.h" |
| 42 #include "net/base/host_port_pair.h" | 42 #include "net/base/host_port_pair.h" |
| 43 #include "net/url_request/url_request_context_getter.h" | 43 #include "net/url_request/url_request_context_getter.h" |
| 44 #include "sync/internal_api/public/base_transaction.h" | 44 #include "sync/internal_api/public/base_transaction.h" |
| 45 #include "sync/internal_api/public/engine/model_safe_worker.h" | 45 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 46 #include "sync/internal_api/public/http_bridge.h" |
| 46 #include "sync/internal_api/public/internal_components_factory_impl.h" | 47 #include "sync/internal_api/public/internal_components_factory_impl.h" |
| 47 #include "sync/internal_api/public/http_bridge.h" | |
| 48 #include "sync/internal_api/public/read_transaction.h" | 48 #include "sync/internal_api/public/read_transaction.h" |
| 49 #include "sync/internal_api/public/sync_manager_factory.h" | 49 #include "sync/internal_api/public/sync_manager_factory.h" |
| 50 #include "sync/internal_api/public/util/experiments.h" | 50 #include "sync/internal_api/public/util/experiments.h" |
| 51 #include "sync/notifier/sync_notifier.h" | 51 #include "sync/notifier/sync_notifier.h" |
| 52 #include "sync/protocol/encryption.pb.h" | 52 #include "sync/protocol/encryption.pb.h" |
| 53 #include "sync/protocol/sync.pb.h" | 53 #include "sync/protocol/sync.pb.h" |
| 54 #include "sync/util/nigori.h" | 54 #include "sync/util/nigori.h" |
| 55 | 55 |
| 56 static const int kSaveChangesIntervalSeconds = 10; | 56 static const int kSaveChangesIntervalSeconds = 10; |
| 57 static const FilePath::CharType kSyncDataFolderName[] = | 57 static const FilePath::CharType kSyncDataFolderName[] = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 71 | 71 |
| 72 // Helper macros to log with the syncer thread name; useful when there | 72 // Helper macros to log with the syncer thread name; useful when there |
| 73 // are multiple syncers involved. | 73 // are multiple syncers involved. |
| 74 | 74 |
| 75 #define SLOG(severity) LOG(severity) << name_ << ": " | 75 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 76 | 76 |
| 77 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 77 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
| 78 | 78 |
| 79 class SyncBackendHost::Core | 79 class SyncBackendHost::Core |
| 80 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 80 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| 81 public syncer::SyncManager::Observer { | 81 public syncer::SyncManager::Observer, |
| 82 public syncer::SyncNotifierObserver { |
| 82 public: | 83 public: |
| 83 Core(const std::string& name, | 84 Core(const std::string& name, |
| 84 const FilePath& sync_data_folder_path, | 85 const FilePath& sync_data_folder_path, |
| 85 const base::WeakPtr<SyncBackendHost>& backend); | 86 const base::WeakPtr<SyncBackendHost>& backend); |
| 86 | 87 |
| 87 // SyncManager::Observer implementation. The Core just acts like an air | 88 // SyncManager::Observer implementation. The Core just acts like an air |
| 88 // traffic controller here, forwarding incoming messages to appropriate | 89 // traffic controller here, forwarding incoming messages to appropriate |
| 89 // landing threads. | 90 // landing threads. |
| 90 virtual void OnSyncCycleCompleted( | 91 virtual void OnSyncCycleCompleted( |
| 91 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 92 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 const std::string& bootstrap_token) OVERRIDE; | 104 const std::string& bootstrap_token) OVERRIDE; |
| 104 virtual void OnStopSyncingPermanently() OVERRIDE; | 105 virtual void OnStopSyncingPermanently() OVERRIDE; |
| 105 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; | 106 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| 106 virtual void OnEncryptedTypesChanged( | 107 virtual void OnEncryptedTypesChanged( |
| 107 syncer::ModelTypeSet encrypted_types, | 108 syncer::ModelTypeSet encrypted_types, |
| 108 bool encrypt_everything) OVERRIDE; | 109 bool encrypt_everything) OVERRIDE; |
| 109 virtual void OnEncryptionComplete() OVERRIDE; | 110 virtual void OnEncryptionComplete() OVERRIDE; |
| 110 virtual void OnActionableError( | 111 virtual void OnActionableError( |
| 111 const syncer::SyncProtocolError& sync_error) OVERRIDE; | 112 const syncer::SyncProtocolError& sync_error) OVERRIDE; |
| 112 | 113 |
| 114 // syncer::SyncNotifierObserver implementation. |
| 115 virtual void OnNotificationsEnabled() OVERRIDE; |
| 116 virtual void OnNotificationsDisabled( |
| 117 syncer::NotificationsDisabledReason reason) OVERRIDE; |
| 118 virtual void OnIncomingNotification( |
| 119 const syncer::ObjectIdPayloadMap& id_payloads, |
| 120 syncer::IncomingNotificationSource source) OVERRIDE; |
| 121 |
| 113 // Note: | 122 // Note: |
| 114 // | 123 // |
| 115 // The Do* methods are the various entry points from our | 124 // The Do* methods are the various entry points from our |
| 116 // SyncBackendHost. They are all called on the sync thread to | 125 // SyncBackendHost. They are all called on the sync thread to |
| 117 // actually perform synchronous (and potentially blocking) syncapi | 126 // actually perform synchronous (and potentially blocking) syncapi |
| 118 // operations. | 127 // operations. |
| 119 // | 128 // |
| 120 // Called to perform initialization of the syncapi on behalf of | 129 // Called to perform initialization of the syncapi on behalf of |
| 121 // SyncBackendHost::Initialize. | 130 // SyncBackendHost::Initialize. |
| 122 void DoInitialize(const DoInitializeOptions& options); | 131 void DoInitialize(const DoInitializeOptions& options); |
| 123 | 132 |
| 124 // Called to perform credential update on behalf of | 133 // Called to perform credential update on behalf of |
| 125 // SyncBackendHost::UpdateCredentials | 134 // SyncBackendHost::UpdateCredentials |
| 126 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); | 135 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); |
| 127 | 136 |
| 137 // Called to update the given registered ids on behalf of |
| 138 // SyncBackendHost::UpdateRegisteredIds |
| 139 void DoUpdateRegisteredIds(const syncer::ObjectIdSet& ids); |
| 140 |
| 128 // Called to tell the syncapi to start syncing (generally after | 141 // Called to tell the syncapi to start syncing (generally after |
| 129 // initialization and authentication). | 142 // initialization and authentication). |
| 130 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); | 143 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); |
| 131 | 144 |
| 132 // Called to set the passphrase for encryption. | 145 // Called to set the passphrase for encryption. |
| 133 void DoSetEncryptionPassphrase(const std::string& passphrase, | 146 void DoSetEncryptionPassphrase(const std::string& passphrase, |
| 134 bool is_explicit); | 147 bool is_explicit); |
| 135 | 148 |
| 136 // Called to decrypt the pending keys. | 149 // Called to decrypt the pending keys. |
| 137 void DoSetDecryptionPassphrase(const std::string& passphrase); | 150 void DoSetDecryptionPassphrase(const std::string& passphrase); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 unrecoverable_error_handler, | 428 unrecoverable_error_handler, |
| 416 report_unrecoverable_error_function)); | 429 report_unrecoverable_error_function)); |
| 417 } | 430 } |
| 418 | 431 |
| 419 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 432 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
| 420 sync_thread_.message_loop()->PostTask(FROM_HERE, | 433 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 421 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), | 434 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), |
| 422 credentials)); | 435 credentials)); |
| 423 } | 436 } |
| 424 | 437 |
| 438 void SyncBackendHost::UpdateRegisteredIds(const syncer::ObjectIdSet& ids) { |
| 439 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 440 DCHECK(sync_thread_.IsRunning()); |
| 441 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 442 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredIds, |
| 443 core_.get(), ids)); |
| 444 } |
| 445 |
| 425 void SyncBackendHost::StartSyncingWithServer() { | 446 void SyncBackendHost::StartSyncingWithServer() { |
| 426 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; | 447 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; |
| 427 | 448 |
| 428 syncer::ModelSafeRoutingInfo routing_info; | 449 syncer::ModelSafeRoutingInfo routing_info; |
| 429 registrar_->GetModelSafeRoutingInfo(&routing_info); | 450 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 430 | 451 |
| 431 sync_thread_.message_loop()->PostTask(FROM_HERE, | 452 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 432 base::Bind(&SyncBackendHost::Core::DoStartSyncing, | 453 base::Bind(&SyncBackendHost::Core::DoStartSyncing, |
| 433 core_.get(), routing_info)); | 454 core_.get(), routing_info)); |
| 434 } | 455 } |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 const syncer::SyncProtocolError& sync_error) { | 964 const syncer::SyncProtocolError& sync_error) { |
| 944 if (!sync_loop_) | 965 if (!sync_loop_) |
| 945 return; | 966 return; |
| 946 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 967 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 947 host_.Call( | 968 host_.Call( |
| 948 FROM_HERE, | 969 FROM_HERE, |
| 949 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 970 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
| 950 sync_error); | 971 sync_error); |
| 951 } | 972 } |
| 952 | 973 |
| 974 void SyncBackendHost::Core::OnNotificationsEnabled() { |
| 975 if (!sync_loop_) |
| 976 return; |
| 977 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 978 host_.Call(FROM_HERE, |
| 979 &SyncBackendHost::HandleNotificationsEnabledOnFrontendLoop); |
| 980 } |
| 981 |
| 982 void SyncBackendHost::Core::OnNotificationsDisabled( |
| 983 syncer::NotificationsDisabledReason reason) { |
| 984 if (!sync_loop_) |
| 985 return; |
| 986 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 987 host_.Call(FROM_HERE, |
| 988 &SyncBackendHost::HandleNotificationsDisabledOnFrontendLoop, |
| 989 reason); |
| 990 } |
| 991 |
| 992 void SyncBackendHost::Core::OnIncomingNotification( |
| 993 const syncer::ObjectIdPayloadMap& id_payloads, |
| 994 syncer::IncomingNotificationSource source) { |
| 995 if (!sync_loop_) |
| 996 return; |
| 997 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 998 host_.Call(FROM_HERE, |
| 999 &SyncBackendHost::HandleIncomingNotificationOnFrontendLoop, |
| 1000 id_payloads, source); |
| 1001 } |
| 1002 |
| 953 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { | 1003 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
| 954 DCHECK(!sync_loop_); | 1004 DCHECK(!sync_loop_); |
| 955 sync_loop_ = options.sync_loop; | 1005 sync_loop_ = options.sync_loop; |
| 956 DCHECK(sync_loop_); | 1006 DCHECK(sync_loop_); |
| 957 | 1007 |
| 958 // Blow away the partial or corrupt sync data folder before doing any more | 1008 // Blow away the partial or corrupt sync data folder before doing any more |
| 959 // initialization, if necessary. | 1009 // initialization, if necessary. |
| 960 if (options.delete_sync_data_folder) { | 1010 if (options.delete_sync_data_folder) { |
| 961 DeleteSyncDataFolder(); | 1011 DeleteSyncDataFolder(); |
| 962 } | 1012 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 sync_manager_->ThrowUnrecoverableError(); | 1060 sync_manager_->ThrowUnrecoverableError(); |
| 1011 } | 1061 } |
| 1012 } | 1062 } |
| 1013 | 1063 |
| 1014 void SyncBackendHost::Core::DoUpdateCredentials( | 1064 void SyncBackendHost::Core::DoUpdateCredentials( |
| 1015 const SyncCredentials& credentials) { | 1065 const SyncCredentials& credentials) { |
| 1016 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1066 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1017 sync_manager_->UpdateCredentials(credentials); | 1067 sync_manager_->UpdateCredentials(credentials); |
| 1018 } | 1068 } |
| 1019 | 1069 |
| 1070 void SyncBackendHost::Core::DoUpdateRegisteredIds( |
| 1071 const syncer::ObjectIdSet& ids) { |
| 1072 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1073 sync_manager_->UpdateRegisteredIds(this, ids); |
| 1074 } |
| 1075 |
| 1020 void SyncBackendHost::Core::DoStartSyncing( | 1076 void SyncBackendHost::Core::DoStartSyncing( |
| 1021 const syncer::ModelSafeRoutingInfo& routing_info) { | 1077 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 1022 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1078 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1023 sync_manager_->StartSyncingNormally(routing_info); | 1079 sync_manager_->StartSyncingNormally(routing_info); |
| 1024 } | 1080 } |
| 1025 | 1081 |
| 1026 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1082 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| 1027 const std::string& passphrase, | 1083 const std::string& passphrase, |
| 1028 bool is_explicit) { | 1084 bool is_explicit) { |
| 1029 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1085 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1054 DCHECK(sync_manager_.get()); | 1110 DCHECK(sync_manager_.get()); |
| 1055 sync_manager_->StopSyncingForShutdown(closure); | 1111 sync_manager_->StopSyncingForShutdown(closure); |
| 1056 } | 1112 } |
| 1057 | 1113 |
| 1058 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 1114 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
| 1059 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1115 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1060 if (!sync_manager_.get()) | 1116 if (!sync_manager_.get()) |
| 1061 return; | 1117 return; |
| 1062 | 1118 |
| 1063 save_changes_timer_.reset(); | 1119 save_changes_timer_.reset(); |
| 1120 sync_manager_->UpdateRegisteredIds(this, syncer::ObjectIdSet()); |
| 1064 sync_manager_->ShutdownOnSyncThread(); | 1121 sync_manager_->ShutdownOnSyncThread(); |
| 1065 sync_manager_->RemoveObserver(this); | 1122 sync_manager_->RemoveObserver(this); |
| 1066 sync_manager_.reset(); | 1123 sync_manager_.reset(); |
| 1067 chrome_sync_notification_bridge_ = NULL; | 1124 chrome_sync_notification_bridge_ = NULL; |
| 1068 registrar_ = NULL; | 1125 registrar_ = NULL; |
| 1069 | 1126 |
| 1070 if (sync_disabled) | 1127 if (sync_disabled) |
| 1071 DeleteSyncDataFolder(); | 1128 DeleteSyncDataFolder(); |
| 1072 | 1129 |
| 1073 sync_loop_ = NULL; | 1130 sync_loop_ = NULL; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 } | 1322 } |
| 1266 | 1323 |
| 1267 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( | 1324 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( |
| 1268 const syncer::SyncProtocolError& sync_error) { | 1325 const syncer::SyncProtocolError& sync_error) { |
| 1269 if (!frontend_) | 1326 if (!frontend_) |
| 1270 return; | 1327 return; |
| 1271 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1328 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1272 frontend_->OnActionableError(sync_error); | 1329 frontend_->OnActionableError(sync_error); |
| 1273 } | 1330 } |
| 1274 | 1331 |
| 1332 void SyncBackendHost::HandleNotificationsEnabledOnFrontendLoop() { |
| 1333 if (!frontend_) |
| 1334 return; |
| 1335 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1336 frontend_->OnNotificationsEnabled(); |
| 1337 } |
| 1338 |
| 1339 void SyncBackendHost::HandleNotificationsDisabledOnFrontendLoop( |
| 1340 syncer::NotificationsDisabledReason reason) { |
| 1341 if (!frontend_) |
| 1342 return; |
| 1343 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1344 frontend_->OnNotificationsDisabled(reason); |
| 1345 } |
| 1346 |
| 1347 void SyncBackendHost::HandleIncomingNotificationOnFrontendLoop( |
| 1348 const syncer::ObjectIdPayloadMap& id_payloads, |
| 1349 syncer::IncomingNotificationSource source) { |
| 1350 if (!frontend_) |
| 1351 return; |
| 1352 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1353 frontend_->OnIncomingNotification(id_payloads, source); |
| 1354 } |
| 1355 |
| 1275 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( | 1356 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( |
| 1276 const std::string& passphrase) const { | 1357 const std::string& passphrase) const { |
| 1277 DCHECK(cached_pending_keys_.has_blob()); | 1358 DCHECK(cached_pending_keys_.has_blob()); |
| 1278 DCHECK(!passphrase.empty()); | 1359 DCHECK(!passphrase.empty()); |
| 1279 syncer::Nigori nigori; | 1360 syncer::Nigori nigori; |
| 1280 nigori.InitByDerivation("localhost", "dummy", passphrase); | 1361 nigori.InitByDerivation("localhost", "dummy", passphrase); |
| 1281 std::string plaintext; | 1362 std::string plaintext; |
| 1282 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); | 1363 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); |
| 1283 return result; | 1364 return result; |
| 1284 } | 1365 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 FROM_HERE, | 1460 FROM_HERE, |
| 1380 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1461 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| 1381 core_.get(), sync_thread_done_callback)); | 1462 core_.get(), sync_thread_done_callback)); |
| 1382 } | 1463 } |
| 1383 | 1464 |
| 1384 #undef SDVLOG | 1465 #undef SDVLOG |
| 1385 | 1466 |
| 1386 #undef SLOG | 1467 #undef SLOG |
| 1387 | 1468 |
| 1388 } // namespace browser_sync | 1469 } // namespace browser_sync |
| OLD | NEW |