Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: jingle/notifier/communicator/login.cc

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "jingle/notifier/communicator/login.h" 5 #include "jingle/notifier/communicator/login.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 24 matching lines...) Expand all
35 request_context_getter, 35 request_context_getter,
36 const ServerList& servers, 36 const ServerList& servers,
37 bool try_ssltcp_first, 37 bool try_ssltcp_first,
38 const std::string& auth_mechanism) 38 const std::string& auth_mechanism)
39 : delegate_(delegate), 39 : delegate_(delegate),
40 login_settings_(user_settings, 40 login_settings_(user_settings,
41 request_context_getter, 41 request_context_getter,
42 servers, 42 servers,
43 try_ssltcp_first, 43 try_ssltcp_first,
44 auth_mechanism) { 44 auth_mechanism) {
45 net::NetworkChangeNotifier::AddIPAddressObserver(this); 45 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
46 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
47 // TODO(akalin): Add as DNSObserver once bug 130610 is fixed. 46 // TODO(akalin): Add as DNSObserver once bug 130610 is fixed.
48 ResetReconnectState(); 47 ResetReconnectState();
49 } 48 }
50 49
51 Login::~Login() { 50 Login::~Login() {
52 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 51 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
53 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
54 } 52 }
55 53
56 void Login::StartConnection() { 54 void Login::StartConnection() {
57 DVLOG(1) << "Starting connection..."; 55 DVLOG(1) << "Starting connection...";
58 single_attempt_.reset(new SingleLoginAttempt(login_settings_, this)); 56 single_attempt_.reset(new SingleLoginAttempt(login_settings_, this));
59 } 57 }
60 58
61 void Login::UpdateXmppSettings(const buzz::XmppClientSettings& user_settings) { 59 void Login::UpdateXmppSettings(const buzz::XmppClientSettings& user_settings) {
62 DVLOG(1) << "XMPP settings updated"; 60 DVLOG(1) << "XMPP settings updated";
63 login_settings_.set_user_settings(user_settings); 61 login_settings_.set_user_settings(user_settings);
(...skipping 23 matching lines...) Expand all
87 TryReconnect(); 85 TryReconnect();
88 delegate_->OnCredentialsRejected(); 86 delegate_->OnCredentialsRejected();
89 } 87 }
90 88
91 void Login::OnSettingsExhausted() { 89 void Login::OnSettingsExhausted() {
92 DVLOG(1) << "Settings exhausted"; 90 DVLOG(1) << "Settings exhausted";
93 TryReconnect(); 91 TryReconnect();
94 delegate_->OnTransientDisconnection(); 92 delegate_->OnTransientDisconnection();
95 } 93 }
96 94
97 void Login::OnIPAddressChanged() { 95 void Login::OnNetworkChanged(
98 DVLOG(1) << "IP address changed";
99 OnNetworkEvent();
100 }
101
102 void Login::OnConnectionTypeChanged(
103 net::NetworkChangeNotifier::ConnectionType type) { 96 net::NetworkChangeNotifier::ConnectionType type) {
104 DVLOG(1) << "Connection type changed"; 97 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) {
105 OnNetworkEvent(); 98 DVLOG(1) << "Network changed";
99 OnNetworkEvent();
100 }
106 } 101 }
107 102
108 void Login::OnDNSChanged() { 103 void Login::OnDNSChanged() {
109 DVLOG(1) << "DNS changed"; 104 DVLOG(1) << "DNS changed";
110 OnNetworkEvent(); 105 OnNetworkEvent();
111 } 106 }
112 107
113 void Login::OnNetworkEvent() { 108 void Login::OnNetworkEvent() {
114 // Reconnect in 1 to 9 seconds (vary the time a little to try to 109 // Reconnect in 1 to 9 seconds (vary the time a little to try to
115 // avoid spikey behavior on network hiccups). 110 // avoid spikey behavior on network hiccups).
(...skipping 23 matching lines...) Expand all
139 const base::TimeDelta kMaxReconnectInterval = 134 const base::TimeDelta kMaxReconnectInterval =
140 base::TimeDelta::FromMinutes(30); 135 base::TimeDelta::FromMinutes(30);
141 reconnect_interval_ *= 2; 136 reconnect_interval_ *= 2;
142 if (reconnect_interval_ > kMaxReconnectInterval) 137 if (reconnect_interval_ > kMaxReconnectInterval)
143 reconnect_interval_ = kMaxReconnectInterval; 138 reconnect_interval_ = kMaxReconnectInterval;
144 DVLOG(1) << "Reconnecting..."; 139 DVLOG(1) << "Reconnecting...";
145 StartConnection(); 140 StartConnection();
146 } 141 }
147 142
148 } // namespace notifier 143 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698