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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "sync/engine/sync_scheduler.h" | 19 #include "sync/engine/sync_scheduler.h" |
20 #include "sync/engine/syncer_types.h" | 20 #include "sync/engine/syncer_types.h" |
21 #include "sync/internal_api/change_reorder_buffer.h" | 21 #include "sync/internal_api/change_reorder_buffer.h" |
| 22 #include "sync/internal_api/public/base/cancellation_signal.h" |
22 #include "sync/internal_api/public/base/model_type.h" | 23 #include "sync/internal_api/public/base/model_type.h" |
23 #include "sync/internal_api/public/base/model_type_invalidation_map.h" | 24 #include "sync/internal_api/public/base/model_type_invalidation_map.h" |
24 #include "sync/internal_api/public/base_node.h" | 25 #include "sync/internal_api/public/base_node.h" |
25 #include "sync/internal_api/public/configure_reason.h" | 26 #include "sync/internal_api/public/configure_reason.h" |
26 #include "sync/internal_api/public/engine/polling_constants.h" | 27 #include "sync/internal_api/public/engine/polling_constants.h" |
27 #include "sync/internal_api/public/http_post_provider_factory.h" | 28 #include "sync/internal_api/public/http_post_provider_factory.h" |
28 #include "sync/internal_api/public/internal_components_factory.h" | 29 #include "sync/internal_api/public/internal_components_factory.h" |
29 #include "sync/internal_api/public/read_node.h" | 30 #include "sync/internal_api/public/read_node.h" |
30 #include "sync/internal_api/public/read_transaction.h" | 31 #include "sync/internal_api/public/read_transaction.h" |
31 #include "sync/internal_api/public/user_share.h" | 32 #include "sync/internal_api/public/user_share.h" |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 ExtensionsActivity* extensions_activity, | 349 ExtensionsActivity* extensions_activity, |
349 SyncManager::ChangeDelegate* change_delegate, | 350 SyncManager::ChangeDelegate* change_delegate, |
350 const SyncCredentials& credentials, | 351 const SyncCredentials& credentials, |
351 const std::string& invalidator_client_id, | 352 const std::string& invalidator_client_id, |
352 const std::string& restored_key_for_bootstrapping, | 353 const std::string& restored_key_for_bootstrapping, |
353 const std::string& restored_keystore_key_for_bootstrapping, | 354 const std::string& restored_keystore_key_for_bootstrapping, |
354 InternalComponentsFactory* internal_components_factory, | 355 InternalComponentsFactory* internal_components_factory, |
355 Encryptor* encryptor, | 356 Encryptor* encryptor, |
356 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler, | 357 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler, |
357 ReportUnrecoverableErrorFunction report_unrecoverable_error_function, | 358 ReportUnrecoverableErrorFunction report_unrecoverable_error_function, |
358 bool use_oauth2_token) { | 359 bool use_oauth2_token, |
| 360 CancellationSignal* cancellation_signal) { |
359 CHECK(!initialized_); | 361 CHECK(!initialized_); |
360 DCHECK(thread_checker_.CalledOnValidThread()); | 362 DCHECK(thread_checker_.CalledOnValidThread()); |
361 DCHECK(post_factory.get()); | 363 DCHECK(post_factory.get()); |
362 DCHECK(!credentials.email.empty()); | 364 DCHECK(!credentials.email.empty()); |
363 DCHECK(!credentials.sync_token.empty()); | 365 DCHECK(!credentials.sync_token.empty()); |
| 366 DCHECK(cancellation_signal); |
364 DVLOG(1) << "SyncManager starting Init..."; | 367 DVLOG(1) << "SyncManager starting Init..."; |
365 | 368 |
366 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 369 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
367 | 370 |
368 change_delegate_ = change_delegate; | 371 change_delegate_ = change_delegate; |
369 | 372 |
370 AddObserver(&js_sync_manager_observer_); | 373 AddObserver(&js_sync_manager_observer_); |
371 SetJsEventHandler(event_handler); | 374 SetJsEventHandler(event_handler); |
372 | 375 |
373 AddObserver(&debug_info_event_listener_); | 376 AddObserver(&debug_info_event_listener_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 416 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
414 MakeWeakHandle( | 417 MakeWeakHandle( |
415 debug_info_event_listener_.GetWeakPtr()), | 418 debug_info_event_listener_.GetWeakPtr()), |
416 false, ModelTypeSet())); | 419 false, ModelTypeSet())); |
417 LOG(ERROR) << "Sync manager initialization failed!"; | 420 LOG(ERROR) << "Sync manager initialization failed!"; |
418 return; | 421 return; |
419 } | 422 } |
420 | 423 |
421 connection_manager_.reset(new SyncAPIServerConnectionManager( | 424 connection_manager_.reset(new SyncAPIServerConnectionManager( |
422 sync_server_and_path, port, use_ssl, use_oauth2_token, | 425 sync_server_and_path, port, use_ssl, use_oauth2_token, |
423 post_factory.release())); | 426 post_factory.release(), cancellation_signal)); |
424 connection_manager_->set_client_id(directory()->cache_guid()); | 427 connection_manager_->set_client_id(directory()->cache_guid()); |
425 connection_manager_->AddListener(this); | 428 connection_manager_->AddListener(this); |
426 | 429 |
427 std::string sync_id = directory()->cache_guid(); | 430 std::string sync_id = directory()->cache_guid(); |
428 | 431 |
429 allstatus_.SetSyncId(sync_id); | 432 allstatus_.SetSyncId(sync_id); |
430 allstatus_.SetInvalidatorClientId(invalidator_client_id); | 433 allstatus_.SetInvalidatorClientId(invalidator_client_id); |
431 | 434 |
432 DVLOG(1) << "Setting sync client ID: " << sync_id; | 435 DVLOG(1) << "Setting sync client ID: " << sync_id; |
433 DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id; | 436 DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id; |
434 | 437 |
435 // Build a SyncSessionContext and store the worker in it. | 438 // Build a SyncSessionContext and store the worker in it. |
436 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | 439 DVLOG(1) << "Sync is bringing up SyncSessionContext."; |
437 std::vector<SyncEngineEventListener*> listeners; | 440 std::vector<SyncEngineEventListener*> listeners; |
438 listeners.push_back(&allstatus_); | 441 listeners.push_back(&allstatus_); |
439 listeners.push_back(this); | 442 listeners.push_back(this); |
440 session_context_ = internal_components_factory->BuildContext( | 443 session_context_ = internal_components_factory->BuildContext( |
441 connection_manager_.get(), | 444 connection_manager_.get(), |
442 directory(), | 445 directory(), |
443 workers, | 446 workers, |
444 extensions_activity, | 447 extensions_activity, |
445 listeners, | 448 listeners, |
446 &debug_info_event_listener_, | 449 &debug_info_event_listener_, |
447 &traffic_recorder_, | 450 &traffic_recorder_, |
448 invalidator_client_id).Pass(); | 451 invalidator_client_id).Pass(); |
449 session_context_->set_account_name(credentials.email); | 452 session_context_->set_account_name(credentials.email); |
450 scheduler_ = internal_components_factory->BuildScheduler( | 453 scheduler_ = internal_components_factory->BuildScheduler( |
451 name_, session_context_.get()).Pass(); | 454 name_, session_context_.get(), cancellation_signal).Pass(); |
452 | 455 |
453 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); | 456 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); |
454 | 457 |
455 initialized_ = true; | 458 initialized_ = true; |
456 | 459 |
457 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 460 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
458 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 461 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
459 observing_network_connectivity_changes_ = true; | 462 observing_network_connectivity_changes_ = true; |
460 | 463 |
461 UpdateCredentials(credentials); | 464 UpdateCredentials(credentials); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { | 615 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { |
613 DCHECK(thread_checker_.CalledOnValidThread()); | 616 DCHECK(thread_checker_.CalledOnValidThread()); |
614 observers_.AddObserver(observer); | 617 observers_.AddObserver(observer); |
615 } | 618 } |
616 | 619 |
617 void SyncManagerImpl::RemoveObserver(SyncManager::Observer* observer) { | 620 void SyncManagerImpl::RemoveObserver(SyncManager::Observer* observer) { |
618 DCHECK(thread_checker_.CalledOnValidThread()); | 621 DCHECK(thread_checker_.CalledOnValidThread()); |
619 observers_.RemoveObserver(observer); | 622 observers_.RemoveObserver(observer); |
620 } | 623 } |
621 | 624 |
622 void SyncManagerImpl::StopSyncingForShutdown() { | |
623 DVLOG(2) << "StopSyncingForShutdown"; | |
624 scheduler_->RequestStop(); | |
625 if (connection_manager_) | |
626 connection_manager_->TerminateAllIO(); | |
627 } | |
628 | |
629 void SyncManagerImpl::ShutdownOnSyncThread() { | 625 void SyncManagerImpl::ShutdownOnSyncThread() { |
630 DCHECK(thread_checker_.CalledOnValidThread()); | 626 DCHECK(thread_checker_.CalledOnValidThread()); |
631 | 627 |
632 // Prevent any in-flight method calls from running. Also | 628 // Prevent any in-flight method calls from running. Also |
633 // invalidates |weak_handle_this_| and |change_observer_|. | 629 // invalidates |weak_handle_this_| and |change_observer_|. |
634 weak_ptr_factory_.InvalidateWeakPtrs(); | 630 weak_ptr_factory_.InvalidateWeakPtrs(); |
635 js_mutation_event_observer_.InvalidateWeakPtrs(); | 631 js_mutation_event_observer_.InvalidateWeakPtrs(); |
636 | 632 |
637 scheduler_.reset(); | 633 scheduler_.reset(); |
638 session_context_.reset(); | 634 session_context_.reset(); |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1317 int SyncManagerImpl::GetDefaultNudgeDelay() { |
1322 return kDefaultNudgeDelayMilliseconds; | 1318 return kDefaultNudgeDelayMilliseconds; |
1323 } | 1319 } |
1324 | 1320 |
1325 // static. | 1321 // static. |
1326 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1322 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
1327 return kPreferencesNudgeDelayMilliseconds; | 1323 return kPreferencesNudgeDelayMilliseconds; |
1328 } | 1324 } |
1329 | 1325 |
1330 } // namespace syncer | 1326 } // namespace syncer |
OLD | NEW |