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, ¶ms.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() && |