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