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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/AutoLoginAccountDelegate.java

Issue 24109002: [InfoBar] Upstram basic infobar flow for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@upstream_infobar_full
Patch Set: Fix License header in two more files Created 7 years, 3 months 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/android/java/src/org/chromium/chrome/browser/infobar/AutoLoginAccountDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutoLoginAccountDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutoLoginAccountDelegate.java
new file mode 100644
index 0000000000000000000000000000000000000000..befc64532e187d9d7d57927753aa8f0de4f3ddc6
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutoLoginAccountDelegate.java
@@ -0,0 +1,92 @@
+// Copyright (c) 2013 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.
+
+package org.chromium.chrome.browser.infobar;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+import org.chromium.content.common.CommandLine;
+import org.chromium.sync.signin.AccountManagerHelper;
+import org.chromium.sync.signin.ChromeSigninController;
+
+/**
+ * Performs the actual login to the requried service.
+ */
+public class AutoLoginAccountDelegate implements AccountManagerCallback<Bundle> {
+
+ private static final String WEB_LOGIN_PREFIX = "weblogin:";
+ private final Activity mActivity;
+ private final AutoLoginProcessor mAutoLoginProcessor;
+ private final AccountManager mAccountManager;
+ private final Account mAccount;
+ private boolean mLogInRequested;
+ private String mAuthTokenType;
+
+ public AutoLoginAccountDelegate(Activity activity, AutoLoginProcessor autoLoginProcessor,
+ String realm, String account, String accountArgs) {
+ mActivity = activity;
+ mAutoLoginProcessor = autoLoginProcessor;
+ mAccountManager = AccountManager.get(activity);
+ mAccount = ChromeSigninController.get(activity).getSignedInUser();
+ mLogInRequested = false;
+ mAuthTokenType = WEB_LOGIN_PREFIX + accountArgs;
+ }
+
+ public boolean logIn() {
+ Log.i("AutoLoginAccountDelegate", "auto-login requested for "
+ + (mAccount != null ? mAccount.toString() : "?"));
+
+ Account currentAccount = ChromeSigninController.get(mActivity).getSignedInUser();
+ if (mAccount == null || !mAccount.equals(currentAccount)) {
+ Log.i("InfoBar", "auto-login failed because account is no longer valid");
+ return false;
+ }
+
+ // The callback for this request comes in on a non-UI thread.
+ mAccountManager.getAuthToken(mAccount, mAuthTokenType, null, mActivity, this, null);
+ mLogInRequested = true;
+ return true;
+ }
+
+ String getAuthToken() {
+ return mAuthTokenType;
+ }
+
+ String getAccountName() {
+ return mAccount != null ? mAccount.name : "";
+ }
+
+ boolean loginRequested() {
+ return mLogInRequested;
+ }
+
+ boolean hasAccount() {
+ return mAccount != null;
+ }
+
+ @Override
+ public void run(AccountManagerFuture<Bundle> value) {
+ String result = null;
+ try {
+ result = value.getResult().getString(AccountManager.KEY_AUTHTOKEN);
+ } catch (Exception e) {
+ result = null;
+ }
+
+ final boolean success = result != null;
+
+ // Can't rely on the Bundle's auth token or account name as they might be null
+ // if this was a failed attempt.
+ if (mAutoLoginProcessor != null) {
+ mAutoLoginProcessor.processAutoLoginResult(getAccountName(), getAuthToken(),
+ success, result);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698