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

Side by Side Diff: remoting/test/access_token_fetcher.cc

Issue 1008043003: Adding Test Fixture for initial test cases for the App Remoting Test Driver. Also includes the pub… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Wez's feedback Created 5 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "remoting/test/access_token_fetcher.h" 5 #include "remoting/test/access_token_fetcher.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "google_apis/gaia/gaia_constants.h" 14 #include "google_apis/gaia/gaia_constants.h"
15 #include "google_apis/google_api_keys.h" 15 #include "google_apis/google_api_keys.h"
16 #include "net/url_request/url_fetcher.h" 16 #include "net/url_request/url_fetcher.h"
17 #include "remoting/base/url_request_context_getter.h" 17 #include "remoting/base/url_request_context_getter.h"
18 18
19 namespace { 19 namespace {
20 const int kMaxGetTokensRetries = 3; 20 const int kMaxGetTokensRetries = 3;
21 const char kOauthRedirectUrl[] = 21 const char kOauthRedirectUrl[] =
22 "https://chromoting-oauth.talkgadget." 22 "https://chromoting-oauth.talkgadget."
23 "google.com/talkgadget/oauth/chrome-remote-desktop/dev"; 23 "google.com/talkgadget/oauth/chrome-remote-desktop/dev";
24 24
25 // Factory function used to initialize our scope vector below, this is needed 25 // Factory function used to initialize an app remoting scope vector.
Wez 2015/03/21 00:14:01 nit: This is confusing since it almost reads like
joedow 2015/03/21 01:23:59 Removed since it wasn't needed : )
26 // because initializer lists are only supported on C++11 compilers.
27 const std::vector<std::string> MakeAppRemotingScopeVector() { 26 const std::vector<std::string> MakeAppRemotingScopeVector() {
28 std::vector<std::string> app_remoting_scopes; 27 std::vector<std::string> app_remoting_scopes;
29 28
30 // Populate the vector with the required permissions for app remoting. 29 // Populate the vector with the required permissions for app remoting.
31 app_remoting_scopes.push_back( 30 app_remoting_scopes.push_back(
32 "https://www.googleapis.com/auth/appremoting.runapplication"); 31 "https://www.googleapis.com/auth/appremoting.runapplication");
33 app_remoting_scopes.push_back("https://www.googleapis.com/auth/googletalk"); 32 app_remoting_scopes.push_back("https://www.googleapis.com/auth/googletalk");
34 app_remoting_scopes.push_back( 33 app_remoting_scopes.push_back(
35 "https://www.googleapis.com/auth/userinfo.email"); 34 "https://www.googleapis.com/auth/userinfo.email");
36 app_remoting_scopes.push_back("https://docs.google.com/feeds"); 35 app_remoting_scopes.push_back("https://docs.google.com/feeds");
37 app_remoting_scopes.push_back("https://www.googleapis.com/auth/drive"); 36 app_remoting_scopes.push_back("https://www.googleapis.com/auth/drive");
38 37
39 return app_remoting_scopes; 38 return app_remoting_scopes;
40 } 39 }
41
42 const std::vector<std::string> kAppRemotingScopeVector =
43 MakeAppRemotingScopeVector();
44 } // namespace 40 } // namespace
45 41
46 namespace remoting { 42 namespace remoting {
47 namespace test { 43 namespace test {
48 44
49 AccessTokenFetcher::AccessTokenFetcher() { 45 AccessTokenFetcher::AccessTokenFetcher() {
50 oauth_client_info_ = { 46 oauth_client_info_ = {
51 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), 47 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING),
52 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING), 48 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING),
53 kOauthRedirectUrl}; 49 kOauthRedirectUrl};
50
51 oauth_scopes_vector_ = MakeAppRemotingScopeVector();
Wez 2015/03/21 00:14:01 Why do you need to save this into a member variabl
joedow 2015/03/21 01:23:59 Acknowledged.
54 } 52 }
55 53
56 AccessTokenFetcher::~AccessTokenFetcher() {} 54 AccessTokenFetcher::~AccessTokenFetcher() {}
57 55
58 void AccessTokenFetcher::GetAccessTokenFromAuthCode( 56 void AccessTokenFetcher::GetAccessTokenFromAuthCode(
59 const std::string& auth_code, 57 const std::string& auth_code,
60 const AccessTokenCallback& callback) { 58 const AccessTokenCallback& callback) {
61 DCHECK(!auth_code.empty()); 59 DCHECK(!auth_code.empty());
62 DCHECK(!callback.is_null()); 60 DCHECK(!callback.is_null());
63 DCHECK(access_token_callback_.is_null()); 61 DCHECK(access_token_callback_.is_null());
(...skipping 22 matching lines...) Expand all
86 84
87 access_token_.clear(); 85 access_token_.clear();
88 refresh_token_ = refresh_token; 86 refresh_token_ = refresh_token;
89 access_token_callback_ = callback; 87 access_token_callback_ = callback;
90 88
91 // Create a new GaiaOAuthClient for each request to GAIA. 89 // Create a new GaiaOAuthClient for each request to GAIA.
92 CreateNewGaiaOAuthClientInstance(); 90 CreateNewGaiaOAuthClientInstance();
93 auth_client_->RefreshToken( 91 auth_client_->RefreshToken(
94 oauth_client_info_, 92 oauth_client_info_,
95 refresh_token_, 93 refresh_token_,
96 kAppRemotingScopeVector, 94 oauth_scopes_vector_,
97 kMaxGetTokensRetries, 95 kMaxGetTokensRetries,
98 this); // GaiaOAuthClient::Delegate* delegate 96 this); // GaiaOAuthClient::Delegate* delegate
99 } 97 }
100 98
101 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() { 99 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() {
102 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; 100 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter;
103 request_context_getter = new remoting::URLRequestContextGetter( 101 request_context_getter = new remoting::URLRequestContextGetter(
104 base::ThreadTaskRunnerHandle::Get(), // network_runner 102 base::ThreadTaskRunnerHandle::Get(), // network_runner
105 base::ThreadTaskRunnerHandle::Get()); // file_runner 103 base::ThreadTaskRunnerHandle::Get()); // file_runner
106 104
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // Create a new GaiaOAuthClient for each request to GAIA. 200 // Create a new GaiaOAuthClient for each request to GAIA.
203 CreateNewGaiaOAuthClientInstance(); 201 CreateNewGaiaOAuthClientInstance();
204 auth_client_->GetTokenInfo( 202 auth_client_->GetTokenInfo(
205 access_token_, 203 access_token_,
206 kMaxGetTokensRetries, 204 kMaxGetTokensRetries,
207 this); // GaiaOAuthClient::Delegate* delegate 205 this); // GaiaOAuthClient::Delegate* delegate
208 } 206 }
209 207
210 } // namespace test 208 } // namespace test
211 } // namespace remoting 209 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698