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.
5 #include "chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retriever.h"
9 #include "google_apis/gaia/gaia_auth_util.h"
10 #include "google_apis/gaia/gaia_constants.h"
11 #include "google_apis/gaia/google_service_auth_error.h"
12 #include "net/url_request/url_request_context_getter.h"
16 AuthenticatedUserEmailRetriever::AuthenticatedUserEmailRetriever(
17 const AuthenticatedUserEmailCallback
& callback
,
18 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter
)
19 : callback_(callback
),
20 gaia_auth_fetcher_(this,
21 GaiaConstants::kChromeSource
,
22 url_request_context_getter
) {
23 gaia_auth_fetcher_
.StartListAccounts();
26 AuthenticatedUserEmailRetriever::~AuthenticatedUserEmailRetriever() {
29 void AuthenticatedUserEmailRetriever::OnListAccountsSuccess(
30 const std::string
& data
) {
31 std::vector
<std::string
> accounts
= gaia::ParseListAccountsData(data
);
32 if (accounts
.size() != 1)
33 callback_
.Run(std::string());
35 callback_
.Run(accounts
.front());
38 void AuthenticatedUserEmailRetriever::OnListAccountsFailure(
39 const GoogleServiceAuthError
& error
) {
40 callback_
.Run(std::string());
43 } // namespace chromeos