| 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/auth/arc_background_auth_code_fetcher.h" | 5 #include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 17 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 15 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 18 #include "components/signin/core/account_id/account_id.h" | 16 #include "components/signin/core/account_id/account_id.h" |
| 19 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 17 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 20 #include "components/signin/core/browser/signin_manager_base.h" | |
| 21 #include "components/user_manager/known_user.h" | 18 #include "components/user_manager/known_user.h" |
| 22 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 24 #include "google_apis/gaia/gaia_auth_fetcher.h" | 21 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 25 #include "google_apis/gaia/gaia_constants.h" | 22 #include "google_apis/gaia/gaia_constants.h" |
| 26 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 27 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
| 28 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
| 29 | 26 |
| 30 namespace arc { | 27 namespace arc { |
| 31 | 28 |
| 32 namespace { | 29 namespace { |
| 33 | 30 |
| 34 constexpr int kGetAuthCodeNetworkRetry = 3; | 31 constexpr int kGetAuthCodeNetworkRetry = 3; |
| 35 | 32 |
| 36 constexpr char kConsumerName[] = "ArcAuthContext"; | 33 constexpr char kConsumerName[] = "ArcAuthContext"; |
| 37 constexpr char kToken[] = "token"; | 34 constexpr char kToken[] = "token"; |
| 38 constexpr char kDeviceId[] = "device_id"; | 35 constexpr char kDeviceId[] = "device_id"; |
| 39 constexpr char kDeviceType[] = "device_type"; | 36 constexpr char kDeviceType[] = "device_type"; |
| 40 constexpr char kDeviceTypeArc[] = "arc_plus_plus"; | 37 constexpr char kDeviceTypeArc[] = "arc_plus_plus"; |
| 41 constexpr char kLoginScopedToken[] = "login_scoped_token"; | 38 constexpr char kLoginScopedToken[] = "login_scoped_token"; |
| 42 constexpr char kGetAuthCodeHeaders[] = | 39 constexpr char kGetAuthCodeHeaders[] = |
| 43 "Content-Type: application/json; charset=utf-8"; | 40 "Content-Type: application/json; charset=utf-8"; |
| 44 constexpr char kContentTypeJSON[] = "application/json"; | 41 constexpr char kContentTypeJSON[] = "application/json"; |
| 45 constexpr char kEndPoint[] = | |
| 46 "https://www.googleapis.com/oauth2/v4/ExchangeToken"; | |
| 47 | 42 |
| 48 } // namespace | 43 } // namespace |
| 49 | 44 |
| 45 const char kAuthTokenExchangeEndPoint[] = |
| 46 "https://www.googleapis.com/oauth2/v4/ExchangeToken"; |
| 47 |
| 50 ArcBackgroundAuthCodeFetcher::ArcBackgroundAuthCodeFetcher( | 48 ArcBackgroundAuthCodeFetcher::ArcBackgroundAuthCodeFetcher( |
| 51 Profile* profile, | 49 Profile* profile, |
| 52 ArcAuthContext* context) | 50 ArcAuthContext* context) |
| 53 : OAuth2TokenService::Consumer(kConsumerName), | 51 : OAuth2TokenService::Consumer(kConsumerName), |
| 54 profile_(profile), | 52 profile_(profile), |
| 55 context_(context), | 53 context_(context), |
| 56 weak_ptr_factory_(this) {} | 54 weak_ptr_factory_(this) {} |
| 57 | 55 |
| 58 ArcBackgroundAuthCodeFetcher::~ArcBackgroundAuthCodeFetcher() = default; | 56 ArcBackgroundAuthCodeFetcher::~ArcBackgroundAuthCodeFetcher() = default; |
| 59 | 57 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 multi_user_util::GetAccountIdFromProfile(profile_)); | 93 multi_user_util::GetAccountIdFromProfile(profile_)); |
| 96 DCHECK(!device_id.empty()); | 94 DCHECK(!device_id.empty()); |
| 97 | 95 |
| 98 base::DictionaryValue request_data; | 96 base::DictionaryValue request_data; |
| 99 request_data.SetString(kLoginScopedToken, access_token); | 97 request_data.SetString(kLoginScopedToken, access_token); |
| 100 request_data.SetString(kDeviceType, kDeviceTypeArc); | 98 request_data.SetString(kDeviceType, kDeviceTypeArc); |
| 101 request_data.SetString(kDeviceId, device_id); | 99 request_data.SetString(kDeviceId, device_id); |
| 102 std::string request_string; | 100 std::string request_string; |
| 103 base::JSONWriter::Write(request_data, &request_string); | 101 base::JSONWriter::Write(request_data, &request_string); |
| 104 | 102 |
| 105 auth_code_fetcher_ = | 103 auth_code_fetcher_ = net::URLFetcher::Create( |
| 106 net::URLFetcher::Create(0, GURL(kEndPoint), net::URLFetcher::POST, this); | 104 0, GURL(kAuthTokenExchangeEndPoint), net::URLFetcher::POST, this); |
| 107 auth_code_fetcher_->SetRequestContext(request_context_getter_); | 105 auth_code_fetcher_->SetRequestContext(request_context_getter_); |
| 108 auth_code_fetcher_->SetUploadData(kContentTypeJSON, request_string); | 106 auth_code_fetcher_->SetUploadData(kContentTypeJSON, request_string); |
| 109 auth_code_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 107 auth_code_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
| 110 net::LOAD_BYPASS_CACHE); | 108 net::LOAD_BYPASS_CACHE); |
| 111 auth_code_fetcher_->SetAutomaticallyRetryOnNetworkChanges( | 109 auth_code_fetcher_->SetAutomaticallyRetryOnNetworkChanges( |
| 112 kGetAuthCodeNetworkRetry); | 110 kGetAuthCodeNetworkRetry); |
| 113 auth_code_fetcher_->SetExtraRequestHeaders(kGetAuthCodeHeaders); | 111 auth_code_fetcher_->SetExtraRequestHeaders(kGetAuthCodeHeaders); |
| 114 auth_code_fetcher_->Start(); | 112 auth_code_fetcher_->Start(); |
| 115 } | 113 } |
| 116 | 114 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 178 } |
| 181 | 179 |
| 182 void ArcBackgroundAuthCodeFetcher::ReportResult( | 180 void ArcBackgroundAuthCodeFetcher::ReportResult( |
| 183 const std::string& auth_code, | 181 const std::string& auth_code, |
| 184 OptInSilentAuthCode uma_status) { | 182 OptInSilentAuthCode uma_status) { |
| 185 UpdateSilentAuthCodeUMA(uma_status); | 183 UpdateSilentAuthCodeUMA(uma_status); |
| 186 base::ResetAndReturn(&callback_).Run(!auth_code.empty(), auth_code); | 184 base::ResetAndReturn(&callback_).Run(!auth_code.empty(), auth_code); |
| 187 } | 185 } |
| 188 | 186 |
| 189 } // namespace arc | 187 } // namespace arc |
| OLD | NEW |