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

Side by Side Diff: remoting/host/signaling_connector.h

Issue 10873050: [Chromoting] Hook up host talkgadget policy checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extra LOGs Created 8 years, 4 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 #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 "net/url_request/url_fetcher_delegate.h"
13 #include "remoting/host/gaia_oauth_client.h" 14 #include "remoting/host/gaia_oauth_client.h"
14 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 15 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
15 16
16 namespace net { 17 namespace net {
18 class URLFetcher;
17 class URLRequestContextGetter; 19 class URLRequestContextGetter;
18 } // namespace net 20 } // namespace net
19 21
20 namespace remoting { 22 namespace remoting {
21 23
24 class ChromotingHostContext;
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,
36 public net::URLFetcherDelegate,
Sergey Ulanov 2012/08/24 19:43:33 Can you please move the new connectivity checking
garykac 2012/08/27 22:34:57 Done.
32 public net::NetworkChangeNotifier::ConnectionTypeObserver, 37 public net::NetworkChangeNotifier::ConnectionTypeObserver,
33 public net::NetworkChangeNotifier::IPAddressObserver, 38 public net::NetworkChangeNotifier::IPAddressObserver,
34 public GaiaOAuthClient::Delegate { 39 public GaiaOAuthClient::Delegate {
35 public: 40 public:
36 // This structure contains information required to perform 41 // This structure contains information required to perform
37 // authentication to OAuth2. 42 // authentication to OAuth2.
38 struct OAuthCredentials { 43 struct OAuthCredentials {
39 OAuthCredentials(const std::string& login_value, 44 OAuthCredentials(const std::string& login_value,
40 const std::string& refresh_token_value, 45 const std::string& refresh_token_value,
41 const OAuthClientInfo& client_info); 46 const OAuthClientInfo& client_info);
42 47
43 // The user's account name (i.e. their email address). 48 // The user's account name (i.e. their email address).
44 std::string login; 49 std::string login;
45 50
46 // Token delegating authority to us to act as the user. 51 // Token delegating authority to us to act as the user.
47 std::string refresh_token; 52 std::string refresh_token;
48 53
49 // Credentials identifying the application to OAuth. 54 // Credentials identifying the application to OAuth.
50 OAuthClientInfo client_info; 55 OAuthClientInfo client_info;
51 }; 56 };
52 57
53 // The |auth_failed_callback| is called when authentication fails. 58 // The |auth_failed_callback| is called when authentication fails.
54 SignalingConnector(XmppSignalStrategy* signal_strategy, 59 SignalingConnector(XmppSignalStrategy* signal_strategy,
60 ChromotingHostContext* context,
61 std::string talkgadget_prefix,
55 const base::Closure& auth_failed_callback); 62 const base::Closure& auth_failed_callback);
56 virtual ~SignalingConnector(); 63 virtual ~SignalingConnector();
57 64
58 // May be called immediately after the constructor to enable OAuth 65 // May be called immediately after the constructor to enable OAuth
59 // access token updating. 66 // access token updating.
60 void EnableOAuth(scoped_ptr<OAuthCredentials> oauth_credentials, 67 void EnableOAuth(scoped_ptr<OAuthCredentials> oauth_credentials);
61 net::URLRequestContextGetter* url_context);
62 68
63 // SignalStrategy::Listener interface. 69 // SignalStrategy::Listener interface.
64 virtual void OnSignalStrategyStateChange( 70 virtual void OnSignalStrategyStateChange(
65 SignalStrategy::State state) OVERRIDE; 71 SignalStrategy::State state) OVERRIDE;
66 virtual bool OnSignalStrategyIncomingStanza( 72 virtual bool OnSignalStrategyIncomingStanza(
67 const buzz::XmlElement* stanza) OVERRIDE; 73 const buzz::XmlElement* stanza) OVERRIDE;
68 74
69 // NetworkChangeNotifier::IPAddressObserver interface. 75 // net::URLFetcherDelegate interface.
70 virtual void OnIPAddressChanged() OVERRIDE; 76 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
71 77
72 // NetworkChangeNotifier::ConnectionTypeObserver interface. 78 // NetworkChangeNotifier::ConnectionTypeObserver interface.
73 virtual void OnConnectionTypeChanged( 79 virtual void OnConnectionTypeChanged(
74 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 80 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
75 81
82 // NetworkChangeNotifier::IPAddressObserver interface.
83 virtual void OnIPAddressChanged() OVERRIDE;
84
76 // GaiaOAuthClient::Delegate interface. 85 // GaiaOAuthClient::Delegate interface.
77 virtual void OnRefreshTokenResponse(const std::string& user_email, 86 virtual void OnRefreshTokenResponse(const std::string& user_email,
78 const std::string& access_token, 87 const std::string& access_token,
79 int expires_seconds) OVERRIDE; 88 int expires_seconds) OVERRIDE;
80 virtual void OnOAuthError() OVERRIDE; 89 virtual void OnOAuthError() OVERRIDE;
81 virtual void OnNetworkError(int response_code) OVERRIDE; 90 virtual void OnNetworkError(int response_code) OVERRIDE;
82 91
83 private: 92 private:
84 void ScheduleTryReconnect(); 93 void ScheduleTryReconnect();
85 void ResetAndTryReconnect(); 94 void ResetAndTryReconnect();
86 void TryReconnect(); 95 void TryReconnect();
87 96
88 void RefreshOAuthToken(); 97 void RefreshOAuthToken();
89 98
90 XmppSignalStrategy* signal_strategy_; 99 XmppSignalStrategy* signal_strategy_;
100 ChromotingHostContext* context_;
91 base::Closure auth_failed_callback_; 101 base::Closure auth_failed_callback_;
92 102
93 scoped_ptr<OAuthCredentials> oauth_credentials_; 103 scoped_ptr<OAuthCredentials> oauth_credentials_;
94 scoped_ptr<GaiaOAuthClient> gaia_oauth_client_; 104 scoped_ptr<GaiaOAuthClient> gaia_oauth_client_;
95 105
106 // URL fetcher used to verify access to the host talkgadget.
107 scoped_ptr<net::URLFetcher> url_fetcher_;
108
109 // The string pre-pended to '.talkgadget.google.com' to create the full
110 // talkgadget domain name for the host.
111 std::string talkgadget_prefix_;
112
113 // Did we make a successful connection to the host talkgadget?
114 bool found_talkgadget_;
115
96 // Number of times we tried to connect without success. 116 // Number of times we tried to connect without success.
97 int reconnect_attempts_; 117 int reconnect_attempts_;
98 118
99 bool refreshing_oauth_token_; 119 bool refreshing_oauth_token_;
100 base::Time auth_token_expiry_time_; 120 base::Time auth_token_expiry_time_;
101 121
102 base::OneShotTimer<SignalingConnector> timer_; 122 base::OneShotTimer<SignalingConnector> timer_;
103 123
104 DISALLOW_COPY_AND_ASSIGN(SignalingConnector); 124 DISALLOW_COPY_AND_ASSIGN(SignalingConnector);
105 }; 125 };
106 126
107 } // namespace remoting 127 } // namespace remoting
108 128
109 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H_ 129 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698