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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retrie ver.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "google_apis/gaia/gaia_auth_fetcher.h"
13 #include "google_apis/gaia/gaia_constants.h"
14 #include "google_apis/gaia/gaia_urls.h"
15 #include "google_apis/gaia/google_service_auth_error.h"
16 #include "net/cookies/cookie_monster.h"
17 #include "net/url_request/url_request_context.h"
18 #include "url/gurl.h"
19
20 namespace chromeos {
21
22 namespace {
23
24 scoped_refptr<net::CookieStore> GetCookieStoreOnIO(
25 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
27 return url_request_context_getter->GetURLRequestContext()->cookie_store();
28 }
29
30 } // namespace
31
32 AuthenticatedUserEmailRetriever::AuthenticatedUserEmailRetriever(
33 const AuthenticatedUserEmailCallback& callback,
34 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
35 : callback_(callback),
36 url_request_context_getter_(url_request_context_getter),
37 weak_factory_(this) {
38 content::BrowserThread::PostTaskAndReplyWithResult(
39 content::BrowserThread::IO,
40 FROM_HERE,
41 base::Bind(&GetCookieStoreOnIO, url_request_context_getter),
42 base::Bind(&AuthenticatedUserEmailRetriever::ExtractCookies,
43 weak_factory_.GetWeakPtr()));
44 }
45
46 AuthenticatedUserEmailRetriever::~AuthenticatedUserEmailRetriever() {
47 }
48
49 void AuthenticatedUserEmailRetriever::OnGetUserInfoSuccess(
50 const UserInfoMap& data) {
51 UserInfoMap::const_iterator it = data.find("email");
52 callback_.Run(it != data.end() ? it->second : "");
53 }
54
55 void AuthenticatedUserEmailRetriever::OnGetUserInfoFailure(
56 const GoogleServiceAuthError& error) {
57 callback_.Run(std::string());
58 }
59
60 void AuthenticatedUserEmailRetriever::ExtractCookies(
61 scoped_refptr<net::CookieStore> cookie_store) {
62 if (!cookie_store) {
63 callback_.Run(std::string());
64 return;
65 }
66 cookie_store->GetCookieMonster()->GetAllCookiesForURLAsync(
67 GaiaUrls::GetInstance()->gaia_url(),
68 base::Bind(&AuthenticatedUserEmailRetriever::ExtractLSIDFromCookies,
69 weak_factory_.GetWeakPtr()));
70 }
71
72 void AuthenticatedUserEmailRetriever::ExtractLSIDFromCookies(
73 const net::CookieList& cookies) {
74 for (net::CookieList::const_iterator it = cookies.begin();
75 it != cookies.end(); ++it) {
76 if (it->Name() == "LSID") {
77 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(
78 this,
79 GaiaConstants::kChromeSource,
80 url_request_context_getter_));
81 gaia_auth_fetcher_->StartGetUserInfo(it->Value());
82 return;
83 }
84 }
85 callback_.Run(std::string());
86 }
87
88 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698