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/dummy_invalidator.h" | |
35 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 31 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
36 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 32 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
37 #include "chrome/browser/sync/sync_prefs.h" | 33 #include "chrome/browser/sync/sync_prefs.h" |
38 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
39 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
40 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
41 #include "chrome/common/chrome_version_info.h" | 37 #include "chrome/common/chrome_version_info.h" |
42 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/notification_details.h" | 39 #include "content/public/browser/notification_details.h" |
44 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
46 #include "content/public/common/content_client.h" | 42 #include "content/public/common/content_client.h" |
47 #include "google_apis/gaia/gaia_constants.h" | 43 #include "google_apis/gaia/gaia_constants.h" |
48 #include "jingle/notifier/base/notification_method.h" | 44 #include "jingle/notifier/base/notification_method.h" |
49 #include "jingle/notifier/base/notifier_options.h" | 45 #include "jingle/notifier/base/notifier_options.h" |
50 #include "net/base/host_port_pair.h" | 46 #include "net/base/host_port_pair.h" |
51 #include "net/url_request/url_request_context_getter.h" | 47 #include "net/url_request/url_request_context_getter.h" |
52 #include "sync/internal_api/public/base_transaction.h" | 48 #include "sync/internal_api/public/base_transaction.h" |
53 #include "sync/internal_api/public/engine/model_safe_worker.h" | 49 #include "sync/internal_api/public/engine/model_safe_worker.h" |
54 #include "sync/internal_api/public/http_bridge.h" | 50 #include "sync/internal_api/public/http_bridge.h" |
55 #include "sync/internal_api/public/internal_components_factory_impl.h" | 51 #include "sync/internal_api/public/internal_components_factory_impl.h" |
56 #include "sync/internal_api/public/read_transaction.h" | 52 #include "sync/internal_api/public/read_transaction.h" |
57 #include "sync/internal_api/public/sync_manager_factory.h" | 53 #include "sync/internal_api/public/sync_manager_factory.h" |
58 #include "sync/internal_api/public/util/experiments.h" | 54 #include "sync/internal_api/public/util/experiments.h" |
59 #include "sync/internal_api/public/util/sync_string_conversions.h" | 55 #include "sync/internal_api/public/util/sync_string_conversions.h" |
60 #include "sync/notifier/invalidator.h" | |
61 #include "sync/protocol/encryption.pb.h" | 56 #include "sync/protocol/encryption.pb.h" |
62 #include "sync/protocol/sync.pb.h" | 57 #include "sync/protocol/sync.pb.h" |
63 #include "sync/util/nigori.h" | 58 #include "sync/util/nigori.h" |
64 | 59 |
65 #if defined(ENABLE_MANAGED_USERS) | 60 #if defined(ENABLE_MANAGED_USERS) |
66 #include "chrome/browser/managed_mode/managed_user_service.h" | 61 #include "chrome/browser/managed_mode/managed_user_service.h" |
67 #endif | 62 #endif |
68 | 63 |
69 static const int kSaveChangesIntervalSeconds = 10; | 64 static const int kSaveChangesIntervalSeconds = 10; |
70 static const base::FilePath::CharType kSyncDataFolderName[] = | 65 static const base::FilePath::CharType kSyncDataFolderName[] = |
(...skipping 29 matching lines...) Expand all Loading... |
100 // Helper macros to log with the syncer thread name; useful when there | 95 // Helper macros to log with the syncer thread name; useful when there |
101 // are multiple syncers involved. | 96 // are multiple syncers involved. |
102 | 97 |
103 #define SLOG(severity) LOG(severity) << name_ << ": " | 98 #define SLOG(severity) LOG(severity) << name_ << ": " |
104 | 99 |
105 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 100 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
106 | 101 |
107 class SyncBackendHost::Core | 102 class SyncBackendHost::Core |
108 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 103 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
109 public syncer::SyncEncryptionHandler::Observer, | 104 public syncer::SyncEncryptionHandler::Observer, |
110 public syncer::SyncManager::Observer, | 105 public syncer::SyncManager::Observer { |
111 public syncer::InvalidationHandler { | |
112 public: | 106 public: |
113 Core(const std::string& name, | 107 Core(const std::string& name, |
114 const base::FilePath& sync_data_folder_path, | 108 const base::FilePath& sync_data_folder_path, |
115 const base::WeakPtr<SyncBackendHost>& backend); | 109 const base::WeakPtr<SyncBackendHost>& backend); |
116 | 110 |
117 // SyncManager::Observer implementation. The Core just acts like an air | 111 // SyncManager::Observer implementation. The Core just acts like an air |
118 // traffic controller here, forwarding incoming messages to appropriate | 112 // traffic controller here, forwarding incoming messages to appropriate |
119 // landing threads. | 113 // landing threads. |
120 virtual void OnSyncCycleCompleted( | 114 virtual void OnSyncCycleCompleted( |
121 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 115 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... |
142 syncer::BootstrapTokenType type) OVERRIDE; | 136 syncer::BootstrapTokenType type) OVERRIDE; |
143 virtual void OnEncryptedTypesChanged( | 137 virtual void OnEncryptedTypesChanged( |
144 syncer::ModelTypeSet encrypted_types, | 138 syncer::ModelTypeSet encrypted_types, |
145 bool encrypt_everything) OVERRIDE; | 139 bool encrypt_everything) OVERRIDE; |
146 virtual void OnEncryptionComplete() OVERRIDE; | 140 virtual void OnEncryptionComplete() OVERRIDE; |
147 virtual void OnCryptographerStateChanged( | 141 virtual void OnCryptographerStateChanged( |
148 syncer::Cryptographer* cryptographer) OVERRIDE; | 142 syncer::Cryptographer* cryptographer) OVERRIDE; |
149 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, | 143 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, |
150 base::Time passphrase_time) OVERRIDE; | 144 base::Time passphrase_time) OVERRIDE; |
151 | 145 |
152 // syncer::InvalidationHandler implementation. | 146 // Forwards an invalidation state change to the sync manager. |
153 virtual void OnInvalidatorStateChange( | 147 void DoOnInvalidatorStateChange(syncer::InvalidatorState state); |
154 syncer::InvalidatorState state) OVERRIDE; | 148 |
155 virtual void OnIncomingInvalidation( | 149 // Forwards an invalidation to the sync manager. |
156 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 150 void DoOnIncomingInvalidation( |
| 151 syncer::ObjectIdInvalidationMap invalidation_map); |
157 | 152 |
158 // Note: | 153 // Note: |
159 // | 154 // |
160 // The Do* methods are the various entry points from our | 155 // The Do* methods are the various entry points from our |
161 // SyncBackendHost. They are all called on the sync thread to | 156 // SyncBackendHost. They are all called on the sync thread to |
162 // actually perform synchronous (and potentially blocking) syncapi | 157 // actually perform synchronous (and potentially blocking) syncapi |
163 // operations. | 158 // operations. |
164 // | 159 // |
165 // Called to perform initialization of the syncapi on behalf of | 160 // Called to perform initialization of the syncapi on behalf of |
166 // SyncBackendHost::Initialize. | 161 // SyncBackendHost::Initialize. |
167 void DoInitialize(const DoInitializeOptions& options); | 162 void DoInitialize(const DoInitializeOptions& options); |
168 | 163 |
169 // Called to perform credential update on behalf of | 164 // Called to perform credential update on behalf of |
170 // SyncBackendHost::UpdateCredentials. | 165 // SyncBackendHost::UpdateCredentials. |
171 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); | 166 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); |
172 | 167 |
173 // Called to update the given registered ids on behalf of | |
174 // SyncBackendHost::UpdateRegisteredInvalidationIds. | |
175 void DoUpdateRegisteredInvalidationIds(const syncer::ObjectIdSet& ids); | |
176 | |
177 // Called to acknowledge an invalidation on behalf of | |
178 // SyncBackendHost::AcknowledgeInvalidation. | |
179 void DoAcknowledgeInvalidation(const invalidation::ObjectId& id, | |
180 const syncer::AckHandle& ack_handle); | |
181 | |
182 // Called to tell the syncapi to start syncing (generally after | 168 // Called to tell the syncapi to start syncing (generally after |
183 // initialization and authentication). | 169 // initialization and authentication). |
184 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); | 170 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); |
185 | 171 |
186 // Called to set the passphrase for encryption. | 172 // Called to set the passphrase for encryption. |
187 void DoSetEncryptionPassphrase(const std::string& passphrase, | 173 void DoSetEncryptionPassphrase(const std::string& passphrase, |
188 bool is_explicit); | 174 bool is_explicit); |
189 | 175 |
190 // Called to decrypt the pending keys. | 176 // Called to decrypt the pending keys. |
191 void DoSetDecryptionPassphrase(const std::string& passphrase); | 177 void DoSetDecryptionPassphrase(const std::string& passphrase); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 288 |
303 // Our encryptor, which uses Chrome's encryption functions. | 289 // Our encryptor, which uses Chrome's encryption functions. |
304 ChromeEncryptor encryptor_; | 290 ChromeEncryptor encryptor_; |
305 | 291 |
306 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. | 292 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
307 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; | 293 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; |
308 | 294 |
309 // The top-level syncapi entry point. Lives on the sync thread. | 295 // The top-level syncapi entry point. Lives on the sync thread. |
310 scoped_ptr<syncer::SyncManager> sync_manager_; | 296 scoped_ptr<syncer::SyncManager> sync_manager_; |
311 | 297 |
312 // Whether or not we registered with |sync_manager_| as an invalidation | |
313 // handler. Necessary since we may end up trying to unregister before we | |
314 // register in tests (in synchronous initialization mode). | |
315 // | |
316 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
317 bool registered_as_invalidation_handler_; | |
318 | |
319 DISALLOW_COPY_AND_ASSIGN(Core); | 298 DISALLOW_COPY_AND_ASSIGN(Core); |
320 }; | 299 }; |
321 | 300 |
322 namespace { | |
323 | |
324 // Parses the given command line for notifier options. | |
325 notifier::NotifierOptions ParseNotifierOptions( | |
326 const CommandLine& command_line, | |
327 const scoped_refptr<net::URLRequestContextGetter>& | |
328 request_context_getter) { | |
329 notifier::NotifierOptions notifier_options; | |
330 notifier_options.request_context_getter = request_context_getter; | |
331 if (!command_line.HasSwitch(switches::kSyncDisableOAuth2Token)) | |
332 notifier_options.auth_mechanism = "X-OAUTH2"; | |
333 | |
334 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { | |
335 notifier_options.xmpp_host_port = | |
336 net::HostPortPair::FromString( | |
337 command_line.GetSwitchValueASCII( | |
338 switches::kSyncNotificationHostPort)); | |
339 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() | |
340 << " for test sync notification server."; | |
341 } | |
342 | |
343 notifier_options.try_ssltcp_first = | |
344 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); | |
345 DVLOG_IF(1, notifier_options.try_ssltcp_first) | |
346 << "Trying SSL/TCP port before XMPP port for notifications."; | |
347 | |
348 notifier_options.invalidate_xmpp_login = | |
349 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); | |
350 DVLOG_IF(1, notifier_options.invalidate_xmpp_login) | |
351 << "Invalidating sync XMPP login."; | |
352 | |
353 notifier_options.allow_insecure_connection = | |
354 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); | |
355 DVLOG_IF(1, notifier_options.allow_insecure_connection) | |
356 << "Allowing insecure XMPP connections."; | |
357 | |
358 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { | |
359 const std::string notification_method_str( | |
360 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); | |
361 notifier_options.notification_method = | |
362 notifier::StringToNotificationMethod(notification_method_str); | |
363 } | |
364 | |
365 return notifier_options; | |
366 } | |
367 | |
368 } // namespace | |
369 | |
370 SyncBackendHost::SyncBackendHost( | 301 SyncBackendHost::SyncBackendHost( |
371 const std::string& name, | 302 const std::string& name, |
372 Profile* profile, | 303 Profile* profile, |
373 const base::WeakPtr<SyncPrefs>& sync_prefs, | 304 const base::WeakPtr<SyncPrefs>& sync_prefs) |
374 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage) | |
375 : weak_ptr_factory_(this), | 305 : weak_ptr_factory_(this), |
376 sync_thread_("Chrome_SyncThread"), | 306 sync_thread_("Chrome_SyncThread"), |
377 frontend_loop_(base::MessageLoop::current()), | 307 frontend_loop_(base::MessageLoop::current()), |
378 profile_(profile), | 308 profile_(profile), |
379 name_(name), | 309 name_(name), |
380 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), | 310 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), |
381 weak_ptr_factory_.GetWeakPtr())), | 311 weak_ptr_factory_.GetWeakPtr())), |
382 initialization_state_(NOT_ATTEMPTED), | 312 initialization_state_(NOT_ATTEMPTED), |
383 sync_prefs_(sync_prefs), | 313 sync_prefs_(sync_prefs), |
384 invalidator_factory_( | |
385 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
386 profile_->GetRequestContext()), | |
387 content::GetUserAgent(GURL()), | |
388 invalidator_storage), | |
389 frontend_(NULL), | 314 frontend_(NULL), |
390 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 315 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), |
| 316 invalidator_( |
| 317 invalidation::InvalidationServiceFactory::GetForProfile(profile)) { |
391 } | 318 } |
392 | 319 |
393 SyncBackendHost::SyncBackendHost(Profile* profile) | 320 SyncBackendHost::SyncBackendHost(Profile* profile) |
394 : weak_ptr_factory_(this), | 321 : weak_ptr_factory_(this), |
395 sync_thread_("Chrome_SyncThread"), | 322 sync_thread_("Chrome_SyncThread"), |
396 frontend_loop_(base::MessageLoop::current()), | 323 frontend_loop_(base::MessageLoop::current()), |
397 profile_(profile), | 324 profile_(profile), |
398 name_("Unknown"), | 325 name_("Unknown"), |
399 initialization_state_(NOT_ATTEMPTED), | 326 initialization_state_(NOT_ATTEMPTED), |
400 invalidator_factory_( | |
401 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
402 profile_->GetRequestContext()), | |
403 content::GetUserAgent(GURL()), | |
404 base::WeakPtr<syncer::InvalidationStateTracker>()), | |
405 frontend_(NULL), | 327 frontend_(NULL), |
406 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 328 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
407 } | 329 } |
408 | 330 |
409 SyncBackendHost::~SyncBackendHost() { | 331 SyncBackendHost::~SyncBackendHost() { |
410 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; | 332 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; |
411 DCHECK(!android_invalidator_bridge_.get()); | |
412 DCHECK(!registrar_.get()); | 333 DCHECK(!registrar_.get()); |
413 } | 334 } |
414 | 335 |
415 namespace { | 336 namespace { |
416 | 337 |
417 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | 338 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( |
418 const scoped_refptr<net::URLRequestContextGetter>& getter, | 339 const scoped_refptr<net::URLRequestContextGetter>& getter, |
419 const NetworkTimeTracker::UpdateCallback& update_callback) { | 340 const NetworkTimeTracker::UpdateCallback& update_callback) { |
420 chrome::VersionInfo version_info; | 341 chrome::VersionInfo version_info; |
421 return scoped_ptr<syncer::HttpPostProviderFactory>( | 342 return scoped_ptr<syncer::HttpPostProviderFactory>( |
(...skipping 11 matching lines...) Expand all Loading... |
433 const GURL& sync_service_url, | 354 const GURL& sync_service_url, |
434 const SyncCredentials& credentials, | 355 const SyncCredentials& credentials, |
435 bool delete_sync_data_folder, | 356 bool delete_sync_data_folder, |
436 syncer::SyncManagerFactory* sync_manager_factory, | 357 syncer::SyncManagerFactory* sync_manager_factory, |
437 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 358 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
438 syncer::ReportUnrecoverableErrorFunction | 359 syncer::ReportUnrecoverableErrorFunction |
439 report_unrecoverable_error_function) { | 360 report_unrecoverable_error_function) { |
440 if (!sync_thread_.Start()) | 361 if (!sync_thread_.Start()) |
441 return; | 362 return; |
442 | 363 |
443 android_invalidator_bridge_.reset( | |
444 new AndroidInvalidatorBridge( | |
445 profile_, sync_thread_.message_loop_proxy())); | |
446 | |
447 frontend_ = frontend; | 364 frontend_ = frontend; |
448 DCHECK(frontend); | 365 DCHECK(frontend); |
449 | 366 |
450 registrar_.reset(new SyncBackendRegistrar(name_, | 367 registrar_.reset(new SyncBackendRegistrar(name_, |
451 profile_, | 368 profile_, |
452 sync_thread_.message_loop())); | 369 sync_thread_.message_loop())); |
453 syncer::ModelSafeRoutingInfo routing_info; | 370 syncer::ModelSafeRoutingInfo routing_info; |
454 std::vector<syncer::ModelSafeWorker*> workers; | 371 std::vector<syncer::ModelSafeWorker*> workers; |
455 registrar_->GetModelSafeRoutingInfo(&routing_info); | 372 registrar_->GetModelSafeRoutingInfo(&routing_info); |
456 registrar_->GetWorkers(&workers); | 373 registrar_->GetWorkers(&workers); |
457 | 374 |
458 InternalComponentsFactory::Switches factory_switches = { | 375 InternalComponentsFactory::Switches factory_switches = { |
459 InternalComponentsFactory::ENCRYPTION_KEYSTORE, | 376 InternalComponentsFactory::ENCRYPTION_KEYSTORE, |
460 InternalComponentsFactory::BACKOFF_NORMAL | 377 InternalComponentsFactory::BACKOFF_NORMAL |
461 }; | 378 }; |
462 | 379 |
463 CommandLine* cl = CommandLine::ForCurrentProcess(); | 380 CommandLine* cl = CommandLine::ForCurrentProcess(); |
464 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { | 381 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { |
465 factory_switches.backoff_override = | 382 factory_switches.backoff_override = |
466 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; | 383 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; |
467 } | 384 } |
468 | 385 |
469 bool create_invalidator = true; | 386 invalidator_->RegisterInvalidationHandler(this); |
470 #if defined(ENABLE_MANAGED_USERS) | |
471 if (ManagedUserService::ProfileIsManaged(profile_)) | |
472 create_invalidator = false; | |
473 #endif | |
474 | 387 |
475 initialization_state_ = CREATING_SYNC_MANAGER; | 388 initialization_state_ = CREATING_SYNC_MANAGER; |
476 InitCore(DoInitializeOptions( | 389 InitCore(DoInitializeOptions( |
477 sync_thread_.message_loop(), | 390 sync_thread_.message_loop(), |
478 registrar_.get(), | 391 registrar_.get(), |
479 routing_info, | 392 routing_info, |
480 workers, | 393 workers, |
481 &extensions_activity_monitor_, | 394 &extensions_activity_monitor_, |
482 event_handler, | 395 event_handler, |
483 sync_service_url, | 396 sync_service_url, |
484 base::Bind(&MakeHttpBridgeFactory, | 397 base::Bind(&MakeHttpBridgeFactory, |
485 make_scoped_refptr(profile_->GetRequestContext()), | 398 make_scoped_refptr(profile_->GetRequestContext()), |
486 NetworkTimeTracker::BuildNotifierUpdateCallback()), | 399 NetworkTimeTracker::BuildNotifierUpdateCallback()), |
487 credentials, | 400 credentials, |
488 android_invalidator_bridge_.get(), | 401 invalidator_->GetInvalidatorClientId(), |
489 &invalidator_factory_, | |
490 sync_manager_factory, | 402 sync_manager_factory, |
491 delete_sync_data_folder, | 403 delete_sync_data_folder, |
492 sync_prefs_->GetEncryptionBootstrapToken(), | 404 sync_prefs_->GetEncryptionBootstrapToken(), |
493 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 405 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
494 new InternalComponentsFactoryImpl(factory_switches), | 406 new InternalComponentsFactoryImpl(factory_switches), |
495 unrecoverable_error_handler, | 407 unrecoverable_error_handler, |
496 report_unrecoverable_error_function, | 408 report_unrecoverable_error_function, |
497 !cl->HasSwitch(switches::kSyncDisableOAuth2Token), | 409 !cl->HasSwitch(switches::kSyncDisableOAuth2Token))); |
498 create_invalidator)); | |
499 } | 410 } |
500 | 411 |
501 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 412 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
502 DCHECK(sync_thread_.IsRunning()); | 413 DCHECK(sync_thread_.IsRunning()); |
503 sync_thread_.message_loop()->PostTask(FROM_HERE, | 414 sync_thread_.message_loop()->PostTask(FROM_HERE, |
504 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), | 415 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), |
505 credentials)); | 416 credentials)); |
506 } | 417 } |
507 | 418 |
508 void SyncBackendHost::UpdateRegisteredInvalidationIds( | |
509 const syncer::ObjectIdSet& ids) { | |
510 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | |
511 DCHECK(sync_thread_.IsRunning()); | |
512 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
513 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds, | |
514 core_.get(), ids)); | |
515 } | |
516 | |
517 void SyncBackendHost::AcknowledgeInvalidation( | |
518 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { | |
519 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | |
520 DCHECK(sync_thread_.IsRunning()); | |
521 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
522 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation, | |
523 core_.get(), id, ack_handle)); | |
524 } | |
525 | |
526 void SyncBackendHost::StartSyncingWithServer() { | 419 void SyncBackendHost::StartSyncingWithServer() { |
527 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; | 420 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; |
528 | 421 |
529 syncer::ModelSafeRoutingInfo routing_info; | 422 syncer::ModelSafeRoutingInfo routing_info; |
530 registrar_->GetModelSafeRoutingInfo(&routing_info); | 423 registrar_->GetModelSafeRoutingInfo(&routing_info); |
531 | 424 |
532 sync_thread_.message_loop()->PostTask(FROM_HERE, | 425 sync_thread_.message_loop()->PostTask(FROM_HERE, |
533 base::Bind(&SyncBackendHost::Core::DoStartSyncing, | 426 base::Bind(&SyncBackendHost::Core::DoStartSyncing, |
534 core_.get(), routing_info)); | 427 core_.get(), routing_info)); |
535 } | 428 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 // so the registrar won't need stopping either. | 552 // so the registrar won't need stopping either. |
660 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED); | 553 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED); |
661 DCHECK(!registrar_.get()); | 554 DCHECK(!registrar_.get()); |
662 } | 555 } |
663 } | 556 } |
664 | 557 |
665 void SyncBackendHost::Shutdown(bool sync_disabled) { | 558 void SyncBackendHost::Shutdown(bool sync_disabled) { |
666 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 559 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
667 // called first. | 560 // called first. |
668 DCHECK(!frontend_); | 561 DCHECK(!frontend_); |
| 562 |
| 563 if (sync_disabled) |
| 564 invalidator_->UpdateRegisteredInvalidationIds(this, syncer::ObjectIdSet()); |
| 565 invalidator_->UnregisterInvalidationHandler(this); |
| 566 invalidator_ = NULL; |
| 567 |
669 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. | 568 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. |
670 if (sync_thread_.IsRunning()) { | 569 if (sync_thread_.IsRunning()) { |
671 sync_thread_.message_loop()->PostTask(FROM_HERE, | 570 sync_thread_.message_loop()->PostTask(FROM_HERE, |
672 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), | 571 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), |
673 sync_disabled)); | 572 sync_disabled)); |
674 | |
675 if (android_invalidator_bridge_) | |
676 android_invalidator_bridge_->StopForShutdown(); | |
677 } | 573 } |
678 | 574 |
679 // Stop will return once the thread exits, which will be after DoShutdown | 575 // Stop will return once the thread exits, which will be after DoShutdown |
680 // runs. DoShutdown needs to run from sync_thread_ because the sync backend | 576 // runs. DoShutdown needs to run from sync_thread_ because the sync backend |
681 // requires any thread that opened sqlite handles to relinquish them | 577 // requires any thread that opened sqlite handles to relinquish them |
682 // personally. We need to join threads, because otherwise the main Chrome | 578 // personally. We need to join threads, because otherwise the main Chrome |
683 // thread (ui loop) can exit before DoShutdown finishes, at which point | 579 // thread (ui loop) can exit before DoShutdown finishes, at which point |
684 // virtually anything the sync backend does (or the post-back to | 580 // virtually anything the sync backend does (or the post-back to |
685 // frontend_loop_ by our Core) will epically fail because the CRT won't be | 581 // frontend_loop_ by our Core) will epically fail because the CRT won't be |
686 // initialized. | 582 // initialized. |
687 // Since we are blocking the UI thread here, we need to turn ourselves in | 583 // Since we are blocking the UI thread here, we need to turn ourselves in |
688 // with the ThreadRestriction police. For sentencing and how we plan to fix | 584 // with the ThreadRestriction police. For sentencing and how we plan to fix |
689 // this, see bug 19757. | 585 // this, see bug 19757. |
690 base::Time stop_thread_start_time = base::Time::Now(); | 586 base::Time stop_thread_start_time = base::Time::Now(); |
691 { | 587 { |
692 base::ThreadRestrictions::ScopedAllowIO allow_io; | 588 base::ThreadRestrictions::ScopedAllowIO allow_io; |
693 sync_thread_.Stop(); | 589 sync_thread_.Stop(); |
694 } | 590 } |
695 base::TimeDelta stop_sync_thread_time = base::Time::Now() - | 591 base::TimeDelta stop_sync_thread_time = base::Time::Now() - |
696 stop_thread_start_time; | 592 stop_thread_start_time; |
697 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", | 593 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", |
698 stop_sync_thread_time); | 594 stop_sync_thread_time); |
699 | 595 |
700 registrar_.reset(); | 596 registrar_.reset(); |
701 js_backend_.Reset(); | 597 js_backend_.Reset(); |
702 android_invalidator_bridge_.reset(); | |
703 core_ = NULL; // Releases reference to core_. | 598 core_ = NULL; // Releases reference to core_. |
704 } | 599 } |
705 | 600 |
706 void SyncBackendHost::ConfigureDataTypes( | 601 void SyncBackendHost::ConfigureDataTypes( |
707 syncer::ConfigureReason reason, | 602 syncer::ConfigureReason reason, |
708 const DataTypeConfigStateMap& config_state_map, | 603 const DataTypeConfigStateMap& config_state_map, |
709 const base::Callback<void(syncer::ModelTypeSet, | 604 const base::Callback<void(syncer::ModelTypeSet, |
710 syncer::ModelTypeSet)>& ready_task, | 605 syncer::ModelTypeSet)>& ready_task, |
711 const base::Callback<void()>& retry_callback) { | 606 const base::Callback<void()>& retry_callback) { |
712 // Only one configure is allowed at a time. This is guaranteed by our | 607 // Only one configure is allowed at a time. This is guaranteed by our |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer, | 798 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer, |
904 core_.get(), | 799 core_.get(), |
905 reason, | 800 reason, |
906 config_types, | 801 config_types, |
907 routing_info, | 802 routing_info, |
908 ready_task, | 803 ready_task, |
909 retry_callback)); | 804 retry_callback)); |
910 } | 805 } |
911 | 806 |
912 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( | 807 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( |
| 808 const syncer::ModelTypeSet enabled_types, |
913 const syncer::ModelTypeSet succeeded_configuration_types, | 809 const syncer::ModelTypeSet succeeded_configuration_types, |
914 const syncer::ModelTypeSet failed_configuration_types, | 810 const syncer::ModelTypeSet failed_configuration_types, |
915 const base::Callback<void(syncer::ModelTypeSet, | 811 const base::Callback<void(syncer::ModelTypeSet, |
916 syncer::ModelTypeSet)>& ready_task) { | 812 syncer::ModelTypeSet)>& ready_task) { |
917 if (!frontend_) | 813 if (!frontend_) |
918 return; | 814 return; |
919 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 815 |
| 816 invalidator_->UpdateRegisteredInvalidationIds( |
| 817 this, |
| 818 ModelTypeSetToObjectIdSet(enabled_types)); |
| 819 |
920 if (!ready_task.is_null()) | 820 if (!ready_task.is_null()) |
921 ready_task.Run(succeeded_configuration_types, failed_configuration_types); | 821 ready_task.Run(succeeded_configuration_types, failed_configuration_types); |
922 } | 822 } |
923 | 823 |
924 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( | 824 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
925 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 825 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
926 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 826 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
927 debug_info_listener, | 827 debug_info_listener, |
928 syncer::ModelTypeSet restored_types) { | 828 syncer::ModelTypeSet restored_types) { |
929 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); | 829 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); |
(...skipping 10 matching lines...) Expand all Loading... |
940 | 840 |
941 // Start forwarding refresh requests to the SyncManager | 841 // Start forwarding refresh requests to the SyncManager |
942 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 842 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
943 content::Source<Profile>(profile_)); | 843 content::Source<Profile>(profile_)); |
944 | 844 |
945 syncer::ConfigureReason reason = | 845 syncer::ConfigureReason reason = |
946 (sync_prefs_->HasSyncSetupCompleted() ? | 846 (sync_prefs_->HasSyncSetupCompleted() ? |
947 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : | 847 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : |
948 syncer::CONFIGURE_REASON_NEW_CLIENT); | 848 syncer::CONFIGURE_REASON_NEW_CLIENT); |
949 | 849 |
| 850 // Fake a state change to initialize the SyncManager's cached invalidator |
| 851 // state. |
| 852 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); |
| 853 |
950 // Kick off the next step in SyncBackendHost initialization by downloading | 854 // Kick off the next step in SyncBackendHost initialization by downloading |
951 // any necessary control types. | 855 // any necessary control types. |
952 sync_thread_.message_loop()->PostTask( | 856 sync_thread_.message_loop()->PostTask( |
953 FROM_HERE, | 857 FROM_HERE, |
954 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, | 858 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, |
955 core_.get(), | 859 core_.get(), |
956 reason)); | 860 reason)); |
957 } | 861 } |
958 | 862 |
959 void SyncBackendHost::Observe( | 863 void SyncBackendHost::Observe( |
(...skipping 16 matching lines...) Expand all Loading... |
976 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( | 880 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
977 base::MessageLoop* sync_loop, | 881 base::MessageLoop* sync_loop, |
978 SyncBackendRegistrar* registrar, | 882 SyncBackendRegistrar* registrar, |
979 const syncer::ModelSafeRoutingInfo& routing_info, | 883 const syncer::ModelSafeRoutingInfo& routing_info, |
980 const std::vector<syncer::ModelSafeWorker*>& workers, | 884 const std::vector<syncer::ModelSafeWorker*>& workers, |
981 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 885 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
982 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 886 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
983 const GURL& service_url, | 887 const GURL& service_url, |
984 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 888 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
985 const syncer::SyncCredentials& credentials, | 889 const syncer::SyncCredentials& credentials, |
986 AndroidInvalidatorBridge* android_invalidator_bridge, | 890 const std::string& invalidator_client_id, |
987 syncer::InvalidatorFactory* invalidator_factory, | |
988 syncer::SyncManagerFactory* sync_manager_factory, | 891 syncer::SyncManagerFactory* sync_manager_factory, |
989 bool delete_sync_data_folder, | 892 bool delete_sync_data_folder, |
990 const std::string& restored_key_for_bootstrapping, | 893 const std::string& restored_key_for_bootstrapping, |
991 const std::string& restored_keystore_key_for_bootstrapping, | 894 const std::string& restored_keystore_key_for_bootstrapping, |
992 InternalComponentsFactory* internal_components_factory, | 895 InternalComponentsFactory* internal_components_factory, |
993 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 896 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
994 syncer::ReportUnrecoverableErrorFunction | 897 syncer::ReportUnrecoverableErrorFunction |
995 report_unrecoverable_error_function, | 898 report_unrecoverable_error_function, |
996 bool use_oauth2_token, | 899 bool use_oauth2_token) |
997 bool create_invalidator) | |
998 : sync_loop(sync_loop), | 900 : sync_loop(sync_loop), |
999 registrar(registrar), | 901 registrar(registrar), |
1000 routing_info(routing_info), | 902 routing_info(routing_info), |
1001 workers(workers), | 903 workers(workers), |
1002 extensions_activity_monitor(extensions_activity_monitor), | 904 extensions_activity_monitor(extensions_activity_monitor), |
1003 event_handler(event_handler), | 905 event_handler(event_handler), |
1004 service_url(service_url), | 906 service_url(service_url), |
1005 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 907 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
1006 credentials(credentials), | 908 credentials(credentials), |
1007 android_invalidator_bridge(android_invalidator_bridge), | 909 invalidator_client_id(invalidator_client_id), |
1008 invalidator_factory(invalidator_factory), | |
1009 sync_manager_factory(sync_manager_factory), | 910 sync_manager_factory(sync_manager_factory), |
1010 delete_sync_data_folder(delete_sync_data_folder), | 911 delete_sync_data_folder(delete_sync_data_folder), |
1011 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 912 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
1012 restored_keystore_key_for_bootstrapping( | 913 restored_keystore_key_for_bootstrapping( |
1013 restored_keystore_key_for_bootstrapping), | 914 restored_keystore_key_for_bootstrapping), |
1014 internal_components_factory(internal_components_factory), | 915 internal_components_factory(internal_components_factory), |
1015 unrecoverable_error_handler(unrecoverable_error_handler), | 916 unrecoverable_error_handler(unrecoverable_error_handler), |
1016 report_unrecoverable_error_function( | 917 report_unrecoverable_error_function( |
1017 report_unrecoverable_error_function), | 918 report_unrecoverable_error_function), |
1018 use_oauth2_token(use_oauth2_token), | 919 use_oauth2_token(use_oauth2_token) { |
1019 create_invalidator(create_invalidator) { | |
1020 } | 920 } |
1021 | 921 |
1022 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 922 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
1023 | 923 |
1024 SyncBackendHost::Core::Core(const std::string& name, | 924 SyncBackendHost::Core::Core(const std::string& name, |
1025 const base::FilePath& sync_data_folder_path, | 925 const base::FilePath& sync_data_folder_path, |
1026 const base::WeakPtr<SyncBackendHost>& backend) | 926 const base::WeakPtr<SyncBackendHost>& backend) |
1027 : name_(name), | 927 : name_(name), |
1028 sync_data_folder_path_(sync_data_folder_path), | 928 sync_data_folder_path_(sync_data_folder_path), |
1029 host_(backend), | 929 host_(backend), |
1030 sync_loop_(NULL), | 930 sync_loop_(NULL), |
1031 registrar_(NULL), | 931 registrar_(NULL) { |
1032 registered_as_invalidation_handler_(false) { | |
1033 DCHECK(backend.get()); | 932 DCHECK(backend.get()); |
1034 } | 933 } |
1035 | 934 |
1036 SyncBackendHost::Core::~Core() { | 935 SyncBackendHost::Core::~Core() { |
1037 DCHECK(!sync_manager_.get()); | 936 DCHECK(!sync_manager_.get()); |
1038 DCHECK(!sync_loop_); | 937 DCHECK(!sync_loop_); |
1039 } | 938 } |
1040 | 939 |
1041 void SyncBackendHost::Core::OnSyncCycleCompleted( | 940 void SyncBackendHost::Core::OnSyncCycleCompleted( |
1042 const SyncSessionSnapshot& snapshot) { | 941 const SyncSessionSnapshot& snapshot) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 const syncer::SyncProtocolError& sync_error) { | 1120 const syncer::SyncProtocolError& sync_error) { |
1222 if (!sync_loop_) | 1121 if (!sync_loop_) |
1223 return; | 1122 return; |
1224 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1123 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1225 host_.Call( | 1124 host_.Call( |
1226 FROM_HERE, | 1125 FROM_HERE, |
1227 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 1126 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
1228 sync_error); | 1127 sync_error); |
1229 } | 1128 } |
1230 | 1129 |
1231 void SyncBackendHost::Core::OnInvalidatorStateChange( | 1130 void SyncBackendHost::Core::DoOnInvalidatorStateChange( |
1232 syncer::InvalidatorState state) { | 1131 syncer::InvalidatorState state) { |
1233 if (!sync_loop_) | |
1234 return; | |
1235 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1132 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1236 host_.Call(FROM_HERE, | 1133 sync_manager_->OnInvalidatorStateChange(state); |
1237 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop, | |
1238 state); | |
1239 } | 1134 } |
1240 | 1135 |
1241 void SyncBackendHost::Core::OnIncomingInvalidation( | 1136 void SyncBackendHost::Core::DoOnIncomingInvalidation( |
1242 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 1137 syncer::ObjectIdInvalidationMap invalidation_map) { |
1243 if (!sync_loop_) | |
1244 return; | |
1245 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1138 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1246 host_.Call(FROM_HERE, | 1139 sync_manager_->OnIncomingInvalidation(invalidation_map); |
1247 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop, | |
1248 invalidation_map); | |
1249 } | 1140 } |
1250 | 1141 |
1251 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { | 1142 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
1252 DCHECK(!sync_loop_); | 1143 DCHECK(!sync_loop_); |
1253 sync_loop_ = options.sync_loop; | 1144 sync_loop_ = options.sync_loop; |
1254 DCHECK(sync_loop_); | 1145 DCHECK(sync_loop_); |
1255 | 1146 |
1256 // Blow away the partial or corrupt sync data folder before doing any more | 1147 // Blow away the partial or corrupt sync data folder before doing any more |
1257 // initialization, if necessary. | 1148 // initialization, if necessary. |
1258 if (options.delete_sync_data_folder) { | 1149 if (options.delete_sync_data_folder) { |
1259 DeleteSyncDataFolder(); | 1150 DeleteSyncDataFolder(); |
1260 } | 1151 } |
1261 | 1152 |
1262 // Make sure that the directory exists before initializing the backend. | 1153 // Make sure that the directory exists before initializing the backend. |
1263 // If it already exists, this will do no harm. | 1154 // If it already exists, this will do no harm. |
1264 if (!file_util::CreateDirectory(sync_data_folder_path_)) { | 1155 if (!file_util::CreateDirectory(sync_data_folder_path_)) { |
1265 DLOG(FATAL) << "Sync Data directory creation failed."; | 1156 DLOG(FATAL) << "Sync Data directory creation failed."; |
1266 } | 1157 } |
1267 | 1158 |
1268 DCHECK(!registrar_); | 1159 DCHECK(!registrar_); |
1269 registrar_ = options.registrar; | 1160 registrar_ = options.registrar; |
1270 DCHECK(registrar_); | 1161 DCHECK(registrar_); |
1271 | 1162 |
1272 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); | 1163 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); |
1273 sync_manager_->AddObserver(this); | 1164 sync_manager_->AddObserver(this); |
1274 scoped_ptr<syncer::Invalidator> invalidator; | |
1275 if (options.create_invalidator) { | |
1276 #if defined(OS_ANDROID) | |
1277 invalidator.reset( | |
1278 new AndroidInvalidatorBridgeProxy(options.android_invalidator_bridge)); | |
1279 #else | |
1280 invalidator.reset(options.invalidator_factory->CreateInvalidator()); | |
1281 #endif | |
1282 } else { | |
1283 invalidator.reset(new DummyInvalidator()); | |
1284 } | |
1285 sync_manager_->Init(sync_data_folder_path_, | 1165 sync_manager_->Init(sync_data_folder_path_, |
1286 options.event_handler, | 1166 options.event_handler, |
1287 options.service_url.host() + options.service_url.path(), | 1167 options.service_url.host() + options.service_url.path(), |
1288 options.service_url.EffectiveIntPort(), | 1168 options.service_url.EffectiveIntPort(), |
1289 options.service_url.SchemeIsSecure(), | 1169 options.service_url.SchemeIsSecure(), |
1290 options.make_http_bridge_factory_fn.Run().Pass(), | 1170 options.make_http_bridge_factory_fn.Run().Pass(), |
1291 options.workers, | 1171 options.workers, |
1292 options.extensions_activity_monitor, | 1172 options.extensions_activity_monitor, |
1293 options.registrar /* as SyncManager::ChangeDelegate */, | 1173 options.registrar /* as SyncManager::ChangeDelegate */, |
1294 options.credentials, | 1174 options.credentials, |
1295 invalidator.Pass(), | 1175 options.invalidator_client_id, |
1296 options.invalidator_factory->GetInvalidatorClientId(), | |
1297 options.restored_key_for_bootstrapping, | 1176 options.restored_key_for_bootstrapping, |
1298 options.restored_keystore_key_for_bootstrapping, | 1177 options.restored_keystore_key_for_bootstrapping, |
1299 scoped_ptr<InternalComponentsFactory>( | 1178 scoped_ptr<InternalComponentsFactory>( |
1300 options.internal_components_factory), | 1179 options.internal_components_factory), |
1301 &encryptor_, | 1180 &encryptor_, |
1302 options.unrecoverable_error_handler, | 1181 options.unrecoverable_error_handler, |
1303 options.report_unrecoverable_error_function, | 1182 options.report_unrecoverable_error_function, |
1304 options.use_oauth2_token); | 1183 options.use_oauth2_token); |
1305 | 1184 |
1306 // |sync_manager_| may end up being NULL here in tests (in | 1185 // |sync_manager_| may end up being NULL here in tests (in |
1307 // synchronous initialization mode). | 1186 // synchronous initialization mode). |
1308 // | 1187 // |
1309 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 1188 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
1310 if (sync_manager_) { | 1189 if (sync_manager_) { |
1311 sync_manager_->RegisterInvalidationHandler(this); | |
1312 registered_as_invalidation_handler_ = true; | |
1313 | |
1314 // Now check the command line to see if we need to simulate an | 1190 // Now check the command line to see if we need to simulate an |
1315 // unrecoverable error for testing purpose. Note the error is thrown | 1191 // unrecoverable error for testing purpose. Note the error is thrown |
1316 // only if the initialization succeeded. Also it makes sense to use this | 1192 // only if the initialization succeeded. Also it makes sense to use this |
1317 // flag only when restarting the browser with an account already setup. If | 1193 // flag only when restarting the browser with an account already setup. If |
1318 // you use this before setting up the setup would not succeed as an error | 1194 // you use this before setting up the setup would not succeed as an error |
1319 // would be encountered. | 1195 // would be encountered. |
1320 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1196 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1321 switches::kSyncThrowUnrecoverableError)) { | 1197 switches::kSyncThrowUnrecoverableError)) { |
1322 sync_manager_->ThrowUnrecoverableError(); | 1198 sync_manager_->ThrowUnrecoverableError(); |
1323 } | 1199 } |
1324 } | 1200 } |
1325 } | 1201 } |
1326 | 1202 |
1327 void SyncBackendHost::Core::DoUpdateCredentials( | 1203 void SyncBackendHost::Core::DoUpdateCredentials( |
1328 const SyncCredentials& credentials) { | 1204 const SyncCredentials& credentials) { |
1329 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1205 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1330 // UpdateCredentials can be called during backend initialization, possibly | 1206 // UpdateCredentials can be called during backend initialization, possibly |
1331 // when backend initialization has failed but hasn't notified the UI thread | 1207 // when backend initialization has failed but hasn't notified the UI thread |
1332 // yet. In that case, the sync manager may have been destroyed on the sync | 1208 // yet. In that case, the sync manager may have been destroyed on the sync |
1333 // thread before this task was executed, so we do nothing. | 1209 // thread before this task was executed, so we do nothing. |
1334 if (sync_manager_) { | 1210 if (sync_manager_) { |
1335 sync_manager_->UpdateCredentials(credentials); | 1211 sync_manager_->UpdateCredentials(credentials); |
1336 } | 1212 } |
1337 } | 1213 } |
1338 | 1214 |
1339 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds( | |
1340 const syncer::ObjectIdSet& ids) { | |
1341 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | |
1342 // |sync_manager_| may end up being NULL here in tests (in | |
1343 // synchronous initialization mode) since this is called during | |
1344 // shutdown. | |
1345 // | |
1346 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
1347 if (sync_manager_) { | |
1348 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); | |
1349 } | |
1350 } | |
1351 | |
1352 void SyncBackendHost::Core::DoAcknowledgeInvalidation( | |
1353 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { | |
1354 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | |
1355 // |sync_manager_| may end up being NULL here in tests (in | |
1356 // synchronous initialization mode). | |
1357 // | |
1358 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
1359 if (sync_manager_) { | |
1360 sync_manager_->AcknowledgeInvalidation(id, ack_handle); | |
1361 } | |
1362 } | |
1363 | |
1364 void SyncBackendHost::Core::DoStartSyncing( | 1215 void SyncBackendHost::Core::DoStartSyncing( |
1365 const syncer::ModelSafeRoutingInfo& routing_info) { | 1216 const syncer::ModelSafeRoutingInfo& routing_info) { |
1366 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1217 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1367 sync_manager_->StartSyncingNormally(routing_info); | 1218 sync_manager_->StartSyncingNormally(routing_info); |
1368 } | 1219 } |
1369 | 1220 |
1370 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1221 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
1371 const std::string& passphrase, | 1222 const std::string& passphrase, |
1372 bool is_explicit) { | 1223 bool is_explicit) { |
1373 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1224 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 | 1314 |
1464 sync_loop_ = NULL; | 1315 sync_loop_ = NULL; |
1465 | 1316 |
1466 host_.Reset(); | 1317 host_.Reset(); |
1467 } | 1318 } |
1468 | 1319 |
1469 void SyncBackendHost::Core::DoDestroySyncManager() { | 1320 void SyncBackendHost::Core::DoDestroySyncManager() { |
1470 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1321 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1471 if (sync_manager_) { | 1322 if (sync_manager_) { |
1472 save_changes_timer_.reset(); | 1323 save_changes_timer_.reset(); |
1473 if (registered_as_invalidation_handler_) { | |
1474 sync_manager_->UnregisterInvalidationHandler(this); | |
1475 registered_as_invalidation_handler_ = false; | |
1476 } | |
1477 sync_manager_->RemoveObserver(this); | 1324 sync_manager_->RemoveObserver(this); |
1478 sync_manager_->ShutdownOnSyncThread(); | 1325 sync_manager_->ShutdownOnSyncThread(); |
1479 sync_manager_.reset(); | 1326 sync_manager_.reset(); |
1480 } | 1327 } |
1481 } | 1328 } |
1482 | 1329 |
1483 void SyncBackendHost::Core::DoConfigureSyncer( | 1330 void SyncBackendHost::Core::DoConfigureSyncer( |
1484 syncer::ConfigureReason reason, | 1331 syncer::ConfigureReason reason, |
1485 const DoConfigureSyncerTypes& config_types, | 1332 const DoConfigureSyncerTypes& config_types, |
1486 const syncer::ModelSafeRoutingInfo routing_info, | 1333 const syncer::ModelSafeRoutingInfo routing_info, |
(...skipping 21 matching lines...) Expand all Loading... |
1508 syncer::ModelTypeSet types_to_config, | 1355 syncer::ModelTypeSet types_to_config, |
1509 const base::Callback<void(syncer::ModelTypeSet, | 1356 const base::Callback<void(syncer::ModelTypeSet, |
1510 syncer::ModelTypeSet)>& ready_task) { | 1357 syncer::ModelTypeSet)>& ready_task) { |
1511 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1358 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1512 | 1359 |
1513 // Update the enabled types for the bridge and sync manager. | 1360 // Update the enabled types for the bridge and sync manager. |
1514 syncer::ModelSafeRoutingInfo routing_info; | 1361 syncer::ModelSafeRoutingInfo routing_info; |
1515 registrar_->GetModelSafeRoutingInfo(&routing_info); | 1362 registrar_->GetModelSafeRoutingInfo(&routing_info); |
1516 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); | 1363 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); |
1517 enabled_types.RemoveAll(syncer::ProxyTypes()); | 1364 enabled_types.RemoveAll(syncer::ProxyTypes()); |
1518 sync_manager_->UpdateEnabledTypes(enabled_types); | |
1519 | 1365 |
1520 const syncer::ModelTypeSet failed_configuration_types = | 1366 const syncer::ModelTypeSet failed_configuration_types = |
1521 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); | 1367 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); |
1522 const syncer::ModelTypeSet succeeded_configuration_types = | 1368 const syncer::ModelTypeSet succeeded_configuration_types = |
1523 Difference(types_to_config, failed_configuration_types); | 1369 Difference(types_to_config, failed_configuration_types); |
1524 host_.Call(FROM_HERE, | 1370 host_.Call(FROM_HERE, |
1525 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, | 1371 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, |
1526 succeeded_configuration_types, failed_configuration_types, | 1372 enabled_types, |
| 1373 succeeded_configuration_types, |
| 1374 failed_configuration_types, |
1527 ready_task); | 1375 ready_task); |
1528 } | 1376 } |
1529 | 1377 |
1530 void SyncBackendHost::Core::DoRetryConfiguration( | 1378 void SyncBackendHost::Core::DoRetryConfiguration( |
1531 const base::Closure& retry_callback) { | 1379 const base::Closure& retry_callback) { |
1532 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1380 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1533 host_.Call(FROM_HERE, | 1381 host_.Call(FROM_HERE, |
1534 &SyncBackendHost::RetryConfigurationOnFrontendLoop, | 1382 &SyncBackendHost::RetryConfigurationOnFrontendLoop, |
1535 retry_callback); | 1383 retry_callback); |
1536 } | 1384 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 } | 1494 } |
1647 | 1495 |
1648 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( | 1496 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( |
1649 const syncer::SyncProtocolError& sync_error) { | 1497 const syncer::SyncProtocolError& sync_error) { |
1650 if (!frontend_) | 1498 if (!frontend_) |
1651 return; | 1499 return; |
1652 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 1500 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
1653 frontend_->OnActionableError(sync_error); | 1501 frontend_->OnActionableError(sync_error); |
1654 } | 1502 } |
1655 | 1503 |
1656 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( | 1504 void SyncBackendHost::OnInvalidatorStateChange(syncer::InvalidatorState state) { |
1657 syncer::InvalidatorState state) { | 1505 sync_thread_.message_loop()->PostTask( |
1658 if (!frontend_) | 1506 FROM_HERE, |
1659 return; | 1507 base::Bind(&SyncBackendHost::Core::DoOnInvalidatorStateChange, |
1660 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 1508 core_.get(), |
1661 frontend_->OnInvalidatorStateChange(state); | 1509 state)); |
1662 } | 1510 } |
1663 | 1511 |
1664 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( | 1512 void SyncBackendHost::OnIncomingInvalidation( |
1665 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 1513 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
1666 if (!frontend_) | 1514 // TODO(dcheng): Acknowledge immediately for now. Fix this once the |
1667 return; | 1515 // invalidator doesn't repeatedly ping for unacknowledged invaliations, since |
1668 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 1516 // it conflicts with the sync scheduler's internal backoff algorithm. |
1669 frontend_->OnIncomingInvalidation(invalidation_map); | 1517 // See http://crbug.com/124149 for more information. |
| 1518 for (syncer::ObjectIdInvalidationMap::const_iterator it = |
| 1519 invalidation_map.begin(); it != invalidation_map.end(); ++it) { |
| 1520 invalidator_->AcknowledgeInvalidation(it->first, it->second.ack_handle); |
| 1521 } |
| 1522 |
| 1523 sync_thread_.message_loop()->PostTask( |
| 1524 FROM_HERE, |
| 1525 base::Bind(&SyncBackendHost::Core::DoOnIncomingInvalidation, |
| 1526 core_.get(), |
| 1527 invalidation_map)); |
1670 } | 1528 } |
1671 | 1529 |
1672 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( | 1530 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( |
1673 const std::string& passphrase) const { | 1531 const std::string& passphrase) const { |
1674 DCHECK(cached_pending_keys_.has_blob()); | 1532 DCHECK(cached_pending_keys_.has_blob()); |
1675 DCHECK(!passphrase.empty()); | 1533 DCHECK(!passphrase.empty()); |
1676 syncer::Nigori nigori; | 1534 syncer::Nigori nigori; |
1677 nigori.InitByDerivation("localhost", "dummy", passphrase); | 1535 nigori.InitByDerivation("localhost", "dummy", passphrase); |
1678 std::string plaintext; | 1536 std::string plaintext; |
1679 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); | 1537 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 DVLOG(1) << "Connection status changed: " | 1618 DVLOG(1) << "Connection status changed: " |
1761 << syncer::ConnectionStatusToString(status); | 1619 << syncer::ConnectionStatusToString(status); |
1762 frontend_->OnConnectionStatusChange(status); | 1620 frontend_->OnConnectionStatusChange(status); |
1763 } | 1621 } |
1764 | 1622 |
1765 #undef SDVLOG | 1623 #undef SDVLOG |
1766 | 1624 |
1767 #undef SLOG | 1625 #undef SLOG |
1768 | 1626 |
1769 } // namespace browser_sync | 1627 } // namespace browser_sync |
OLD | NEW |