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("...", R"( |
Bernhard Bauer
2017/03/14 10:02:49
safe_search_url_reporter
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
114 semantics { | |
115 sender: "..." | |
Bernhard Bauer
2017/03/14 10:02:49
supervised_users
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
116 description: "..." | |
Bernhard Bauer
2017/03/14 10:02:49
Reports a URL wrongfully flagged by SafeSearch.
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
117 trigger: "..." | |
Bernhard Bauer
2017/03/14 10:02:49
Initiated by the user.
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
118 data: "..." | |
Bernhard Bauer
2017/03/14 10:02:49
The request is authenticated with an OAuth2 access
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
119 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
Bernhard Bauer
2017/03/14 10:02:50
GOOGLE_OWNED_SERVICE
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
120 } | |
121 policy { | |
122 cookies_allowed: false/true | |
Bernhard Bauer
2017/03/14 10:02:49
false
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
123 cookies_store: "..." | |
Bernhard Bauer
2017/03/14 10:02:49
user
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
124 setting: "..." | |
Bernhard Bauer
2017/03/14 10:02:50
This feature is only enabled for child accounts. I
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
125 chrome_policy { | |
126 [POLICY_NAME] { | |
Bernhard Bauer
2017/03/14 10:02:50
RestrictSigninToPattern
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
127 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
Bernhard Bauer
2017/03/14 10:02:49
MANDATORY
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
128 [POLICY_NAME]: ... //(value to disable it) | |
Bernhard Bauer
2017/03/14 10:02:50
"*@manageddomain.com"
Ramin Halavati
2017/03/14 10:56:20
Done.
| |
129 } | |
130 } | |
131 policy_exception_justification: "..." | |
132 })"); | |
133 (*it)->url_fetcher = | |
134 URLFetcher::Create((*it)->url_fetcher_id, GURL(kApiUrl), URLFetcher::POST, | |
135 this, traffic_annotation); | |
113 | 136 |
114 data_use_measurement::DataUseUserData::AttachToFetcher( | 137 data_use_measurement::DataUseUserData::AttachToFetcher( |
115 (*it)->url_fetcher.get(), | 138 (*it)->url_fetcher.get(), |
116 data_use_measurement::DataUseUserData::SUPERVISED_USER); | 139 data_use_measurement::DataUseUserData::SUPERVISED_USER); |
117 (*it)->url_fetcher->SetRequestContext(context_); | 140 (*it)->url_fetcher->SetRequestContext(context_); |
118 (*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 141 (*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
119 net::LOAD_DO_NOT_SAVE_COOKIES); | 142 net::LOAD_DO_NOT_SAVE_COOKIES); |
120 (*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); | 143 (*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); |
121 (*it)->url_fetcher->AddExtraRequestHeader( | 144 (*it)->url_fetcher->AddExtraRequestHeader( |
122 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); | 145 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 return; | 201 return; |
179 } | 202 } |
180 | 203 |
181 DispatchResult(it, true); | 204 DispatchResult(it, true); |
182 } | 205 } |
183 | 206 |
184 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) { | 207 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) { |
185 (*it)->callback.Run(success); | 208 (*it)->callback.Run(success); |
186 reports_.erase(it); | 209 reports_.erase(it); |
187 } | 210 } |
OLD | NEW |