1 // Copyright (c) 2012 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 "components/policy/core/common/cloud/user_info_fetcher.h"
7 #include "base/json/json_reader.h"
8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/values.h"
11 #include "google_apis/gaia/gaia_urls.h"
12 #include "google_apis/gaia/google_service_auth_error.h"
13 #include "net/base/load_flags.h"
14 #include "net/http/http_status_code.h"
15 #include "net/url_request/url_fetcher.h"
16 #include "net/url_request/url_request_status.h"
21 UserInfoFetcher::UserInfoFetcher(Delegate* delegate,
22 net::URLRequestContextGetter* context)
23 : delegate_(delegate), gaia_client_(context) {
27 UserInfoFetcher::~UserInfoFetcher() {
30 void UserInfoFetcher::Start(const std::string& access_token) {
31 // Create a URLFetcher and start it.
32 gaia_client_.GetUserInfo(access_token, 0, &delegate_);
35 UserInfoFetcher::GaiaDelegate::GaiaDelegate(UserInfoFetcher::Delegate* delegate)
36 : delegate_(delegate) {
39 void UserInfoFetcher::GaiaDelegate::OnGetUserInfoResponse(
40 scoped_ptr<base::DictionaryValue> user_info) {
41 delegate_->OnGetUserInfoSuccess(user_info.get());
44 void UserInfoFetcher::GaiaDelegate::OnOAuthError() {
45 GoogleServiceAuthError error =
46 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
47 delegate_->OnGetUserInfoFailure(error);
50 void UserInfoFetcher::GaiaDelegate::OnNetworkError(int response_code) {
51 GoogleServiceAuthError error =
52 GoogleServiceAuthError::FromConnectionError(response_code);
53 delegate_->OnGetUserInfoFailure(error);
56 }; // namespace policy