| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
| 9 #include "base/logging.h" |
| 10 #include "chrome/browser/chromeos/arc/arc_auth_context.h" |
| 11 |
| 12 namespace arc { |
| 13 |
| 14 ArcManualAuthCodeFetcher::ArcManualAuthCodeFetcher(ArcAuthContext* context, |
| 15 ArcSupportHost* support_host) |
| 16 : context_(context), support_host_(support_host), weak_ptr_factory_(this) { |
| 17 DCHECK(context_); |
| 18 DCHECK(support_host_); |
| 19 support_host_->AddObserver(this); |
| 20 } |
| 21 |
| 22 ArcManualAuthCodeFetcher::~ArcManualAuthCodeFetcher() { |
| 23 support_host_->RemoveObserver(this); |
| 24 } |
| 25 |
| 26 void ArcManualAuthCodeFetcher::Fetch(const FetchCallback& callback) { |
| 27 DCHECK(pending_callback_.is_null()); |
| 28 pending_callback_ = callback; |
| 29 |
| 30 FetchInternal(); |
| 31 } |
| 32 |
| 33 void ArcManualAuthCodeFetcher::FetchInternal() { |
| 34 DCHECK(!pending_callback_.is_null()); |
| 35 context_->Prepare(base::Bind(&ArcManualAuthCodeFetcher::OnContextPrepared, |
| 36 weak_ptr_factory_.GetWeakPtr())); |
| 37 } |
| 38 |
| 39 void ArcManualAuthCodeFetcher::OnContextPrepared( |
| 40 net::URLRequestContextGetter* request_context_getter) { |
| 41 DCHECK(!pending_callback_.is_null()); |
| 42 if (!request_context_getter) { |
| 43 support_host_->ShowError(ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR, |
| 44 false); |
| 45 return; |
| 46 } |
| 47 |
| 48 support_host_->ShowLso(); |
| 49 } |
| 50 |
| 51 void ArcManualAuthCodeFetcher::OnAuthSucceeded(const std::string& auth_code) { |
| 52 DCHECK(!pending_callback_.is_null()); |
| 53 base::ResetAndReturn(&pending_callback_).Run(auth_code); |
| 54 } |
| 55 |
| 56 void ArcManualAuthCodeFetcher::OnRetryClicked() { |
| 57 DCHECK(!pending_callback_.is_null()); |
| 58 FetchInternal(); |
| 59 } |
| 60 |
| 61 } // namespace arc |
| OLD | NEW |