Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: components/domain_reliability/monitor.cc

Issue 1180223006: Domain Reliability: Simplify configs and reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, make requested changes Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/profiler/scoped_tracker.h" 9 #include "base/profiler/scoped_tracker.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/task_runner.h" 11 #include "base/task_runner.h"
12 #include "components/domain_reliability/baked_in_configs.h" 12 #include "components/domain_reliability/baked_in_configs.h"
13 #include "components/domain_reliability/google_configs.h"
14 #include "net/base/ip_endpoint.h"
13 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
14 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
15 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
16 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
17 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
20 22
21 namespace domain_reliability { 23 namespace domain_reliability {
22 24
(...skipping 11 matching lines...) Expand all
34 return status.error(); 36 return status.error();
35 default: 37 default:
36 NOTREACHED(); 38 NOTREACHED();
37 return net::ERR_UNEXPECTED; 39 return net::ERR_UNEXPECTED;
38 } 40 }
39 } 41 }
40 42
41 // Updates the status, chrome_error, and server_ip fields of |beacon| from 43 // Updates the status, chrome_error, and server_ip fields of |beacon| from
42 // the endpoint and result of |attempt|. If there is no matching status for 44 // the endpoint and result of |attempt|. If there is no matching status for
43 // the result, returns false (which means the attempt should not result in a 45 // the result, returns false (which means the attempt should not result in a
44 // beacon being reported). 46 // beacon being reported).
Randy Smith (Not in Mondays) 2015/10/29 22:36:11 This comment needs to be updated?
Deprecated (see juliatuttle) 2015/11/02 23:19:30 Done.
45 bool UpdateBeaconFromAttempt(DomainReliabilityBeacon* beacon, 47 scoped_ptr<DomainReliabilityBeacon> CreateBeaconFromAttempt(
46 const net::ConnectionAttempt& attempt) { 48 const DomainReliabilityBeacon& beacon_template,
49 const net::ConnectionAttempt& attempt) {
50 std::string status;
47 if (!GetDomainReliabilityBeaconStatus( 51 if (!GetDomainReliabilityBeaconStatus(
48 attempt.result, beacon->http_response_code, &beacon->status)) { 52 attempt.result, beacon_template.http_response_code, &status)) {
49 return false; 53 return scoped_ptr<DomainReliabilityBeacon>();
50 } 54 }
55
56 scoped_ptr<DomainReliabilityBeacon> beacon(
57 new DomainReliabilityBeacon(beacon_template));
58 beacon->status = status;
51 beacon->chrome_error = attempt.result; 59 beacon->chrome_error = attempt.result;
52 if (!attempt.endpoint.address().empty()) 60 if (!attempt.endpoint.address().empty())
53 beacon->server_ip = attempt.endpoint.ToString(); 61 beacon->server_ip = attempt.endpoint.ToString();
54 else 62 else
55 beacon->server_ip = ""; 63 beacon->server_ip = "";
56 return true; 64 return beacon.Pass();
57 } 65 }
58 66
59 } // namespace 67 } // namespace
60 68
61 DomainReliabilityMonitor::DomainReliabilityMonitor( 69 DomainReliabilityMonitor::DomainReliabilityMonitor(
62 const std::string& upload_reporter_string, 70 const std::string& upload_reporter_string,
63 const scoped_refptr<base::SingleThreadTaskRunner>& pref_thread, 71 const scoped_refptr<base::SingleThreadTaskRunner>& pref_thread,
64 const scoped_refptr<base::SingleThreadTaskRunner>& network_thread) 72 const scoped_refptr<base::SingleThreadTaskRunner>& network_thread)
65 : time_(new ActualTime()), 73 : time_(new ActualTime()),
66 upload_reporter_string_(upload_reporter_string), 74 upload_reporter_string_(upload_reporter_string),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 FROM_HERE_WITH_EXPLICIT_FUNCTION( 153 FROM_HERE_WITH_EXPLICIT_FUNCTION(
146 "436671 DomainReliabilityMonitor::AddBakedInConfigs")); 154 "436671 DomainReliabilityMonitor::AddBakedInConfigs"));
147 155
148 DCHECK(OnNetworkThread()); 156 DCHECK(OnNetworkThread());
149 DCHECK(moved_to_network_thread_); 157 DCHECK(moved_to_network_thread_);
150 158
151 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) { 159 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) {
152 base::StringPiece json(kBakedInJsonConfigs[i]); 160 base::StringPiece json(kBakedInJsonConfigs[i]);
153 scoped_ptr<const DomainReliabilityConfig> config = 161 scoped_ptr<const DomainReliabilityConfig> config =
154 DomainReliabilityConfig::FromJSON(json); 162 DomainReliabilityConfig::FromJSON(json);
155 if (!config) 163 if (!config) {
164 LOG(WARNING) << "Baked-in Domain Reliability config failed to parse: "
165 << json;
Randy Smith (Not in Mondays) 2015/10/29 22:36:11 I don't think a log makes sense here--it would be
Deprecated (see juliatuttle) 2015/11/02 23:19:30 Done.
156 continue; 166 continue;
167 }
157 context_manager_.AddContextForConfig(config.Pass()); 168 context_manager_.AddContextForConfig(config.Pass());
158 } 169 }
170
171 std::vector<DomainReliabilityConfig*> google_configs;
172 GetAllGoogleConfigs(&google_configs);
173 for (auto google_config : google_configs)
174 context_manager_.AddContextForConfig(make_scoped_ptr(google_config));
159 } 175 }
160 176
161 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) { 177 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) {
162 DCHECK(OnNetworkThread()); 178 DCHECK(OnNetworkThread());
163 DCHECK(moved_to_network_thread_); 179 DCHECK(moved_to_network_thread_);
164 DCHECK(uploader_); 180 DCHECK(uploader_);
165 181
166 uploader_->set_discard_uploads(discard_uploads); 182 uploader_->set_discard_uploads(discard_uploads);
167 discard_uploads_set_ = true; 183 discard_uploads_set_ = true;
168 } 184 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 307
292 int response_code; 308 int response_code;
293 if (request.response_info.headers.get()) 309 if (request.response_info.headers.get())
294 response_code = request.response_info.headers->response_code(); 310 response_code = request.response_info.headers->response_code();
295 else 311 else
296 response_code = -1; 312 response_code = -1;
297 313
298 net::ConnectionAttempt url_request_attempt( 314 net::ConnectionAttempt url_request_attempt(
299 request.remote_endpoint, URLRequestStatusToNetError(request.status)); 315 request.remote_endpoint, URLRequestStatusToNetError(request.status));
300 316
301 DomainReliabilityBeacon beacon; 317 DomainReliabilityBeacon beacon_template;
302 beacon.protocol = GetDomainReliabilityProtocol( 318 beacon_template.protocol =
303 request.response_info.connection_info, 319 GetDomainReliabilityProtocol(request.response_info.connection_info,
304 request.response_info.ssl_info.is_valid()); 320 request.response_info.ssl_info.is_valid());
305 beacon.http_response_code = response_code; 321 beacon_template.http_response_code = response_code;
306 beacon.start_time = request.load_timing_info.request_start; 322 beacon_template.start_time = request.load_timing_info.request_start;
307 beacon.elapsed = time_->NowTicks() - beacon.start_time; 323 beacon_template.elapsed = time_->NowTicks() - beacon_template.start_time;
308 beacon.was_proxied = request.response_info.was_fetched_via_proxy; 324 beacon_template.was_proxied = request.response_info.was_fetched_via_proxy;
309 beacon.domain = request.url.host(); 325 beacon_template.url = request.url;
310 326
311 // This is not foolproof -- it's possible that we'll see the same error twice 327 // This is not foolproof -- it's possible that we'll see the same error twice
312 // (e.g. an SSL error during connection on one attempt, and then an error 328 // (e.g. an SSL error during connection on one attempt, and then an error
313 // that maps to the same code during a read). 329 // that maps to the same code during a read).
314 // TODO(ttuttle): Find a way for this code to reliably tell whether we 330 // TODO(ttuttle): Find a way for this code to reliably tell whether we
315 // eventually established a connection or not. 331 // eventually established a connection or not.
316 bool url_request_attempt_is_duplicate = false; 332 bool url_request_attempt_is_duplicate = false;
317 for (const auto& attempt : request.connection_attempts) { 333 for (const auto& attempt : request.connection_attempts) {
318 if (attempt.result == url_request_attempt.result) 334 if (attempt.result == url_request_attempt.result)
319 url_request_attempt_is_duplicate = true; 335 url_request_attempt_is_duplicate = true;
320 if (!UpdateBeaconFromAttempt(&beacon, attempt)) 336
321 continue; 337 scoped_ptr<DomainReliabilityBeacon> beacon =
322 context_manager_.RouteBeacon(request.url, beacon); 338 CreateBeaconFromAttempt(beacon_template, attempt);
Randy Smith (Not in Mondays) 2015/10/29 22:36:11 Why are we creating a new beacon rather than updat
Deprecated (see juliatuttle) 2015/11/02 23:19:30 I think we're doing the opposite -- creating a new
Randy Smith (Not in Mondays) 2015/11/03 21:48:12 That's how I'd describe what CreateBeaconFromAttem
Randy Smith (Not in Mondays) 2015/11/09 21:23:24 Just wanted to confirm that you read this and made
339 if (beacon)
340 context_manager_.RouteBeacon(beacon.Pass());
323 } 341 }
324 342
325 if (url_request_attempt_is_duplicate) 343 if (url_request_attempt_is_duplicate)
326 return; 344 return;
327 if (!UpdateBeaconFromAttempt(&beacon, url_request_attempt)) 345
328 return; 346 scoped_ptr<DomainReliabilityBeacon> beacon =
329 context_manager_.RouteBeacon(request.url, beacon); 347 CreateBeaconFromAttempt(beacon_template, url_request_attempt);
348 if (beacon)
349 context_manager_.RouteBeacon(beacon.Pass());
330 } 350 }
331 351
332 base::WeakPtr<DomainReliabilityMonitor> 352 base::WeakPtr<DomainReliabilityMonitor>
333 DomainReliabilityMonitor::MakeWeakPtr() { 353 DomainReliabilityMonitor::MakeWeakPtr() {
334 return weak_factory_.GetWeakPtr(); 354 return weak_factory_.GetWeakPtr();
335 } 355 }
336 356
337 } // namespace domain_reliability 357 } // namespace domain_reliability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698