diff options
author | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 19:29:41 +0000 |
---|---|---|
committer | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 19:29:41 +0000 |
commit | 1777a4add066e749212268d4ef71f14697d48080 (patch) | |
tree | 9668fe18b71b20608fce6267bb4c4b45b6c014c7 /sync | |
parent | b97def0e4fd0381fccfed0b23be3849551b93629 (diff) | |
download | chromium_src-1777a4add066e749212268d4ef71f14697d48080.zip chromium_src-1777a4add066e749212268d4ef71f14697d48080.tar.gz chromium_src-1777a4add066e749212268d4ef71f14697d48080.tar.bz2 |
[sync] Upstream Android connection observer for sync.
Android has framework support for online state changes. This pings adds
support in sync to receive such notifications.
BUG=139259, 106034
TEST=Verify that online state change detection works on Android builds.
Review URL: https://chromiumcodereview.appspot.com/10829050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165992 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r-- | sync/internal_api/sync_manager_impl.cc | 29 | ||||
-rw-r--r-- | sync/internal_api/sync_manager_impl.h | 28 |
2 files changed, 37 insertions, 20 deletions
diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index eb86bb4..2eb60c6 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -167,7 +167,7 @@ SyncManagerImpl::SyncManagerImpl(const std::string& name) weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), change_delegate_(NULL), initialized_(false), - observing_ip_address_changes_(false), + observing_network_connectivity_changes_(false), invalidator_state_(DEFAULT_INVALIDATION_ERROR), throttled_data_type_tracker_(&allstatus_), traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), @@ -465,7 +465,8 @@ void SyncManagerImpl::Init( initialized_ = true; net::NetworkChangeNotifier::AddIPAddressObserver(this); - observing_ip_address_changes_ = true; + net::NetworkChangeNotifier::AddConnectionTypeObserver(this); + observing_network_connectivity_changes_ = true; UpdateCredentials(credentials); @@ -604,7 +605,7 @@ void SyncManagerImpl::UpdateCredentials( DCHECK(!credentials.email.empty()); DCHECK(!credentials.sync_token.empty()); - observing_ip_address_changes_ = true; + observing_network_connectivity_changes_ = true; if (!connection_manager_->set_auth_token(credentials.sync_token)) return; // Auth token is known to be invalid, so exit early. @@ -694,7 +695,8 @@ void SyncManagerImpl::ShutdownOnSyncThread() { connection_manager_.reset(); net::NetworkChangeNotifier::RemoveIPAddressObserver(this); - observing_ip_address_changes_ = false; + net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); + observing_network_connectivity_changes_ = false; if (initialized_ && directory()) { directory()->SaveChanges(); @@ -713,16 +715,25 @@ void SyncManagerImpl::ShutdownOnSyncThread() { } void SyncManagerImpl::OnIPAddressChanged() { - DVLOG(1) << "IP address change detected"; - if (!observing_ip_address_changes_) { + if (!observing_network_connectivity_changes_) { DVLOG(1) << "IP address change dropped."; return; } + DVLOG(1) << "IP address change detected."; + OnNetworkConnectivityChangedImpl(); +} - OnIPAddressChangedImpl(); +void SyncManagerImpl::OnConnectionTypeChanged( + net::NetworkChangeNotifier::ConnectionType) { + if (!observing_network_connectivity_changes_) { + DVLOG(1) << "Connection type change dropped."; + return; + } + DVLOG(1) << "Connection type change detected."; + OnNetworkConnectivityChangedImpl(); } -void SyncManagerImpl::OnIPAddressChangedImpl() { +void SyncManagerImpl::OnNetworkConnectivityChangedImpl() { DCHECK(thread_checker_.CalledOnValidThread()); scheduler_->OnConnectionStatusChange(); } @@ -737,7 +748,7 @@ void SyncManagerImpl::OnServerConnectionEvent( } if (event.connection_code == HttpResponse::SYNC_AUTH_ERROR) { - observing_ip_address_changes_ = false; + observing_network_connectivity_changes_ = false; FOR_EACH_OBSERVER(SyncManager::Observer, observers_, OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); } diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h index 53b882e..6037e8c 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -46,14 +46,16 @@ class SyncSessionContext; // // Unless stated otherwise, all methods of SyncManager should be called on the // same thread. -class SyncManagerImpl : public SyncManager, - public net::NetworkChangeNotifier::IPAddressObserver, - public InvalidationHandler, - public JsBackend, - public SyncEngineEventListener, - public ServerConnectionEventListener, - public syncable::DirectoryChangeDelegate, - public SyncEncryptionHandler::Observer { +class SyncManagerImpl : + public SyncManager, + public net::NetworkChangeNotifier::IPAddressObserver, + public net::NetworkChangeNotifier::ConnectionTypeObserver, + public InvalidationHandler, + public JsBackend, + public SyncEngineEventListener, + public ServerConnectionEventListener, + public syncable::DirectoryChangeDelegate, + public SyncEncryptionHandler::Observer { public: // Create an uninitialized SyncManager. Callers must Init() before using. explicit SyncManagerImpl(const std::string& name); @@ -174,8 +176,12 @@ class SyncManagerImpl : public SyncManager, const ObjectIdInvalidationMap& invalidation_map, IncomingInvalidationSource source) OVERRIDE; - // Called only by our NetworkChangeNotifier. + // These OnYYYChanged() methods are only called by our NetworkChangeNotifier. + // Called when IP address of primary interface changes. virtual void OnIPAddressChanged() OVERRIDE; + // Called when the connection type of the system has changed. + virtual void OnConnectionTypeChanged( + net::NetworkChangeNotifier::ConnectionType) OVERRIDE; const SyncScheduler* scheduler() const; @@ -252,7 +258,7 @@ class SyncManagerImpl : public SyncManager, const ModelTypeInvalidationMap& invalidation_map); // Checks for server reachabilty and requests a nudge. - void OnIPAddressChangedImpl(); + void OnNetworkConnectivityChangedImpl(); // Helper function used only by the constructor. void BindJsMessageHandler( @@ -342,7 +348,7 @@ class SyncManagerImpl : public SyncManager, // Set to true once Init has been called. bool initialized_; - bool observing_ip_address_changes_; + bool observing_network_connectivity_changes_; InvalidatorState invalidator_state_; |