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

Side by Side Diff: chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.cc

Issue 2547073002: Fix race issue in ArcAuthService. (Closed)
Patch Set: Created 4 years 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
(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 DCHECK(!preparing_context_);
36 preparing_context_ = true;
37 context_->Prepare(base::Bind(&ArcManualAuthCodeFetcher::OnContextPrepared,
38 weak_ptr_factory_.GetWeakPtr()));
39 }
40
41 void ArcManualAuthCodeFetcher::OnContextPrepared(
42 net::URLRequestContextGetter* request_context_getter) {
43 DCHECK(!pending_callback_.is_null());
44 preparing_context_ = false;
45 if (!request_context_getter) {
46 support_host_->ShowError(ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR,
47 false);
48 return;
49 }
50
51 support_host_->ShowLso();
52 }
53
54 void ArcManualAuthCodeFetcher::OnAuthSucceeded(const std::string& auth_code) {
55 DCHECK(!pending_callback_.is_null());
56 base::ResetAndReturn(&pending_callback_).Run(auth_code);
57 }
58
59 void ArcManualAuthCodeFetcher::OnRetryClicked() {
60 DCHECK(!pending_callback_.is_null());
61 // If a user clicks "TRY AGAIN" button very quickly, this can be called
62 // twice or more consecutively. Then, do not run the FetchInternal(), because
63 // there should be an inflight operation.
64 if (preparing_context_)
65 return;
66 FetchInternal();
Luis Héctor Chávez 2016/12/03 01:27:54 Don't we want to transition to another page at thi
Luis Héctor Chávez 2016/12/03 14:24:26 i thought about this a bit more: that would still
hidehiko 2016/12/05 06:00:31 SGTM. Can I work on the UI change in another CL,
67 }
68
69 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698