diff --git a/jingle/notifier/communicator/login.cc b/jingle/notifier/communicator/login.cc index db4813b433b324..5f6a286176d79d 100644 --- a/jingle/notifier/communicator/login.cc +++ b/jingle/notifier/communicator/login.cc @@ -43,15 +43,19 @@ Login::Login(Delegate* delegate, try_ssltcp_first, auth_mechanism) { net::NetworkChangeNotifier::AddIPAddressObserver(this); + net::NetworkChangeNotifier::AddConnectionTypeObserver(this); + net::NetworkChangeNotifier::AddDNSObserver(this); ResetReconnectState(); } Login::~Login() { + net::NetworkChangeNotifier::RemoveDNSObserver(this); + net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); net::NetworkChangeNotifier::RemoveIPAddressObserver(this); } void Login::StartConnection() { - VLOG(1) << "Starting connection..."; + DVLOG(1) << "Starting connection..."; single_attempt_.reset(new SingleLoginAttempt(login_settings_, this)); } @@ -87,7 +91,22 @@ void Login::OnSettingsExhausted() { } void Login::OnIPAddressChanged() { - VLOG(1) << "Detected IP address change"; + DVLOG(1) << "Detected IP address change"; + OnNetworkEvent(); +} + +void Login::OnConnectionTypeChanged( + net::NetworkChangeNotifier::ConnectionType type) { + DVLOG(1) << "Detected connection type change"; + OnNetworkEvent(); +} + +void Login::OnDNSChanged(unsigned detail) { + DVLOG(1) << "Detected DNS change"; + OnNetworkEvent(); +} + +void Login::OnNetworkEvent() { // Reconnect in 1 to 9 seconds (vary the time a little to try to // avoid spikey behavior on network hiccups). reconnect_interval_ = base::TimeDelta::FromSeconds(base::RandInt(1, 9)); @@ -105,8 +124,8 @@ void Login::TryReconnect() { DCHECK_GT(reconnect_interval_.InSeconds(), 0); single_attempt_.reset(); reconnect_timer_.Stop(); - VLOG(1) << "Reconnecting in " - << reconnect_interval_.InSeconds() << " seconds"; + DVLOG(1) << "Reconnecting in " + << reconnect_interval_.InSeconds() << " seconds"; reconnect_timer_.Start( FROM_HERE, reconnect_interval_, this, &Login::DoReconnect); } @@ -118,7 +137,7 @@ void Login::DoReconnect() { reconnect_interval_ *= 2; if (reconnect_interval_ > kMaxReconnectInterval) reconnect_interval_ = kMaxReconnectInterval; - VLOG(1) << "Reconnecting..."; + DVLOG(1) << "Reconnecting..."; StartConnection(); } diff --git a/jingle/notifier/communicator/login.h b/jingle/notifier/communicator/login.h index 29be4039c2d489..7acde1173b32fb 100644 --- a/jingle/notifier/communicator/login.h +++ b/jingle/notifier/communicator/login.h @@ -36,7 +36,11 @@ class LoginSettings; // Does the login, keeps it alive (with refreshing cookies and // reattempting login when disconnected), and figures out what actions // to take on the various errors that may occur. +// +// TODO(akalin): Make this observe proxy config changes also. class Login : public net::NetworkChangeNotifier::IPAddressObserver, + public net::NetworkChangeNotifier::ConnectionTypeObserver, + public net::NetworkChangeNotifier::DNSObserver, public SingleLoginAttempt::Delegate { public: class Delegate { @@ -81,6 +85,13 @@ class Login : public net::NetworkChangeNotifier::IPAddressObserver, // net::NetworkChangeNotifier::IPAddressObserver implementation. virtual void OnIPAddressChanged() OVERRIDE; + // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. + virtual void OnConnectionTypeChanged( + net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; + + // net::NetworkChangeNotifier::DNSObserver implementation. + virtual void OnDNSChanged(unsigned detail) OVERRIDE; + // SingleLoginAttempt::Delegate implementation. virtual void OnConnect( base::WeakPtr base_task) OVERRIDE; @@ -89,7 +100,8 @@ class Login : public net::NetworkChangeNotifier::IPAddressObserver, virtual void OnSettingsExhausted() OVERRIDE; private: - void OnLogoff(); + // Called by the various network notifications. + void OnNetworkEvent(); // Stops any existing reconnect timer and sets an initial reconnect // interval. diff --git a/sync/tools/DEPS b/sync/tools/DEPS index 4c7287a524dff8..e36048b9a82d48 100644 --- a/sync/tools/DEPS +++ b/sync/tools/DEPS @@ -1,8 +1,6 @@ include_rules = [ "+jingle/notifier/base", - "+net/base/host_port_pair.h", - "+net/base/host_resolver.h", - "+net/url_request/url_request_test_util.h", + "+net", "+sync/notifier", "+sync/internal_api/public/syncable", ] diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc index ad0608079effd6..0b0f0606a5fc98 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -19,6 +19,7 @@ #include "jingle/notifier/base/notifier_options.h" #include "net/base/host_port_pair.h" #include "net/base/host_resolver.h" +#include "net/base/network_change_notifier.h" #include "net/url_request/url_request_test_util.h" #include "sync/internal_api/public/syncable/model_type.h" #include "sync/internal_api/public/syncable/model_type_payload_map.h" @@ -28,6 +29,10 @@ #include "sync/notifier/sync_notifier_factory.h" #include "sync/notifier/sync_notifier_observer.h" +#if defined(OS_MACOSX) +#include "base/mac/scoped_nsautorelease_pool.h" +#endif + // This is a simple utility that initializes a sync notifier and // listens to any received notifications. @@ -174,6 +179,9 @@ class MyTestURLRequestContextGetter : public TestURLRequestContextGetter { } // namespace int main(int argc, char* argv[]) { +#if defined(OS_MACOSX) + base::mac::ScopedNSAutoreleasePool pool; +#endif base::AtExitManager exit_manager; CommandLine::Init(argc, argv); logging::InitLogging( @@ -210,6 +218,10 @@ int main(int argc, char* argv[]) { return -1; } + // Set up objects that monitor the network. + scoped_ptr network_change_notifier( + net::NetworkChangeNotifier::Create()); + const notifier::NotifierOptions& notifier_options = ParseNotifierOptions( command_line,