| OLD | NEW |
| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 constexpr char kConsumerName[] = "ArcAuthContext"; | 34 constexpr char kConsumerName[] = "ArcAuthContext"; |
| 35 constexpr char kToken[] = "token"; | 35 constexpr char kToken[] = "token"; |
| 36 constexpr char kDeviceId[] = "device_id"; | 36 constexpr char kDeviceId[] = "device_id"; |
| 37 constexpr char kDeviceType[] = "device_type"; | 37 constexpr char kDeviceType[] = "device_type"; |
| 38 constexpr char kDeviceTypeArc[] = "arc_plus_plus"; | 38 constexpr char kDeviceTypeArc[] = "arc_plus_plus"; |
| 39 constexpr char kLoginScopedToken[] = "login_scoped_token"; | 39 constexpr char kLoginScopedToken[] = "login_scoped_token"; |
| 40 constexpr char kGetAuthCodeHeaders[] = | 40 constexpr char kGetAuthCodeHeaders[] = |
| 41 "Content-Type: application/json; charset=utf-8"; | 41 "Content-Type: application/json; charset=utf-8"; |
| 42 constexpr char kContentTypeJSON[] = "application/json"; | 42 constexpr char kContentTypeJSON[] = "application/json"; |
| 43 constexpr char kEndPoint[] = |
| 44 "https://www.googleapis.com/oauth2/v4/ExchangeToken"; |
| 43 | 45 |
| 44 } // namespace | 46 } // namespace |
| 45 | 47 |
| 46 ArcAuthCodeFetcher::ArcAuthCodeFetcher(Profile* profile, | 48 ArcAuthCodeFetcher::ArcAuthCodeFetcher(Profile* profile, |
| 47 ArcAuthContext* context, | 49 ArcAuthContext* context) |
| 48 const std::string& auth_endpoint) | |
| 49 : OAuth2TokenService::Consumer(kConsumerName), | 50 : OAuth2TokenService::Consumer(kConsumerName), |
| 50 profile_(profile), | 51 profile_(profile), |
| 51 context_(context), | 52 context_(context), |
| 52 auth_endpoint_(auth_endpoint), | |
| 53 weak_ptr_factory_(this) {} | 53 weak_ptr_factory_(this) {} |
| 54 | 54 |
| 55 ArcAuthCodeFetcher::~ArcAuthCodeFetcher() = default; | 55 ArcAuthCodeFetcher::~ArcAuthCodeFetcher() = default; |
| 56 | 56 |
| 57 void ArcAuthCodeFetcher::Fetch(const FetchCallback& callback) { | 57 void ArcAuthCodeFetcher::Fetch(const FetchCallback& callback) { |
| 58 DCHECK(callback_.is_null()); | 58 DCHECK(callback_.is_null()); |
| 59 callback_ = callback; | 59 callback_ = callback; |
| 60 | 60 |
| 61 context_->Prepare(base::Bind(&ArcAuthCodeFetcher::OnPrepared, | 61 context_->Prepare(base::Bind(&ArcAuthCodeFetcher::OnPrepared, |
| 62 weak_ptr_factory_.GetWeakPtr())); | 62 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 multi_user_util::GetAccountIdFromProfile(profile_)); | 92 multi_user_util::GetAccountIdFromProfile(profile_)); |
| 93 DCHECK(!device_id.empty()); | 93 DCHECK(!device_id.empty()); |
| 94 | 94 |
| 95 base::DictionaryValue request_data; | 95 base::DictionaryValue request_data; |
| 96 request_data.SetString(kLoginScopedToken, access_token); | 96 request_data.SetString(kLoginScopedToken, access_token); |
| 97 request_data.SetString(kDeviceType, kDeviceTypeArc); | 97 request_data.SetString(kDeviceType, kDeviceTypeArc); |
| 98 request_data.SetString(kDeviceId, device_id); | 98 request_data.SetString(kDeviceId, device_id); |
| 99 std::string request_string; | 99 std::string request_string; |
| 100 base::JSONWriter::Write(request_data, &request_string); | 100 base::JSONWriter::Write(request_data, &request_string); |
| 101 | 101 |
| 102 DCHECK(!auth_endpoint_.empty()); | 102 auth_code_fetcher_ = |
| 103 auth_code_fetcher_ = net::URLFetcher::Create(0, GURL(auth_endpoint_), | 103 net::URLFetcher::Create(0, GURL(kEndPoint), net::URLFetcher::POST, this); |
| 104 net::URLFetcher::POST, this); | |
| 105 auth_code_fetcher_->SetRequestContext(request_context_getter_); | 104 auth_code_fetcher_->SetRequestContext(request_context_getter_); |
| 106 auth_code_fetcher_->SetUploadData(kContentTypeJSON, request_string); | 105 auth_code_fetcher_->SetUploadData(kContentTypeJSON, request_string); |
| 107 auth_code_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 106 auth_code_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
| 108 net::LOAD_BYPASS_CACHE); | 107 net::LOAD_BYPASS_CACHE); |
| 109 auth_code_fetcher_->SetAutomaticallyRetryOnNetworkChanges( | 108 auth_code_fetcher_->SetAutomaticallyRetryOnNetworkChanges( |
| 110 kGetAuthCodeNetworkRetry); | 109 kGetAuthCodeNetworkRetry); |
| 111 auth_code_fetcher_->SetExtraRequestHeaders(kGetAuthCodeHeaders); | 110 auth_code_fetcher_->SetExtraRequestHeaders(kGetAuthCodeHeaders); |
| 112 auth_code_fetcher_->Start(); | 111 auth_code_fetcher_->Start(); |
| 113 } | 112 } |
| 114 | 113 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 161 |
| 163 base::ResetAndReturn(&callback_).Run(auth_code); | 162 base::ResetAndReturn(&callback_).Run(auth_code); |
| 164 } | 163 } |
| 165 | 164 |
| 166 void ArcAuthCodeFetcher::ResetFetchers() { | 165 void ArcAuthCodeFetcher::ResetFetchers() { |
| 167 login_token_request_.reset(); | 166 login_token_request_.reset(); |
| 168 auth_code_fetcher_.reset(); | 167 auth_code_fetcher_.reset(); |
| 169 } | 168 } |
| 170 | 169 |
| 171 } // namespace arc | 170 } // namespace arc |
| OLD | NEW |