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

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/sync/engine/syncapi.h" 5 #include "chrome/browser/sync/engine/syncapi.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <iomanip> 9 #include <iomanip>
10 #include <list> 10 #include <list>
11 #include <string> 11 #include <string>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "chrome/browser/sync/syncable/directory_manager.h" 47 #include "chrome/browser/sync/syncable/directory_manager.h"
48 #include "chrome/browser/sync/syncable/syncable.h" 48 #include "chrome/browser/sync/syncable/syncable.h"
49 #include "chrome/browser/sync/util/character_set_converters.h" 49 #include "chrome/browser/sync/util/character_set_converters.h"
50 #include "chrome/browser/sync/util/closure.h" 50 #include "chrome/browser/sync/util/closure.h"
51 #include "chrome/browser/sync/util/crypto_helpers.h" 51 #include "chrome/browser/sync/util/crypto_helpers.h"
52 #include "chrome/browser/sync/util/path_helpers.h" 52 #include "chrome/browser/sync/util/path_helpers.h"
53 #include "chrome/browser/sync/util/user_settings.h" 53 #include "chrome/browser/sync/util/user_settings.h"
54 #include "chrome/common/chrome_switches.h" 54 #include "chrome/common/chrome_switches.h"
55 #include "chrome/common/deprecated/event_sys.h" 55 #include "chrome/common/deprecated/event_sys.h"
56 #include "chrome/common/net/gaia/gaia_authenticator.h" 56 #include "chrome/common/net/gaia/gaia_authenticator.h"
57 #include "chrome/common/net/network_change_notifier_proxy.h"
58 #include "chrome/common/net/notifier/listener/mediator_thread_impl.h" 57 #include "chrome/common/net/notifier/listener/mediator_thread_impl.h"
59 #include "chrome/common/net/notifier/listener/notification_constants.h" 58 #include "chrome/common/net/notifier/listener/notification_constants.h"
60 #include "chrome/common/net/notifier/listener/talk_mediator.h" 59 #include "chrome/common/net/notifier/listener/talk_mediator.h"
61 #include "chrome/common/net/notifier/listener/talk_mediator_impl.h" 60 #include "chrome/common/net/notifier/listener/talk_mediator_impl.h"
62 #include "net/base/network_change_notifier.h" 61 #include "net/base/network_change_notifier.h"
63 62
64 using browser_sync::AllStatus; 63 using browser_sync::AllStatus;
65 using browser_sync::AllStatusEvent; 64 using browser_sync::AllStatusEvent;
66 using browser_sync::AuthWatcher; 65 using browser_sync::AuthWatcher;
67 using browser_sync::AuthWatcherEvent; 66 using browser_sync::AuthWatcherEvent;
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 DCHECK(!core_message_loop_); 875 DCHECK(!core_message_loop_);
877 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 876 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
878 } 877 }
879 878
880 bool Init(const FilePath& database_location, 879 bool Init(const FilePath& database_location,
881 const std::string& sync_server_and_path, 880 const std::string& sync_server_and_path,
882 int port, 881 int port,
883 const char* gaia_service_id, 882 const char* gaia_service_id,
884 const char* gaia_source, 883 const char* gaia_source,
885 bool use_ssl, 884 bool use_ssl,
886 chrome_common_net::NetworkChangeNotifierThread*
887 network_change_notifier_thread,
888 HttpPostProviderFactory* post_factory, 885 HttpPostProviderFactory* post_factory,
889 HttpPostProviderFactory* auth_post_factory, 886 HttpPostProviderFactory* auth_post_factory,
890 ModelSafeWorkerRegistrar* model_safe_worker_registrar, 887 ModelSafeWorkerRegistrar* model_safe_worker_registrar,
891 bool attempt_last_user_authentication, 888 bool attempt_last_user_authentication,
892 bool invalidate_last_user_auth_token, 889 bool invalidate_last_user_auth_token,
893 bool invalidate_xmpp_auth_token, 890 bool invalidate_xmpp_auth_token,
894 const char* user_agent, 891 const char* user_agent,
895 const std::string& lsid, 892 const std::string& lsid,
896 browser_sync::NotificationMethod notification_method); 893 browser_sync::NotificationMethod notification_method);
897 894
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 scoped_ptr<EventListenerHookup> authwatcher_hookup_; 1156 scoped_ptr<EventListenerHookup> authwatcher_hookup_;
1160 1157
1161 // Our cache of a recent authentication problem. If no authentication problem 1158 // Our cache of a recent authentication problem. If no authentication problem
1162 // occurred, or if the last problem encountered has been cleared (by a 1159 // occurred, or if the last problem encountered has been cleared (by a
1163 // subsequent AuthWatcherEvent), this is set to NONE. 1160 // subsequent AuthWatcherEvent), this is set to NONE.
1164 AuthError::State auth_problem_; 1161 AuthError::State auth_problem_;
1165 1162
1166 // The sync dir_manager to which we belong. 1163 // The sync dir_manager to which we belong.
1167 SyncManager* const sync_manager_; 1164 SyncManager* const sync_manager_;
1168 1165
1169 // An object that notifies us whenever there is a network-related
1170 // change (e.g., disconnections).
1171 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
1172
1173 // The entity that provides us with information about which types to sync. 1166 // The entity that provides us with information about which types to sync.
1174 // The instance is shared between the SyncManager and the Syncer. 1167 // The instance is shared between the SyncManager and the Syncer.
1175 ModelSafeWorkerRegistrar* registrar_; 1168 ModelSafeWorkerRegistrar* registrar_;
1176 1169
1177 // True if the next SyncCycle should notify peers of an update. 1170 // True if the next SyncCycle should notify peers of an update.
1178 bool notification_pending_; 1171 bool notification_pending_;
1179 1172
1180 // Set to true once Init has been called, and we know of an authenticated 1173 // Set to true once Init has been called, and we know of an authenticated
1181 // valid) username either from a fresh authentication attempt (as in 1174 // valid) username either from a fresh authentication attempt (as in
1182 // first-use case) or from a previous attempt stored in our UserSettings 1175 // first-use case) or from a previous attempt stored in our UserSettings
(...skipping 11 matching lines...) Expand all
1194 SyncManager::SyncManager() { 1187 SyncManager::SyncManager() {
1195 data_ = new SyncInternal(this); 1188 data_ = new SyncInternal(this);
1196 } 1189 }
1197 1190
1198 bool SyncManager::Init(const FilePath& database_location, 1191 bool SyncManager::Init(const FilePath& database_location,
1199 const char* sync_server_and_path, 1192 const char* sync_server_and_path,
1200 int sync_server_port, 1193 int sync_server_port,
1201 const char* gaia_service_id, 1194 const char* gaia_service_id,
1202 const char* gaia_source, 1195 const char* gaia_source,
1203 bool use_ssl, 1196 bool use_ssl,
1204 chrome_common_net::NetworkChangeNotifierThread*
1205 network_change_notifier_thread,
1206 HttpPostProviderFactory* post_factory, 1197 HttpPostProviderFactory* post_factory,
1207 HttpPostProviderFactory* auth_post_factory, 1198 HttpPostProviderFactory* auth_post_factory,
1208 ModelSafeWorkerRegistrar* registrar, 1199 ModelSafeWorkerRegistrar* registrar,
1209 bool attempt_last_user_authentication, 1200 bool attempt_last_user_authentication,
1210 bool invalidate_last_user_auth_token, 1201 bool invalidate_last_user_auth_token,
1211 bool invalidate_xmpp_auth_token, 1202 bool invalidate_xmpp_auth_token,
1212 const char* user_agent, 1203 const char* user_agent,
1213 const char* lsid, 1204 const char* lsid,
1214 browser_sync::NotificationMethod notification_method) { 1205 browser_sync::NotificationMethod notification_method) {
1215 DCHECK(post_factory); 1206 DCHECK(post_factory);
1216 LOG(INFO) << "SyncManager starting Init..."; 1207 LOG(INFO) << "SyncManager starting Init...";
1217 string server_string(sync_server_and_path); 1208 string server_string(sync_server_and_path);
1218 return data_->Init(database_location, 1209 return data_->Init(database_location,
1219 server_string, 1210 server_string,
1220 sync_server_port, 1211 sync_server_port,
1221 gaia_service_id, 1212 gaia_service_id,
1222 gaia_source, 1213 gaia_source,
1223 use_ssl, 1214 use_ssl,
1224 network_change_notifier_thread,
1225 post_factory, 1215 post_factory,
1226 auth_post_factory, 1216 auth_post_factory,
1227 registrar, 1217 registrar,
1228 attempt_last_user_authentication, 1218 attempt_last_user_authentication,
1229 invalidate_last_user_auth_token, 1219 invalidate_last_user_auth_token,
1230 invalidate_xmpp_auth_token, 1220 invalidate_xmpp_auth_token,
1231 user_agent, 1221 user_agent,
1232 lsid, 1222 lsid,
1233 notification_method); 1223 notification_method);
1234 } 1224 }
(...skipping 29 matching lines...) Expand all
1264 return data_->username_for_share(); 1254 return data_->username_for_share();
1265 } 1255 }
1266 1256
1267 bool SyncManager::SyncInternal::Init( 1257 bool SyncManager::SyncInternal::Init(
1268 const FilePath& database_location, 1258 const FilePath& database_location,
1269 const std::string& sync_server_and_path, 1259 const std::string& sync_server_and_path,
1270 int port, 1260 int port,
1271 const char* gaia_service_id, 1261 const char* gaia_service_id,
1272 const char* gaia_source, 1262 const char* gaia_source,
1273 bool use_ssl, 1263 bool use_ssl,
1274 chrome_common_net::NetworkChangeNotifierThread*
1275 network_change_notifier_thread,
1276 HttpPostProviderFactory* post_factory, 1264 HttpPostProviderFactory* post_factory,
1277 HttpPostProviderFactory* auth_post_factory, 1265 HttpPostProviderFactory* auth_post_factory,
1278 ModelSafeWorkerRegistrar* model_safe_worker_registrar, 1266 ModelSafeWorkerRegistrar* model_safe_worker_registrar,
1279 bool attempt_last_user_authentication, 1267 bool attempt_last_user_authentication,
1280 bool invalidate_last_user_auth_token, 1268 bool invalidate_last_user_auth_token,
1281 bool invalidate_xmpp_auth_token, 1269 bool invalidate_xmpp_auth_token,
1282 const char* user_agent, 1270 const char* user_agent,
1283 const std::string& lsid, 1271 const std::string& lsid,
1284 browser_sync::NotificationMethod notification_method) { 1272 browser_sync::NotificationMethod notification_method) {
1285 1273
(...skipping 17 matching lines...) Expand all
1303 share_.dir_manager.reset(new DirectoryManager(database_location)); 1291 share_.dir_manager.reset(new DirectoryManager(database_location));
1304 1292
1305 string client_id = user_settings_->GetClientId(); 1293 string client_id = user_settings_->GetClientId();
1306 connection_manager_.reset(new SyncAPIServerConnectionManager( 1294 connection_manager_.reset(new SyncAPIServerConnectionManager(
1307 sync_server_and_path, port, use_ssl, user_agent, client_id, 1295 sync_server_and_path, port, use_ssl, user_agent, client_id,
1308 post_factory)); 1296 post_factory));
1309 1297
1310 // Watch various objects for aggregated status. 1298 // Watch various objects for aggregated status.
1311 allstatus_.WatchConnectionManager(connection_manager()); 1299 allstatus_.WatchConnectionManager(connection_manager());
1312 1300
1313 network_change_notifier_.reset( 1301 net::NetworkChangeNotifier::AddObserver(this);
1314 new chrome_common_net::NetworkChangeNotifierProxy( 1302 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we
1315 network_change_notifier_thread)); 1303 // try to shut down sync. Fix this.
1316 network_change_notifier_->AddObserver(this);
1317 // TODO(akalin): CheckServerReachable() can block, which may cause
1318 // jank if we try to shut down sync. Fix this.
1319 connection_manager()->CheckServerReachable(); 1304 connection_manager()->CheckServerReachable();
1320 1305
1321 // NOTIFICATION_SERVER uses a substantially different notification 1306 // NOTIFICATION_SERVER uses a substantially different notification method, so
1322 // method, so it has its own MediatorThread implementation. 1307 // it has its own MediatorThread implementation. Everything else just uses
1323 // Everything else just uses MediatorThreadImpl. 1308 // MediatorThreadImpl.
1324 notifier::MediatorThread* mediator_thread = 1309 notifier::MediatorThread* mediator_thread =
1325 (notification_method == browser_sync::NOTIFICATION_SERVER) ? 1310 (notification_method == browser_sync::NOTIFICATION_SERVER) ?
1326 static_cast<notifier::MediatorThread*>( 1311 new sync_notifier::ServerNotifierThread() :
1327 new sync_notifier::ServerNotifierThread( 1312 new notifier::MediatorThreadImpl();
1328 network_change_notifier_thread)) :
1329 static_cast<notifier::MediatorThread*>(
1330 new notifier::MediatorThreadImpl(network_change_notifier_thread));
1331 const bool kInitializeSsl = true; 1313 const bool kInitializeSsl = true;
1332 const bool kConnectImmediately = false; 1314 const bool kConnectImmediately = false;
1333 talk_mediator_.reset(new TalkMediatorImpl( 1315 talk_mediator_.reset(new TalkMediatorImpl(mediator_thread, kInitializeSsl,
1334 mediator_thread, 1316 kConnectImmediately, invalidate_xmpp_auth_token));
1335 kInitializeSsl, kConnectImmediately, invalidate_xmpp_auth_token));
1336 if (notification_method != browser_sync::NOTIFICATION_LEGACY && 1317 if (notification_method != browser_sync::NOTIFICATION_LEGACY &&
1337 notification_method != browser_sync::NOTIFICATION_SERVER) { 1318 notification_method != browser_sync::NOTIFICATION_SERVER) {
1338 if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) { 1319 if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) {
1339 talk_mediator_->AddSubscribedServiceUrl( 1320 talk_mediator_->AddSubscribedServiceUrl(
1340 browser_sync::kSyncLegacyServiceUrl); 1321 browser_sync::kSyncLegacyServiceUrl);
1341 } 1322 }
1342 talk_mediator_->AddSubscribedServiceUrl(browser_sync::kSyncServiceUrl); 1323 talk_mediator_->AddSubscribedServiceUrl(browser_sync::kSyncServiceUrl);
1343 } 1324 }
1344 1325
1345 // Listen to TalkMediator events ourselves 1326 // Listen to TalkMediator events ourselves
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 // HandleAuthWatcherEvent(), and HandleTalkMediatorEvent() for the 1569 // HandleAuthWatcherEvent(), and HandleTalkMediatorEvent() for the
1589 // events that may be posted.) 1570 // events that may be posted.)
1590 { 1571 {
1591 CHECK(core_message_loop_); 1572 CHECK(core_message_loop_);
1592 bool old_state = core_message_loop_->NestableTasksAllowed(); 1573 bool old_state = core_message_loop_->NestableTasksAllowed();
1593 core_message_loop_->SetNestableTasksAllowed(true); 1574 core_message_loop_->SetNestableTasksAllowed(true);
1594 core_message_loop_->RunAllPending(); 1575 core_message_loop_->RunAllPending();
1595 core_message_loop_->SetNestableTasksAllowed(old_state); 1576 core_message_loop_->SetNestableTasksAllowed(old_state);
1596 } 1577 }
1597 1578
1598 if (network_change_notifier_.get()) { 1579 net::NetworkChangeNotifier::RemoveObserver(this);
1599 network_change_notifier_->RemoveObserver(this);
1600 network_change_notifier_.reset();
1601 }
1602 1580
1603 if (dir_manager()) { 1581 if (dir_manager()) {
1604 dir_manager()->FinalSaveChangesForAll(); 1582 dir_manager()->FinalSaveChangesForAll();
1605 dir_manager()->Close(username_for_share()); 1583 dir_manager()->Close(username_for_share());
1606 } 1584 }
1607 1585
1608 // Reset the DirectoryManager and UserSettings so they relinquish sqlite 1586 // Reset the DirectoryManager and UserSettings so they relinquish sqlite
1609 // handles to backing files. 1587 // handles to backing files.
1610 share_.dir_manager.reset(); 1588 share_.dir_manager.reset();
1611 user_settings_.reset(); 1589 user_settings_.reset();
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 UserShare* SyncManager::GetUserShare() const { 2098 UserShare* SyncManager::GetUserShare() const {
2121 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; 2099 DCHECK(data_->initialized()) << "GetUserShare requires initialization!";
2122 return data_->GetUserShare(); 2100 return data_->GetUserShare();
2123 } 2101 }
2124 2102
2125 SyncManager::ExtraAutofillChangeRecordData::~ExtraAutofillChangeRecordData() { 2103 SyncManager::ExtraAutofillChangeRecordData::~ExtraAutofillChangeRecordData() {
2126 delete pre_deletion_data; 2104 delete pre_deletion_data;
2127 } 2105 }
2128 2106
2129 } // namespace sync_api 2107 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698