| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/policy/core/common/cloud/user_info_fetcher.h" | 5 #include "components/policy/core/common/cloud/user_info_fetcher.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "components/data_use_measurement/core/data_use_user_data.h" | |
| 12 #include "google_apis/gaia/gaia_urls.h" | 11 #include "google_apis/gaia/gaia_urls.h" |
| 13 #include "google_apis/gaia/google_service_auth_error.h" | 12 #include "google_apis/gaia/google_service_auth_error.h" |
| 14 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 15 #include "net/http/http_status_code.h" | 14 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 17 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 38 } | 37 } |
| 39 | 38 |
| 40 UserInfoFetcher::~UserInfoFetcher() { | 39 UserInfoFetcher::~UserInfoFetcher() { |
| 41 } | 40 } |
| 42 | 41 |
| 43 void UserInfoFetcher::Start(const std::string& access_token) { | 42 void UserInfoFetcher::Start(const std::string& access_token) { |
| 44 // Create a URLFetcher and start it. | 43 // Create a URLFetcher and start it. |
| 45 url_fetcher_ = | 44 url_fetcher_ = |
| 46 net::URLFetcher::Create(0, GaiaUrls::GetInstance()->oauth_user_info_url(), | 45 net::URLFetcher::Create(0, GaiaUrls::GetInstance()->oauth_user_info_url(), |
| 47 net::URLFetcher::GET, this); | 46 net::URLFetcher::GET, this); |
| 48 data_use_measurement::DataUseUserData::AttachToFetcher( | |
| 49 url_fetcher_.get(), data_use_measurement::DataUseUserData::POLICY); | |
| 50 url_fetcher_->SetRequestContext(context_); | 47 url_fetcher_->SetRequestContext(context_); |
| 51 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 48 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 52 net::LOAD_DO_NOT_SAVE_COOKIES); | 49 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 53 url_fetcher_->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); | 50 url_fetcher_->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); |
| 54 url_fetcher_->Start(); // Results in a call to OnURLFetchComplete(). | 51 url_fetcher_->Start(); // Results in a call to OnURLFetchComplete(). |
| 55 } | 52 } |
| 56 | 53 |
| 57 void UserInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 54 void UserInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 58 net::URLRequestStatus status = source->GetStatus(); | 55 net::URLRequestStatus status = source->GetStatus(); |
| 59 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); | 56 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 83 if (parsed_value.get() && parsed_value->GetAsDictionary(&dict)) { | 80 if (parsed_value.get() && parsed_value->GetAsDictionary(&dict)) { |
| 84 delegate_->OnGetUserInfoSuccess(dict); | 81 delegate_->OnGetUserInfoSuccess(dict); |
| 85 } else { | 82 } else { |
| 86 NOTREACHED() << "Could not parse userinfo response from server"; | 83 NOTREACHED() << "Could not parse userinfo response from server"; |
| 87 delegate_->OnGetUserInfoFailure(GoogleServiceAuthError( | 84 delegate_->OnGetUserInfoFailure(GoogleServiceAuthError( |
| 88 GoogleServiceAuthError::CONNECTION_FAILED)); | 85 GoogleServiceAuthError::CONNECTION_FAILED)); |
| 89 } | 86 } |
| 90 } | 87 } |
| 91 | 88 |
| 92 }; // namespace policy | 89 }; // namespace policy |
| OLD | NEW |