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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
21 #include "base/timer.h" | 21 #include "base/timer.h" |
22 #include "base/tracked_objects.h" | 22 #include "base/tracked_objects.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
26 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" | 26 #include "chrome/browser/sync/glue/bridged_invalidator.h" |
27 #include "chrome/browser/sync/glue/change_processor.h" | 27 #include "chrome/browser/sync/glue/change_processor.h" |
28 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 28 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
29 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 29 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
30 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 30 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
31 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 31 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
32 #include "chrome/browser/sync/sync_prefs.h" | 32 #include "chrome/browser/sync/sync_prefs.h" |
33 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/chrome_version_info.h" | 35 #include "chrome/common/chrome_version_info.h" |
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/http_bridge.h" |
47 #include "sync/internal_api/public/internal_components_factory_impl.h" | 47 #include "sync/internal_api/public/internal_components_factory_impl.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/internal_api/public/util/sync_string_conversions.h" | 51 #include "sync/internal_api/public/util/sync_string_conversions.h" |
52 #include "sync/notifier/sync_notifier.h" | 52 #include "sync/notifier/invalidator.h" |
53 #include "sync/protocol/encryption.pb.h" | 53 #include "sync/protocol/encryption.pb.h" |
54 #include "sync/protocol/sync.pb.h" | 54 #include "sync/protocol/sync.pb.h" |
55 #include "sync/util/nigori.h" | 55 #include "sync/util/nigori.h" |
56 | 56 |
57 static const int kSaveChangesIntervalSeconds = 10; | 57 static const int kSaveChangesIntervalSeconds = 10; |
58 static const FilePath::CharType kSyncDataFolderName[] = | 58 static const FilePath::CharType kSyncDataFolderName[] = |
59 FILE_PATH_LITERAL("Sync Data"); | 59 FILE_PATH_LITERAL("Sync Data"); |
60 | 60 |
61 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; | 61 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; |
62 | 62 |
(...skipping 11 matching lines...) Expand all Loading... |
74 // are multiple syncers involved. | 74 // are multiple syncers involved. |
75 | 75 |
76 #define SLOG(severity) LOG(severity) << name_ << ": " | 76 #define SLOG(severity) LOG(severity) << name_ << ": " |
77 | 77 |
78 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 78 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
79 | 79 |
80 class SyncBackendHost::Core | 80 class SyncBackendHost::Core |
81 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 81 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
82 public syncer::SyncEncryptionHandler::Observer, | 82 public syncer::SyncEncryptionHandler::Observer, |
83 public syncer::SyncManager::Observer, | 83 public syncer::SyncManager::Observer, |
84 public syncer::SyncNotifierObserver { | 84 public syncer::InvalidationHandler { |
85 public: | 85 public: |
86 Core(const std::string& name, | 86 Core(const std::string& name, |
87 const FilePath& sync_data_folder_path, | 87 const FilePath& sync_data_folder_path, |
88 const base::WeakPtr<SyncBackendHost>& backend); | 88 const base::WeakPtr<SyncBackendHost>& backend); |
89 | 89 |
90 // SyncManager::Observer implementation. The Core just acts like an air | 90 // SyncManager::Observer implementation. The Core just acts like an air |
91 // traffic controller here, forwarding incoming messages to appropriate | 91 // traffic controller here, forwarding incoming messages to appropriate |
92 // landing threads. | 92 // landing threads. |
93 virtual void OnSyncCycleCompleted( | 93 virtual void OnSyncCycleCompleted( |
94 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 94 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
(...skipping 16 matching lines...) Expand all Loading... |
111 virtual void OnBootstrapTokenUpdated( | 111 virtual void OnBootstrapTokenUpdated( |
112 const std::string& bootstrap_token) OVERRIDE; | 112 const std::string& bootstrap_token) OVERRIDE; |
113 virtual void OnEncryptedTypesChanged( | 113 virtual void OnEncryptedTypesChanged( |
114 syncer::ModelTypeSet encrypted_types, | 114 syncer::ModelTypeSet encrypted_types, |
115 bool encrypt_everything) OVERRIDE; | 115 bool encrypt_everything) OVERRIDE; |
116 virtual void OnEncryptionComplete() OVERRIDE; | 116 virtual void OnEncryptionComplete() OVERRIDE; |
117 virtual void OnCryptographerStateChanged( | 117 virtual void OnCryptographerStateChanged( |
118 syncer::Cryptographer* cryptographer) OVERRIDE; | 118 syncer::Cryptographer* cryptographer) OVERRIDE; |
119 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE; | 119 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE; |
120 | 120 |
121 // syncer::SyncNotifierObserver implementation. | 121 // syncer::InvalidationHandler implementation. |
122 virtual void OnNotificationsEnabled() OVERRIDE; | 122 virtual void OnNotificationsEnabled() OVERRIDE; |
123 virtual void OnNotificationsDisabled( | 123 virtual void OnNotificationsDisabled( |
124 syncer::NotificationsDisabledReason reason) OVERRIDE; | 124 syncer::NotificationsDisabledReason reason) OVERRIDE; |
125 virtual void OnIncomingNotification( | 125 virtual void OnIncomingNotification( |
126 const syncer::ObjectIdStateMap& id_state_map, | 126 const syncer::ObjectIdStateMap& id_state_map, |
127 syncer::IncomingNotificationSource source) OVERRIDE; | 127 syncer::IncomingNotificationSource source) OVERRIDE; |
128 | 128 |
129 // Note: | 129 // Note: |
130 // | 130 // |
131 // The Do* methods are the various entry points from our | 131 // The Do* methods are the various entry points from our |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 const base::WeakPtr<InvalidatorStorage>& invalidator_storage) | 315 const base::WeakPtr<InvalidatorStorage>& invalidator_storage) |
316 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 316 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
317 sync_thread_("Chrome_SyncThread"), | 317 sync_thread_("Chrome_SyncThread"), |
318 frontend_loop_(MessageLoop::current()), | 318 frontend_loop_(MessageLoop::current()), |
319 profile_(profile), | 319 profile_(profile), |
320 name_(name), | 320 name_(name), |
321 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), | 321 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), |
322 weak_ptr_factory_.GetWeakPtr())), | 322 weak_ptr_factory_.GetWeakPtr())), |
323 initialization_state_(NOT_ATTEMPTED), | 323 initialization_state_(NOT_ATTEMPTED), |
324 sync_prefs_(sync_prefs), | 324 sync_prefs_(sync_prefs), |
325 sync_notifier_factory_( | 325 invalidator_factory_( |
326 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 326 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
327 profile_->GetRequestContext()), | 327 profile_->GetRequestContext()), |
328 content::GetUserAgent(GURL()), | 328 content::GetUserAgent(GURL()), |
329 invalidator_storage), | 329 invalidator_storage), |
330 frontend_(NULL), | 330 frontend_(NULL), |
331 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) { | 331 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) { |
332 } | 332 } |
333 | 333 |
334 SyncBackendHost::SyncBackendHost(Profile* profile) | 334 SyncBackendHost::SyncBackendHost(Profile* profile) |
335 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 335 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
336 sync_thread_("Chrome_SyncThread"), | 336 sync_thread_("Chrome_SyncThread"), |
337 frontend_loop_(MessageLoop::current()), | 337 frontend_loop_(MessageLoop::current()), |
338 profile_(profile), | 338 profile_(profile), |
339 name_("Unknown"), | 339 name_("Unknown"), |
340 initialization_state_(NOT_ATTEMPTED), | 340 initialization_state_(NOT_ATTEMPTED), |
341 sync_notifier_factory_( | 341 invalidator_factory_( |
342 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 342 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
343 profile_->GetRequestContext()), | 343 profile_->GetRequestContext()), |
344 content::GetUserAgent(GURL()), | 344 content::GetUserAgent(GURL()), |
345 base::WeakPtr<syncer::InvalidationStateTracker>()), | 345 base::WeakPtr<syncer::InvalidationStateTracker>()), |
346 frontend_(NULL), | 346 frontend_(NULL), |
347 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) { | 347 cached_passphrase_state_(syncer::IMPLICIT_PASSPHRASE) { |
348 } | 348 } |
349 | 349 |
350 SyncBackendHost::~SyncBackendHost() { | 350 SyncBackendHost::~SyncBackendHost() { |
351 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 351 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 registrar_.get(), | 444 registrar_.get(), |
445 routing_info, | 445 routing_info, |
446 workers, | 446 workers, |
447 &extensions_activity_monitor_, | 447 &extensions_activity_monitor_, |
448 event_handler, | 448 event_handler, |
449 sync_service_url, | 449 sync_service_url, |
450 base::Bind(&MakeHttpBridgeFactory, | 450 base::Bind(&MakeHttpBridgeFactory, |
451 make_scoped_refptr(profile_->GetRequestContext())), | 451 make_scoped_refptr(profile_->GetRequestContext())), |
452 credentials, | 452 credentials, |
453 chrome_sync_notification_bridge_.get(), | 453 chrome_sync_notification_bridge_.get(), |
454 &sync_notifier_factory_, | 454 &invalidator_factory_, |
455 sync_manager_factory, | 455 sync_manager_factory, |
456 delete_sync_data_folder, | 456 delete_sync_data_folder, |
457 sync_prefs_->GetEncryptionBootstrapToken(), | 457 sync_prefs_->GetEncryptionBootstrapToken(), |
458 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 458 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
459 new InternalComponentsFactoryImpl(factory_switches), | 459 new InternalComponentsFactoryImpl(factory_switches), |
460 unrecoverable_error_handler, | 460 unrecoverable_error_handler, |
461 report_unrecoverable_error_function)); | 461 report_unrecoverable_error_function)); |
462 } | 462 } |
463 | 463 |
464 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 464 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 MessageLoop* sync_loop, | 832 MessageLoop* sync_loop, |
833 SyncBackendRegistrar* registrar, | 833 SyncBackendRegistrar* registrar, |
834 const syncer::ModelSafeRoutingInfo& routing_info, | 834 const syncer::ModelSafeRoutingInfo& routing_info, |
835 const std::vector<syncer::ModelSafeWorker*>& workers, | 835 const std::vector<syncer::ModelSafeWorker*>& workers, |
836 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 836 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
837 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 837 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
838 const GURL& service_url, | 838 const GURL& service_url, |
839 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 839 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
840 const syncer::SyncCredentials& credentials, | 840 const syncer::SyncCredentials& credentials, |
841 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, | 841 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, |
842 syncer::SyncNotifierFactory* sync_notifier_factory, | 842 syncer::InvalidatorFactory* invalidator_factory, |
843 syncer::SyncManagerFactory* sync_manager_factory, | 843 syncer::SyncManagerFactory* sync_manager_factory, |
844 bool delete_sync_data_folder, | 844 bool delete_sync_data_folder, |
845 const std::string& restored_key_for_bootstrapping, | 845 const std::string& restored_key_for_bootstrapping, |
846 const std::string& restored_keystore_key_for_bootstrapping, | 846 const std::string& restored_keystore_key_for_bootstrapping, |
847 InternalComponentsFactory* internal_components_factory, | 847 InternalComponentsFactory* internal_components_factory, |
848 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 848 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
849 syncer::ReportUnrecoverableErrorFunction | 849 syncer::ReportUnrecoverableErrorFunction |
850 report_unrecoverable_error_function) | 850 report_unrecoverable_error_function) |
851 : sync_loop(sync_loop), | 851 : sync_loop(sync_loop), |
852 registrar(registrar), | 852 registrar(registrar), |
853 routing_info(routing_info), | 853 routing_info(routing_info), |
854 workers(workers), | 854 workers(workers), |
855 extensions_activity_monitor(extensions_activity_monitor), | 855 extensions_activity_monitor(extensions_activity_monitor), |
856 event_handler(event_handler), | 856 event_handler(event_handler), |
857 service_url(service_url), | 857 service_url(service_url), |
858 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 858 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
859 credentials(credentials), | 859 credentials(credentials), |
860 chrome_sync_notification_bridge(chrome_sync_notification_bridge), | 860 chrome_sync_notification_bridge(chrome_sync_notification_bridge), |
861 sync_notifier_factory(sync_notifier_factory), | 861 invalidator_factory(invalidator_factory), |
862 sync_manager_factory(sync_manager_factory), | 862 sync_manager_factory(sync_manager_factory), |
863 delete_sync_data_folder(delete_sync_data_folder), | 863 delete_sync_data_folder(delete_sync_data_folder), |
864 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 864 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
865 restored_keystore_key_for_bootstrapping( | 865 restored_keystore_key_for_bootstrapping( |
866 restored_keystore_key_for_bootstrapping), | 866 restored_keystore_key_for_bootstrapping), |
867 internal_components_factory(internal_components_factory), | 867 internal_components_factory(internal_components_factory), |
868 unrecoverable_error_handler(unrecoverable_error_handler), | 868 unrecoverable_error_handler(unrecoverable_error_handler), |
869 report_unrecoverable_error_function( | 869 report_unrecoverable_error_function( |
870 report_unrecoverable_error_function) { | 870 report_unrecoverable_error_function) { |
871 } | 871 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 options.event_handler, | 1109 options.event_handler, |
1110 options.service_url.host() + options.service_url.path(), | 1110 options.service_url.host() + options.service_url.path(), |
1111 options.service_url.EffectiveIntPort(), | 1111 options.service_url.EffectiveIntPort(), |
1112 options.service_url.SchemeIsSecure(), | 1112 options.service_url.SchemeIsSecure(), |
1113 BrowserThread::GetBlockingPool(), | 1113 BrowserThread::GetBlockingPool(), |
1114 options.make_http_bridge_factory_fn.Run().Pass(), | 1114 options.make_http_bridge_factory_fn.Run().Pass(), |
1115 options.workers, | 1115 options.workers, |
1116 options.extensions_activity_monitor, | 1116 options.extensions_activity_monitor, |
1117 options.registrar /* as SyncManager::ChangeDelegate */, | 1117 options.registrar /* as SyncManager::ChangeDelegate */, |
1118 options.credentials, | 1118 options.credentials, |
1119 scoped_ptr<syncer::SyncNotifier>(new BridgedSyncNotifier( | 1119 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( |
1120 options.chrome_sync_notification_bridge, | 1120 options.chrome_sync_notification_bridge, |
1121 options.sync_notifier_factory->CreateSyncNotifier())), | 1121 options.invalidator_factory->CreateInvalidator())), |
1122 options.restored_key_for_bootstrapping, | 1122 options.restored_key_for_bootstrapping, |
1123 options.restored_keystore_key_for_bootstrapping, | 1123 options.restored_keystore_key_for_bootstrapping, |
1124 scoped_ptr<InternalComponentsFactory>( | 1124 scoped_ptr<InternalComponentsFactory>( |
1125 options.internal_components_factory), | 1125 options.internal_components_factory), |
1126 &encryptor_, | 1126 &encryptor_, |
1127 options.unrecoverable_error_handler, | 1127 options.unrecoverable_error_handler, |
1128 options.report_unrecoverable_error_function); | 1128 options.report_unrecoverable_error_function); |
1129 | 1129 |
1130 // |sync_manager_| may end up being NULL here in tests (in | 1130 // |sync_manager_| may end up being NULL here in tests (in |
1131 // synchronous initialization mode). | 1131 // synchronous initialization mode). |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 const syncer::ModelTypeSet failed_configuration_types) { | 1562 const syncer::ModelTypeSet failed_configuration_types) { |
1563 HandleInitializationCompletedOnFrontendLoop( | 1563 HandleInitializationCompletedOnFrontendLoop( |
1564 failed_configuration_types.Empty()); | 1564 failed_configuration_types.Empty()); |
1565 } | 1565 } |
1566 | 1566 |
1567 #undef SDVLOG | 1567 #undef SDVLOG |
1568 | 1568 |
1569 #undef SLOG | 1569 #undef SLOG |
1570 | 1570 |
1571 } // namespace browser_sync | 1571 } // namespace browser_sync |
OLD | NEW |