Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 10916131: [Invalidations] Add GetInvalidatorState() to Invalidator{,Frontend} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "build/build_config.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/signin/token_service.h" 26 #include "chrome/browser/signin/token_service.h"
26 #include "chrome/browser/sync/glue/bridged_invalidator.h" 27 #include "chrome/browser/sync/glue/bridged_invalidator.h"
27 #include "chrome/browser/sync/glue/change_processor.h" 28 #include "chrome/browser/sync/glue/change_processor.h"
28 #include "chrome/browser/sync/glue/chrome_encryptor.h" 29 #include "chrome/browser/sync/glue/chrome_encryptor.h"
29 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" 30 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h"
30 #include "chrome/browser/sync/glue/sync_backend_registrar.h" 31 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
31 #include "chrome/browser/sync/invalidations/invalidator_storage.h" 32 #include "chrome/browser/sync/invalidations/invalidator_storage.h"
32 #include "chrome/browser/sync/sync_prefs.h" 33 #include "chrome/browser/sync/sync_prefs.h"
33 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 syncer::BootstrapTokenType type) OVERRIDE; 114 syncer::BootstrapTokenType type) OVERRIDE;
114 virtual void OnEncryptedTypesChanged( 115 virtual void OnEncryptedTypesChanged(
115 syncer::ModelTypeSet encrypted_types, 116 syncer::ModelTypeSet encrypted_types,
116 bool encrypt_everything) OVERRIDE; 117 bool encrypt_everything) OVERRIDE;
117 virtual void OnEncryptionComplete() OVERRIDE; 118 virtual void OnEncryptionComplete() OVERRIDE;
118 virtual void OnCryptographerStateChanged( 119 virtual void OnCryptographerStateChanged(
119 syncer::Cryptographer* cryptographer) OVERRIDE; 120 syncer::Cryptographer* cryptographer) OVERRIDE;
120 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE; 121 virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE;
121 122
122 // syncer::InvalidationHandler implementation. 123 // syncer::InvalidationHandler implementation.
123 virtual void OnNotificationsEnabled() OVERRIDE; 124 virtual void OnInvalidatorStateChange(
124 virtual void OnNotificationsDisabled( 125 syncer::InvalidatorState state) OVERRIDE;
125 syncer::NotificationsDisabledReason reason) OVERRIDE; 126 virtual void OnIncomingInvalidation(
126 virtual void OnIncomingNotification(
127 const syncer::ObjectIdStateMap& id_state_map, 127 const syncer::ObjectIdStateMap& id_state_map,
128 syncer::IncomingNotificationSource source) OVERRIDE; 128 syncer::IncomingInvalidationSource source) OVERRIDE;
129 129
130 // Note: 130 // Note:
131 // 131 //
132 // The Do* methods are the various entry points from our 132 // The Do* methods are the various entry points from our
133 // SyncBackendHost. They are all called on the sync thread to 133 // SyncBackendHost. They are all called on the sync thread to
134 // actually perform synchronous (and potentially blocking) syncapi 134 // actually perform synchronous (and potentially blocking) syncapi
135 // operations. 135 // operations.
136 // 136 //
137 // Called to perform initialization of the syncapi on behalf of 137 // Called to perform initialization of the syncapi on behalf of
138 // SyncBackendHost::Initialize. 138 // SyncBackendHost::Initialize.
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 const syncer::SyncProtocolError& sync_error) { 1031 const syncer::SyncProtocolError& sync_error) {
1032 if (!sync_loop_) 1032 if (!sync_loop_)
1033 return; 1033 return;
1034 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1034 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1035 host_.Call( 1035 host_.Call(
1036 FROM_HERE, 1036 FROM_HERE,
1037 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1037 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1038 sync_error); 1038 sync_error);
1039 } 1039 }
1040 1040
1041 void SyncBackendHost::Core::OnNotificationsEnabled() { 1041 void SyncBackendHost::Core::OnInvalidatorStateChange(
1042 syncer::InvalidatorState state) {
1042 if (!sync_loop_) 1043 if (!sync_loop_)
1043 return; 1044 return;
1044 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1045 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1045 host_.Call(FROM_HERE, 1046 host_.Call(FROM_HERE,
1046 &SyncBackendHost::HandleNotificationsEnabledOnFrontendLoop); 1047 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop,
1048 state);
1047 } 1049 }
1048 1050
1049 void SyncBackendHost::Core::OnNotificationsDisabled( 1051 void SyncBackendHost::Core::OnIncomingInvalidation(
1050 syncer::NotificationsDisabledReason reason) { 1052 const syncer::ObjectIdStateMap& id_state_map,
1053 syncer::IncomingInvalidationSource source) {
1051 if (!sync_loop_) 1054 if (!sync_loop_)
1052 return; 1055 return;
1053 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1056 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1054 host_.Call(FROM_HERE, 1057 host_.Call(FROM_HERE,
1055 &SyncBackendHost::HandleNotificationsDisabledOnFrontendLoop, 1058 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop,
1056 reason);
1057 }
1058
1059 void SyncBackendHost::Core::OnIncomingNotification(
1060 const syncer::ObjectIdStateMap& id_state_map,
1061 syncer::IncomingNotificationSource source) {
1062 if (!sync_loop_)
1063 return;
1064 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1065 host_.Call(FROM_HERE,
1066 &SyncBackendHost::HandleIncomingNotificationOnFrontendLoop,
1067 id_state_map, source); 1059 id_state_map, source);
1068 } 1060 }
1069 1061
1070 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { 1062 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
1071 DCHECK(!sync_loop_); 1063 DCHECK(!sync_loop_);
1072 sync_loop_ = options.sync_loop; 1064 sync_loop_ = options.sync_loop;
1073 DCHECK(sync_loop_); 1065 DCHECK(sync_loop_);
1074 1066
1075 // Blow away the partial or corrupt sync data folder before doing any more 1067 // Blow away the partial or corrupt sync data folder before doing any more
1076 // initialization, if necessary. 1068 // initialization, if necessary.
1077 if (options.delete_sync_data_folder) { 1069 if (options.delete_sync_data_folder) {
1078 DeleteSyncDataFolder(); 1070 DeleteSyncDataFolder();
1079 } 1071 }
1080 1072
1081 // Make sure that the directory exists before initializing the backend. 1073 // Make sure that the directory exists before initializing the backend.
1082 // If it already exists, this will do no harm. 1074 // If it already exists, this will do no harm.
1083 if (!file_util::CreateDirectory(sync_data_folder_path_)) { 1075 if (!file_util::CreateDirectory(sync_data_folder_path_)) {
1084 DLOG(FATAL) << "Sync Data directory creation failed."; 1076 DLOG(FATAL) << "Sync Data directory creation failed.";
1085 } 1077 }
1086 1078
1087 DCHECK(!registrar_); 1079 DCHECK(!registrar_);
1088 registrar_ = options.registrar; 1080 registrar_ = options.registrar;
1089 DCHECK(registrar_); 1081 DCHECK(registrar_);
1090 1082
1091 DCHECK(!chrome_sync_notification_bridge_); 1083 DCHECK(!chrome_sync_notification_bridge_);
1092 chrome_sync_notification_bridge_ = options.chrome_sync_notification_bridge; 1084 chrome_sync_notification_bridge_ = options.chrome_sync_notification_bridge;
1093 DCHECK(chrome_sync_notification_bridge_); 1085 DCHECK(chrome_sync_notification_bridge_);
1094 1086
1087 #if defined(OS_ANDROID)
1088 // Android uses ChromeSyncNotificationBridge exclusively.
1089 const syncer::InvalidatorState kDefaultInvalidatorState =
1090 syncer::INVALIDATIONS_ENABLED;
1091 #else
1092 const syncer::InvalidatorState kDefaultInvalidatorState =
1093 syncer::DEFAULT_INVALIDATION_ERROR;
1094 #endif
1095
1095 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); 1096 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_);
1096 sync_manager_->AddObserver(this); 1097 sync_manager_->AddObserver(this);
1097 sync_manager_->Init( 1098 sync_manager_->Init(
1098 sync_data_folder_path_, 1099 sync_data_folder_path_,
1099 options.event_handler, 1100 options.event_handler,
1100 options.service_url.host() + options.service_url.path(), 1101 options.service_url.host() + options.service_url.path(),
1101 options.service_url.EffectiveIntPort(), 1102 options.service_url.EffectiveIntPort(),
1102 options.service_url.SchemeIsSecure(), 1103 options.service_url.SchemeIsSecure(),
1103 BrowserThread::GetBlockingPool(), 1104 BrowserThread::GetBlockingPool(),
1104 options.make_http_bridge_factory_fn.Run().Pass(), 1105 options.make_http_bridge_factory_fn.Run().Pass(),
1105 options.workers, 1106 options.workers,
1106 options.extensions_activity_monitor, 1107 options.extensions_activity_monitor,
1107 options.registrar /* as SyncManager::ChangeDelegate */, 1108 options.registrar /* as SyncManager::ChangeDelegate */,
1108 options.credentials, 1109 options.credentials,
1109 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( 1110 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator(
1110 options.chrome_sync_notification_bridge, 1111 options.chrome_sync_notification_bridge,
1111 options.invalidator_factory->CreateInvalidator())), 1112 options.invalidator_factory->CreateInvalidator(),
1113 kDefaultInvalidatorState)),
1112 options.restored_key_for_bootstrapping, 1114 options.restored_key_for_bootstrapping,
1113 options.restored_keystore_key_for_bootstrapping, 1115 options.restored_keystore_key_for_bootstrapping,
1114 scoped_ptr<InternalComponentsFactory>( 1116 scoped_ptr<InternalComponentsFactory>(
1115 options.internal_components_factory), 1117 options.internal_components_factory),
1116 &encryptor_, 1118 &encryptor_,
1117 options.unrecoverable_error_handler, 1119 options.unrecoverable_error_handler,
1118 options.report_unrecoverable_error_function); 1120 options.report_unrecoverable_error_function);
1119 1121
1120 // |sync_manager_| may end up being NULL here in tests (in 1122 // |sync_manager_| may end up being NULL here in tests (in
1121 // synchronous initialization mode). 1123 // synchronous initialization mode).
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 } 1425 }
1424 1426
1425 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1427 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1426 const syncer::SyncProtocolError& sync_error) { 1428 const syncer::SyncProtocolError& sync_error) {
1427 if (!frontend_) 1429 if (!frontend_)
1428 return; 1430 return;
1429 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1431 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1430 frontend_->OnActionableError(sync_error); 1432 frontend_->OnActionableError(sync_error);
1431 } 1433 }
1432 1434
1433 void SyncBackendHost::HandleNotificationsEnabledOnFrontendLoop() { 1435 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop(
1436 syncer::InvalidatorState state) {
1434 if (!frontend_) 1437 if (!frontend_)
1435 return; 1438 return;
1436 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1439 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1437 frontend_->OnNotificationsEnabled(); 1440 frontend_->OnInvalidatorStateChange(state);
1438 } 1441 }
1439 1442
1440 void SyncBackendHost::HandleNotificationsDisabledOnFrontendLoop( 1443 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop(
1441 syncer::NotificationsDisabledReason reason) { 1444 const syncer::ObjectIdStateMap& id_state_map,
1445 syncer::IncomingInvalidationSource source) {
1442 if (!frontend_) 1446 if (!frontend_)
1443 return; 1447 return;
1444 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1448 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1445 frontend_->OnNotificationsDisabled(reason); 1449 frontend_->OnIncomingInvalidation(id_state_map, source);
1446 }
1447
1448 void SyncBackendHost::HandleIncomingNotificationOnFrontendLoop(
1449 const syncer::ObjectIdStateMap& id_state_map,
1450 syncer::IncomingNotificationSource source) {
1451 if (!frontend_)
1452 return;
1453 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1454 frontend_->OnIncomingNotification(id_state_map, source);
1455 } 1450 }
1456 1451
1457 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1452 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1458 const std::string& passphrase) const { 1453 const std::string& passphrase) const {
1459 DCHECK(cached_pending_keys_.has_blob()); 1454 DCHECK(cached_pending_keys_.has_blob());
1460 DCHECK(!passphrase.empty()); 1455 DCHECK(!passphrase.empty());
1461 syncer::Nigori nigori; 1456 syncer::Nigori nigori;
1462 nigori.InitByDerivation("localhost", "dummy", passphrase); 1457 nigori.InitByDerivation("localhost", "dummy", passphrase);
1463 std::string plaintext; 1458 std::string plaintext;
1464 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1459 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 const syncer::ModelTypeSet failed_configuration_types) { 1542 const syncer::ModelTypeSet failed_configuration_types) {
1548 HandleInitializationCompletedOnFrontendLoop( 1543 HandleInitializationCompletedOnFrontendLoop(
1549 failed_configuration_types.Empty()); 1544 failed_configuration_types.Empty());
1550 } 1545 }
1551 1546
1552 #undef SDVLOG 1547 #undef SDVLOG
1553 1548
1554 #undef SLOG 1549 #undef SLOG
1555 1550
1556 } // namespace browser_sync 1551 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/glue/sync_backend_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698