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: "OAuth2 token." |
| 54 destination: GOOGLE_OWNED_SERVICE |
| 55 } |
| 56 policy { |
| 57 cookies_allowed: false |
| 58 setting: |
| 59 "This feature cannot be controlled by Chrome settings, but users " |
| 60 "can sign out of Chrome to disable it." |
| 61 chrome_policy { |
| 62 SigninAllowed { |
| 63 policy_options {mode: MANDATORY} |
| 64 SigninAllowed: false |
| 65 } |
| 66 } |
| 67 })"); |
44 // Create a URLFetcher and start it. | 68 // Create a URLFetcher and start it. |
45 url_fetcher_ = | 69 url_fetcher_ = |
46 net::URLFetcher::Create(0, GaiaUrls::GetInstance()->oauth_user_info_url(), | 70 net::URLFetcher::Create(0, GaiaUrls::GetInstance()->oauth_user_info_url(), |
47 net::URLFetcher::GET, this); | 71 net::URLFetcher::GET, this, traffic_annotation); |
48 data_use_measurement::DataUseUserData::AttachToFetcher( | 72 data_use_measurement::DataUseUserData::AttachToFetcher( |
49 url_fetcher_.get(), data_use_measurement::DataUseUserData::POLICY); | 73 url_fetcher_.get(), data_use_measurement::DataUseUserData::POLICY); |
50 url_fetcher_->SetRequestContext(context_); | 74 url_fetcher_->SetRequestContext(context_); |
51 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 75 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
52 net::LOAD_DO_NOT_SAVE_COOKIES); | 76 net::LOAD_DO_NOT_SAVE_COOKIES); |
53 url_fetcher_->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); | 77 url_fetcher_->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); |
54 url_fetcher_->Start(); // Results in a call to OnURLFetchComplete(). | 78 url_fetcher_->Start(); // Results in a call to OnURLFetchComplete(). |
55 } | 79 } |
56 | 80 |
57 void UserInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 81 void UserInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
(...skipping 26 matching lines...) Expand all Loading... |
84 if (parsed_value.get() && parsed_value->GetAsDictionary(&dict)) { | 108 if (parsed_value.get() && parsed_value->GetAsDictionary(&dict)) { |
85 delegate_->OnGetUserInfoSuccess(dict); | 109 delegate_->OnGetUserInfoSuccess(dict); |
86 } else { | 110 } else { |
87 NOTREACHED() << "Could not parse userinfo response from server"; | 111 NOTREACHED() << "Could not parse userinfo response from server"; |
88 delegate_->OnGetUserInfoFailure(GoogleServiceAuthError( | 112 delegate_->OnGetUserInfoFailure(GoogleServiceAuthError( |
89 GoogleServiceAuthError::CONNECTION_FAILED)); | 113 GoogleServiceAuthError::CONNECTION_FAILED)); |
90 } | 114 } |
91 } | 115 } |
92 | 116 |
93 }; // namespace policy | 117 }; // namespace policy |
OLD | NEW |