Chromium Code Reviews| 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 { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 50 ArcBackgroundAuthCodeFetcher::ArcBackgroundAuthCodeFetcher( | 47 ArcBackgroundAuthCodeFetcher::ArcBackgroundAuthCodeFetcher( |
| 51 Profile* profile, | 48 Profile* profile, |
| 52 ArcAuthContext* context) | 49 ArcAuthContext* context) |
| 53 : OAuth2TokenService::Consumer(kConsumerName), | 50 : OAuth2TokenService::Consumer(kConsumerName), |
| 54 profile_(profile), | 51 profile_(profile), |
| 55 context_(context), | 52 context_(context), |
| 56 weak_ptr_factory_(this) {} | 53 weak_ptr_factory_(this) {} |
| 57 | 54 |
| 58 ArcBackgroundAuthCodeFetcher::~ArcBackgroundAuthCodeFetcher() = default; | 55 ArcBackgroundAuthCodeFetcher::~ArcBackgroundAuthCodeFetcher() = default; |
| 59 | 56 |
| 57 // static | |
| 58 std::string ArcBackgroundAuthCodeFetcher::GetTokenExchangeEndpointForTesting() { | |
| 59 return kEndPoint; | |
|
khmel
2017/05/12 15:52:28
nit: probably better to expose this via header
blundell
2017/05/15 08:32:32
Done.
| |
| 60 } | |
| 61 | |
| 60 void ArcBackgroundAuthCodeFetcher::Fetch(const FetchCallback& callback) { | 62 void ArcBackgroundAuthCodeFetcher::Fetch(const FetchCallback& callback) { |
| 61 DCHECK(callback_.is_null()); | 63 DCHECK(callback_.is_null()); |
| 62 callback_ = callback; | 64 callback_ = callback; |
| 63 | 65 |
| 64 context_->Prepare(base::Bind(&ArcBackgroundAuthCodeFetcher::OnPrepared, | 66 context_->Prepare(base::Bind(&ArcBackgroundAuthCodeFetcher::OnPrepared, |
| 65 weak_ptr_factory_.GetWeakPtr())); | 67 weak_ptr_factory_.GetWeakPtr())); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void ArcBackgroundAuthCodeFetcher::OnPrepared( | 70 void ArcBackgroundAuthCodeFetcher::OnPrepared( |
| 69 net::URLRequestContextGetter* request_context_getter) { | 71 net::URLRequestContextGetter* request_context_getter) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 } | 182 } |
| 181 | 183 |
| 182 void ArcBackgroundAuthCodeFetcher::ReportResult( | 184 void ArcBackgroundAuthCodeFetcher::ReportResult( |
| 183 const std::string& auth_code, | 185 const std::string& auth_code, |
| 184 OptInSilentAuthCode uma_status) { | 186 OptInSilentAuthCode uma_status) { |
| 185 UpdateSilentAuthCodeUMA(uma_status); | 187 UpdateSilentAuthCodeUMA(uma_status); |
| 186 base::ResetAndReturn(&callback_).Run(!auth_code.empty(), auth_code); | 188 base::ResetAndReturn(&callback_).Run(!auth_code.empty(), auth_code); |
| 187 } | 189 } |
| 188 | 190 |
| 189 } // namespace arc | 191 } // namespace arc |
| OLD | NEW |