Chromium Code Reviews| 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" | 11 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 12 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/gaia/gaia_urls.h" |
| 13 #include "google_apis/gaia/google_service_auth_error.h" | 13 #include "google_apis/gaia/google_service_auth_error.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 16 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 17 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 static const char kAuthorizationHeaderFormat[] = | 23 static const char kAuthorizationHeaderFormat[] = |
| 23 "Authorization: Bearer %s"; | 24 "Authorization: Bearer %s"; |
| 24 | 25 |
| 25 static std::string MakeAuthorizationHeader(const std::string& auth_token) { | 26 static std::string MakeAuthorizationHeader(const std::string& auth_token) { |
| 26 return base::StringPrintf(kAuthorizationHeaderFormat, auth_token.c_str()); | 27 return base::StringPrintf(kAuthorizationHeaderFormat, auth_token.c_str()); |
| 27 } | 28 } |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 namespace policy { | 32 namespace policy { |
| 32 | 33 |
| 33 UserInfoFetcher::UserInfoFetcher(Delegate* delegate, | 34 UserInfoFetcher::UserInfoFetcher(Delegate* delegate, |
| 34 net::URLRequestContextGetter* context) | 35 net::URLRequestContextGetter* context) |
| 35 : delegate_(delegate), | 36 : delegate_(delegate), |
| 36 context_(context) { | 37 context_(context) { |
| 37 DCHECK(delegate); | 38 DCHECK(delegate); |
| 38 } | 39 } |
| 39 | 40 |
| 40 UserInfoFetcher::~UserInfoFetcher() { | 41 UserInfoFetcher::~UserInfoFetcher() { |
| 41 } | 42 } |
| 42 | 43 |
| 43 void UserInfoFetcher::Start(const std::string& access_token) { | 44 void UserInfoFetcher::Start(const std::string& access_token) { |
| 45 net::NetworkTrafficAnnotationTag traffic_annotation = | |
| 46 net::DefineNetworkTrafficAnnotation("user_info_fetcher", R"( | |
| 47 semantics { | |
| 48 sender: "Cloud Policy" | |
| 49 description: | |
| 50 "Calls to the Google Account service to check if the signed-in " | |
| 51 "user is managed." | |
| 52 trigger: "User signing in to Chrome." | |
| 53 data: | |
| 54 "Information about the user (specifically whether they are " | |
| 55 "managed, along with basic profile information from their Google " | |
|
Andrew T Wilson (Slow)
2017/04/27 12:15:31
Sorry, this is incorrect. The information we send
Ramin Halavati
2017/04/27 12:25:36
Thank you, Done.
| |
| 56 "Account)." | |
| 57 destination: GOOGLE_OWNED_SERVICE | |
| 58 } | |
| 59 policy { | |
| 60 cookies_allowed: false | |
| 61 setting: | |
| 62 "This feature cannot be controlled by Chrome settings, but users " | |
| 63 "can sign out of Chrome to disable it." | |
| 64 chrome_policy { | |
| 65 SigninAllowed { | |
| 66 policy_options {mode: MANDATORY} | |
| 67 SigninAllowed: false | |
| 68 } | |
| 69 } | |
| 70 })"); | |
| 44 // Create a URLFetcher and start it. | 71 // Create a URLFetcher and start it. |
| 45 url_fetcher_ = | 72 url_fetcher_ = |
| 46 net::URLFetcher::Create(0, GaiaUrls::GetInstance()->oauth_user_info_url(), | 73 net::URLFetcher::Create(0, GaiaUrls::GetInstance()->oauth_user_info_url(), |
| 47 net::URLFetcher::GET, this); | 74 net::URLFetcher::GET, this, traffic_annotation); |
| 48 data_use_measurement::DataUseUserData::AttachToFetcher( | 75 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 49 url_fetcher_.get(), data_use_measurement::DataUseUserData::POLICY); | 76 url_fetcher_.get(), data_use_measurement::DataUseUserData::POLICY); |
| 50 url_fetcher_->SetRequestContext(context_); | 77 url_fetcher_->SetRequestContext(context_); |
| 51 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 78 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 52 net::LOAD_DO_NOT_SAVE_COOKIES); | 79 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 53 url_fetcher_->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); | 80 url_fetcher_->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); |
| 54 url_fetcher_->Start(); // Results in a call to OnURLFetchComplete(). | 81 url_fetcher_->Start(); // Results in a call to OnURLFetchComplete(). |
| 55 } | 82 } |
| 56 | 83 |
| 57 void UserInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 84 void UserInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 84 if (parsed_value.get() && parsed_value->GetAsDictionary(&dict)) { | 111 if (parsed_value.get() && parsed_value->GetAsDictionary(&dict)) { |
| 85 delegate_->OnGetUserInfoSuccess(dict); | 112 delegate_->OnGetUserInfoSuccess(dict); |
| 86 } else { | 113 } else { |
| 87 NOTREACHED() << "Could not parse userinfo response from server"; | 114 NOTREACHED() << "Could not parse userinfo response from server"; |
| 88 delegate_->OnGetUserInfoFailure(GoogleServiceAuthError( | 115 delegate_->OnGetUserInfoFailure(GoogleServiceAuthError( |
| 89 GoogleServiceAuthError::CONNECTION_FAILED)); | 116 GoogleServiceAuthError::CONNECTION_FAILED)); |
| 90 } | 117 } |
| 91 } | 118 } |
| 92 | 119 |
| 93 }; // namespace policy | 120 }; // namespace policy |
| OLD | NEW |