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

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_code_fetcher.cc

Issue 2508713003: arc: Prepare ArcAuthEndpoint flag for finch experiment. (Closed)
Patch Set: Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h" 5 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h"
6 6
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher_delegate.h" 10 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher_delegate.h"
(...skipping 20 matching lines...) Expand all
31 31
32 constexpr char kConsumerName[] = "ArcAuthContext"; 32 constexpr char kConsumerName[] = "ArcAuthContext";
33 constexpr char kToken[] = "token"; 33 constexpr char kToken[] = "token";
34 constexpr char kDeviceId[] = "device_id"; 34 constexpr char kDeviceId[] = "device_id";
35 constexpr char kDeviceType[] = "device_type"; 35 constexpr char kDeviceType[] = "device_type";
36 constexpr char kDeviceTypeArc[] = "arc_plus_plus"; 36 constexpr char kDeviceTypeArc[] = "arc_plus_plus";
37 constexpr char kLoginScopedToken[] = "login_scoped_token"; 37 constexpr char kLoginScopedToken[] = "login_scoped_token";
38 constexpr char kGetAuthCodeHeaders[] = 38 constexpr char kGetAuthCodeHeaders[] =
39 "Content-Type: application/json; charset=utf-8"; 39 "Content-Type: application/json; charset=utf-8";
40 constexpr char kContentTypeJSON[] = "application/json"; 40 constexpr char kContentTypeJSON[] = "application/json";
41 constexpr char kEndPoint[] =
42 "https://www.googleapis.com/oauth2/v4/ExchangeToken";
41 43
42 } // namespace 44 } // namespace
43 45
44 ArcAuthCodeFetcher::ArcAuthCodeFetcher( 46 ArcAuthCodeFetcher::ArcAuthCodeFetcher(
45 ArcAuthCodeFetcherDelegate* delegate, 47 ArcAuthCodeFetcherDelegate* delegate,
46 net::URLRequestContextGetter* request_context_getter, 48 net::URLRequestContextGetter* request_context_getter,
47 Profile* profile, 49 Profile* profile)
48 const std::string& auth_endpoint)
49 : OAuth2TokenService::Consumer(kConsumerName), 50 : OAuth2TokenService::Consumer(kConsumerName),
50 delegate_(delegate), 51 delegate_(delegate),
51 request_context_getter_(request_context_getter), 52 request_context_getter_(request_context_getter),
52 profile_(profile), 53 profile_(profile) {
53 auth_endpoint_(auth_endpoint) {
54 // Get token service and account ID to fetch auth tokens. 54 // Get token service and account ID to fetch auth tokens.
55 ProfileOAuth2TokenService* const token_service = 55 ProfileOAuth2TokenService* const token_service =
56 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 56 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
57 const SigninManagerBase* const signin_manager = 57 const SigninManagerBase* const signin_manager =
58 SigninManagerFactory::GetForProfile(profile_); 58 SigninManagerFactory::GetForProfile(profile_);
59 CHECK(token_service && signin_manager); 59 CHECK(token_service && signin_manager);
60 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); 60 const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
61 DCHECK(!account_id.empty()); 61 DCHECK(!account_id.empty());
62 DCHECK(token_service->RefreshTokenIsAvailable(account_id)); 62 DCHECK(token_service->RefreshTokenIsAvailable(account_id));
63 63
(...skipping 15 matching lines...) Expand all
79 multi_user_util::GetAccountIdFromProfile(profile_)); 79 multi_user_util::GetAccountIdFromProfile(profile_));
80 DCHECK(!device_id.empty()); 80 DCHECK(!device_id.empty());
81 81
82 base::DictionaryValue request_data; 82 base::DictionaryValue request_data;
83 request_data.SetString(kLoginScopedToken, access_token); 83 request_data.SetString(kLoginScopedToken, access_token);
84 request_data.SetString(kDeviceType, kDeviceTypeArc); 84 request_data.SetString(kDeviceType, kDeviceTypeArc);
85 request_data.SetString(kDeviceId, device_id); 85 request_data.SetString(kDeviceId, device_id);
86 std::string request_string; 86 std::string request_string;
87 base::JSONWriter::Write(request_data, &request_string); 87 base::JSONWriter::Write(request_data, &request_string);
88 88
89 DCHECK(!auth_endpoint_.empty()); 89 auth_code_fetcher_ =
90 auth_code_fetcher_ = net::URLFetcher::Create(0, GURL(auth_endpoint_), 90 net::URLFetcher::Create(0, GURL(kEndPoint), net::URLFetcher::POST, this);
91 net::URLFetcher::POST, this);
92 auth_code_fetcher_->SetRequestContext(request_context_getter_); 91 auth_code_fetcher_->SetRequestContext(request_context_getter_);
93 auth_code_fetcher_->SetUploadData(kContentTypeJSON, request_string); 92 auth_code_fetcher_->SetUploadData(kContentTypeJSON, request_string);
94 auth_code_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | 93 auth_code_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE |
95 net::LOAD_BYPASS_CACHE); 94 net::LOAD_BYPASS_CACHE);
96 auth_code_fetcher_->SetAutomaticallyRetryOnNetworkChanges( 95 auth_code_fetcher_->SetAutomaticallyRetryOnNetworkChanges(
97 kGetAuthCodeNetworkRetry); 96 kGetAuthCodeNetworkRetry);
98 auth_code_fetcher_->SetExtraRequestHeaders(kGetAuthCodeHeaders); 97 auth_code_fetcher_->SetExtraRequestHeaders(kGetAuthCodeHeaders);
99 auth_code_fetcher_->Start(); 98 auth_code_fetcher_->Start();
100 } 99 }
101 100
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 149
151 delegate_->OnAuthCodeSuccess(auth_code); 150 delegate_->OnAuthCodeSuccess(auth_code);
152 } 151 }
153 152
154 void ArcAuthCodeFetcher::ResetFetchers() { 153 void ArcAuthCodeFetcher::ResetFetchers() {
155 login_token_request_.reset(); 154 login_token_request_.reset();
156 auth_code_fetcher_.reset(); 155 auth_code_fetcher_.reset();
157 } 156 }
158 157
159 } // namespace arc 158 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698