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

Unified Diff: chrome/browser/ui/auto_login_prompter.cc

Issue 208393015: Revert "Remove desktop auto-login since we don't plan on shipping it there. Refactor the base and … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « chrome/browser/ui/auto_login_prompter.h ('k') | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/auto_login_prompter.cc
diff --git a/chrome/browser/ui/android/infobars/auto_login_prompter.cc b/chrome/browser/ui/auto_login_prompter.cc
similarity index 77%
rename from chrome/browser/ui/android/infobars/auto_login_prompter.cc
rename to chrome/browser/ui/auto_login_prompter.cc
index ef13339398c9ae636fe05bc1b7cd7213405453ba..c158fb73733ac2eb21d8aac37fd527bd4494b7df 100644
--- a/chrome/browser/ui/android/infobars/auto_login_prompter.cc
+++ b/chrome/browser/ui/auto_login_prompter.cc
@@ -1,8 +1,8 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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/ui/android/infobars/auto_login_prompter.h"
+#include "chrome/browser/ui/auto_login_prompter.h"
#include "base/bind.h"
#include "base/command_line.h"
@@ -26,6 +26,30 @@
using content::BrowserThread;
using content::WebContents;
+namespace {
+
+#if !defined(OS_ANDROID)
+bool FetchUsernameThroughSigninManager(Profile* profile, std::string* output) {
+ // In an incognito window these services are not available.
+ SigninManagerBase* signin_manager =
+ SigninManagerFactory::GetInstance()->GetForProfile(profile);
+ if (!signin_manager)
+ return false;
+
+ ProfileOAuth2TokenService* token_service =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
+ if (!token_service || !token_service->RefreshTokenIsAvailable(
+ signin_manager->GetAuthenticatedAccountId())) {
+ return false;
+ }
+
+ *output = signin_manager->GetAuthenticatedUsername();
+ return true;
+}
+#endif // !defined(OS_ANDROID)
+
+} // namespace
+
AutoLoginPrompter::AutoLoginPrompter(WebContents* web_contents,
const Params& params,
const GURL& url)
@@ -47,6 +71,9 @@ AutoLoginPrompter::~AutoLoginPrompter() {
void AutoLoginPrompter::ShowInfoBarIfPossible(net::URLRequest* request,
int child_id,
int route_id) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin))
+ return;
+
// See if the response contains the X-Auto-Login header. If so, this was
// a request for a login page, and the server is allowing the browser to
// suggest auto-login, if available.
@@ -79,6 +106,13 @@ void AutoLoginPrompter::ShowInfoBarUIThread(Params params,
if (!profile->GetPrefs()->GetBoolean(prefs::kAutologinEnabled))
return;
+#if !defined(OS_ANDROID)
+ // On Android, the username is fetched on the Java side from the
+ // AccountManager provided by the platform.
+ if (!FetchUsernameThroughSigninManager(profile, &params.username))
+ return;
+#endif
+
// Make sure that |account|, if specified, matches the logged in user.
// However, |account| is usually empty.
if (!params.username.empty() && !params.header.account.empty() &&
« no previous file with comments | « chrome/browser/ui/auto_login_prompter.h ('k') | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698