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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRIEVER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRIEVER_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/callback.h" 12 #include "base/compiler_specific.h" 13 #include "base/memory/ref_counted.h" 14 #include "google_apis/gaia/gaia_auth_consumer.h" 15 #include "google_apis/gaia/gaia_auth_fetcher.h" 16 17 class GaiaAuthFetcher; 18 19 namespace net { 20 class URLRequestContextGetter; 21 } 22 23 namespace chromeos { 24 25 // Helper class that retrieves the authenticated user's e-mail address. 26 class AuthenticatedUserEmailRetriever : public GaiaAuthConsumer { 27 public: 28 typedef base::Callback<void(const std::string&)> 29 AuthenticatedUserEmailCallback; 30 31 // Retrieves the authenticated user's e-mail address from GAIA and passes it 32 // to |callback|. Requires that |url_request_context_getter| contain the GAIA 33 // cookies for exactly one user. If the e-mail address cannot be retrieved, an 34 // empty string is passed to the |callback|. 35 AuthenticatedUserEmailRetriever( 36 const AuthenticatedUserEmailCallback& callback, 37 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); 38 virtual ~AuthenticatedUserEmailRetriever(); 39 40 // GaiaAuthConsumer: 41 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; 42 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) 43 OVERRIDE; 44 45 private: 46 const AuthenticatedUserEmailCallback callback_; 47 GaiaAuthFetcher gaia_auth_fetcher_; 48 49 DISALLOW_COPY_AND_ASSIGN(AuthenticatedUserEmailRetriever); 50 }; 51 52 } // namespace chromeos 53 54 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_AUTHENTICATED_USER_EMAIL_RETRIEVER_H_ 55