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

Unified Diff: chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.cc

Issue 2547073002: Fix race issue in ArcAuthService. (Closed)
Patch Set: Address comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.cc
diff --git a/chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.cc b/chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..28fe5ef52f801d4b6f98eae79e86573329e666a1
--- /dev/null
+++ b/chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.cc
@@ -0,0 +1,61 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h"
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "base/logging.h"
+#include "chrome/browser/chromeos/arc/arc_auth_context.h"
+
+namespace arc {
+
+ArcManualAuthCodeFetcher::ArcManualAuthCodeFetcher(ArcAuthContext* context,
+ ArcSupportHost* support_host)
+ : context_(context), support_host_(support_host), weak_ptr_factory_(this) {
+ DCHECK(context_);
+ DCHECK(support_host_);
+ support_host_->AddObserver(this);
+}
+
+ArcManualAuthCodeFetcher::~ArcManualAuthCodeFetcher() {
+ support_host_->RemoveObserver(this);
+}
+
+void ArcManualAuthCodeFetcher::Fetch(const FetchCallback& callback) {
+ DCHECK(pending_callback_.is_null());
+ pending_callback_ = callback;
+
+ FetchInternal();
+}
+
+void ArcManualAuthCodeFetcher::FetchInternal() {
+ DCHECK(!pending_callback_.is_null());
+ context_->Prepare(base::Bind(&ArcManualAuthCodeFetcher::OnContextPrepared,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ArcManualAuthCodeFetcher::OnContextPrepared(
+ net::URLRequestContextGetter* request_context_getter) {
+ DCHECK(!pending_callback_.is_null());
+ if (!request_context_getter) {
+ support_host_->ShowError(ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR,
+ false);
+ return;
+ }
+
+ support_host_->ShowLso();
+}
+
+void ArcManualAuthCodeFetcher::OnAuthSucceeded(const std::string& auth_code) {
+ DCHECK(!pending_callback_.is_null());
+ base::ResetAndReturn(&pending_callback_).Run(auth_code);
+}
+
+void ArcManualAuthCodeFetcher::OnRetryClicked() {
+ DCHECK(!pending_callback_.is_null());
+ FetchInternal();
+}
+
+} // namespace arc
« no previous file with comments | « chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h ('k') | chrome/browser/chromeos/arc/auth/arc_robot_auth.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698