Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "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" |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 &debug_info_event_listener_, | 447 &debug_info_event_listener_, |
| 448 &traffic_recorder_).Pass(); | 448 &traffic_recorder_).Pass(); |
| 449 session_context_->set_account_name(credentials.email); | 449 session_context_->set_account_name(credentials.email); |
| 450 scheduler_ = internal_components_factory->BuildScheduler( | 450 scheduler_ = internal_components_factory->BuildScheduler( |
| 451 name_, session_context_.get()).Pass(); | 451 name_, session_context_.get()).Pass(); |
| 452 | 452 |
| 453 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); | 453 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); |
| 454 | 454 |
| 455 initialized_ = true; | 455 initialized_ = true; |
| 456 | 456 |
| 457 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 457 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 458 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | |
| 459 observing_network_connectivity_changes_ = true; | 458 observing_network_connectivity_changes_ = true; |
| 460 | 459 |
| 461 UpdateCredentials(credentials); | 460 UpdateCredentials(credentials); |
| 462 | 461 |
| 463 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 462 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 464 OnInitializationComplete( | 463 OnInitializationComplete( |
| 465 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 464 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 466 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), | 465 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), |
| 467 true, InitialSyncEndedTypes())); | 466 true, InitialSyncEndedTypes())); |
| 468 } | 467 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 // TODO(akalin): Fix this behavior. | 683 // TODO(akalin): Fix this behavior. |
| 685 | 684 |
| 686 if (invalidator_.get()) | 685 if (invalidator_.get()) |
| 687 invalidator_->UnregisterHandler(this); | 686 invalidator_->UnregisterHandler(this); |
| 688 invalidator_.reset(); | 687 invalidator_.reset(); |
| 689 | 688 |
| 690 if (connection_manager_.get()) | 689 if (connection_manager_.get()) |
| 691 connection_manager_->RemoveListener(this); | 690 connection_manager_->RemoveListener(this); |
| 692 connection_manager_.reset(); | 691 connection_manager_.reset(); |
| 693 | 692 |
| 694 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 693 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 695 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | |
| 696 observing_network_connectivity_changes_ = false; | 694 observing_network_connectivity_changes_ = false; |
| 697 | 695 |
| 698 if (initialized_ && directory()) { | 696 if (initialized_ && directory()) { |
| 699 directory()->SaveChanges(); | 697 directory()->SaveChanges(); |
| 700 } | 698 } |
| 701 | 699 |
| 702 share_.directory.reset(); | 700 share_.directory.reset(); |
| 703 | 701 |
| 704 change_delegate_ = NULL; | 702 change_delegate_ = NULL; |
| 705 | 703 |
| 706 initialized_ = false; | 704 initialized_ = false; |
| 707 | 705 |
| 708 // We reset these here, since only now we know they will not be | 706 // We reset these here, since only now we know they will not be |
| 709 // accessed from other threads (since we shut down everything). | 707 // accessed from other threads (since we shut down everything). |
| 710 change_observer_.Reset(); | 708 change_observer_.Reset(); |
| 711 weak_handle_this_.Reset(); | 709 weak_handle_this_.Reset(); |
| 712 } | 710 } |
| 713 | 711 |
| 714 void SyncManagerImpl::OnIPAddressChanged() { | 712 void SyncManagerImpl::OnNetworkChanged( |
| 713 net::NetworkChangeNotifier::ConnectionType type) { | |
| 714 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) | |
| 715 return; | |
|
szym
2013/01/20 06:52:08
It's not immediately apparent to me that scheduler
| |
| 715 if (!observing_network_connectivity_changes_) { | 716 if (!observing_network_connectivity_changes_) { |
| 716 DVLOG(1) << "IP address change dropped."; | 717 DVLOG(1) << "Network change dropped."; |
| 717 return; | 718 return; |
| 718 } | 719 } |
| 719 DVLOG(1) << "IP address change detected."; | 720 DVLOG(1) << "Network change detected."; |
| 720 OnNetworkConnectivityChangedImpl(); | 721 OnNetworkConnectivityChangedImpl(); |
| 721 } | 722 } |
| 722 | 723 |
| 723 void SyncManagerImpl::OnConnectionTypeChanged( | |
| 724 net::NetworkChangeNotifier::ConnectionType) { | |
| 725 if (!observing_network_connectivity_changes_) { | |
| 726 DVLOG(1) << "Connection type change dropped."; | |
| 727 return; | |
| 728 } | |
| 729 DVLOG(1) << "Connection type change detected."; | |
| 730 OnNetworkConnectivityChangedImpl(); | |
| 731 } | |
| 732 | |
| 733 void SyncManagerImpl::OnNetworkConnectivityChangedImpl() { | 724 void SyncManagerImpl::OnNetworkConnectivityChangedImpl() { |
| 734 DCHECK(thread_checker_.CalledOnValidThread()); | 725 DCHECK(thread_checker_.CalledOnValidThread()); |
| 735 scheduler_->OnConnectionStatusChange(); | 726 scheduler_->OnConnectionStatusChange(); |
| 736 } | 727 } |
| 737 | 728 |
| 738 void SyncManagerImpl::OnServerConnectionEvent( | 729 void SyncManagerImpl::OnServerConnectionEvent( |
| 739 const ServerConnectionEvent& event) { | 730 const ServerConnectionEvent& event) { |
| 740 DCHECK(thread_checker_.CalledOnValidThread()); | 731 DCHECK(thread_checker_.CalledOnValidThread()); |
| 741 if (event.connection_code == | 732 if (event.connection_code == |
| 742 HttpResponse::SERVER_CONNECTION_OK) { | 733 HttpResponse::SERVER_CONNECTION_OK) { |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1356 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1347 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1357 return kDefaultNudgeDelayMilliseconds; | 1348 return kDefaultNudgeDelayMilliseconds; |
| 1358 } | 1349 } |
| 1359 | 1350 |
| 1360 // static. | 1351 // static. |
| 1361 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1352 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1362 return kPreferencesNudgeDelayMilliseconds; | 1353 return kPreferencesNudgeDelayMilliseconds; |
| 1363 } | 1354 } |
| 1364 | 1355 |
| 1365 } // namespace syncer | 1356 } // namespace syncer |
| OLD | NEW |