| 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 URLRequestContextGetter; | 17 class URLRequestContextGetter; |
| 18 } // namespace net | 18 } // namespace net |
| 19 | 19 |
| 20 namespace remoting { | 20 namespace remoting { |
| 21 | 21 |
| 22 // SignalingConnector listens for SignalStrategy status notifications | 22 // SignalingConnector listens for SignalStrategy status notifications |
| 23 // and attempts to keep it connected when possible. When signalling is | 23 // and attempts to keep it connected when possible. When signalling is |
| 24 // not connected it keeps trying to reconnect it until it is | 24 // not connected it keeps trying to reconnect it until it is |
| 25 // connected. It limits connection attempt rate using exponential | 25 // connected. It limits connection attempt rate using exponential |
| 26 // backoff. It also monitors network state and reconnects signalling | 26 // backoff. It also monitors network state and reconnects signalling |
| 27 // whenever online state changes or IP address changes. | 27 // whenever connection type changes or IP address changes. |
| 28 class SignalingConnector | 28 class SignalingConnector |
| 29 : public base::SupportsWeakPtr<SignalingConnector>, | 29 : public base::SupportsWeakPtr<SignalingConnector>, |
| 30 public base::NonThreadSafe, | 30 public base::NonThreadSafe, |
| 31 public SignalStrategy::Listener, | 31 public SignalStrategy::Listener, |
| 32 public net::NetworkChangeNotifier::OnlineStateObserver, | 32 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 33 public net::NetworkChangeNotifier::IPAddressObserver, | 33 public net::NetworkChangeNotifier::IPAddressObserver, |
| 34 public GaiaOAuthClient::Delegate { | 34 public GaiaOAuthClient::Delegate { |
| 35 public: | 35 public: |
| 36 // This structure contains information required to perform | 36 // This structure contains information required to perform |
| 37 // authentication to OAuth2. | 37 // authentication to OAuth2. |
| 38 struct OAuthCredentials { | 38 struct OAuthCredentials { |
| 39 OAuthCredentials(const std::string& login_value, | 39 OAuthCredentials(const std::string& login_value, |
| 40 const std::string& refresh_token_value, | 40 const std::string& refresh_token_value, |
| 41 const OAuthClientInfo& client_info); | 41 const OAuthClientInfo& client_info); |
| 42 | 42 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 void EnableOAuth(scoped_ptr<OAuthCredentials> oauth_credentials, | 60 void EnableOAuth(scoped_ptr<OAuthCredentials> oauth_credentials, |
| 61 net::URLRequestContextGetter* url_context); | 61 net::URLRequestContextGetter* url_context); |
| 62 | 62 |
| 63 // SignalStrategy::Listener interface. | 63 // SignalStrategy::Listener interface. |
| 64 virtual void OnSignalStrategyStateChange( | 64 virtual void OnSignalStrategyStateChange( |
| 65 SignalStrategy::State state) OVERRIDE; | 65 SignalStrategy::State state) OVERRIDE; |
| 66 | 66 |
| 67 // NetworkChangeNotifier::IPAddressObserver interface. | 67 // NetworkChangeNotifier::IPAddressObserver interface. |
| 68 virtual void OnIPAddressChanged() OVERRIDE; | 68 virtual void OnIPAddressChanged() OVERRIDE; |
| 69 | 69 |
| 70 // NetworkChangeNotifier::OnlineStateObserver interface. | 70 // NetworkChangeNotifier::ConnectionTypeObserver interface. |
| 71 virtual void OnOnlineStateChanged(bool online) OVERRIDE; | 71 virtual void OnConnectionTypeChanged( |
| 72 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 72 | 73 |
| 73 // GaiaOAuthClient::Delegate interface. | 74 // GaiaOAuthClient::Delegate interface. |
| 74 virtual void OnRefreshTokenResponse(const std::string& user_email, | 75 virtual void OnRefreshTokenResponse(const std::string& user_email, |
| 75 const std::string& access_token, | 76 const std::string& access_token, |
| 76 int expires_seconds) OVERRIDE; | 77 int expires_seconds) OVERRIDE; |
| 77 virtual void OnOAuthError() OVERRIDE; | 78 virtual void OnOAuthError() OVERRIDE; |
| 78 virtual void OnNetworkError(int response_code) OVERRIDE; | 79 virtual void OnNetworkError(int response_code) OVERRIDE; |
| 79 | 80 |
| 80 private: | 81 private: |
| 81 void ScheduleTryReconnect(); | 82 void ScheduleTryReconnect(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 97 base::Time auth_token_expiry_time_; | 98 base::Time auth_token_expiry_time_; |
| 98 | 99 |
| 99 base::OneShotTimer<SignalingConnector> timer_; | 100 base::OneShotTimer<SignalingConnector> timer_; |
| 100 | 101 |
| 101 DISALLOW_COPY_AND_ASSIGN(SignalingConnector); | 102 DISALLOW_COPY_AND_ASSIGN(SignalingConnector); |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 } // namespace remoting | 105 } // namespace remoting |
| 105 | 106 |
| 106 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H | 107 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H |
| OLD | NEW |