Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 28 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 29 #include "chrome/browser/sync/internal_api/base_transaction.h" | 29 #include "chrome/browser/sync/internal_api/base_transaction.h" |
| 30 #include "chrome/browser/sync/internal_api/read_transaction.h" | 30 #include "chrome/browser/sync/internal_api/read_transaction.h" |
| 31 #include "chrome/browser/sync/notifier/sync_notifier.h" | 31 #include "chrome/browser/sync/notifier/sync_notifier.h" |
| 32 #include "chrome/browser/sync/protocol/encryption.pb.h" | 32 #include "chrome/browser/sync/protocol/encryption.pb.h" |
| 33 #include "chrome/browser/sync/protocol/sync.pb.h" | 33 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 34 #include "chrome/browser/sync/sessions/session_state.h" | 34 #include "chrome/browser/sync/sessions/session_state.h" |
| 35 #include "chrome/browser/sync/sync_prefs.h" | 35 #include "chrome/browser/sync/sync_prefs.h" |
| 36 #include "chrome/browser/sync/util/nigori.h" | 36 #include "chrome/browser/sync/util/nigori.h" |
| 37 #include "chrome/common/chrome_notification_types.h" | 37 #include "chrome/common/chrome_notification_types.h" |
| 38 #include "chrome/common/chrome_switches.h" | |
| 38 #include "chrome/common/chrome_version_info.h" | 39 #include "chrome/common/chrome_version_info.h" |
| 39 #include "chrome/common/net/gaia/gaia_constants.h" | 40 #include "chrome/common/net/gaia/gaia_constants.h" |
| 40 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| 42 #include "content/public/common/content_client.h" | 43 #include "content/public/common/content_client.h" |
| 44 #include "jingle/notifier/base/notification_method.h" | |
| 45 #include "jingle/notifier/base/notifier_options.h" | |
| 46 #include "net/base/host_port_pair.h" | |
| 47 #include "net/url_request/url_request_context_getter.h" | |
| 43 | 48 |
| 44 static const int kSaveChangesIntervalSeconds = 10; | 49 static const int kSaveChangesIntervalSeconds = 10; |
| 45 static const FilePath::CharType kSyncDataFolderName[] = | 50 static const FilePath::CharType kSyncDataFolderName[] = |
| 46 FILE_PATH_LITERAL("Sync Data"); | 51 FILE_PATH_LITERAL("Sync Data"); |
| 47 | 52 |
| 48 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; | 53 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; |
| 49 | 54 |
| 50 typedef GoogleServiceAuthError AuthError; | 55 typedef GoogleServiceAuthError AuthError; |
| 51 | 56 |
| 52 namespace browser_sync { | 57 namespace browser_sync { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 222 |
| 218 // Our encryptor, which uses Chrome's encryption functions. | 223 // Our encryptor, which uses Chrome's encryption functions. |
| 219 ChromeEncryptor encryptor_; | 224 ChromeEncryptor encryptor_; |
| 220 | 225 |
| 221 // The top-level syncapi entry point. Lives on the sync thread. | 226 // The top-level syncapi entry point. Lives on the sync thread. |
| 222 scoped_ptr<sync_api::SyncManager> sync_manager_; | 227 scoped_ptr<sync_api::SyncManager> sync_manager_; |
| 223 | 228 |
| 224 DISALLOW_COPY_AND_ASSIGN(Core); | 229 DISALLOW_COPY_AND_ASSIGN(Core); |
| 225 }; | 230 }; |
| 226 | 231 |
| 232 namespace { | |
| 233 | |
| 234 // Parses the given command line for notifier options. | |
| 235 notifier::NotifierOptions ParseNotifierOptions( | |
|
Nicolas Zea
2012/03/06 19:00:58
Can this be in it's own file within glue/ (so sync
akalin
2012/03/06 22:27:57
Ideally, sync_listen_notifications wouldn't depend
| |
| 236 const CommandLine& command_line, | |
| 237 const scoped_refptr<net::URLRequestContextGetter>& | |
| 238 request_context_getter) { | |
| 239 notifier::NotifierOptions notifier_options; | |
| 240 notifier_options.request_context_getter = request_context_getter; | |
| 241 | |
| 242 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { | |
| 243 notifier_options.xmpp_host_port = | |
| 244 net::HostPortPair::FromString( | |
| 245 command_line.GetSwitchValueASCII( | |
| 246 switches::kSyncNotificationHostPort)); | |
| 247 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() | |
| 248 << " for test sync notification server."; | |
| 249 } | |
| 250 | |
| 251 notifier_options.try_ssltcp_first = | |
| 252 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); | |
| 253 if (notifier_options.try_ssltcp_first) | |
| 254 DVLOG(1) << "Trying SSL/TCP port before XMPP port for notifications."; | |
|
Nicolas Zea
2012/03/06 19:00:58
dvlog_if (here and below)
akalin
2012/03/06 22:27:57
Done. Also fixed sync_listen_notifications to use
| |
| 255 | |
| 256 notifier_options.invalidate_xmpp_login = | |
| 257 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); | |
| 258 if (notifier_options.invalidate_xmpp_login) { | |
| 259 DVLOG(1) << "Invalidating sync XMPP login."; | |
| 260 } | |
| 261 | |
| 262 notifier_options.allow_insecure_connection = | |
| 263 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); | |
| 264 if (notifier_options.allow_insecure_connection) { | |
| 265 DVLOG(1) << "Allowing insecure XMPP connections."; | |
| 266 } | |
| 267 | |
| 268 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { | |
| 269 const std::string notification_method_str( | |
| 270 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); | |
| 271 notifier_options.notification_method = | |
| 272 notifier::StringToNotificationMethod(notification_method_str); | |
| 273 } | |
| 274 | |
| 275 return notifier_options; | |
| 276 } | |
| 277 | |
| 278 } // namespace | |
| 279 | |
| 227 SyncBackendHost::SyncBackendHost(const std::string& name, | 280 SyncBackendHost::SyncBackendHost(const std::string& name, |
| 228 Profile* profile, | 281 Profile* profile, |
| 229 const base::WeakPtr<SyncPrefs>& sync_prefs) | 282 const base::WeakPtr<SyncPrefs>& sync_prefs) |
| 230 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 283 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 231 sync_thread_("Chrome_SyncThread"), | 284 sync_thread_("Chrome_SyncThread"), |
| 232 frontend_loop_(MessageLoop::current()), | 285 frontend_loop_(MessageLoop::current()), |
| 233 profile_(profile), | 286 profile_(profile), |
| 234 name_(name), | 287 name_(name), |
| 235 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), | 288 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), |
| 236 weak_ptr_factory_.GetWeakPtr())), | 289 weak_ptr_factory_.GetWeakPtr())), |
| 237 initialization_state_(NOT_ATTEMPTED), | 290 initialization_state_(NOT_ATTEMPTED), |
| 238 sync_prefs_(sync_prefs), | 291 sync_prefs_(sync_prefs), |
| 239 chrome_sync_notification_bridge_(profile_), | 292 chrome_sync_notification_bridge_(profile_), |
| 240 sync_notifier_factory_( | 293 sync_notifier_factory_( |
| 294 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
| 295 profile_->GetRequestContext()), | |
| 241 content::GetUserAgent(GURL()), | 296 content::GetUserAgent(GURL()), |
| 242 profile_->GetRequestContext(), | 297 sync_prefs), |
| 243 sync_prefs, | |
| 244 *CommandLine::ForCurrentProcess()), | |
| 245 frontend_(NULL), | 298 frontend_(NULL), |
| 246 last_auth_error_(AuthError::None()) { | 299 last_auth_error_(AuthError::None()) { |
| 247 } | 300 } |
| 248 | 301 |
| 249 SyncBackendHost::SyncBackendHost(Profile* profile) | 302 SyncBackendHost::SyncBackendHost(Profile* profile) |
| 250 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 303 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 251 sync_thread_("Chrome_SyncThread"), | 304 sync_thread_("Chrome_SyncThread"), |
| 252 frontend_loop_(MessageLoop::current()), | 305 frontend_loop_(MessageLoop::current()), |
| 253 profile_(profile), | 306 profile_(profile), |
| 254 name_("Unknown"), | 307 name_("Unknown"), |
| 255 initialization_state_(NOT_ATTEMPTED), | 308 initialization_state_(NOT_ATTEMPTED), |
| 256 chrome_sync_notification_bridge_(profile_), | 309 chrome_sync_notification_bridge_(profile_), |
| 257 sync_notifier_factory_( | 310 sync_notifier_factory_( |
| 311 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
| 312 profile_->GetRequestContext()), | |
| 258 content::GetUserAgent(GURL()), | 313 content::GetUserAgent(GURL()), |
| 259 NULL, | 314 base::WeakPtr<sync_notifier::InvalidationVersionTracker>()), |
| 260 base::WeakPtr<sync_notifier::InvalidationVersionTracker>(), | |
| 261 *CommandLine::ForCurrentProcess()), | |
| 262 frontend_(NULL), | 315 frontend_(NULL), |
| 263 last_auth_error_(AuthError::None()) { | 316 last_auth_error_(AuthError::None()) { |
| 264 } | 317 } |
| 265 | 318 |
| 266 SyncBackendHost::~SyncBackendHost() { | 319 SyncBackendHost::~SyncBackendHost() { |
| 267 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 320 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| 268 DCHECK(!registrar_.get()); | 321 DCHECK(!registrar_.get()); |
| 269 } | 322 } |
| 270 | 323 |
| 271 namespace { | 324 namespace { |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1314 FROM_HERE, | 1367 FROM_HERE, |
| 1315 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1368 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| 1316 core_.get(), sync_thread_done_callback)); | 1369 core_.get(), sync_thread_done_callback)); |
| 1317 } | 1370 } |
| 1318 | 1371 |
| 1319 #undef SDVLOG | 1372 #undef SDVLOG |
| 1320 | 1373 |
| 1321 #undef SLOG | 1374 #undef SLOG |
| 1322 | 1375 |
| 1323 } // namespace browser_sync | 1376 } // namespace browser_sync |
| OLD | NEW |