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

Unified Diff: chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retriever.cc

Issue 136573002: Retrieve the authenticated user's e-mail from GAIA during SAML login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 11 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/browser/ui/webui/chromeos/login/authenticated_user_email_retriever.cc
diff --git a/chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retriever.cc b/chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retriever.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a092d53acb2067c59b8623e584b20e3f7eec979e
--- /dev/null
+++ b/chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retriever.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2014 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/webui/chromeos/login/authenticated_user_email_retriever.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "content/public/browser/browser_thread.h"
+#include "google_apis/gaia/gaia_auth_fetcher.h"
+#include "google_apis/gaia/gaia_constants.h"
+#include "google_apis/gaia/gaia_urls.h"
+#include "google_apis/gaia/google_service_auth_error.h"
+#include "net/cookies/cookie_monster.h"
+#include "net/url_request/url_request_context.h"
+#include "url/gurl.h"
+
+namespace chromeos {
+
+namespace {
+
+scoped_refptr<net::CookieStore> GetCookieStoreOnIO(
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ return url_request_context_getter->GetURLRequestContext()->cookie_store();
+}
+
+} // namespace
+
+AuthenticatedUserEmailRetriever::AuthenticatedUserEmailRetriever(
+ const AuthenticatedUserEmailCallback& callback,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
+ : callback_(callback),
+ url_request_context_getter_(url_request_context_getter),
+ weak_factory_(this) {
+ content::BrowserThread::PostTaskAndReplyWithResult(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GetCookieStoreOnIO, url_request_context_getter),
+ base::Bind(&AuthenticatedUserEmailRetriever::ExtractCookies,
+ weak_factory_.GetWeakPtr()));
+}
+
+AuthenticatedUserEmailRetriever::~AuthenticatedUserEmailRetriever() {
+}
+
+void AuthenticatedUserEmailRetriever::OnGetUserInfoSuccess(
+ const UserInfoMap& data) {
+ UserInfoMap::const_iterator it = data.find("email");
+ callback_.Run(it != data.end() ? it->second : "");
+}
+
+void AuthenticatedUserEmailRetriever::OnGetUserInfoFailure(
+ const GoogleServiceAuthError& error) {
+ callback_.Run(std::string());
+}
+
+void AuthenticatedUserEmailRetriever::ExtractCookies(
+ scoped_refptr<net::CookieStore> cookie_store) {
+ if (!cookie_store) {
+ callback_.Run(std::string());
+ return;
+ }
+ cookie_store->GetCookieMonster()->GetAllCookiesForURLAsync(
+ GaiaUrls::GetInstance()->gaia_url(),
+ base::Bind(&AuthenticatedUserEmailRetriever::ExtractLSIDFromCookies,
+ weak_factory_.GetWeakPtr()));
+}
+
+void AuthenticatedUserEmailRetriever::ExtractLSIDFromCookies(
+ const net::CookieList& cookies) {
+ for (net::CookieList::const_iterator it = cookies.begin();
+ it != cookies.end(); ++it) {
+ if (it->Name() == "LSID") {
+ gaia_auth_fetcher_.reset(new GaiaAuthFetcher(
+ this,
+ GaiaConstants::kChromeSource,
+ url_request_context_getter_));
+ gaia_auth_fetcher_->StartGetUserInfo(it->Value());
+ return;
+ }
+ }
+ callback_.Run(std::string());
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698