| 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 #ifndef REMOTING_HOST_SIGNALING_CONNECTOR_H_ | 5 #ifndef REMOTING_HOST_SIGNALING_CONNECTOR_H_ |
| 6 #define REMOTING_HOST_SIGNALING_CONNECTOR_H_ | 6 #define REMOTING_HOST_SIGNALING_CONNECTOR_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
| 11 #include "base/timer.h" | 11 #include "base/timer.h" |
| 12 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
| 13 #include "remoting/host/gaia_oauth_client.h" | 13 #include "remoting/host/gaia_oauth_client.h" |
| 14 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 14 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class URLFetcher; |
| 17 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
| 18 } // namespace net | 19 } // namespace net |
| 19 | 20 |
| 20 namespace remoting { | 21 namespace remoting { |
| 21 | 22 |
| 23 class ChromotingHostContext; |
| 24 class DnsBlackholeChecker; |
| 25 |
| 22 // SignalingConnector listens for SignalStrategy status notifications | 26 // SignalingConnector listens for SignalStrategy status notifications |
| 23 // and attempts to keep it connected when possible. When signalling is | 27 // and attempts to keep it connected when possible. When signalling is |
| 24 // not connected it keeps trying to reconnect it until it is | 28 // not connected it keeps trying to reconnect it until it is |
| 25 // connected. It limits connection attempt rate using exponential | 29 // connected. It limits connection attempt rate using exponential |
| 26 // backoff. It also monitors network state and reconnects signalling | 30 // backoff. It also monitors network state and reconnects signalling |
| 27 // whenever connection type changes or IP address changes. | 31 // whenever connection type changes or IP address changes. |
| 28 class SignalingConnector | 32 class SignalingConnector |
| 29 : public base::SupportsWeakPtr<SignalingConnector>, | 33 : public base::SupportsWeakPtr<SignalingConnector>, |
| 30 public base::NonThreadSafe, | 34 public base::NonThreadSafe, |
| 31 public SignalStrategy::Listener, | 35 public SignalStrategy::Listener, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 45 | 49 |
| 46 // Token delegating authority to us to act as the user. | 50 // Token delegating authority to us to act as the user. |
| 47 std::string refresh_token; | 51 std::string refresh_token; |
| 48 | 52 |
| 49 // Credentials identifying the application to OAuth. | 53 // Credentials identifying the application to OAuth. |
| 50 OAuthClientInfo client_info; | 54 OAuthClientInfo client_info; |
| 51 }; | 55 }; |
| 52 | 56 |
| 53 // The |auth_failed_callback| is called when authentication fails. | 57 // The |auth_failed_callback| is called when authentication fails. |
| 54 SignalingConnector(XmppSignalStrategy* signal_strategy, | 58 SignalingConnector(XmppSignalStrategy* signal_strategy, |
| 59 ChromotingHostContext* context, |
| 60 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker, |
| 55 const base::Closure& auth_failed_callback); | 61 const base::Closure& auth_failed_callback); |
| 56 virtual ~SignalingConnector(); | 62 virtual ~SignalingConnector(); |
| 57 | 63 |
| 58 // May be called immediately after the constructor to enable OAuth | 64 // May be called immediately after the constructor to enable OAuth |
| 59 // access token updating. | 65 // access token updating. |
| 60 void EnableOAuth(scoped_ptr<OAuthCredentials> oauth_credentials, | 66 void EnableOAuth(scoped_ptr<OAuthCredentials> oauth_credentials); |
| 61 net::URLRequestContextGetter* url_context); | |
| 62 | 67 |
| 63 // SignalStrategy::Listener interface. | 68 // SignalStrategy::Listener interface. |
| 64 virtual void OnSignalStrategyStateChange( | 69 virtual void OnSignalStrategyStateChange( |
| 65 SignalStrategy::State state) OVERRIDE; | 70 SignalStrategy::State state) OVERRIDE; |
| 66 virtual bool OnSignalStrategyIncomingStanza( | 71 virtual bool OnSignalStrategyIncomingStanza( |
| 67 const buzz::XmlElement* stanza) OVERRIDE; | 72 const buzz::XmlElement* stanza) OVERRIDE; |
| 68 | 73 |
| 69 // NetworkChangeNotifier::IPAddressObserver interface. | |
| 70 virtual void OnIPAddressChanged() OVERRIDE; | |
| 71 | |
| 72 // NetworkChangeNotifier::ConnectionTypeObserver interface. | 74 // NetworkChangeNotifier::ConnectionTypeObserver interface. |
| 73 virtual void OnConnectionTypeChanged( | 75 virtual void OnConnectionTypeChanged( |
| 74 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 76 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 75 | 77 |
| 78 // NetworkChangeNotifier::IPAddressObserver interface. |
| 79 virtual void OnIPAddressChanged() OVERRIDE; |
| 80 |
| 76 // GaiaOAuthClient::Delegate interface. | 81 // GaiaOAuthClient::Delegate interface. |
| 77 virtual void OnRefreshTokenResponse(const std::string& user_email, | 82 virtual void OnRefreshTokenResponse(const std::string& user_email, |
| 78 const std::string& access_token, | 83 const std::string& access_token, |
| 79 int expires_seconds) OVERRIDE; | 84 int expires_seconds) OVERRIDE; |
| 80 virtual void OnOAuthError() OVERRIDE; | 85 virtual void OnOAuthError() OVERRIDE; |
| 81 virtual void OnNetworkError(int response_code) OVERRIDE; | 86 virtual void OnNetworkError(int response_code) OVERRIDE; |
| 82 | 87 |
| 83 private: | 88 private: |
| 84 void ScheduleTryReconnect(); | 89 void ScheduleTryReconnect(); |
| 85 void ResetAndTryReconnect(); | 90 void ResetAndTryReconnect(); |
| 86 void TryReconnect(); | 91 void TryReconnect(); |
| 92 void OnDnsBlackholeCheckerDone(bool allow); |
| 87 | 93 |
| 88 void RefreshOAuthToken(); | 94 void RefreshOAuthToken(); |
| 89 | 95 |
| 90 XmppSignalStrategy* signal_strategy_; | 96 XmppSignalStrategy* signal_strategy_; |
| 97 ChromotingHostContext* context_; |
| 91 base::Closure auth_failed_callback_; | 98 base::Closure auth_failed_callback_; |
| 92 | 99 |
| 93 scoped_ptr<OAuthCredentials> oauth_credentials_; | 100 scoped_ptr<OAuthCredentials> oauth_credentials_; |
| 94 scoped_ptr<GaiaOAuthClient> gaia_oauth_client_; | 101 scoped_ptr<GaiaOAuthClient> gaia_oauth_client_; |
| 102 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker_; |
| 95 | 103 |
| 96 // Number of times we tried to connect without success. | 104 // Number of times we tried to connect without success. |
| 97 int reconnect_attempts_; | 105 int reconnect_attempts_; |
| 98 | 106 |
| 99 bool refreshing_oauth_token_; | 107 bool refreshing_oauth_token_; |
| 100 base::Time auth_token_expiry_time_; | 108 base::Time auth_token_expiry_time_; |
| 101 | 109 |
| 102 base::OneShotTimer<SignalingConnector> timer_; | 110 base::OneShotTimer<SignalingConnector> timer_; |
| 103 | 111 |
| 104 DISALLOW_COPY_AND_ASSIGN(SignalingConnector); | 112 DISALLOW_COPY_AND_ASSIGN(SignalingConnector); |
| 105 }; | 113 }; |
| 106 | 114 |
| 107 } // namespace remoting | 115 } // namespace remoting |
| 108 | 116 |
| 109 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H_ | 117 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H_ |
| OLD | NEW |