OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
20 #include "base/timer.h" | 20 #include "base/timer.h" |
21 #include "base/tracked_objects.h" | 21 #include "base/tracked_objects.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "chrome/browser/invalidation_service.h" | |
25 #include "chrome/browser/invalidation_service_factory.h" | |
24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/signin/token_service.h" | 27 #include "chrome/browser/signin/token_service.h" |
26 #include "chrome/browser/signin/token_service_factory.h" | 28 #include "chrome/browser/signin/token_service_factory.h" |
27 #include "chrome/browser/sync/glue/android_invalidator_bridge.h" | |
28 #include "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h" | |
29 #include "chrome/browser/sync/glue/change_processor.h" | 29 #include "chrome/browser/sync/glue/change_processor.h" |
30 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 30 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
31 #include "chrome/browser/sync/glue/device_info.h" | 31 #include "chrome/browser/sync/glue/device_info.h" |
32 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 32 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
33 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 33 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
34 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | |
35 #include "chrome/browser/sync/sync_prefs.h" | 34 #include "chrome/browser/sync/sync_prefs.h" |
36 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
37 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
38 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/chrome_version_info.h" | 38 #include "chrome/common/chrome_version_info.h" |
40 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
41 #include "content/public/browser/notification_details.h" | 40 #include "content/public/browser/notification_details.h" |
42 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
43 #include "content/public/browser/notification_source.h" | 42 #include "content/public/browser/notification_source.h" |
44 #include "content/public/common/content_client.h" | 43 #include "content/public/common/content_client.h" |
45 #include "google_apis/gaia/gaia_constants.h" | 44 #include "google_apis/gaia/gaia_constants.h" |
46 #include "jingle/notifier/base/notification_method.h" | 45 #include "jingle/notifier/base/notification_method.h" |
47 #include "jingle/notifier/base/notifier_options.h" | 46 #include "jingle/notifier/base/notifier_options.h" |
48 #include "net/base/host_port_pair.h" | 47 #include "net/base/host_port_pair.h" |
49 #include "net/url_request/url_request_context_getter.h" | 48 #include "net/url_request/url_request_context_getter.h" |
50 #include "sync/internal_api/public/base_transaction.h" | 49 #include "sync/internal_api/public/base_transaction.h" |
51 #include "sync/internal_api/public/engine/model_safe_worker.h" | 50 #include "sync/internal_api/public/engine/model_safe_worker.h" |
52 #include "sync/internal_api/public/http_bridge.h" | 51 #include "sync/internal_api/public/http_bridge.h" |
53 #include "sync/internal_api/public/internal_components_factory_impl.h" | 52 #include "sync/internal_api/public/internal_components_factory_impl.h" |
54 #include "sync/internal_api/public/read_transaction.h" | 53 #include "sync/internal_api/public/read_transaction.h" |
55 #include "sync/internal_api/public/sync_manager_factory.h" | 54 #include "sync/internal_api/public/sync_manager_factory.h" |
56 #include "sync/internal_api/public/util/experiments.h" | 55 #include "sync/internal_api/public/util/experiments.h" |
57 #include "sync/internal_api/public/util/sync_string_conversions.h" | 56 #include "sync/internal_api/public/util/sync_string_conversions.h" |
58 #include "sync/notifier/invalidator.h" | |
59 #include "sync/protocol/encryption.pb.h" | 57 #include "sync/protocol/encryption.pb.h" |
60 #include "sync/protocol/sync.pb.h" | 58 #include "sync/protocol/sync.pb.h" |
61 #include "sync/util/nigori.h" | 59 #include "sync/util/nigori.h" |
62 | 60 |
63 static const int kSaveChangesIntervalSeconds = 10; | 61 static const int kSaveChangesIntervalSeconds = 10; |
64 static const base::FilePath::CharType kSyncDataFolderName[] = | 62 static const base::FilePath::CharType kSyncDataFolderName[] = |
65 FILE_PATH_LITERAL("Sync Data"); | 63 FILE_PATH_LITERAL("Sync Data"); |
66 | 64 |
67 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; | 65 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; |
68 | 66 |
(...skipping 10 matching lines...) Expand all Loading... | |
79 // Helper macros to log with the syncer thread name; useful when there | 77 // Helper macros to log with the syncer thread name; useful when there |
80 // are multiple syncers involved. | 78 // are multiple syncers involved. |
81 | 79 |
82 #define SLOG(severity) LOG(severity) << name_ << ": " | 80 #define SLOG(severity) LOG(severity) << name_ << ": " |
83 | 81 |
84 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 82 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
85 | 83 |
86 class SyncBackendHost::Core | 84 class SyncBackendHost::Core |
87 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 85 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
88 public syncer::SyncEncryptionHandler::Observer, | 86 public syncer::SyncEncryptionHandler::Observer, |
89 public syncer::SyncManager::Observer, | 87 public syncer::SyncManager::Observer { |
90 public syncer::InvalidationHandler { | |
91 public: | 88 public: |
92 Core(const std::string& name, | 89 Core(const std::string& name, |
93 const base::FilePath& sync_data_folder_path, | 90 const base::FilePath& sync_data_folder_path, |
94 const base::WeakPtr<SyncBackendHost>& backend); | 91 const base::WeakPtr<SyncBackendHost>& backend); |
95 | 92 |
96 // SyncManager::Observer implementation. The Core just acts like an air | 93 // SyncManager::Observer implementation. The Core just acts like an air |
97 // traffic controller here, forwarding incoming messages to appropriate | 94 // traffic controller here, forwarding incoming messages to appropriate |
98 // landing threads. | 95 // landing threads. |
99 virtual void OnSyncCycleCompleted( | 96 virtual void OnSyncCycleCompleted( |
100 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 97 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... | |
121 syncer::BootstrapTokenType type) OVERRIDE; | 118 syncer::BootstrapTokenType type) OVERRIDE; |
122 virtual void OnEncryptedTypesChanged( | 119 virtual void OnEncryptedTypesChanged( |
123 syncer::ModelTypeSet encrypted_types, | 120 syncer::ModelTypeSet encrypted_types, |
124 bool encrypt_everything) OVERRIDE; | 121 bool encrypt_everything) OVERRIDE; |
125 virtual void OnEncryptionComplete() OVERRIDE; | 122 virtual void OnEncryptionComplete() OVERRIDE; |
126 virtual void OnCryptographerStateChanged( | 123 virtual void OnCryptographerStateChanged( |
127 syncer::Cryptographer* cryptographer) OVERRIDE; | 124 syncer::Cryptographer* cryptographer) OVERRIDE; |
128 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, | 125 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, |
129 base::Time passphrase_time) OVERRIDE; | 126 base::Time passphrase_time) OVERRIDE; |
130 | 127 |
131 // syncer::InvalidationHandler implementation. | 128 // Forwards an invalidation state change to the sync manager. |
132 virtual void OnInvalidatorStateChange( | 129 void DoOnInvalidatorStateChange(syncer::InvalidatorState state); |
133 syncer::InvalidatorState state) OVERRIDE; | 130 |
134 virtual void OnIncomingInvalidation( | 131 // Forwards an invalidation to the sync manager. |
135 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 132 void DoOnIncomingInvalidation( |
133 syncer::ObjectIdInvalidationMap invalidation_map); | |
136 | 134 |
137 // Note: | 135 // Note: |
138 // | 136 // |
139 // The Do* methods are the various entry points from our | 137 // The Do* methods are the various entry points from our |
140 // SyncBackendHost. They are all called on the sync thread to | 138 // SyncBackendHost. They are all called on the sync thread to |
141 // actually perform synchronous (and potentially blocking) syncapi | 139 // actually perform synchronous (and potentially blocking) syncapi |
142 // operations. | 140 // operations. |
143 // | 141 // |
144 // Called to perform initialization of the syncapi on behalf of | 142 // Called to perform initialization of the syncapi on behalf of |
145 // SyncBackendHost::Initialize. | 143 // SyncBackendHost::Initialize. |
146 void DoInitialize(const DoInitializeOptions& options); | 144 void DoInitialize(const DoInitializeOptions& options); |
147 | 145 |
148 // Called to perform credential update on behalf of | 146 // Called to perform credential update on behalf of |
149 // SyncBackendHost::UpdateCredentials. | 147 // SyncBackendHost::UpdateCredentials. |
150 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); | 148 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); |
151 | 149 |
152 // Called to update the given registered ids on behalf of | |
153 // SyncBackendHost::UpdateRegisteredInvalidationIds. | |
154 void DoUpdateRegisteredInvalidationIds(const syncer::ObjectIdSet& ids); | |
155 | |
156 // Called to acknowledge an invalidation on behalf of | |
157 // SyncBackendHost::AcknowledgeInvalidation. | |
158 void DoAcknowledgeInvalidation(const invalidation::ObjectId& id, | |
159 const syncer::AckHandle& ack_handle); | |
160 | |
161 // Called to tell the syncapi to start syncing (generally after | 150 // Called to tell the syncapi to start syncing (generally after |
162 // initialization and authentication). | 151 // initialization and authentication). |
163 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); | 152 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); |
164 | 153 |
165 // Called to set the passphrase for encryption. | 154 // Called to set the passphrase for encryption. |
166 void DoSetEncryptionPassphrase(const std::string& passphrase, | 155 void DoSetEncryptionPassphrase(const std::string& passphrase, |
167 bool is_explicit); | 156 bool is_explicit); |
168 | 157 |
169 // Called to decrypt the pending keys. | 158 // Called to decrypt the pending keys. |
170 void DoSetDecryptionPassphrase(const std::string& passphrase); | 159 void DoSetDecryptionPassphrase(const std::string& passphrase); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 | 269 |
281 // Our encryptor, which uses Chrome's encryption functions. | 270 // Our encryptor, which uses Chrome's encryption functions. |
282 ChromeEncryptor encryptor_; | 271 ChromeEncryptor encryptor_; |
283 | 272 |
284 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. | 273 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
285 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; | 274 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; |
286 | 275 |
287 // The top-level syncapi entry point. Lives on the sync thread. | 276 // The top-level syncapi entry point. Lives on the sync thread. |
288 scoped_ptr<syncer::SyncManager> sync_manager_; | 277 scoped_ptr<syncer::SyncManager> sync_manager_; |
289 | 278 |
290 // Whether or not we registered with |sync_manager_| as an invalidation | |
291 // handler. Necessary since we may end up trying to unregister before we | |
292 // register in tests (in synchronous initialization mode). | |
293 // | |
294 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
295 bool registered_as_invalidation_handler_; | |
296 | |
297 DISALLOW_COPY_AND_ASSIGN(Core); | 279 DISALLOW_COPY_AND_ASSIGN(Core); |
298 }; | 280 }; |
299 | 281 |
300 namespace { | |
301 | |
302 // Parses the given command line for notifier options. | |
303 notifier::NotifierOptions ParseNotifierOptions( | |
304 const CommandLine& command_line, | |
305 const scoped_refptr<net::URLRequestContextGetter>& | |
306 request_context_getter) { | |
307 notifier::NotifierOptions notifier_options; | |
308 notifier_options.request_context_getter = request_context_getter; | |
309 | |
310 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { | |
311 notifier_options.xmpp_host_port = | |
312 net::HostPortPair::FromString( | |
313 command_line.GetSwitchValueASCII( | |
314 switches::kSyncNotificationHostPort)); | |
315 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() | |
316 << " for test sync notification server."; | |
317 } | |
318 | |
319 notifier_options.try_ssltcp_first = | |
320 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); | |
321 DVLOG_IF(1, notifier_options.try_ssltcp_first) | |
322 << "Trying SSL/TCP port before XMPP port for notifications."; | |
323 | |
324 notifier_options.invalidate_xmpp_login = | |
325 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); | |
326 DVLOG_IF(1, notifier_options.invalidate_xmpp_login) | |
327 << "Invalidating sync XMPP login."; | |
328 | |
329 notifier_options.allow_insecure_connection = | |
330 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); | |
331 DVLOG_IF(1, notifier_options.allow_insecure_connection) | |
332 << "Allowing insecure XMPP connections."; | |
333 | |
334 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { | |
335 const std::string notification_method_str( | |
336 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); | |
337 notifier_options.notification_method = | |
338 notifier::StringToNotificationMethod(notification_method_str); | |
339 } | |
340 | |
341 return notifier_options; | |
342 } | |
343 | |
344 } // namespace | |
345 | |
346 SyncBackendHost::SyncBackendHost( | 282 SyncBackendHost::SyncBackendHost( |
347 const std::string& name, | 283 const std::string& name, |
348 Profile* profile, | 284 Profile* profile, |
349 const base::WeakPtr<SyncPrefs>& sync_prefs, | 285 const base::WeakPtr<SyncPrefs>& sync_prefs) |
350 const base::WeakPtr<InvalidatorStorage>& invalidator_storage) | |
351 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 286 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
352 sync_thread_("Chrome_SyncThread"), | 287 sync_thread_("Chrome_SyncThread"), |
353 frontend_loop_(MessageLoop::current()), | 288 frontend_loop_(MessageLoop::current()), |
354 profile_(profile), | 289 profile_(profile), |
355 name_(name), | 290 name_(name), |
356 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), | 291 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), |
357 weak_ptr_factory_.GetWeakPtr())), | 292 weak_ptr_factory_.GetWeakPtr())), |
358 initialization_state_(NOT_ATTEMPTED), | 293 initialization_state_(NOT_ATTEMPTED), |
359 sync_prefs_(sync_prefs), | 294 sync_prefs_(sync_prefs), |
360 invalidator_factory_( | |
361 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
362 profile_->GetRequestContext()), | |
363 content::GetUserAgent(GURL()), | |
364 invalidator_storage), | |
365 frontend_(NULL), | 295 frontend_(NULL), |
366 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 296 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), |
297 invalidator_(InvalidationServiceFactory::GetForProfile(profile)) { | |
367 } | 298 } |
368 | 299 |
369 SyncBackendHost::SyncBackendHost(Profile* profile) | 300 SyncBackendHost::SyncBackendHost(Profile* profile) |
370 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 301 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
371 sync_thread_("Chrome_SyncThread"), | 302 sync_thread_("Chrome_SyncThread"), |
372 frontend_loop_(MessageLoop::current()), | 303 frontend_loop_(MessageLoop::current()), |
373 profile_(profile), | 304 profile_(profile), |
374 name_("Unknown"), | 305 name_("Unknown"), |
375 initialization_state_(NOT_ATTEMPTED), | 306 initialization_state_(NOT_ATTEMPTED), |
376 invalidator_factory_( | |
377 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | |
378 profile_->GetRequestContext()), | |
379 content::GetUserAgent(GURL()), | |
380 base::WeakPtr<syncer::InvalidationStateTracker>()), | |
381 frontend_(NULL), | 307 frontend_(NULL), |
382 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 308 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
383 } | 309 } |
384 | 310 |
385 SyncBackendHost::~SyncBackendHost() { | 311 SyncBackendHost::~SyncBackendHost() { |
386 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 312 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
387 DCHECK(!android_invalidator_bridge_.get()); | |
388 DCHECK(!registrar_.get()); | 313 DCHECK(!registrar_.get()); |
389 } | 314 } |
390 | 315 |
391 namespace { | 316 namespace { |
392 | 317 |
393 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | 318 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( |
394 const scoped_refptr<net::URLRequestContextGetter>& getter) { | 319 const scoped_refptr<net::URLRequestContextGetter>& getter) { |
395 chrome::VersionInfo version_info; | 320 chrome::VersionInfo version_info; |
396 return scoped_ptr<syncer::HttpPostProviderFactory>( | 321 return scoped_ptr<syncer::HttpPostProviderFactory>( |
397 new syncer::HttpBridgeFactory( | 322 new syncer::HttpBridgeFactory( |
398 getter, DeviceInfo::MakeUserAgentForSyncApi(version_info))); | 323 getter, DeviceInfo::MakeUserAgentForSyncApi(version_info))); |
399 } | 324 } |
400 | 325 |
401 } // namespace | 326 } // namespace |
402 | 327 |
403 void SyncBackendHost::Initialize( | 328 void SyncBackendHost::Initialize( |
404 SyncFrontend* frontend, | 329 SyncFrontend* frontend, |
405 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 330 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
406 const GURL& sync_service_url, | 331 const GURL& sync_service_url, |
407 const SyncCredentials& credentials, | 332 const SyncCredentials& credentials, |
408 bool delete_sync_data_folder, | 333 bool delete_sync_data_folder, |
409 syncer::SyncManagerFactory* sync_manager_factory, | 334 syncer::SyncManagerFactory* sync_manager_factory, |
410 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 335 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
411 syncer::ReportUnrecoverableErrorFunction | 336 syncer::ReportUnrecoverableErrorFunction |
412 report_unrecoverable_error_function) { | 337 report_unrecoverable_error_function) { |
413 if (!sync_thread_.Start()) | 338 if (!sync_thread_.Start()) |
414 return; | 339 return; |
415 | 340 |
416 android_invalidator_bridge_.reset( | |
417 new AndroidInvalidatorBridge( | |
418 profile_, sync_thread_.message_loop_proxy())); | |
419 | |
420 frontend_ = frontend; | 341 frontend_ = frontend; |
421 DCHECK(frontend); | 342 DCHECK(frontend); |
422 | 343 |
423 registrar_.reset(new SyncBackendRegistrar(name_, | 344 registrar_.reset(new SyncBackendRegistrar(name_, |
424 profile_, | 345 profile_, |
425 sync_thread_.message_loop())); | 346 sync_thread_.message_loop())); |
426 syncer::ModelSafeRoutingInfo routing_info; | 347 syncer::ModelSafeRoutingInfo routing_info; |
427 std::vector<syncer::ModelSafeWorker*> workers; | 348 std::vector<syncer::ModelSafeWorker*> workers; |
428 registrar_->GetModelSafeRoutingInfo(&routing_info); | 349 registrar_->GetModelSafeRoutingInfo(&routing_info); |
429 registrar_->GetWorkers(&workers); | 350 registrar_->GetWorkers(&workers); |
430 | 351 |
431 InternalComponentsFactory::Switches factory_switches = { | 352 InternalComponentsFactory::Switches factory_switches = { |
432 InternalComponentsFactory::ENCRYPTION_KEYSTORE, | 353 InternalComponentsFactory::ENCRYPTION_KEYSTORE, |
433 InternalComponentsFactory::BACKOFF_NORMAL | 354 InternalComponentsFactory::BACKOFF_NORMAL |
434 }; | 355 }; |
435 | 356 |
436 CommandLine* cl = CommandLine::ForCurrentProcess(); | 357 CommandLine* cl = CommandLine::ForCurrentProcess(); |
437 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { | 358 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { |
438 factory_switches.backoff_override = | 359 factory_switches.backoff_override = |
439 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; | 360 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; |
440 } | 361 } |
441 | 362 |
363 invalidator_->RegisterInvalidationHandler(this); | |
364 | |
442 initialization_state_ = CREATING_SYNC_MANAGER; | 365 initialization_state_ = CREATING_SYNC_MANAGER; |
443 InitCore(DoInitializeOptions( | 366 InitCore(DoInitializeOptions( |
444 sync_thread_.message_loop(), | 367 sync_thread_.message_loop(), |
445 registrar_.get(), | 368 registrar_.get(), |
446 routing_info, | 369 routing_info, |
447 workers, | 370 workers, |
448 &extensions_activity_monitor_, | 371 &extensions_activity_monitor_, |
449 event_handler, | 372 event_handler, |
450 sync_service_url, | 373 sync_service_url, |
451 base::Bind(&MakeHttpBridgeFactory, | 374 base::Bind(&MakeHttpBridgeFactory, |
452 make_scoped_refptr(profile_->GetRequestContext())), | 375 make_scoped_refptr(profile_->GetRequestContext())), |
453 credentials, | 376 credentials, |
454 android_invalidator_bridge_.get(), | 377 invalidator_->GetInvalidatorClientId(), |
455 &invalidator_factory_, | |
456 sync_manager_factory, | 378 sync_manager_factory, |
457 delete_sync_data_folder, | 379 delete_sync_data_folder, |
458 sync_prefs_->GetEncryptionBootstrapToken(), | 380 sync_prefs_->GetEncryptionBootstrapToken(), |
459 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 381 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
460 new InternalComponentsFactoryImpl(factory_switches), | 382 new InternalComponentsFactoryImpl(factory_switches), |
461 unrecoverable_error_handler, | 383 unrecoverable_error_handler, |
462 report_unrecoverable_error_function)); | 384 report_unrecoverable_error_function)); |
463 } | 385 } |
464 | 386 |
465 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 387 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
466 DCHECK(sync_thread_.IsRunning()); | 388 DCHECK(sync_thread_.IsRunning()); |
467 sync_thread_.message_loop()->PostTask(FROM_HERE, | 389 sync_thread_.message_loop()->PostTask(FROM_HERE, |
468 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), | 390 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), |
469 credentials)); | 391 credentials)); |
470 } | 392 } |
471 | 393 |
472 void SyncBackendHost::UpdateRegisteredInvalidationIds( | |
473 const syncer::ObjectIdSet& ids) { | |
474 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | |
475 DCHECK(sync_thread_.IsRunning()); | |
476 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
477 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds, | |
478 core_.get(), ids)); | |
479 } | |
480 | |
481 void SyncBackendHost::AcknowledgeInvalidation( | |
482 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { | |
483 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | |
484 DCHECK(sync_thread_.IsRunning()); | |
485 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
486 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation, | |
487 core_.get(), id, ack_handle)); | |
488 } | |
489 | |
490 void SyncBackendHost::StartSyncingWithServer() { | 394 void SyncBackendHost::StartSyncingWithServer() { |
491 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; | 395 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; |
492 | 396 |
493 syncer::ModelSafeRoutingInfo routing_info; | 397 syncer::ModelSafeRoutingInfo routing_info; |
494 registrar_->GetModelSafeRoutingInfo(&routing_info); | 398 registrar_->GetModelSafeRoutingInfo(&routing_info); |
495 | 399 |
496 sync_thread_.message_loop()->PostTask(FROM_HERE, | 400 sync_thread_.message_loop()->PostTask(FROM_HERE, |
497 base::Bind(&SyncBackendHost::Core::DoStartSyncing, | 401 base::Bind(&SyncBackendHost::Core::DoStartSyncing, |
498 core_.get(), routing_info)); | 402 core_.get(), routing_info)); |
499 } | 403 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 // so the registrar won't need stopping either. | 527 // so the registrar won't need stopping either. |
624 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED); | 528 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED); |
625 DCHECK(!registrar_.get()); | 529 DCHECK(!registrar_.get()); |
626 } | 530 } |
627 } | 531 } |
628 | 532 |
629 void SyncBackendHost::Shutdown(bool sync_disabled) { | 533 void SyncBackendHost::Shutdown(bool sync_disabled) { |
630 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 534 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
631 // called first. | 535 // called first. |
632 DCHECK(!frontend_); | 536 DCHECK(!frontend_); |
537 | |
538 invalidator_->UnregisterInvalidationHandler(this); | |
tim (not reviewing)
2013/04/15 16:48:24
I'm trying to convince myself this is a safe chang
rlarocque
2013/04/22 21:47:15
It's actually pretty easy to verify that this is s
| |
539 invalidator_ = NULL; | |
540 | |
633 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. | 541 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. |
634 if (sync_thread_.IsRunning()) { | 542 if (sync_thread_.IsRunning()) { |
635 sync_thread_.message_loop()->PostTask(FROM_HERE, | 543 sync_thread_.message_loop()->PostTask(FROM_HERE, |
636 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), | 544 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), |
637 sync_disabled)); | 545 sync_disabled)); |
638 | |
639 if (android_invalidator_bridge_.get()) | |
640 android_invalidator_bridge_->StopForShutdown(); | |
641 } | 546 } |
642 | 547 |
643 // Stop will return once the thread exits, which will be after DoShutdown | 548 // Stop will return once the thread exits, which will be after DoShutdown |
644 // runs. DoShutdown needs to run from sync_thread_ because the sync backend | 549 // runs. DoShutdown needs to run from sync_thread_ because the sync backend |
645 // requires any thread that opened sqlite handles to relinquish them | 550 // requires any thread that opened sqlite handles to relinquish them |
646 // personally. We need to join threads, because otherwise the main Chrome | 551 // personally. We need to join threads, because otherwise the main Chrome |
647 // thread (ui loop) can exit before DoShutdown finishes, at which point | 552 // thread (ui loop) can exit before DoShutdown finishes, at which point |
648 // virtually anything the sync backend does (or the post-back to | 553 // virtually anything the sync backend does (or the post-back to |
649 // frontend_loop_ by our Core) will epically fail because the CRT won't be | 554 // frontend_loop_ by our Core) will epically fail because the CRT won't be |
650 // initialized. | 555 // initialized. |
651 // Since we are blocking the UI thread here, we need to turn ourselves in | 556 // Since we are blocking the UI thread here, we need to turn ourselves in |
652 // with the ThreadRestriction police. For sentencing and how we plan to fix | 557 // with the ThreadRestriction police. For sentencing and how we plan to fix |
653 // this, see bug 19757. | 558 // this, see bug 19757. |
654 base::Time stop_thread_start_time = base::Time::Now(); | 559 base::Time stop_thread_start_time = base::Time::Now(); |
655 { | 560 { |
656 base::ThreadRestrictions::ScopedAllowIO allow_io; | 561 base::ThreadRestrictions::ScopedAllowIO allow_io; |
657 sync_thread_.Stop(); | 562 sync_thread_.Stop(); |
658 } | 563 } |
659 base::TimeDelta stop_sync_thread_time = base::Time::Now() - | 564 base::TimeDelta stop_sync_thread_time = base::Time::Now() - |
660 stop_thread_start_time; | 565 stop_thread_start_time; |
661 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", | 566 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", |
662 stop_sync_thread_time); | 567 stop_sync_thread_time); |
663 | 568 |
664 registrar_.reset(); | 569 registrar_.reset(); |
665 js_backend_.Reset(); | 570 js_backend_.Reset(); |
666 android_invalidator_bridge_.reset(); | |
667 core_ = NULL; // Releases reference to core_. | 571 core_ = NULL; // Releases reference to core_. |
668 } | 572 } |
669 | 573 |
670 void SyncBackendHost::ConfigureDataTypes( | 574 void SyncBackendHost::ConfigureDataTypes( |
671 syncer::ConfigureReason reason, | 575 syncer::ConfigureReason reason, |
672 const DataTypeConfigStateMap& config_state_map, | 576 const DataTypeConfigStateMap& config_state_map, |
673 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 577 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
674 const base::Callback<void()>& retry_callback) { | 578 const base::Callback<void()>& retry_callback) { |
675 // Only one configure is allowed at a time. This is guaranteed by our | 579 // Only one configure is allowed at a time. This is guaranteed by our |
676 // callers. The SyncBackendHost requests one configure as the backend is | 580 // callers. The SyncBackendHost requests one configure as the backend is |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 core_.get(), | 730 core_.get(), |
827 reason, | 731 reason, |
828 types_to_config, | 732 types_to_config, |
829 failed_types, | 733 failed_types, |
830 routing_info, | 734 routing_info, |
831 ready_task, | 735 ready_task, |
832 retry_callback)); | 736 retry_callback)); |
833 } | 737 } |
834 | 738 |
835 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( | 739 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( |
740 syncer::ModelTypeSet enabled_types, | |
836 syncer::ModelTypeSet failed_configuration_types, | 741 syncer::ModelTypeSet failed_configuration_types, |
837 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { | 742 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { |
743 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | |
744 | |
838 if (!frontend_) | 745 if (!frontend_) |
839 return; | 746 return; |
840 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 747 |
748 invalidator_->UpdateRegisteredInvalidationIds( | |
749 this, | |
750 ModelTypeSetToObjectIdSet(enabled_types)); | |
751 | |
841 if (!ready_task.is_null()) | 752 if (!ready_task.is_null()) |
842 ready_task.Run(failed_configuration_types); | 753 ready_task.Run(failed_configuration_types); |
843 } | 754 } |
844 | 755 |
845 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( | 756 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
846 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 757 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
847 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 758 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
848 debug_info_listener, | 759 debug_info_listener, |
849 syncer::ModelTypeSet restored_types) { | 760 syncer::ModelTypeSet restored_types) { |
850 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); | 761 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); |
851 DCHECK(!js_backend_.IsInitialized()); | 762 DCHECK(!js_backend_.IsInitialized()); |
852 | 763 |
853 initialization_state_ = INITIALIZATING_CONTROL_TYPES; | 764 initialization_state_ = INITIALIZATING_CONTROL_TYPES; |
854 | 765 |
855 js_backend_ = js_backend; | 766 js_backend_ = js_backend; |
856 debug_info_listener_ = debug_info_listener; | 767 debug_info_listener_ = debug_info_listener; |
857 | 768 |
858 // Inform the registrar of those types that have been fully downloaded and | 769 // Inform the registrar of those types that have been fully downloaded and |
859 // applied. | 770 // applied. |
860 registrar_->SetInitialTypes(restored_types); | 771 registrar_->SetInitialTypes(restored_types); |
861 | 772 |
862 // Start forwarding refresh requests to the SyncManager | 773 // Start forwarding refresh requests to the SyncManager |
863 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 774 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
864 content::Source<Profile>(profile_)); | 775 content::Source<Profile>(profile_)); |
865 | 776 |
777 // Fake a state change to initialize the SyncManager's cached invalidator | |
778 // state. | |
779 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); | |
780 | |
866 // Kick off the next step in SyncBackendHost initialization by downloading | 781 // Kick off the next step in SyncBackendHost initialization by downloading |
867 // any necessary control types. | 782 // any necessary control types. |
868 sync_thread_.message_loop()->PostTask( | 783 sync_thread_.message_loop()->PostTask( |
869 FROM_HERE, | 784 FROM_HERE, |
870 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, | 785 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, |
871 core_.get())); | 786 core_.get())); |
872 } | 787 } |
873 | 788 |
874 void SyncBackendHost::Observe( | 789 void SyncBackendHost::Observe( |
875 int type, | 790 int type, |
(...skipping 15 matching lines...) Expand all Loading... | |
891 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( | 806 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
892 MessageLoop* sync_loop, | 807 MessageLoop* sync_loop, |
893 SyncBackendRegistrar* registrar, | 808 SyncBackendRegistrar* registrar, |
894 const syncer::ModelSafeRoutingInfo& routing_info, | 809 const syncer::ModelSafeRoutingInfo& routing_info, |
895 const std::vector<syncer::ModelSafeWorker*>& workers, | 810 const std::vector<syncer::ModelSafeWorker*>& workers, |
896 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 811 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
897 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 812 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
898 const GURL& service_url, | 813 const GURL& service_url, |
899 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 814 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
900 const syncer::SyncCredentials& credentials, | 815 const syncer::SyncCredentials& credentials, |
901 AndroidInvalidatorBridge* android_invalidator_bridge, | 816 const std::string& invalidator_client_id, |
902 syncer::InvalidatorFactory* invalidator_factory, | |
903 syncer::SyncManagerFactory* sync_manager_factory, | 817 syncer::SyncManagerFactory* sync_manager_factory, |
904 bool delete_sync_data_folder, | 818 bool delete_sync_data_folder, |
905 const std::string& restored_key_for_bootstrapping, | 819 const std::string& restored_key_for_bootstrapping, |
906 const std::string& restored_keystore_key_for_bootstrapping, | 820 const std::string& restored_keystore_key_for_bootstrapping, |
907 InternalComponentsFactory* internal_components_factory, | 821 InternalComponentsFactory* internal_components_factory, |
908 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 822 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
909 syncer::ReportUnrecoverableErrorFunction | 823 syncer::ReportUnrecoverableErrorFunction |
910 report_unrecoverable_error_function) | 824 report_unrecoverable_error_function) |
911 : sync_loop(sync_loop), | 825 : sync_loop(sync_loop), |
912 registrar(registrar), | 826 registrar(registrar), |
913 routing_info(routing_info), | 827 routing_info(routing_info), |
914 workers(workers), | 828 workers(workers), |
915 extensions_activity_monitor(extensions_activity_monitor), | 829 extensions_activity_monitor(extensions_activity_monitor), |
916 event_handler(event_handler), | 830 event_handler(event_handler), |
917 service_url(service_url), | 831 service_url(service_url), |
918 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 832 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
919 credentials(credentials), | 833 credentials(credentials), |
920 android_invalidator_bridge(android_invalidator_bridge), | 834 invalidator_client_id(invalidator_client_id), |
921 invalidator_factory(invalidator_factory), | |
922 sync_manager_factory(sync_manager_factory), | 835 sync_manager_factory(sync_manager_factory), |
923 delete_sync_data_folder(delete_sync_data_folder), | 836 delete_sync_data_folder(delete_sync_data_folder), |
924 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 837 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
925 restored_keystore_key_for_bootstrapping( | 838 restored_keystore_key_for_bootstrapping( |
926 restored_keystore_key_for_bootstrapping), | 839 restored_keystore_key_for_bootstrapping), |
927 internal_components_factory(internal_components_factory), | 840 internal_components_factory(internal_components_factory), |
928 unrecoverable_error_handler(unrecoverable_error_handler), | 841 unrecoverable_error_handler(unrecoverable_error_handler), |
929 report_unrecoverable_error_function( | 842 report_unrecoverable_error_function( |
930 report_unrecoverable_error_function) { | 843 report_unrecoverable_error_function) { |
931 } | 844 } |
932 | 845 |
933 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 846 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
934 | 847 |
935 SyncBackendHost::Core::Core(const std::string& name, | 848 SyncBackendHost::Core::Core(const std::string& name, |
936 const base::FilePath& sync_data_folder_path, | 849 const base::FilePath& sync_data_folder_path, |
937 const base::WeakPtr<SyncBackendHost>& backend) | 850 const base::WeakPtr<SyncBackendHost>& backend) |
938 : name_(name), | 851 : name_(name), |
939 sync_data_folder_path_(sync_data_folder_path), | 852 sync_data_folder_path_(sync_data_folder_path), |
940 host_(backend), | 853 host_(backend), |
941 sync_loop_(NULL), | 854 sync_loop_(NULL), |
942 registrar_(NULL), | 855 registrar_(NULL) { |
943 registered_as_invalidation_handler_(false) { | |
944 DCHECK(backend.get()); | 856 DCHECK(backend.get()); |
945 } | 857 } |
946 | 858 |
947 SyncBackendHost::Core::~Core() { | 859 SyncBackendHost::Core::~Core() { |
948 DCHECK(!sync_manager_.get()); | 860 DCHECK(!sync_manager_.get()); |
949 DCHECK(!sync_loop_); | 861 DCHECK(!sync_loop_); |
950 } | 862 } |
951 | 863 |
952 void SyncBackendHost::Core::OnSyncCycleCompleted( | 864 void SyncBackendHost::Core::OnSyncCycleCompleted( |
953 const SyncSessionSnapshot& snapshot) { | 865 const SyncSessionSnapshot& snapshot) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 const syncer::SyncProtocolError& sync_error) { | 1037 const syncer::SyncProtocolError& sync_error) { |
1126 if (!sync_loop_) | 1038 if (!sync_loop_) |
1127 return; | 1039 return; |
1128 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1040 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1129 host_.Call( | 1041 host_.Call( |
1130 FROM_HERE, | 1042 FROM_HERE, |
1131 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 1043 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
1132 sync_error); | 1044 sync_error); |
1133 } | 1045 } |
1134 | 1046 |
1135 void SyncBackendHost::Core::OnInvalidatorStateChange( | 1047 void SyncBackendHost::Core::DoOnInvalidatorStateChange( |
1136 syncer::InvalidatorState state) { | 1048 syncer::InvalidatorState state) { |
1137 if (!sync_loop_) | |
1138 return; | |
1139 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1049 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1140 host_.Call(FROM_HERE, | 1050 sync_manager_->UpdateInvalidatorState(state); |
1141 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop, | |
1142 state); | |
1143 } | 1051 } |
1144 | 1052 |
1145 void SyncBackendHost::Core::OnIncomingInvalidation( | 1053 void SyncBackendHost::Core::DoOnIncomingInvalidation( |
1146 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 1054 syncer::ObjectIdInvalidationMap invalidation_map) { |
1147 if (!sync_loop_) | |
1148 return; | |
1149 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1055 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1150 host_.Call(FROM_HERE, | 1056 sync_manager_->Invalidate(invalidation_map); |
1151 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop, | |
1152 invalidation_map); | |
1153 } | 1057 } |
1154 | 1058 |
1155 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { | 1059 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
1156 DCHECK(!sync_loop_); | 1060 DCHECK(!sync_loop_); |
1157 sync_loop_ = options.sync_loop; | 1061 sync_loop_ = options.sync_loop; |
1158 DCHECK(sync_loop_); | 1062 DCHECK(sync_loop_); |
1159 | 1063 |
1160 // Blow away the partial or corrupt sync data folder before doing any more | 1064 // Blow away the partial or corrupt sync data folder before doing any more |
1161 // initialization, if necessary. | 1065 // initialization, if necessary. |
1162 if (options.delete_sync_data_folder) { | 1066 if (options.delete_sync_data_folder) { |
(...skipping 16 matching lines...) Expand all Loading... | |
1179 sync_data_folder_path_, | 1083 sync_data_folder_path_, |
1180 options.event_handler, | 1084 options.event_handler, |
1181 options.service_url.host() + options.service_url.path(), | 1085 options.service_url.host() + options.service_url.path(), |
1182 options.service_url.EffectiveIntPort(), | 1086 options.service_url.EffectiveIntPort(), |
1183 options.service_url.SchemeIsSecure(), | 1087 options.service_url.SchemeIsSecure(), |
1184 options.make_http_bridge_factory_fn.Run().Pass(), | 1088 options.make_http_bridge_factory_fn.Run().Pass(), |
1185 options.workers, | 1089 options.workers, |
1186 options.extensions_activity_monitor, | 1090 options.extensions_activity_monitor, |
1187 options.registrar /* as SyncManager::ChangeDelegate */, | 1091 options.registrar /* as SyncManager::ChangeDelegate */, |
1188 options.credentials, | 1092 options.credentials, |
1189 #if defined(OS_ANDROID) | 1093 options.invalidator_client_id, |
1190 scoped_ptr<syncer::Invalidator>( | |
1191 new AndroidInvalidatorBridgeProxy( | |
1192 options.android_invalidator_bridge)), | |
1193 #else | |
1194 scoped_ptr<syncer::Invalidator>( | |
1195 options.invalidator_factory->CreateInvalidator()), | |
1196 #endif | |
1197 options.invalidator_factory->GetInvalidatorClientId(), | |
1198 options.restored_key_for_bootstrapping, | 1094 options.restored_key_for_bootstrapping, |
1199 options.restored_keystore_key_for_bootstrapping, | 1095 options.restored_keystore_key_for_bootstrapping, |
1200 scoped_ptr<InternalComponentsFactory>( | 1096 scoped_ptr<InternalComponentsFactory>( |
1201 options.internal_components_factory), | 1097 options.internal_components_factory), |
1202 &encryptor_, | 1098 &encryptor_, |
1203 options.unrecoverable_error_handler, | 1099 options.unrecoverable_error_handler, |
1204 options.report_unrecoverable_error_function); | 1100 options.report_unrecoverable_error_function); |
1205 | 1101 |
1206 // |sync_manager_| may end up being NULL here in tests (in | 1102 // |sync_manager_| may end up being NULL here in tests (in |
1207 // synchronous initialization mode). | 1103 // synchronous initialization mode). |
1208 // | 1104 // |
1209 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 1105 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
1210 if (sync_manager_.get()) { | 1106 if (sync_manager_.get()) { |
1211 sync_manager_->RegisterInvalidationHandler(this); | |
1212 registered_as_invalidation_handler_ = true; | |
1213 | |
1214 // Now check the command line to see if we need to simulate an | 1107 // Now check the command line to see if we need to simulate an |
1215 // unrecoverable error for testing purpose. Note the error is thrown | 1108 // unrecoverable error for testing purpose. Note the error is thrown |
1216 // only if the initialization succeeded. Also it makes sense to use this | 1109 // only if the initialization succeeded. Also it makes sense to use this |
1217 // flag only when restarting the browser with an account already setup. If | 1110 // flag only when restarting the browser with an account already setup. If |
1218 // you use this before setting up the setup would not succeed as an error | 1111 // you use this before setting up the setup would not succeed as an error |
1219 // would be encountered. | 1112 // would be encountered. |
1220 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1113 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1221 switches::kSyncThrowUnrecoverableError)) { | 1114 switches::kSyncThrowUnrecoverableError)) { |
1222 sync_manager_->ThrowUnrecoverableError(); | 1115 sync_manager_->ThrowUnrecoverableError(); |
1223 } | 1116 } |
1224 } | 1117 } |
1225 } | 1118 } |
1226 | 1119 |
1227 void SyncBackendHost::Core::DoUpdateCredentials( | 1120 void SyncBackendHost::Core::DoUpdateCredentials( |
1228 const SyncCredentials& credentials) { | 1121 const SyncCredentials& credentials) { |
1229 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1122 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1230 // UpdateCredentials can be called during backend initialization, possibly | 1123 // UpdateCredentials can be called during backend initialization, possibly |
1231 // when backend initialization has failed but hasn't notified the UI thread | 1124 // when backend initialization has failed but hasn't notified the UI thread |
1232 // yet. In that case, the sync manager may have been destroyed on the sync | 1125 // yet. In that case, the sync manager may have been destroyed on the sync |
1233 // thread before this task was executed, so we do nothing. | 1126 // thread before this task was executed, so we do nothing. |
1234 if (sync_manager_.get()) { | 1127 if (sync_manager_.get()) { |
1235 sync_manager_->UpdateCredentials(credentials); | 1128 sync_manager_->UpdateCredentials(credentials); |
1236 } | 1129 } |
1237 } | 1130 } |
1238 | 1131 |
1239 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds( | |
1240 const syncer::ObjectIdSet& ids) { | |
1241 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
1242 // |sync_manager_| may end up being NULL here in tests (in | |
1243 // synchronous initialization mode) since this is called during | |
1244 // shutdown. | |
1245 // | |
1246 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
1247 if (sync_manager_.get()) { | |
1248 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); | |
1249 } | |
1250 } | |
1251 | |
1252 void SyncBackendHost::Core::DoAcknowledgeInvalidation( | |
1253 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { | |
1254 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
1255 // |sync_manager_| may end up being NULL here in tests (in | |
1256 // synchronous initialization mode). | |
1257 // | |
1258 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | |
1259 if (sync_manager_.get()) { | |
1260 sync_manager_->AcknowledgeInvalidation(id, ack_handle); | |
1261 } | |
1262 } | |
1263 | |
1264 void SyncBackendHost::Core::DoStartSyncing( | 1132 void SyncBackendHost::Core::DoStartSyncing( |
1265 const syncer::ModelSafeRoutingInfo& routing_info) { | 1133 const syncer::ModelSafeRoutingInfo& routing_info) { |
1266 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1134 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1267 sync_manager_->StartSyncingNormally(routing_info); | 1135 sync_manager_->StartSyncingNormally(routing_info); |
1268 } | 1136 } |
1269 | 1137 |
1270 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1138 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
1271 const std::string& passphrase, | 1139 const std::string& passphrase, |
1272 bool is_explicit) { | 1140 bool is_explicit) { |
1273 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1141 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1363 | 1231 |
1364 sync_loop_ = NULL; | 1232 sync_loop_ = NULL; |
1365 | 1233 |
1366 host_.Reset(); | 1234 host_.Reset(); |
1367 } | 1235 } |
1368 | 1236 |
1369 void SyncBackendHost::Core::DoDestroySyncManager() { | 1237 void SyncBackendHost::Core::DoDestroySyncManager() { |
1370 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1238 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1371 if (sync_manager_.get()) { | 1239 if (sync_manager_.get()) { |
1372 save_changes_timer_.reset(); | 1240 save_changes_timer_.reset(); |
1373 if (registered_as_invalidation_handler_) { | |
1374 sync_manager_->UnregisterInvalidationHandler(this); | |
1375 registered_as_invalidation_handler_ = false; | |
1376 } | |
1377 sync_manager_->RemoveObserver(this); | 1241 sync_manager_->RemoveObserver(this); |
1378 sync_manager_->ShutdownOnSyncThread(); | 1242 sync_manager_->ShutdownOnSyncThread(); |
1379 sync_manager_.reset(); | 1243 sync_manager_.reset(); |
1380 } | 1244 } |
1381 } | 1245 } |
1382 | 1246 |
1383 void SyncBackendHost::Core::DoConfigureSyncer( | 1247 void SyncBackendHost::Core::DoConfigureSyncer( |
1384 syncer::ConfigureReason reason, | 1248 syncer::ConfigureReason reason, |
1385 syncer::ModelTypeSet types_to_config, | 1249 syncer::ModelTypeSet types_to_config, |
1386 syncer::ModelTypeSet failed_types, | 1250 syncer::ModelTypeSet failed_types, |
(...skipping 18 matching lines...) Expand all Loading... | |
1405 void SyncBackendHost::Core::DoFinishConfigureDataTypes( | 1269 void SyncBackendHost::Core::DoFinishConfigureDataTypes( |
1406 syncer::ModelTypeSet types_to_config, | 1270 syncer::ModelTypeSet types_to_config, |
1407 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { | 1271 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { |
1408 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1272 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1409 | 1273 |
1410 // Update the enabled types for the bridge and sync manager. | 1274 // Update the enabled types for the bridge and sync manager. |
1411 syncer::ModelSafeRoutingInfo routing_info; | 1275 syncer::ModelSafeRoutingInfo routing_info; |
1412 registrar_->GetModelSafeRoutingInfo(&routing_info); | 1276 registrar_->GetModelSafeRoutingInfo(&routing_info); |
1413 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); | 1277 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); |
1414 enabled_types.RemoveAll(syncer::ProxyTypes()); | 1278 enabled_types.RemoveAll(syncer::ProxyTypes()); |
1415 sync_manager_->UpdateEnabledTypes(enabled_types); | |
1416 | 1279 |
1417 const syncer::ModelTypeSet failed_configuration_types = | 1280 const syncer::ModelTypeSet failed_configuration_types = |
1418 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); | 1281 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); |
1419 host_.Call(FROM_HERE, | 1282 host_.Call(FROM_HERE, |
1420 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, | 1283 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, |
1284 enabled_types, | |
1421 failed_configuration_types, | 1285 failed_configuration_types, |
1422 ready_task); | 1286 ready_task); |
1423 } | 1287 } |
1424 | 1288 |
1425 void SyncBackendHost::Core::DoRetryConfiguration( | 1289 void SyncBackendHost::Core::DoRetryConfiguration( |
1426 const base::Closure& retry_callback) { | 1290 const base::Closure& retry_callback) { |
1427 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1291 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1428 host_.Call(FROM_HERE, | 1292 host_.Call(FROM_HERE, |
1429 &SyncBackendHost::RetryConfigurationOnFrontendLoop, | 1293 &SyncBackendHost::RetryConfigurationOnFrontendLoop, |
1430 retry_callback); | 1294 retry_callback); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1541 } | 1405 } |
1542 | 1406 |
1543 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( | 1407 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( |
1544 const syncer::SyncProtocolError& sync_error) { | 1408 const syncer::SyncProtocolError& sync_error) { |
1545 if (!frontend_) | 1409 if (!frontend_) |
1546 return; | 1410 return; |
1547 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1411 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
1548 frontend_->OnActionableError(sync_error); | 1412 frontend_->OnActionableError(sync_error); |
1549 } | 1413 } |
1550 | 1414 |
1551 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( | 1415 void SyncBackendHost::OnInvalidatorStateChange(syncer::InvalidatorState state) { |
1552 syncer::InvalidatorState state) { | 1416 sync_thread_.message_loop()->PostTask( |
1553 if (!frontend_) | 1417 FROM_HERE, |
1554 return; | 1418 base::Bind(&SyncBackendHost::Core::DoOnInvalidatorStateChange, |
1555 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1419 core_.get(), |
1556 frontend_->OnInvalidatorStateChange(state); | 1420 state)); |
1557 } | 1421 } |
1558 | 1422 |
1559 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( | 1423 void SyncBackendHost::OnIncomingInvalidation( |
1560 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 1424 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
1561 if (!frontend_) | 1425 // TODO(dcheng): Acknowledge immediately for now. Fix this once the |
1562 return; | 1426 // invalidator doesn't repeatedly ping for unacknowledged invaliations, since |
1563 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1427 // it conflicts with the sync scheduler's internal backoff algorithm. |
1564 frontend_->OnIncomingInvalidation(invalidation_map); | 1428 // See http://crbug.com/124149 for more information. |
1429 for (syncer::ObjectIdInvalidationMap::const_iterator it = | |
1430 invalidation_map.begin(); it != invalidation_map.end(); ++it) { | |
1431 invalidator_->AcknowledgeInvalidation(it->first, it->second.ack_handle); | |
1432 } | |
1433 | |
1434 sync_thread_.message_loop()->PostTask( | |
1435 FROM_HERE, | |
1436 base::Bind(&SyncBackendHost::Core::DoOnIncomingInvalidation, | |
1437 core_.get(), | |
1438 invalidation_map)); | |
1565 } | 1439 } |
1566 | 1440 |
1567 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( | 1441 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( |
1568 const std::string& passphrase) const { | 1442 const std::string& passphrase) const { |
1569 DCHECK(cached_pending_keys_.has_blob()); | 1443 DCHECK(cached_pending_keys_.has_blob()); |
1570 DCHECK(!passphrase.empty()); | 1444 DCHECK(!passphrase.empty()); |
1571 syncer::Nigori nigori; | 1445 syncer::Nigori nigori; |
1572 nigori.InitByDerivation("localhost", "dummy", passphrase); | 1446 nigori.InitByDerivation("localhost", "dummy", passphrase); |
1573 std::string plaintext; | 1447 std::string plaintext; |
1574 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); | 1448 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1655 DVLOG(1) << "Connection status changed: " | 1529 DVLOG(1) << "Connection status changed: " |
1656 << syncer::ConnectionStatusToString(status); | 1530 << syncer::ConnectionStatusToString(status); |
1657 frontend_->OnConnectionStatusChange(status); | 1531 frontend_->OnConnectionStatusChange(status); |
1658 } | 1532 } |
1659 | 1533 |
1660 #undef SDVLOG | 1534 #undef SDVLOG |
1661 | 1535 |
1662 #undef SLOG | 1536 #undef SLOG |
1663 | 1537 |
1664 } // namespace browser_sync | 1538 } // namespace browser_sync |
OLD | NEW |