OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRIEVE
R_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRIEVE
R_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRIEVE
R_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRIEVE
R_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback_forward.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | |
15 #include "google_apis/gaia/gaia_auth_consumer.h" | 14 #include "google_apis/gaia/gaia_auth_consumer.h" |
16 #include "net/cookies/canonical_cookie.h" | 15 #include "google_apis/gaia/gaia_auth_fetcher.h" |
17 #include "net/cookies/cookie_store.h" | |
18 #include "net/url_request/url_request_context_getter.h" | |
19 | 16 |
20 class GaiaAuthFetcher; | 17 class GaiaAuthFetcher; |
21 | 18 |
| 19 namespace net { |
| 20 class URLRequestContextGetter; |
| 21 } |
| 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 | 24 |
24 // Helper class that retrieves the authenticated user's e-mail address. | 25 // Helper class that retrieves the authenticated user's e-mail address. |
25 class AuthenticatedUserEmailRetriever : public GaiaAuthConsumer { | 26 class AuthenticatedUserEmailRetriever : public GaiaAuthConsumer { |
26 public: | 27 public: |
27 typedef base::Callback<void(const std::string&)> | 28 typedef base::Callback<void(const std::string&)> |
28 AuthenticatedUserEmailCallback; | 29 AuthenticatedUserEmailCallback; |
29 | 30 |
30 // Extracts the GAIA cookies from |url_request_context_getter|, retrieves the | 31 // Retrieves the authenticated user's e-mail address from GAIA and passes it |
31 // authenticated user's e-mail address from GAIA and passes it to |callback|. | 32 // to |callback|. Requires that |url_request_context_getter| contain the GAIA |
32 // If the e-mail address cannot be retrieved, an empty string is passed to | 33 // cookies for exactly one user. If the e-mail address cannot be retrieved, an |
33 // the |callback|. | 34 // empty string is passed to the |callback|. |
34 AuthenticatedUserEmailRetriever( | 35 AuthenticatedUserEmailRetriever( |
35 const AuthenticatedUserEmailCallback& callback, | 36 const AuthenticatedUserEmailCallback& callback, |
36 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | 37 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); |
37 virtual ~AuthenticatedUserEmailRetriever(); | 38 virtual ~AuthenticatedUserEmailRetriever(); |
38 | 39 |
39 // GaiaAuthConsumer: | 40 // GaiaAuthConsumer: |
40 virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE; | 41 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; |
41 virtual void OnGetUserInfoFailure( | 42 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) |
42 const GoogleServiceAuthError& error) OVERRIDE; | 43 OVERRIDE; |
43 | 44 |
44 private: | 45 private: |
45 void ExtractCookies(scoped_refptr<net::CookieStore> cookie_store); | 46 const AuthenticatedUserEmailCallback callback_; |
46 void ExtractLSIDFromCookies(const net::CookieList& cookies); | 47 GaiaAuthFetcher gaia_auth_fetcher_; |
47 | |
48 AuthenticatedUserEmailCallback callback_; | |
49 | |
50 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
51 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | |
52 | |
53 base::WeakPtrFactory<AuthenticatedUserEmailRetriever> weak_factory_; | |
54 | 48 |
55 DISALLOW_COPY_AND_ASSIGN(AuthenticatedUserEmailRetriever); | 49 DISALLOW_COPY_AND_ASSIGN(AuthenticatedUserEmailRetriever); |
56 }; | 50 }; |
57 | 51 |
58 } // namespace chromeos | 52 } // namespace chromeos |
59 | 53 |
60 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRI
EVER_H_ | 54 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRI
EVER_H_ |
OLD | NEW |