OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/domain_reliability/monitor.h" | 5 #include "components/domain_reliability/monitor.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
23 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
26 | 26 |
27 namespace domain_reliability { | 27 namespace domain_reliability { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 int URLRequestStatusToNetError(const net::URLRequestStatus& status) { | |
32 switch (status.status()) { | |
33 case net::URLRequestStatus::SUCCESS: | |
34 return net::OK; | |
35 case net::URLRequestStatus::IO_PENDING: | |
36 return net::ERR_IO_PENDING; | |
37 case net::URLRequestStatus::CANCELED: | |
38 return net::ERR_ABORTED; | |
39 case net::URLRequestStatus::FAILED: | |
40 return status.error(); | |
41 default: | |
42 NOTREACHED(); | |
43 return net::ERR_UNEXPECTED; | |
44 } | |
45 } | |
46 | |
47 // Creates a new beacon based on |beacon_template| but fills in the status, | 31 // Creates a new beacon based on |beacon_template| but fills in the status, |
48 // chrome_error, and server_ip fields based on the endpoint and result of | 32 // chrome_error, and server_ip fields based on the endpoint and result of |
49 // |attempt|. | 33 // |attempt|. |
50 // | 34 // |
51 // If there is no matching status for the result, returns false (which | 35 // If there is no matching status for the result, returns false (which |
52 // means the attempt should not result in a beacon being reported). | 36 // means the attempt should not result in a beacon being reported). |
53 std::unique_ptr<DomainReliabilityBeacon> CreateBeaconFromAttempt( | 37 std::unique_ptr<DomainReliabilityBeacon> CreateBeaconFromAttempt( |
54 const DomainReliabilityBeacon& beacon_template, | 38 const DomainReliabilityBeacon& beacon_template, |
55 const net::ConnectionAttempt& attempt) { | 39 const net::ConnectionAttempt& attempt) { |
56 std::string status; | 40 std::string status; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 163 |
180 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) { | 164 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) { |
181 DCHECK(OnNetworkThread()); | 165 DCHECK(OnNetworkThread()); |
182 DCHECK(moved_to_network_thread_); | 166 DCHECK(moved_to_network_thread_); |
183 DCHECK(uploader_); | 167 DCHECK(uploader_); |
184 | 168 |
185 uploader_->set_discard_uploads(discard_uploads); | 169 uploader_->set_discard_uploads(discard_uploads); |
186 discard_uploads_set_ = true; | 170 discard_uploads_set_ = true; |
187 } | 171 } |
188 | 172 |
173 // TODO(maksims): Make this take net_error. | |
davidben
2016/09/06 17:07:28
It does not appear this CL does not actually do an
maksims (do not use this acc)
2016/09/12 12:11:54
Thank you for your feedback. I'll leave this for s
| |
189 void DomainReliabilityMonitor::OnBeforeRedirect(net::URLRequest* request) { | 174 void DomainReliabilityMonitor::OnBeforeRedirect(net::URLRequest* request) { |
190 DCHECK(OnNetworkThread()); | 175 DCHECK(OnNetworkThread()); |
191 DCHECK(discard_uploads_set_); | 176 DCHECK(discard_uploads_set_); |
192 | 177 |
193 // Record the redirect itself in addition to the final request. | 178 // Record the redirect itself in addition to the final request. |
194 OnRequestLegComplete(RequestInfo(*request)); | 179 OnRequestLegComplete(RequestInfo(*request, request->status().error())); |
195 } | 180 } |
196 | 181 |
182 // TODO(maksims): Make this take net_error. | |
197 void DomainReliabilityMonitor::OnCompleted(net::URLRequest* request, | 183 void DomainReliabilityMonitor::OnCompleted(net::URLRequest* request, |
198 bool started) { | 184 bool started) { |
199 DCHECK(OnNetworkThread()); | 185 DCHECK(OnNetworkThread()); |
200 DCHECK(discard_uploads_set_); | 186 DCHECK(discard_uploads_set_); |
201 | 187 |
202 if (!started) | 188 if (!started) |
203 return; | 189 return; |
204 RequestInfo request_info(*request); | 190 RequestInfo request_info(*request, request->status().error()); |
205 OnRequestLegComplete(request_info); | 191 OnRequestLegComplete(request_info); |
206 | 192 |
207 if (request_info.response_info.network_accessed) { | 193 if (request_info.response_info.network_accessed) { |
208 // A request was just using the network, so now is a good time to run any | 194 // A request was just using the network, so now is a good time to run any |
209 // pending and eligible uploads. | 195 // pending and eligible uploads. |
210 dispatcher_.RunEligibleTasks(); | 196 dispatcher_.RunEligibleTasks(); |
211 } | 197 } |
212 } | 198 } |
213 | 199 |
214 void DomainReliabilityMonitor::OnNetworkChanged( | 200 void DomainReliabilityMonitor::OnNetworkChanged( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 | 244 |
259 return base::MakeUnique<DomainReliabilityContext>( | 245 return base::MakeUnique<DomainReliabilityContext>( |
260 time_.get(), scheduler_params_, upload_reporter_string_, | 246 time_.get(), scheduler_params_, upload_reporter_string_, |
261 &last_network_change_time_, &dispatcher_, uploader_.get(), | 247 &last_network_change_time_, &dispatcher_, uploader_.get(), |
262 std::move(config)); | 248 std::move(config)); |
263 } | 249 } |
264 | 250 |
265 DomainReliabilityMonitor::RequestInfo::RequestInfo() {} | 251 DomainReliabilityMonitor::RequestInfo::RequestInfo() {} |
266 | 252 |
267 DomainReliabilityMonitor::RequestInfo::RequestInfo( | 253 DomainReliabilityMonitor::RequestInfo::RequestInfo( |
268 const net::URLRequest& request) | 254 const net::URLRequest& request, |
255 int error) | |
269 : url(request.url()), | 256 : url(request.url()), |
270 status(request.status()), | 257 net_error(error), |
271 response_info(request.response_info()), | 258 response_info(request.response_info()), |
272 load_flags(request.load_flags()), | 259 load_flags(request.load_flags()), |
273 upload_depth( | 260 upload_depth( |
274 DomainReliabilityUploader::GetURLRequestUploadDepth(request)) { | 261 DomainReliabilityUploader::GetURLRequestUploadDepth(request)) { |
275 request.GetLoadTimingInfo(&load_timing_info); | 262 request.GetLoadTimingInfo(&load_timing_info); |
276 request.GetConnectionAttempts(&connection_attempts); | 263 request.GetConnectionAttempts(&connection_attempts); |
277 request.PopulateNetErrorDetails(&details); | 264 request.PopulateNetErrorDetails(&details); |
278 if (!request.GetRemoteEndpoint(&remote_endpoint)) | 265 if (!request.GetRemoteEndpoint(&remote_endpoint)) |
279 remote_endpoint = net::IPEndPoint(); | 266 remote_endpoint = net::IPEndPoint(); |
280 } | 267 } |
281 | 268 |
282 DomainReliabilityMonitor::RequestInfo::RequestInfo(const RequestInfo& other) = | 269 DomainReliabilityMonitor::RequestInfo::RequestInfo(const RequestInfo& other) = |
283 default; | 270 default; |
284 | 271 |
285 DomainReliabilityMonitor::RequestInfo::~RequestInfo() {} | 272 DomainReliabilityMonitor::RequestInfo::~RequestInfo() {} |
286 | 273 |
287 // static | 274 // static |
288 bool DomainReliabilityMonitor::RequestInfo::ShouldReportRequest( | 275 bool DomainReliabilityMonitor::RequestInfo::ShouldReportRequest( |
289 const DomainReliabilityMonitor::RequestInfo& request) { | 276 const DomainReliabilityMonitor::RequestInfo& request) { |
290 // Don't report requests that weren't supposed to send cookies. | 277 // Don't report requests that weren't supposed to send cookies. |
291 if (request.load_flags & net::LOAD_DO_NOT_SEND_COOKIES) | 278 if (request.load_flags & net::LOAD_DO_NOT_SEND_COOKIES) |
292 return false; | 279 return false; |
293 | 280 |
294 // Report requests that accessed the network or failed with an error code | 281 // Report requests that accessed the network or failed with an error code |
295 // that Domain Reliability is interested in. | 282 // that Domain Reliability is interested in. |
296 if (request.response_info.network_accessed) | 283 if (request.response_info.network_accessed) |
297 return true; | 284 return true; |
298 if (URLRequestStatusToNetError(request.status) != net::OK) | 285 if (request.net_error != net::OK) |
299 return true; | 286 return true; |
300 if (request.details.quic_port_migration_detected) | 287 if (request.details.quic_port_migration_detected) |
301 return true; | 288 return true; |
302 | 289 |
303 return false; | 290 return false; |
304 } | 291 } |
305 | 292 |
306 void DomainReliabilityMonitor::OnRequestLegComplete( | 293 void DomainReliabilityMonitor::OnRequestLegComplete( |
307 const RequestInfo& request) { | 294 const RequestInfo& request) { |
308 // Check these again because unit tests call this directly. | 295 // Check these again because unit tests call this directly. |
309 DCHECK(OnNetworkThread()); | 296 DCHECK(OnNetworkThread()); |
310 DCHECK(discard_uploads_set_); | 297 DCHECK(discard_uploads_set_); |
311 | 298 |
312 MaybeHandleHeader(request); | 299 MaybeHandleHeader(request); |
313 | 300 |
314 if (!RequestInfo::ShouldReportRequest(request)) | 301 if (!RequestInfo::ShouldReportRequest(request)) |
315 return; | 302 return; |
316 | 303 |
317 int response_code; | 304 int response_code; |
318 if (request.response_info.headers.get()) | 305 if (request.response_info.headers.get()) |
319 response_code = request.response_info.headers->response_code(); | 306 response_code = request.response_info.headers->response_code(); |
320 else | 307 else |
321 response_code = -1; | 308 response_code = -1; |
322 | 309 |
323 net::ConnectionAttempt url_request_attempt( | 310 net::ConnectionAttempt url_request_attempt(request.remote_endpoint, |
324 request.remote_endpoint, URLRequestStatusToNetError(request.status)); | 311 request.net_error); |
325 | 312 |
326 DomainReliabilityBeacon beacon_template; | 313 DomainReliabilityBeacon beacon_template; |
327 if (request.response_info.connection_info != | 314 if (request.response_info.connection_info != |
328 net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN) { | 315 net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN) { |
329 beacon_template.protocol = | 316 beacon_template.protocol = |
330 GetDomainReliabilityProtocol(request.response_info.connection_info, | 317 GetDomainReliabilityProtocol(request.response_info.connection_info, |
331 request.response_info.ssl_info.is_valid()); | 318 request.response_info.ssl_info.is_valid()); |
332 } else { | 319 } else { |
333 // Use the connection info from the network error details if the response | 320 // Use the connection info from the network error details if the response |
334 // is unavailable. | 321 // is unavailable. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 break; | 402 break; |
416 } | 403 } |
417 } | 404 } |
418 | 405 |
419 base::WeakPtr<DomainReliabilityMonitor> | 406 base::WeakPtr<DomainReliabilityMonitor> |
420 DomainReliabilityMonitor::MakeWeakPtr() { | 407 DomainReliabilityMonitor::MakeWeakPtr() { |
421 return weak_factory_.GetWeakPtr(); | 408 return weak_factory_.GetWeakPtr(); |
422 } | 409 } |
423 | 410 |
424 } // namespace domain_reliability | 411 } // namespace domain_reliability |
OLD | NEW |