| 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" | |
| 6 | |
| 7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 8 | 6 |
| 9 #include <algorithm> | 7 #include <algorithm> |
| 10 #include <map> | 8 #include <map> |
| 11 | 9 |
| 12 #include "base/bind.h" | 10 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 15 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 16 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 17 #include "base/location.h" | 15 #include "base/location.h" |
| 18 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/timer.h" | 19 #include "base/timer.h" |
| 22 #include "base/tracked_objects.h" | 20 #include "base/tracked_objects.h" |
| 23 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 24 #include "chrome/browser/invalidation/invalidator_storage.h" | 22 #include "chrome/browser/invalidation/invalidation_service.h" |
| 23 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
| 25 #include "chrome/browser/net/network_time_tracker.h" | 24 #include "chrome/browser/net/network_time_tracker.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/signin/token_service.h" | 26 #include "chrome/browser/signin/token_service.h" |
| 28 #include "chrome/browser/signin/token_service_factory.h" | 27 #include "chrome/browser/signin/token_service_factory.h" |
| 29 #include "chrome/browser/sync/glue/android_invalidator_bridge.h" | |
| 30 #include "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h" | |
| 31 #include "chrome/browser/sync/glue/change_processor.h" | 28 #include "chrome/browser/sync/glue/change_processor.h" |
| 32 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 29 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 33 #include "chrome/browser/sync/glue/device_info.h" | 30 #include "chrome/browser/sync/glue/device_info.h" |
| 34 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 31 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 35 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 32 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 36 #include "chrome/browser/sync/sync_prefs.h" | 33 #include "chrome/browser/sync/sync_prefs.h" |
| 37 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
| 38 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 39 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 40 #include "chrome/common/chrome_version_info.h" | 37 #include "chrome/common/chrome_version_info.h" |
| 41 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/notification_details.h" | 39 #include "content/public/browser/notification_details.h" |
| 43 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
| 45 #include "content/public/common/content_client.h" | 42 #include "content/public/common/content_client.h" |
| 46 #include "google_apis/gaia/gaia_constants.h" | 43 #include "google_apis/gaia/gaia_constants.h" |
| 47 #include "jingle/notifier/base/notification_method.h" | 44 #include "jingle/notifier/base/notification_method.h" |
| 48 #include "jingle/notifier/base/notifier_options.h" | 45 #include "jingle/notifier/base/notifier_options.h" |
| 49 #include "net/base/host_port_pair.h" | 46 #include "net/base/host_port_pair.h" |
| 50 #include "net/url_request/url_request_context_getter.h" | 47 #include "net/url_request/url_request_context_getter.h" |
| 51 #include "sync/internal_api/public/base_transaction.h" | 48 #include "sync/internal_api/public/base_transaction.h" |
| 52 #include "sync/internal_api/public/engine/model_safe_worker.h" | 49 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 53 #include "sync/internal_api/public/http_bridge.h" | 50 #include "sync/internal_api/public/http_bridge.h" |
| 54 #include "sync/internal_api/public/internal_components_factory_impl.h" | 51 #include "sync/internal_api/public/internal_components_factory_impl.h" |
| 55 #include "sync/internal_api/public/read_transaction.h" | 52 #include "sync/internal_api/public/read_transaction.h" |
| 56 #include "sync/internal_api/public/sync_manager_factory.h" | 53 #include "sync/internal_api/public/sync_manager_factory.h" |
| 57 #include "sync/internal_api/public/util/experiments.h" | 54 #include "sync/internal_api/public/util/experiments.h" |
| 58 #include "sync/internal_api/public/util/sync_string_conversions.h" | 55 #include "sync/internal_api/public/util/sync_string_conversions.h" |
| 59 #include "sync/notifier/invalidator.h" | |
| 60 #include "sync/protocol/encryption.pb.h" | 56 #include "sync/protocol/encryption.pb.h" |
| 61 #include "sync/protocol/sync.pb.h" | 57 #include "sync/protocol/sync.pb.h" |
| 62 #include "sync/util/nigori.h" | 58 #include "sync/util/nigori.h" |
| 63 | 59 |
| 64 static const int kSaveChangesIntervalSeconds = 10; | 60 static const int kSaveChangesIntervalSeconds = 10; |
| 65 static const base::FilePath::CharType kSyncDataFolderName[] = | 61 static const base::FilePath::CharType kSyncDataFolderName[] = |
| 66 FILE_PATH_LITERAL("Sync Data"); | 62 FILE_PATH_LITERAL("Sync Data"); |
| 67 | 63 |
| 68 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; | 64 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; |
| 69 | 65 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 95 // Helper macros to log with the syncer thread name; useful when there | 91 // Helper macros to log with the syncer thread name; useful when there |
| 96 // are multiple syncers involved. | 92 // are multiple syncers involved. |
| 97 | 93 |
| 98 #define SLOG(severity) LOG(severity) << name_ << ": " | 94 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 99 | 95 |
| 100 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 96 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
| 101 | 97 |
| 102 class SyncBackendHost::Core | 98 class SyncBackendHost::Core |
| 103 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 99 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| 104 public syncer::SyncEncryptionHandler::Observer, | 100 public syncer::SyncEncryptionHandler::Observer, |
| 105 public syncer::SyncManager::Observer, | 101 public syncer::SyncManager::Observer { |
| 106 public syncer::InvalidationHandler { | |
| 107 public: | 102 public: |
| 108 Core(const std::string& name, | 103 Core(const std::string& name, |
| 109 const base::FilePath& sync_data_folder_path, | 104 const base::FilePath& sync_data_folder_path, |
| 110 const base::WeakPtr<SyncBackendHost>& backend); | 105 const base::WeakPtr<SyncBackendHost>& backend); |
| 111 | 106 |
| 112 // SyncManager::Observer implementation. The Core just acts like an air | 107 // SyncManager::Observer implementation. The Core just acts like an air |
| 113 // traffic controller here, forwarding incoming messages to appropriate | 108 // traffic controller here, forwarding incoming messages to appropriate |
| 114 // landing threads. | 109 // landing threads. |
| 115 virtual void OnSyncCycleCompleted( | 110 virtual void OnSyncCycleCompleted( |
| 116 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 111 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 syncer::BootstrapTokenType type) OVERRIDE; | 132 syncer::BootstrapTokenType type) OVERRIDE; |
| 138 virtual void OnEncryptedTypesChanged( | 133 virtual void OnEncryptedTypesChanged( |
| 139 syncer::ModelTypeSet encrypted_types, | 134 syncer::ModelTypeSet encrypted_types, |
| 140 bool encrypt_everything) OVERRIDE; | 135 bool encrypt_everything) OVERRIDE; |
| 141 virtual void OnEncryptionComplete() OVERRIDE; | 136 virtual void OnEncryptionComplete() OVERRIDE; |
| 142 virtual void OnCryptographerStateChanged( | 137 virtual void OnCryptographerStateChanged( |
| 143 syncer::Cryptographer* cryptographer) OVERRIDE; | 138 syncer::Cryptographer* cryptographer) OVERRIDE; |
| 144 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, | 139 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, |
| 145 base::Time passphrase_time) OVERRIDE; | 140 base::Time passphrase_time) OVERRIDE; |
| 146 | 141 |
| 147 // syncer::InvalidationHandler implementation. | 142 // Forwards an invalidation state change to the sync manager. |
| 148 virtual void OnInvalidatorStateChange( | 143 void DoOnInvalidatorStateChange(syncer::InvalidatorState state); |
| 149 syncer::InvalidatorState state) OVERRIDE; | 144 |
| 150 virtual void OnIncomingInvalidation( | 145 // Forwards an invalidation to the sync manager. |
| 151 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 146 void DoOnIncomingInvalidation( |
| 147 syncer::ObjectIdInvalidationMap invalidation_map); |
| 152 | 148 |
| 153 // Note: | 149 // Note: |
| 154 // | 150 // |
| 155 // The Do* methods are the various entry points from our | 151 // The Do* methods are the various entry points from our |
| 156 // SyncBackendHost. They are all called on the sync thread to | 152 // SyncBackendHost. They are all called on the sync thread to |
| 157 // actually perform synchronous (and potentially blocking) syncapi | 153 // actually perform synchronous (and potentially blocking) syncapi |
| 158 // operations. | 154 // operations. |
| 159 // | 155 // |
| 160 // Called to perform initialization of the syncapi on behalf of | 156 // Called to perform initialization of the syncapi on behalf of |
| 161 // SyncBackendHost::Initialize. | 157 // SyncBackendHost::Initialize. |
| 162 void DoInitialize(const DoInitializeOptions& options); | 158 void DoInitialize(const DoInitializeOptions& options); |
| 163 | 159 |
| 164 // Called to perform credential update on behalf of | 160 // Called to perform credential update on behalf of |
| 165 // SyncBackendHost::UpdateCredentials. | 161 // SyncBackendHost::UpdateCredentials. |
| 166 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); | 162 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); |
| 167 | 163 |
| 168 // Called to update the given registered ids on behalf of | |
| 169 // SyncBackendHost::UpdateRegisteredInvalidationIds. | |
| 170 void DoUpdateRegisteredInvalidationIds(const syncer::ObjectIdSet& ids); | |
| 171 | |
| 172 // Called to acknowledge an invalidation on behalf of | |
| 173 // SyncBackendHost::AcknowledgeInvalidation. | |
| 174 void DoAcknowledgeInvalidation(const invalidation::ObjectId& id, | |
| 175 const syncer::AckHandle& ack_handle); | |
| 176 | |
| 177 // Called to tell the syncapi to start syncing (generally after | 164 // Called to tell the syncapi to start syncing (generally after |
| 178 // initialization and authentication). | 165 // initialization and authentication). |
| 179 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); | 166 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); |
| 180 | 167 |
| 181 // Called to set the passphrase for encryption. | 168 // Called to set the passphrase for encryption. |
| 182 void DoSetEncryptionPassphrase(const std::string& passphrase, | 169 void DoSetEncryptionPassphrase(const std::string& passphrase, |
| 183 bool is_explicit); | 170 bool is_explicit); |
| 184 | 171 |
| 185 // Called to decrypt the pending keys. | 172 // Called to decrypt the pending keys. |
| 186 void DoSetDecryptionPassphrase(const std::string& passphrase); | 173 void DoSetDecryptionPassphrase(const std::string& passphrase); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 284 |
| 298 // Our encryptor, which uses Chrome's encryption functions. | 285 // Our encryptor, which uses Chrome's encryption functions. |
| 299 ChromeEncryptor encryptor_; | 286 ChromeEncryptor encryptor_; |
| 300 | 287 |
| 301 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. | 288 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
| 302 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; | 289 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; |
| 303 | 290 |
| 304 // The top-level syncapi entry point. Lives on the sync thread. | 291 // The top-level syncapi entry point. Lives on the sync thread. |
| 305 scoped_ptr<syncer::SyncManager> sync_manager_; | 292 scoped_ptr<syncer::SyncManager> sync_manager_; |
| 306 | 293 |
| 307 // Whether or not we registered with |sync_manager_| as an invalidation | |
| 308 // handler. Necessary since we may end up trying to unregister before we | |
| 309 // register in tests (in synchronous initialization mode). | |
| 310 // | |
| 311 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
| 312 bool registered_as_invalidation_handler_; | |
| 313 | |
| 314 DISALLOW_COPY_AND_ASSIGN(Core); | 294 DISALLOW_COPY_AND_ASSIGN(Core); |
| 315 }; | 295 }; |
| 316 | 296 |
| 317 namespace { | |
| 318 | |
| 319 // Parses the given command line for notifier options. | |
| 320 notifier::NotifierOptions ParseNotifierOptions( | |
| 321 const CommandLine& command_line, | |
| 322 const scoped_refptr<net::URLRequestContextGetter>& | |
| 323 request_context_getter) { | |
| 324 notifier::NotifierOptions notifier_options; | |
| 325 notifier_options.request_context_getter = request_context_getter; | |
| 326 if (!command_line.HasSwitch(switches::kSyncDisableOAuth2Token)) | |
| 327 notifier_options.auth_mechanism = "X-OAUTH2"; | |
| 328 | |
| 329 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { | |
| 330 notifier_options.xmpp_host_port = | |
| 331 net::HostPortPair::FromString( | |
| 332 command_line.GetSwitchValueASCII( | |
| 333 switches::kSyncNotificationHostPort)); | |
| 334 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() | |
| 335 << " for test sync notification server."; | |
| 336 } | |
| 337 | |
| 338 notifier_options.try_ssltcp_first = | |
| 339 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); | |
| 340 DVLOG_IF(1, notifier_options.try_ssltcp_first) | |
| 341 << "Trying SSL/TCP port before XMPP port for notifications."; | |
| 342 | |
| 343 notifier_options.invalidate_xmpp_login = | |
| 344 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); | |
| 345 DVLOG_IF(1, notifier_options.invalidate_xmpp_login) | |
| 346 << "Invalidating sync XMPP login."; | |
| 347 | |
| 348 notifier_options.allow_insecure_connection = | |
| 349 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); | |
| 350 DVLOG_IF(1, notifier_options.allow_insecure_connection) | |
| 351 << "Allowing insecure XMPP connections."; | |
| 352 | |
| 353 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { | |
| 354 const std::string notification_method_str( | |
| 355 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); | |
| 356 notifier_options.notification_method = | |
| 357 notifier::StringToNotificationMethod(notification_method_str); | |
| 358 } | |
| 359 | |
| 360 return notifier_options; | |
| 361 } | |
| 362 | |
| 363 } // namespace | |
| 364 | |
| 365 SyncBackendHost::SyncBackendHost( | 297 SyncBackendHost::SyncBackendHost( |
| 366 const std::string& name, | 298 const std::string& name, |
| 367 Profile* profile, | 299 Profile* profile, |
| 368 const base::WeakPtr<SyncPrefs>& sync_prefs, | 300 const base::WeakPtr<SyncPrefs>& sync_prefs) |
| 369 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage) | |
| 370 : weak_ptr_factory_(this), | 301 : weak_ptr_factory_(this), |
| 371 sync_thread_("Chrome_SyncThread"), | 302 sync_thread_("Chrome_SyncThread"), |
| 372 frontend_loop_(base::MessageLoop::current()), | 303 frontend_loop_(base::MessageLoop::current()), |
| 373 profile_(profile), | 304 profile_(profile), |
| 374 name_(name), | 305 name_(name), |
| 375 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), | 306 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), |
| 376 weak_ptr_factory_.GetWeakPtr())), | 307 weak_ptr_factory_.GetWeakPtr())), |
| 377 initialization_state_(NOT_ATTEMPTED), | 308 initialization_state_(NOT_ATTEMPTED), |
| 378 sync_prefs_(sync_prefs), | 309 sync_prefs_(sync_prefs), |
| 379 invalidator_factory_( | |
| 380 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
| 381 profile_->GetRequestContext()), | |
| 382 content::GetUserAgent(GURL()), | |
| 383 invalidator_storage), | |
| 384 frontend_(NULL), | 310 frontend_(NULL), |
| 385 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 311 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), |
| 312 invalidator_( |
| 313 invalidation::InvalidationServiceFactory::GetForProfile(profile)) { |
| 386 } | 314 } |
| 387 | 315 |
| 388 SyncBackendHost::SyncBackendHost(Profile* profile) | 316 SyncBackendHost::SyncBackendHost(Profile* profile) |
| 389 : weak_ptr_factory_(this), | 317 : weak_ptr_factory_(this), |
| 390 sync_thread_("Chrome_SyncThread"), | 318 sync_thread_("Chrome_SyncThread"), |
| 391 frontend_loop_(base::MessageLoop::current()), | 319 frontend_loop_(base::MessageLoop::current()), |
| 392 profile_(profile), | 320 profile_(profile), |
| 393 name_("Unknown"), | 321 name_("Unknown"), |
| 394 initialization_state_(NOT_ATTEMPTED), | 322 initialization_state_(NOT_ATTEMPTED), |
| 395 invalidator_factory_( | |
| 396 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
| 397 profile_->GetRequestContext()), | |
| 398 content::GetUserAgent(GURL()), | |
| 399 base::WeakPtr<syncer::InvalidationStateTracker>()), | |
| 400 frontend_(NULL), | 323 frontend_(NULL), |
| 401 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 324 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
| 402 } | 325 } |
| 403 | 326 |
| 404 SyncBackendHost::~SyncBackendHost() { | 327 SyncBackendHost::~SyncBackendHost() { |
| 405 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; | 328 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; |
| 406 DCHECK(!android_invalidator_bridge_.get()); | |
| 407 DCHECK(!registrar_.get()); | 329 DCHECK(!registrar_.get()); |
| 408 } | 330 } |
| 409 | 331 |
| 410 namespace { | 332 namespace { |
| 411 | 333 |
| 412 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | 334 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( |
| 413 const scoped_refptr<net::URLRequestContextGetter>& getter, | 335 const scoped_refptr<net::URLRequestContextGetter>& getter, |
| 414 const NetworkTimeTracker::UpdateCallback& update_callback) { | 336 const NetworkTimeTracker::UpdateCallback& update_callback) { |
| 415 chrome::VersionInfo version_info; | 337 chrome::VersionInfo version_info; |
| 416 return scoped_ptr<syncer::HttpPostProviderFactory>( | 338 return scoped_ptr<syncer::HttpPostProviderFactory>( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 428 const GURL& sync_service_url, | 350 const GURL& sync_service_url, |
| 429 const SyncCredentials& credentials, | 351 const SyncCredentials& credentials, |
| 430 bool delete_sync_data_folder, | 352 bool delete_sync_data_folder, |
| 431 syncer::SyncManagerFactory* sync_manager_factory, | 353 syncer::SyncManagerFactory* sync_manager_factory, |
| 432 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 354 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 433 syncer::ReportUnrecoverableErrorFunction | 355 syncer::ReportUnrecoverableErrorFunction |
| 434 report_unrecoverable_error_function) { | 356 report_unrecoverable_error_function) { |
| 435 if (!sync_thread_.Start()) | 357 if (!sync_thread_.Start()) |
| 436 return; | 358 return; |
| 437 | 359 |
| 438 android_invalidator_bridge_.reset( | |
| 439 new AndroidInvalidatorBridge( | |
| 440 profile_, sync_thread_.message_loop_proxy())); | |
| 441 | |
| 442 frontend_ = frontend; | 360 frontend_ = frontend; |
| 443 DCHECK(frontend); | 361 DCHECK(frontend); |
| 444 | 362 |
| 445 registrar_.reset(new SyncBackendRegistrar(name_, | 363 registrar_.reset(new SyncBackendRegistrar(name_, |
| 446 profile_, | 364 profile_, |
| 447 sync_thread_.message_loop())); | 365 sync_thread_.message_loop())); |
| 448 syncer::ModelSafeRoutingInfo routing_info; | 366 syncer::ModelSafeRoutingInfo routing_info; |
| 449 std::vector<syncer::ModelSafeWorker*> workers; | 367 std::vector<syncer::ModelSafeWorker*> workers; |
| 450 registrar_->GetModelSafeRoutingInfo(&routing_info); | 368 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 451 registrar_->GetWorkers(&workers); | 369 registrar_->GetWorkers(&workers); |
| 452 | 370 |
| 453 InternalComponentsFactory::Switches factory_switches = { | 371 InternalComponentsFactory::Switches factory_switches = { |
| 454 InternalComponentsFactory::ENCRYPTION_KEYSTORE, | 372 InternalComponentsFactory::ENCRYPTION_KEYSTORE, |
| 455 InternalComponentsFactory::BACKOFF_NORMAL | 373 InternalComponentsFactory::BACKOFF_NORMAL |
| 456 }; | 374 }; |
| 457 | 375 |
| 458 CommandLine* cl = CommandLine::ForCurrentProcess(); | 376 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 459 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { | 377 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { |
| 460 factory_switches.backoff_override = | 378 factory_switches.backoff_override = |
| 461 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; | 379 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; |
| 462 } | 380 } |
| 463 | 381 |
| 382 invalidator_->RegisterInvalidationHandler(this); |
| 383 |
| 464 initialization_state_ = CREATING_SYNC_MANAGER; | 384 initialization_state_ = CREATING_SYNC_MANAGER; |
| 465 InitCore(DoInitializeOptions( | 385 InitCore(DoInitializeOptions( |
| 466 sync_thread_.message_loop(), | 386 sync_thread_.message_loop(), |
| 467 registrar_.get(), | 387 registrar_.get(), |
| 468 routing_info, | 388 routing_info, |
| 469 workers, | 389 workers, |
| 470 &extensions_activity_monitor_, | 390 &extensions_activity_monitor_, |
| 471 event_handler, | 391 event_handler, |
| 472 sync_service_url, | 392 sync_service_url, |
| 473 base::Bind(&MakeHttpBridgeFactory, | 393 base::Bind(&MakeHttpBridgeFactory, |
| 474 make_scoped_refptr(profile_->GetRequestContext()), | 394 make_scoped_refptr(profile_->GetRequestContext()), |
| 475 NetworkTimeTracker::BuildNotifierUpdateCallback()), | 395 NetworkTimeTracker::BuildNotifierUpdateCallback()), |
| 476 credentials, | 396 credentials, |
| 477 android_invalidator_bridge_.get(), | 397 invalidator_->GetInvalidatorClientId(), |
| 478 &invalidator_factory_, | |
| 479 sync_manager_factory, | 398 sync_manager_factory, |
| 480 delete_sync_data_folder, | 399 delete_sync_data_folder, |
| 481 sync_prefs_->GetEncryptionBootstrapToken(), | 400 sync_prefs_->GetEncryptionBootstrapToken(), |
| 482 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 401 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
| 483 new InternalComponentsFactoryImpl(factory_switches), | 402 new InternalComponentsFactoryImpl(factory_switches), |
| 484 unrecoverable_error_handler, | 403 unrecoverable_error_handler, |
| 485 report_unrecoverable_error_function, | 404 report_unrecoverable_error_function, |
| 486 !cl->HasSwitch(switches::kSyncDisableOAuth2Token))); | 405 !cl->HasSwitch(switches::kSyncDisableOAuth2Token))); |
| 487 } | 406 } |
| 488 | 407 |
| 489 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 408 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
| 490 DCHECK(sync_thread_.IsRunning()); | 409 DCHECK(sync_thread_.IsRunning()); |
| 491 sync_thread_.message_loop()->PostTask(FROM_HERE, | 410 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 492 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), | 411 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), |
| 493 credentials)); | 412 credentials)); |
| 494 } | 413 } |
| 495 | 414 |
| 496 void SyncBackendHost::UpdateRegisteredInvalidationIds( | |
| 497 const syncer::ObjectIdSet& ids) { | |
| 498 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | |
| 499 DCHECK(sync_thread_.IsRunning()); | |
| 500 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
| 501 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds, | |
| 502 core_.get(), ids)); | |
| 503 } | |
| 504 | |
| 505 void SyncBackendHost::AcknowledgeInvalidation( | |
| 506 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { | |
| 507 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | |
| 508 DCHECK(sync_thread_.IsRunning()); | |
| 509 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
| 510 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation, | |
| 511 core_.get(), id, ack_handle)); | |
| 512 } | |
| 513 | |
| 514 void SyncBackendHost::StartSyncingWithServer() { | 415 void SyncBackendHost::StartSyncingWithServer() { |
| 515 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; | 416 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; |
| 516 | 417 |
| 517 syncer::ModelSafeRoutingInfo routing_info; | 418 syncer::ModelSafeRoutingInfo routing_info; |
| 518 registrar_->GetModelSafeRoutingInfo(&routing_info); | 419 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 519 | 420 |
| 520 sync_thread_.message_loop()->PostTask(FROM_HERE, | 421 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 521 base::Bind(&SyncBackendHost::Core::DoStartSyncing, | 422 base::Bind(&SyncBackendHost::Core::DoStartSyncing, |
| 522 core_.get(), routing_info)); | 423 core_.get(), routing_info)); |
| 523 } | 424 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 // so the registrar won't need stopping either. | 548 // so the registrar won't need stopping either. |
| 648 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED); | 549 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED); |
| 649 DCHECK(!registrar_.get()); | 550 DCHECK(!registrar_.get()); |
| 650 } | 551 } |
| 651 } | 552 } |
| 652 | 553 |
| 653 void SyncBackendHost::Shutdown(bool sync_disabled) { | 554 void SyncBackendHost::Shutdown(bool sync_disabled) { |
| 654 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 555 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| 655 // called first. | 556 // called first. |
| 656 DCHECK(!frontend_); | 557 DCHECK(!frontend_); |
| 558 |
| 559 if (sync_disabled) |
| 560 invalidator_->UpdateRegisteredInvalidationIds(this, syncer::ObjectIdSet()); |
| 561 invalidator_->UnregisterInvalidationHandler(this); |
| 562 invalidator_ = NULL; |
| 563 |
| 657 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. | 564 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. |
| 658 if (sync_thread_.IsRunning()) { | 565 if (sync_thread_.IsRunning()) { |
| 659 sync_thread_.message_loop()->PostTask(FROM_HERE, | 566 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 660 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), | 567 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), |
| 661 sync_disabled)); | 568 sync_disabled)); |
| 662 | |
| 663 if (android_invalidator_bridge_) | |
| 664 android_invalidator_bridge_->StopForShutdown(); | |
| 665 } | 569 } |
| 666 | 570 |
| 667 // Stop will return once the thread exits, which will be after DoShutdown | 571 // Stop will return once the thread exits, which will be after DoShutdown |
| 668 // runs. DoShutdown needs to run from sync_thread_ because the sync backend | 572 // runs. DoShutdown needs to run from sync_thread_ because the sync backend |
| 669 // requires any thread that opened sqlite handles to relinquish them | 573 // requires any thread that opened sqlite handles to relinquish them |
| 670 // personally. We need to join threads, because otherwise the main Chrome | 574 // personally. We need to join threads, because otherwise the main Chrome |
| 671 // thread (ui loop) can exit before DoShutdown finishes, at which point | 575 // thread (ui loop) can exit before DoShutdown finishes, at which point |
| 672 // virtually anything the sync backend does (or the post-back to | 576 // virtually anything the sync backend does (or the post-back to |
| 673 // frontend_loop_ by our Core) will epically fail because the CRT won't be | 577 // frontend_loop_ by our Core) will epically fail because the CRT won't be |
| 674 // initialized. | 578 // initialized. |
| 675 // Since we are blocking the UI thread here, we need to turn ourselves in | 579 // Since we are blocking the UI thread here, we need to turn ourselves in |
| 676 // with the ThreadRestriction police. For sentencing and how we plan to fix | 580 // with the ThreadRestriction police. For sentencing and how we plan to fix |
| 677 // this, see bug 19757. | 581 // this, see bug 19757. |
| 678 base::Time stop_thread_start_time = base::Time::Now(); | 582 base::Time stop_thread_start_time = base::Time::Now(); |
| 679 { | 583 { |
| 680 base::ThreadRestrictions::ScopedAllowIO allow_io; | 584 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 681 sync_thread_.Stop(); | 585 sync_thread_.Stop(); |
| 682 } | 586 } |
| 683 base::TimeDelta stop_sync_thread_time = base::Time::Now() - | 587 base::TimeDelta stop_sync_thread_time = base::Time::Now() - |
| 684 stop_thread_start_time; | 588 stop_thread_start_time; |
| 685 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", | 589 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", |
| 686 stop_sync_thread_time); | 590 stop_sync_thread_time); |
| 687 | 591 |
| 688 registrar_.reset(); | 592 registrar_.reset(); |
| 689 js_backend_.Reset(); | 593 js_backend_.Reset(); |
| 690 android_invalidator_bridge_.reset(); | |
| 691 core_ = NULL; // Releases reference to core_. | 594 core_ = NULL; // Releases reference to core_. |
| 692 } | 595 } |
| 693 | 596 |
| 694 void SyncBackendHost::ConfigureDataTypes( | 597 void SyncBackendHost::ConfigureDataTypes( |
| 695 syncer::ConfigureReason reason, | 598 syncer::ConfigureReason reason, |
| 696 const DataTypeConfigStateMap& config_state_map, | 599 const DataTypeConfigStateMap& config_state_map, |
| 697 const base::Callback<void(syncer::ModelTypeSet, | 600 const base::Callback<void(syncer::ModelTypeSet, |
| 698 syncer::ModelTypeSet)>& ready_task, | 601 syncer::ModelTypeSet)>& ready_task, |
| 699 const base::Callback<void()>& retry_callback) { | 602 const base::Callback<void()>& retry_callback) { |
| 700 // Only one configure is allowed at a time. This is guaranteed by our | 603 // Only one configure is allowed at a time. This is guaranteed by our |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer, | 781 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer, |
| 879 core_.get(), | 782 core_.get(), |
| 880 reason, | 783 reason, |
| 881 config_types, | 784 config_types, |
| 882 routing_info, | 785 routing_info, |
| 883 ready_task, | 786 ready_task, |
| 884 retry_callback)); | 787 retry_callback)); |
| 885 } | 788 } |
| 886 | 789 |
| 887 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( | 790 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( |
| 791 const syncer::ModelTypeSet enabled_types, |
| 888 const syncer::ModelTypeSet succeeded_configuration_types, | 792 const syncer::ModelTypeSet succeeded_configuration_types, |
| 889 const syncer::ModelTypeSet failed_configuration_types, | 793 const syncer::ModelTypeSet failed_configuration_types, |
| 890 const base::Callback<void(syncer::ModelTypeSet, | 794 const base::Callback<void(syncer::ModelTypeSet, |
| 891 syncer::ModelTypeSet)>& ready_task) { | 795 syncer::ModelTypeSet)>& ready_task) { |
| 892 if (!frontend_) | 796 if (!frontend_) |
| 893 return; | 797 return; |
| 894 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 798 |
| 799 invalidator_->UpdateRegisteredInvalidationIds( |
| 800 this, |
| 801 ModelTypeSetToObjectIdSet(enabled_types)); |
| 802 |
| 895 if (!ready_task.is_null()) | 803 if (!ready_task.is_null()) |
| 896 ready_task.Run(succeeded_configuration_types, failed_configuration_types); | 804 ready_task.Run(succeeded_configuration_types, failed_configuration_types); |
| 897 } | 805 } |
| 898 | 806 |
| 899 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( | 807 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
| 900 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 808 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 901 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 809 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 902 debug_info_listener, | 810 debug_info_listener, |
| 903 syncer::ModelTypeSet restored_types) { | 811 syncer::ModelTypeSet restored_types) { |
| 904 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); | 812 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 915 | 823 |
| 916 // Start forwarding refresh requests to the SyncManager | 824 // Start forwarding refresh requests to the SyncManager |
| 917 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 825 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 918 content::Source<Profile>(profile_)); | 826 content::Source<Profile>(profile_)); |
| 919 | 827 |
| 920 syncer::ConfigureReason reason = | 828 syncer::ConfigureReason reason = |
| 921 (sync_prefs_->HasSyncSetupCompleted() ? | 829 (sync_prefs_->HasSyncSetupCompleted() ? |
| 922 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : | 830 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : |
| 923 syncer::CONFIGURE_REASON_NEW_CLIENT); | 831 syncer::CONFIGURE_REASON_NEW_CLIENT); |
| 924 | 832 |
| 833 // Fake a state change to initialize the SyncManager's cached invalidator |
| 834 // state. |
| 835 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); |
| 836 |
| 925 // Kick off the next step in SyncBackendHost initialization by downloading | 837 // Kick off the next step in SyncBackendHost initialization by downloading |
| 926 // any necessary control types. | 838 // any necessary control types. |
| 927 sync_thread_.message_loop()->PostTask( | 839 sync_thread_.message_loop()->PostTask( |
| 928 FROM_HERE, | 840 FROM_HERE, |
| 929 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, | 841 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, |
| 930 core_.get(), | 842 core_.get(), |
| 931 reason)); | 843 reason)); |
| 932 } | 844 } |
| 933 | 845 |
| 934 void SyncBackendHost::Observe( | 846 void SyncBackendHost::Observe( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 951 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( | 863 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
| 952 base::MessageLoop* sync_loop, | 864 base::MessageLoop* sync_loop, |
| 953 SyncBackendRegistrar* registrar, | 865 SyncBackendRegistrar* registrar, |
| 954 const syncer::ModelSafeRoutingInfo& routing_info, | 866 const syncer::ModelSafeRoutingInfo& routing_info, |
| 955 const std::vector<syncer::ModelSafeWorker*>& workers, | 867 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 956 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 868 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
| 957 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 869 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 958 const GURL& service_url, | 870 const GURL& service_url, |
| 959 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 871 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
| 960 const syncer::SyncCredentials& credentials, | 872 const syncer::SyncCredentials& credentials, |
| 961 AndroidInvalidatorBridge* android_invalidator_bridge, | 873 const std::string& invalidator_client_id, |
| 962 syncer::InvalidatorFactory* invalidator_factory, | |
| 963 syncer::SyncManagerFactory* sync_manager_factory, | 874 syncer::SyncManagerFactory* sync_manager_factory, |
| 964 bool delete_sync_data_folder, | 875 bool delete_sync_data_folder, |
| 965 const std::string& restored_key_for_bootstrapping, | 876 const std::string& restored_key_for_bootstrapping, |
| 966 const std::string& restored_keystore_key_for_bootstrapping, | 877 const std::string& restored_keystore_key_for_bootstrapping, |
| 967 InternalComponentsFactory* internal_components_factory, | 878 InternalComponentsFactory* internal_components_factory, |
| 968 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 879 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 969 syncer::ReportUnrecoverableErrorFunction | 880 syncer::ReportUnrecoverableErrorFunction |
| 970 report_unrecoverable_error_function, | 881 report_unrecoverable_error_function, |
| 971 bool use_oauth2_token) | 882 bool use_oauth2_token) |
| 972 : sync_loop(sync_loop), | 883 : sync_loop(sync_loop), |
| 973 registrar(registrar), | 884 registrar(registrar), |
| 974 routing_info(routing_info), | 885 routing_info(routing_info), |
| 975 workers(workers), | 886 workers(workers), |
| 976 extensions_activity_monitor(extensions_activity_monitor), | 887 extensions_activity_monitor(extensions_activity_monitor), |
| 977 event_handler(event_handler), | 888 event_handler(event_handler), |
| 978 service_url(service_url), | 889 service_url(service_url), |
| 979 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 890 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
| 980 credentials(credentials), | 891 credentials(credentials), |
| 981 android_invalidator_bridge(android_invalidator_bridge), | 892 invalidator_client_id(invalidator_client_id), |
| 982 invalidator_factory(invalidator_factory), | |
| 983 sync_manager_factory(sync_manager_factory), | 893 sync_manager_factory(sync_manager_factory), |
| 984 delete_sync_data_folder(delete_sync_data_folder), | 894 delete_sync_data_folder(delete_sync_data_folder), |
| 985 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 895 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
| 986 restored_keystore_key_for_bootstrapping( | 896 restored_keystore_key_for_bootstrapping( |
| 987 restored_keystore_key_for_bootstrapping), | 897 restored_keystore_key_for_bootstrapping), |
| 988 internal_components_factory(internal_components_factory), | 898 internal_components_factory(internal_components_factory), |
| 989 unrecoverable_error_handler(unrecoverable_error_handler), | 899 unrecoverable_error_handler(unrecoverable_error_handler), |
| 990 report_unrecoverable_error_function( | 900 report_unrecoverable_error_function( |
| 991 report_unrecoverable_error_function), | 901 report_unrecoverable_error_function), |
| 992 use_oauth2_token(use_oauth2_token) { | 902 use_oauth2_token(use_oauth2_token) { |
| 993 } | 903 } |
| 994 | 904 |
| 995 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 905 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
| 996 | 906 |
| 997 SyncBackendHost::Core::Core(const std::string& name, | 907 SyncBackendHost::Core::Core(const std::string& name, |
| 998 const base::FilePath& sync_data_folder_path, | 908 const base::FilePath& sync_data_folder_path, |
| 999 const base::WeakPtr<SyncBackendHost>& backend) | 909 const base::WeakPtr<SyncBackendHost>& backend) |
| 1000 : name_(name), | 910 : name_(name), |
| 1001 sync_data_folder_path_(sync_data_folder_path), | 911 sync_data_folder_path_(sync_data_folder_path), |
| 1002 host_(backend), | 912 host_(backend), |
| 1003 sync_loop_(NULL), | 913 sync_loop_(NULL), |
| 1004 registrar_(NULL), | 914 registrar_(NULL) { |
| 1005 registered_as_invalidation_handler_(false) { | |
| 1006 DCHECK(backend.get()); | 915 DCHECK(backend.get()); |
| 1007 } | 916 } |
| 1008 | 917 |
| 1009 SyncBackendHost::Core::~Core() { | 918 SyncBackendHost::Core::~Core() { |
| 1010 DCHECK(!sync_manager_.get()); | 919 DCHECK(!sync_manager_.get()); |
| 1011 DCHECK(!sync_loop_); | 920 DCHECK(!sync_loop_); |
| 1012 } | 921 } |
| 1013 | 922 |
| 1014 void SyncBackendHost::Core::OnSyncCycleCompleted( | 923 void SyncBackendHost::Core::OnSyncCycleCompleted( |
| 1015 const SyncSessionSnapshot& snapshot) { | 924 const SyncSessionSnapshot& snapshot) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 const syncer::SyncProtocolError& sync_error) { | 1099 const syncer::SyncProtocolError& sync_error) { |
| 1191 if (!sync_loop_) | 1100 if (!sync_loop_) |
| 1192 return; | 1101 return; |
| 1193 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1102 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1194 host_.Call( | 1103 host_.Call( |
| 1195 FROM_HERE, | 1104 FROM_HERE, |
| 1196 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 1105 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
| 1197 sync_error); | 1106 sync_error); |
| 1198 } | 1107 } |
| 1199 | 1108 |
| 1200 void SyncBackendHost::Core::OnInvalidatorStateChange( | 1109 void SyncBackendHost::Core::DoOnInvalidatorStateChange( |
| 1201 syncer::InvalidatorState state) { | 1110 syncer::InvalidatorState state) { |
| 1202 if (!sync_loop_) | |
| 1203 return; | |
| 1204 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1111 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1205 host_.Call(FROM_HERE, | 1112 sync_manager_->OnInvalidatorStateChange(state); |
| 1206 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop, | |
| 1207 state); | |
| 1208 } | 1113 } |
| 1209 | 1114 |
| 1210 void SyncBackendHost::Core::OnIncomingInvalidation( | 1115 void SyncBackendHost::Core::DoOnIncomingInvalidation( |
| 1211 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 1116 syncer::ObjectIdInvalidationMap invalidation_map) { |
| 1212 if (!sync_loop_) | |
| 1213 return; | |
| 1214 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1117 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1215 host_.Call(FROM_HERE, | 1118 sync_manager_->OnIncomingInvalidation(invalidation_map); |
| 1216 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop, | |
| 1217 invalidation_map); | |
| 1218 } | 1119 } |
| 1219 | 1120 |
| 1220 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { | 1121 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
| 1221 DCHECK(!sync_loop_); | 1122 DCHECK(!sync_loop_); |
| 1222 sync_loop_ = options.sync_loop; | 1123 sync_loop_ = options.sync_loop; |
| 1223 DCHECK(sync_loop_); | 1124 DCHECK(sync_loop_); |
| 1224 | 1125 |
| 1225 // Blow away the partial or corrupt sync data folder before doing any more | 1126 // Blow away the partial or corrupt sync data folder before doing any more |
| 1226 // initialization, if necessary. | 1127 // initialization, if necessary. |
| 1227 if (options.delete_sync_data_folder) { | 1128 if (options.delete_sync_data_folder) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1244 sync_data_folder_path_, | 1145 sync_data_folder_path_, |
| 1245 options.event_handler, | 1146 options.event_handler, |
| 1246 options.service_url.host() + options.service_url.path(), | 1147 options.service_url.host() + options.service_url.path(), |
| 1247 options.service_url.EffectiveIntPort(), | 1148 options.service_url.EffectiveIntPort(), |
| 1248 options.service_url.SchemeIsSecure(), | 1149 options.service_url.SchemeIsSecure(), |
| 1249 options.make_http_bridge_factory_fn.Run().Pass(), | 1150 options.make_http_bridge_factory_fn.Run().Pass(), |
| 1250 options.workers, | 1151 options.workers, |
| 1251 options.extensions_activity_monitor, | 1152 options.extensions_activity_monitor, |
| 1252 options.registrar /* as SyncManager::ChangeDelegate */, | 1153 options.registrar /* as SyncManager::ChangeDelegate */, |
| 1253 options.credentials, | 1154 options.credentials, |
| 1254 #if defined(OS_ANDROID) | 1155 options.invalidator_client_id, |
| 1255 scoped_ptr<syncer::Invalidator>( | |
| 1256 new AndroidInvalidatorBridgeProxy( | |
| 1257 options.android_invalidator_bridge)), | |
| 1258 #else | |
| 1259 scoped_ptr<syncer::Invalidator>( | |
| 1260 options.invalidator_factory->CreateInvalidator()), | |
| 1261 #endif | |
| 1262 options.invalidator_factory->GetInvalidatorClientId(), | |
| 1263 options.restored_key_for_bootstrapping, | 1156 options.restored_key_for_bootstrapping, |
| 1264 options.restored_keystore_key_for_bootstrapping, | 1157 options.restored_keystore_key_for_bootstrapping, |
| 1265 scoped_ptr<InternalComponentsFactory>( | 1158 scoped_ptr<InternalComponentsFactory>( |
| 1266 options.internal_components_factory), | 1159 options.internal_components_factory), |
| 1267 &encryptor_, | 1160 &encryptor_, |
| 1268 options.unrecoverable_error_handler, | 1161 options.unrecoverable_error_handler, |
| 1269 options.report_unrecoverable_error_function, | 1162 options.report_unrecoverable_error_function, |
| 1270 options.use_oauth2_token); | 1163 options.use_oauth2_token); |
| 1271 | 1164 |
| 1272 // |sync_manager_| may end up being NULL here in tests (in | 1165 // |sync_manager_| may end up being NULL here in tests (in |
| 1273 // synchronous initialization mode). | 1166 // synchronous initialization mode). |
| 1274 // | 1167 // |
| 1275 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 1168 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
| 1276 if (sync_manager_) { | 1169 if (sync_manager_) { |
| 1277 sync_manager_->RegisterInvalidationHandler(this); | |
| 1278 registered_as_invalidation_handler_ = true; | |
| 1279 | |
| 1280 // Now check the command line to see if we need to simulate an | 1170 // Now check the command line to see if we need to simulate an |
| 1281 // unrecoverable error for testing purpose. Note the error is thrown | 1171 // unrecoverable error for testing purpose. Note the error is thrown |
| 1282 // only if the initialization succeeded. Also it makes sense to use this | 1172 // only if the initialization succeeded. Also it makes sense to use this |
| 1283 // flag only when restarting the browser with an account already setup. If | 1173 // flag only when restarting the browser with an account already setup. If |
| 1284 // you use this before setting up the setup would not succeed as an error | 1174 // you use this before setting up the setup would not succeed as an error |
| 1285 // would be encountered. | 1175 // would be encountered. |
| 1286 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1176 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1287 switches::kSyncThrowUnrecoverableError)) { | 1177 switches::kSyncThrowUnrecoverableError)) { |
| 1288 sync_manager_->ThrowUnrecoverableError(); | 1178 sync_manager_->ThrowUnrecoverableError(); |
| 1289 } | 1179 } |
| 1290 } | 1180 } |
| 1291 } | 1181 } |
| 1292 | 1182 |
| 1293 void SyncBackendHost::Core::DoUpdateCredentials( | 1183 void SyncBackendHost::Core::DoUpdateCredentials( |
| 1294 const SyncCredentials& credentials) { | 1184 const SyncCredentials& credentials) { |
| 1295 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1185 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1296 // UpdateCredentials can be called during backend initialization, possibly | 1186 // UpdateCredentials can be called during backend initialization, possibly |
| 1297 // when backend initialization has failed but hasn't notified the UI thread | 1187 // when backend initialization has failed but hasn't notified the UI thread |
| 1298 // yet. In that case, the sync manager may have been destroyed on the sync | 1188 // yet. In that case, the sync manager may have been destroyed on the sync |
| 1299 // thread before this task was executed, so we do nothing. | 1189 // thread before this task was executed, so we do nothing. |
| 1300 if (sync_manager_) { | 1190 if (sync_manager_) { |
| 1301 sync_manager_->UpdateCredentials(credentials); | 1191 sync_manager_->UpdateCredentials(credentials); |
| 1302 } | 1192 } |
| 1303 } | 1193 } |
| 1304 | 1194 |
| 1305 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds( | |
| 1306 const syncer::ObjectIdSet& ids) { | |
| 1307 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | |
| 1308 // |sync_manager_| may end up being NULL here in tests (in | |
| 1309 // synchronous initialization mode) since this is called during | |
| 1310 // shutdown. | |
| 1311 // | |
| 1312 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
| 1313 if (sync_manager_) { | |
| 1314 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); | |
| 1315 } | |
| 1316 } | |
| 1317 | |
| 1318 void SyncBackendHost::Core::DoAcknowledgeInvalidation( | |
| 1319 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { | |
| 1320 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | |
| 1321 // |sync_manager_| may end up being NULL here in tests (in | |
| 1322 // synchronous initialization mode). | |
| 1323 // | |
| 1324 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
| 1325 if (sync_manager_) { | |
| 1326 sync_manager_->AcknowledgeInvalidation(id, ack_handle); | |
| 1327 } | |
| 1328 } | |
| 1329 | |
| 1330 void SyncBackendHost::Core::DoStartSyncing( | 1195 void SyncBackendHost::Core::DoStartSyncing( |
| 1331 const syncer::ModelSafeRoutingInfo& routing_info) { | 1196 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 1332 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1197 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1333 sync_manager_->StartSyncingNormally(routing_info); | 1198 sync_manager_->StartSyncingNormally(routing_info); |
| 1334 } | 1199 } |
| 1335 | 1200 |
| 1336 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1201 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| 1337 const std::string& passphrase, | 1202 const std::string& passphrase, |
| 1338 bool is_explicit) { | 1203 bool is_explicit) { |
| 1339 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1204 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 | 1294 |
| 1430 sync_loop_ = NULL; | 1295 sync_loop_ = NULL; |
| 1431 | 1296 |
| 1432 host_.Reset(); | 1297 host_.Reset(); |
| 1433 } | 1298 } |
| 1434 | 1299 |
| 1435 void SyncBackendHost::Core::DoDestroySyncManager() { | 1300 void SyncBackendHost::Core::DoDestroySyncManager() { |
| 1436 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1301 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1437 if (sync_manager_) { | 1302 if (sync_manager_) { |
| 1438 save_changes_timer_.reset(); | 1303 save_changes_timer_.reset(); |
| 1439 if (registered_as_invalidation_handler_) { | |
| 1440 sync_manager_->UnregisterInvalidationHandler(this); | |
| 1441 registered_as_invalidation_handler_ = false; | |
| 1442 } | |
| 1443 sync_manager_->RemoveObserver(this); | 1304 sync_manager_->RemoveObserver(this); |
| 1444 sync_manager_->ShutdownOnSyncThread(); | 1305 sync_manager_->ShutdownOnSyncThread(); |
| 1445 sync_manager_.reset(); | 1306 sync_manager_.reset(); |
| 1446 } | 1307 } |
| 1447 } | 1308 } |
| 1448 | 1309 |
| 1449 void SyncBackendHost::Core::DoConfigureSyncer( | 1310 void SyncBackendHost::Core::DoConfigureSyncer( |
| 1450 syncer::ConfigureReason reason, | 1311 syncer::ConfigureReason reason, |
| 1451 const DoConfigureSyncerTypes& config_types, | 1312 const DoConfigureSyncerTypes& config_types, |
| 1452 const syncer::ModelSafeRoutingInfo routing_info, | 1313 const syncer::ModelSafeRoutingInfo routing_info, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1474 syncer::ModelTypeSet types_to_config, | 1335 syncer::ModelTypeSet types_to_config, |
| 1475 const base::Callback<void(syncer::ModelTypeSet, | 1336 const base::Callback<void(syncer::ModelTypeSet, |
| 1476 syncer::ModelTypeSet)>& ready_task) { | 1337 syncer::ModelTypeSet)>& ready_task) { |
| 1477 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1338 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1478 | 1339 |
| 1479 // Update the enabled types for the bridge and sync manager. | 1340 // Update the enabled types for the bridge and sync manager. |
| 1480 syncer::ModelSafeRoutingInfo routing_info; | 1341 syncer::ModelSafeRoutingInfo routing_info; |
| 1481 registrar_->GetModelSafeRoutingInfo(&routing_info); | 1342 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 1482 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); | 1343 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); |
| 1483 enabled_types.RemoveAll(syncer::ProxyTypes()); | 1344 enabled_types.RemoveAll(syncer::ProxyTypes()); |
| 1484 sync_manager_->UpdateEnabledTypes(enabled_types); | |
| 1485 | 1345 |
| 1486 const syncer::ModelTypeSet failed_configuration_types = | 1346 const syncer::ModelTypeSet failed_configuration_types = |
| 1487 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); | 1347 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); |
| 1488 const syncer::ModelTypeSet succeeded_configuration_types = | 1348 const syncer::ModelTypeSet succeeded_configuration_types = |
| 1489 Difference(types_to_config, failed_configuration_types); | 1349 Difference(types_to_config, failed_configuration_types); |
| 1490 host_.Call(FROM_HERE, | 1350 host_.Call(FROM_HERE, |
| 1491 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, | 1351 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, |
| 1492 succeeded_configuration_types, failed_configuration_types, | 1352 enabled_types, |
| 1353 succeeded_configuration_types, |
| 1354 failed_configuration_types, |
| 1493 ready_task); | 1355 ready_task); |
| 1494 } | 1356 } |
| 1495 | 1357 |
| 1496 void SyncBackendHost::Core::DoRetryConfiguration( | 1358 void SyncBackendHost::Core::DoRetryConfiguration( |
| 1497 const base::Closure& retry_callback) { | 1359 const base::Closure& retry_callback) { |
| 1498 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1360 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1499 host_.Call(FROM_HERE, | 1361 host_.Call(FROM_HERE, |
| 1500 &SyncBackendHost::RetryConfigurationOnFrontendLoop, | 1362 &SyncBackendHost::RetryConfigurationOnFrontendLoop, |
| 1501 retry_callback); | 1363 retry_callback); |
| 1502 } | 1364 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 } | 1474 } |
| 1613 | 1475 |
| 1614 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( | 1476 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( |
| 1615 const syncer::SyncProtocolError& sync_error) { | 1477 const syncer::SyncProtocolError& sync_error) { |
| 1616 if (!frontend_) | 1478 if (!frontend_) |
| 1617 return; | 1479 return; |
| 1618 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 1480 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 1619 frontend_->OnActionableError(sync_error); | 1481 frontend_->OnActionableError(sync_error); |
| 1620 } | 1482 } |
| 1621 | 1483 |
| 1622 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( | 1484 void SyncBackendHost::OnInvalidatorStateChange(syncer::InvalidatorState state) { |
| 1623 syncer::InvalidatorState state) { | 1485 sync_thread_.message_loop()->PostTask( |
| 1624 if (!frontend_) | 1486 FROM_HERE, |
| 1625 return; | 1487 base::Bind(&SyncBackendHost::Core::DoOnInvalidatorStateChange, |
| 1626 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 1488 core_.get(), |
| 1627 frontend_->OnInvalidatorStateChange(state); | 1489 state)); |
| 1628 } | 1490 } |
| 1629 | 1491 |
| 1630 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( | 1492 void SyncBackendHost::OnIncomingInvalidation( |
| 1631 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 1493 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| 1632 if (!frontend_) | 1494 // TODO(dcheng): Acknowledge immediately for now. Fix this once the |
| 1633 return; | 1495 // invalidator doesn't repeatedly ping for unacknowledged invaliations, since |
| 1634 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 1496 // it conflicts with the sync scheduler's internal backoff algorithm. |
| 1635 frontend_->OnIncomingInvalidation(invalidation_map); | 1497 // See http://crbug.com/124149 for more information. |
| 1498 for (syncer::ObjectIdInvalidationMap::const_iterator it = |
| 1499 invalidation_map.begin(); it != invalidation_map.end(); ++it) { |
| 1500 invalidator_->AcknowledgeInvalidation(it->first, it->second.ack_handle); |
| 1501 } |
| 1502 |
| 1503 sync_thread_.message_loop()->PostTask( |
| 1504 FROM_HERE, |
| 1505 base::Bind(&SyncBackendHost::Core::DoOnIncomingInvalidation, |
| 1506 core_.get(), |
| 1507 invalidation_map)); |
| 1636 } | 1508 } |
| 1637 | 1509 |
| 1638 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( | 1510 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( |
| 1639 const std::string& passphrase) const { | 1511 const std::string& passphrase) const { |
| 1640 DCHECK(cached_pending_keys_.has_blob()); | 1512 DCHECK(cached_pending_keys_.has_blob()); |
| 1641 DCHECK(!passphrase.empty()); | 1513 DCHECK(!passphrase.empty()); |
| 1642 syncer::Nigori nigori; | 1514 syncer::Nigori nigori; |
| 1643 nigori.InitByDerivation("localhost", "dummy", passphrase); | 1515 nigori.InitByDerivation("localhost", "dummy", passphrase); |
| 1644 std::string plaintext; | 1516 std::string plaintext; |
| 1645 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); | 1517 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1726 DVLOG(1) << "Connection status changed: " | 1598 DVLOG(1) << "Connection status changed: " |
| 1727 << syncer::ConnectionStatusToString(status); | 1599 << syncer::ConnectionStatusToString(status); |
| 1728 frontend_->OnConnectionStatusChange(status); | 1600 frontend_->OnConnectionStatusChange(status); |
| 1729 } | 1601 } |
| 1730 | 1602 |
| 1731 #undef SDVLOG | 1603 #undef SDVLOG |
| 1732 | 1604 |
| 1733 #undef SLOG | 1605 #undef SLOG |
| 1734 | 1606 |
| 1735 } // namespace browser_sync | 1607 } // namespace browser_sync |
| OLD | NEW |