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

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

Issue 141063009: Separate access token caching logic from signaling connector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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/timer.h" 11 #include "base/timer/timer.h"
12 #include "google_apis/gaia/gaia_oauth_client.h"
13 #include "net/base/network_change_notifier.h" 12 #include "net/base/network_change_notifier.h"
13 #include "remoting/host/oauth_token_getter.h"
14 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 14 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
15 15
16 namespace net {
17 class URLFetcher;
18 class URLRequestContextGetter;
19 } // namespace net
20
21 namespace remoting { 16 namespace remoting {
22 17
23 class DnsBlackholeChecker; 18 class DnsBlackholeChecker;
24 19
25 // SignalingConnector listens for SignalStrategy status notifications 20 // SignalingConnector listens for SignalStrategy status notifications
26 // and attempts to keep it connected when possible. When signalling is 21 // and attempts to keep it connected when possible. When signalling is
27 // not connected it keeps trying to reconnect it until it is 22 // not connected it keeps trying to reconnect it until it is
28 // connected. It limits connection attempt rate using exponential 23 // connected. It limits connection attempt rate using exponential
29 // backoff. It also monitors network state and reconnects signalling 24 // backoff. It also monitors network state and reconnects signalling
30 // whenever connection type changes or IP address changes. 25 // whenever connection type changes or IP address changes.
31 class SignalingConnector 26 class SignalingConnector
32 : public base::SupportsWeakPtr<SignalingConnector>, 27 : public base::SupportsWeakPtr<SignalingConnector>,
33 public base::NonThreadSafe, 28 public base::NonThreadSafe,
34 public SignalStrategy::Listener, 29 public SignalStrategy::Listener,
35 public net::NetworkChangeNotifier::ConnectionTypeObserver, 30 public net::NetworkChangeNotifier::ConnectionTypeObserver,
36 public net::NetworkChangeNotifier::IPAddressObserver, 31 public net::NetworkChangeNotifier::IPAddressObserver {
37 public gaia::GaiaOAuthClient::Delegate {
38 public: 32 public:
39 // This structure contains information required to perform
40 // authentication to OAuth2.
41 struct OAuthCredentials {
42 OAuthCredentials(const std::string& login_value,
43 const std::string& refresh_token_value,
44 bool is_service_account);
45
46 // The user's account name (i.e. their email address).
47 std::string login;
48
49 // Token delegating authority to us to act as the user.
50 std::string refresh_token;
51
52 // Whether these credentials belong to a service account.
53 bool is_service_account;
54 };
55
56 // The |auth_failed_callback| is called when authentication fails. 33 // The |auth_failed_callback| is called when authentication fails.
57 SignalingConnector( 34 SignalingConnector(
58 XmppSignalStrategy* signal_strategy, 35 XmppSignalStrategy* signal_strategy,
59 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
60 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker, 36 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker,
61 const base::Closure& auth_failed_callback); 37 const base::Closure& auth_failed_callback);
62 virtual ~SignalingConnector(); 38 virtual ~SignalingConnector();
63 39
64 // May be called immediately after the constructor to enable OAuth 40 // May be called immediately after the constructor to enable OAuth
65 // access token updating. 41 // access token updating.
66 void EnableOAuth(scoped_ptr<OAuthCredentials> oauth_credentials); 42 // |oauth_token_getter| must outlive SignalingConnector.
43 void EnableOAuth(OAuthTokenGetter* oauth_token_getter);
Sergey Ulanov 2014/02/08 03:16:36 side note, not related to this CL: we should try t
rmsousa 2014/02/10 23:07:39 Acknowledged.
44
45 // OAuthTokenGetter callbacks.
46 void OnAccessToken(const std::string& user_email,
47 const std::string& access_token);
48 void OnNetworkError();
67 49
68 // SignalStrategy::Listener interface. 50 // SignalStrategy::Listener interface.
69 virtual void OnSignalStrategyStateChange( 51 virtual void OnSignalStrategyStateChange(
70 SignalStrategy::State state) OVERRIDE; 52 SignalStrategy::State state) OVERRIDE;
71 virtual bool OnSignalStrategyIncomingStanza( 53 virtual bool OnSignalStrategyIncomingStanza(
72 const buzz::XmlElement* stanza) OVERRIDE; 54 const buzz::XmlElement* stanza) OVERRIDE;
73 55
74 // NetworkChangeNotifier::ConnectionTypeObserver interface. 56 // NetworkChangeNotifier::ConnectionTypeObserver interface.
75 virtual void OnConnectionTypeChanged( 57 virtual void OnConnectionTypeChanged(
76 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 58 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
77 59
78 // NetworkChangeNotifier::IPAddressObserver interface. 60 // NetworkChangeNotifier::IPAddressObserver interface.
79 virtual void OnIPAddressChanged() OVERRIDE; 61 virtual void OnIPAddressChanged() OVERRIDE;
80 62
81 // gaia::GaiaOAuthClient::Delegate interface.
82 virtual void OnGetTokensResponse(const std::string& user_email,
83 const std::string& access_token,
84 int expires_seconds) OVERRIDE;
85 virtual void OnRefreshTokenResponse(const std::string& access_token,
86 int expires_in_seconds) OVERRIDE;
87 virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE;
88 virtual void OnOAuthError() OVERRIDE;
89 virtual void OnNetworkError(int response_code) OVERRIDE;
90
91 private: 63 private:
92 void ScheduleTryReconnect(); 64 void ScheduleTryReconnect();
93 void ResetAndTryReconnect(); 65 void ResetAndTryReconnect();
94 void TryReconnect(); 66 void TryReconnect();
95 void OnDnsBlackholeCheckerDone(bool allow); 67 void OnDnsBlackholeCheckerDone(bool allow);
96 68
97 void RefreshOAuthToken(); 69 XmppSignalStrategy* signal_strategy_;
70 base::Closure auth_failed_callback_;
71 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker_;
98 72
99 XmppSignalStrategy* signal_strategy_; 73 OAuthTokenGetter* oauth_token_getter_;
100 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
101 base::Closure auth_failed_callback_;
102
103 scoped_ptr<OAuthCredentials> oauth_credentials_;
104 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_;
105 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker_;
106 74
107 // Number of times we tried to connect without success. 75 // Number of times we tried to connect without success.
108 int reconnect_attempts_; 76 int reconnect_attempts_;
109 77
110 bool refreshing_oauth_token_;
111 std::string oauth_access_token_;
112 base::Time auth_token_expiry_time_;
113
114 base::OneShotTimer<SignalingConnector> timer_; 78 base::OneShotTimer<SignalingConnector> timer_;
115 79
116 DISALLOW_COPY_AND_ASSIGN(SignalingConnector); 80 DISALLOW_COPY_AND_ASSIGN(SignalingConnector);
117 }; 81 };
118 82
119 } // namespace remoting 83 } // namespace remoting
120 84
121 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H_ 85 #endif // REMOTING_HOST_SIGNALING_CONNECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698