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

Side by Side Diff: remoting/host/setup/gaia_oauth_client.h

Issue 1099553003: Added unit tests for getCredentialsFromAuthCode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated BUILD.gn file Created 5 years, 8 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
« no previous file with comments | « remoting/host/BUILD.gn ('k') | remoting/host/setup/gaia_oauth_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_SETUP_OAUTH_CLIENT 5 #ifndef REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_
6 #define REMOTING_HOST_SETUP_OAUTH_CLIENT 6 #define REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string>
10 9
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
13 #include "google_apis/gaia/gaia_oauth_client.h" 11 #include "google_apis/gaia/gaia_oauth_client.h"
14 #include "net/url_request/url_request_context_getter.h" 12 #include "net/url_request/url_request_context_getter.h"
15 13
14 #include "remoting/host/setup/oauth_client.h"
15
16 namespace net { 16 namespace net {
17 class URLRequestContext; 17 class URLRequestContext;
18 } 18 }
19 19
20 namespace remoting { 20 namespace remoting {
21 21
22 // A wrapper around GaiaOAuthClient that provides a more convenient interface, 22 // A wrapper around gaia::GaiaOAuthClient that provides a more
23 // with queueing of requests and a callback rather than a delegate. 23 // convenient interface, with queueing of requests and a callback
24 class OAuthClient : public gaia::GaiaOAuthClient::Delegate { 24 // rather than a delegate.
25 class GaiaOAuthClient : public OAuthClient,
26 public gaia::GaiaOAuthClient::Delegate {
25 public: 27 public:
26 // Called when GetCredentialsFromAuthCode is completed, with the |user_email| 28 GaiaOAuthClient(
27 // and |refresh_token| that correspond to the given |auth_code|, or with empty
28 // strings on error.
29 typedef base::Callback<void(
30 const std::string& user_email,
31 const std::string& refresh_token)> CompletionCallback;
32
33 OAuthClient(
34 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); 29 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
35 30
36 ~OAuthClient() override; 31 ~GaiaOAuthClient() override;
37 32
38 // Redeems |auth_code| using |oauth_client_info| to obtain 33 // Redeems |auth_code| using |oauth_client_info| to obtain |refresh_token| and
39 // |refresh_token| and |access_token|, then, if |need_user_email| is 34 // |access_token|, then uses the userinfo endpoint to obtain |user_email|.
40 // true, uses the userinfo endpoint to obtain |user_email|. Calls 35 // Calls CompletionCallback with |user_email| and |refresh_token| when done,
41 // CompletionCallback with |user_email| and |refresh_token| when 36 // or with empty strings on error.
42 // done, or with empty strings on error. If a request is received 37 // If a request is received while another one is being processed, it is
43 // while another one is being processed, it is enqueued and 38 // enqueued and processed after the first one is finished.
44 // processed after the first one is finished.
45 void GetCredentialsFromAuthCode( 39 void GetCredentialsFromAuthCode(
46 const gaia::OAuthClientInfo& oauth_client_info, 40 const gaia::OAuthClientInfo& oauth_client_info,
47 const std::string& auth_code, 41 const std::string& auth_code,
48 bool need_user_email, 42 bool need_user_email,
49 CompletionCallback on_done); 43 CompletionCallback on_done) override;
50 44
51 // gaia::GaiaOAuthClient::Delegate 45 // gaia::GaiaOAuthClient::Delegate
52 void OnGetTokensResponse(const std::string& refresh_token, 46 void OnGetTokensResponse(const std::string& refresh_token,
53 const std::string& access_token, 47 const std::string& access_token,
54 int expires_in_seconds) override; 48 int expires_in_seconds) override;
55 void OnRefreshTokenResponse(const std::string& access_token, 49 void OnRefreshTokenResponse(const std::string& access_token,
56 int expires_in_seconds) override; 50 int expires_in_seconds) override;
57 void OnGetUserEmailResponse(const std::string& user_email) override; 51 void OnGetUserEmailResponse(const std::string& user_email) override;
58 52
59 void OnOAuthError() override; 53 void OnOAuthError() override;
(...skipping 14 matching lines...) Expand all
74 68
75 void SendResponse(const std::string& user_email, 69 void SendResponse(const std::string& user_email,
76 const std::string& refresh_token); 70 const std::string& refresh_token);
77 71
78 std::queue<Request> pending_requests_; 72 std::queue<Request> pending_requests_;
79 gaia::GaiaOAuthClient gaia_oauth_client_; 73 gaia::GaiaOAuthClient gaia_oauth_client_;
80 std::string refresh_token_; 74 std::string refresh_token_;
81 bool need_user_email_; 75 bool need_user_email_;
82 CompletionCallback on_done_; 76 CompletionCallback on_done_;
83 77
84 DISALLOW_COPY_AND_ASSIGN(OAuthClient); 78 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient);
85 }; 79 };
86 80
87 } // namespace remoting 81 } // namespace remoting
88 82
89 #endif // REMOTING_HOST_SETUP_OAUTH_CLIENT 83 #endif // REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_
OLDNEW
« no previous file with comments | « remoting/host/BUILD.gn ('k') | remoting/host/setup/gaia_oauth_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698