OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h
" | 5 #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h
" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
13 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
14 #include "components/data_use_measurement/core/data_use_user_data.h" | 14 #include "components/data_use_measurement/core/data_use_user_data.h" |
15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
16 #include "components/signin/core/browser/signin_manager.h" | 16 #include "components/signin/core/browser/signin_manager.h" |
17 #include "components/signin/core/browser/signin_manager_base.h" | 17 #include "components/signin/core/browser/signin_manager_base.h" |
18 #include "google_apis/gaia/google_service_auth_error.h" | 18 #include "google_apis/gaia/google_service_auth_error.h" |
19 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/http/http_status_code.h" | 21 #include "net/http/http_status_code.h" |
| 22 #include "net/traffic_annotation/network_traffic_annotation.h" |
22 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
23 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 using net::URLFetcher; | 27 using net::URLFetcher; |
27 | 28 |
28 const char kApiUrl[] = "https://safesearch.googleapis.com/v1:report"; | 29 const char kApiUrl[] = "https://safesearch.googleapis.com/v1:report"; |
29 const char kApiScope[] = "https://www.googleapis.com/auth/safesearch.reporting"; | 30 const char kApiScope[] = "https://www.googleapis.com/auth/safesearch.reporting"; |
30 | 31 |
31 const int kNumRetries = 1; | 32 const int kNumRetries = 1; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 ReportIterator it = reports_.begin(); | 102 ReportIterator it = reports_.begin(); |
102 while (it != reports_.end()) { | 103 while (it != reports_.end()) { |
103 if (request == (*it)->access_token_request.get()) | 104 if (request == (*it)->access_token_request.get()) |
104 break; | 105 break; |
105 it++; | 106 it++; |
106 } | 107 } |
107 DCHECK(it != reports_.end()); | 108 DCHECK(it != reports_.end()); |
108 | 109 |
109 (*it)->access_token = access_token; | 110 (*it)->access_token = access_token; |
110 | 111 |
111 (*it)->url_fetcher = URLFetcher::Create((*it)->url_fetcher_id, GURL(kApiUrl), | 112 net::NetworkTrafficAnnotationTag traffic_annotation = |
112 URLFetcher::POST, this); | 113 net::DefineNetworkTrafficAnnotation("safe_search_url_reporter", R"( |
| 114 semantics { |
| 115 sender: "Supervised Users" |
| 116 description: "Reports a URL wrongfully flagged by SafeSearch." |
| 117 trigger: "Initiated by the user." |
| 118 data: |
| 119 "The request is authenticated with an OAuth2 access token " |
| 120 "identifying the Google account and contains the URL that was " |
| 121 "wrongfully flagged." |
| 122 destination: GOOGLE_OWNED_SERVICE |
| 123 } |
| 124 policy { |
| 125 cookies_allowed: false |
| 126 setting: |
| 127 "This feature cannot be disabled by settings and is only enabled " |
| 128 "for child accounts. If sign-in is restricted to accounts from a " |
| 129 "managed domain, those accounts are not going to be child accounts." |
| 130 chrome_policy { |
| 131 RestrictSigninToPattern { |
| 132 policy_options {mode: MANDATORY} |
| 133 RestrictSigninToPattern: "*@manageddomain.com" |
| 134 } |
| 135 } |
| 136 })"); |
| 137 (*it)->url_fetcher = |
| 138 URLFetcher::Create((*it)->url_fetcher_id, GURL(kApiUrl), URLFetcher::POST, |
| 139 this, traffic_annotation); |
113 | 140 |
114 data_use_measurement::DataUseUserData::AttachToFetcher( | 141 data_use_measurement::DataUseUserData::AttachToFetcher( |
115 (*it)->url_fetcher.get(), | 142 (*it)->url_fetcher.get(), |
116 data_use_measurement::DataUseUserData::SUPERVISED_USER); | 143 data_use_measurement::DataUseUserData::SUPERVISED_USER); |
117 (*it)->url_fetcher->SetRequestContext(context_); | 144 (*it)->url_fetcher->SetRequestContext(context_); |
118 (*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 145 (*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
119 net::LOAD_DO_NOT_SAVE_COOKIES); | 146 net::LOAD_DO_NOT_SAVE_COOKIES); |
120 (*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); | 147 (*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); |
121 (*it)->url_fetcher->AddExtraRequestHeader( | 148 (*it)->url_fetcher->AddExtraRequestHeader( |
122 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); | 149 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 return; | 205 return; |
179 } | 206 } |
180 | 207 |
181 DispatchResult(it, true); | 208 DispatchResult(it, true); |
182 } | 209 } |
183 | 210 |
184 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) { | 211 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) { |
185 (*it)->callback.Run(success); | 212 (*it)->callback.Run(success); |
186 reports_.erase(it); | 213 reports_.erase(it); |
187 } | 214 } |
OLD | NEW |