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

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: 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
23 namespace { 25 namespace {
24 26
25 int URLRequestStatusToNetError(const net::URLRequestStatus& status) { 27 int URLRequestStatusToNetError(const net::URLRequestStatus& status) {
26 switch (status.status()) { 28 switch (status.status()) {
27 case net::URLRequestStatus::SUCCESS: 29 case net::URLRequestStatus::SUCCESS:
28 return net::OK; 30 return net::OK;
29 case net::URLRequestStatus::IO_PENDING: 31 case net::URLRequestStatus::IO_PENDING:
30 return net::ERR_IO_PENDING; 32 return net::ERR_IO_PENDING;
31 case net::URLRequestStatus::CANCELED: 33 case net::URLRequestStatus::CANCELED:
32 return net::ERR_ABORTED; 34 return net::ERR_ABORTED;
33 case net::URLRequestStatus::FAILED: 35 case net::URLRequestStatus::FAILED:
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 // Creates a new beacon based on |beacon_template| but fills in the status,
42 // the endpoint and result of |attempt|. If there is no matching status for 44 // chrome_error, and server_ip fields based on the endpoint and result of
43 // the result, returns false (which means the attempt should not result in a 45 // |attempt|.
44 // beacon being reported). 46 //
45 bool UpdateBeaconFromAttempt(DomainReliabilityBeacon* beacon, 47 // If there is no matching status for the result, returns false (which
46 const net::ConnectionAttempt& attempt) { 48 // means the attempt should not result in a beacon being reported).
49 scoped_ptr<DomainReliabilityBeacon> CreateBeaconFromAttempt(
50 const DomainReliabilityBeacon& beacon_template,
51 const net::ConnectionAttempt& attempt) {
52 std::string status;
47 if (!GetDomainReliabilityBeaconStatus( 53 if (!GetDomainReliabilityBeaconStatus(
48 attempt.result, beacon->http_response_code, &beacon->status)) { 54 attempt.result, beacon_template.http_response_code, &status)) {
49 return false; 55 return scoped_ptr<DomainReliabilityBeacon>();
50 } 56 }
57
58 scoped_ptr<DomainReliabilityBeacon> beacon(
59 new DomainReliabilityBeacon(beacon_template));
60 beacon->status = status;
51 beacon->chrome_error = attempt.result; 61 beacon->chrome_error = attempt.result;
52 if (!attempt.endpoint.address().empty()) 62 if (!attempt.endpoint.address().empty())
53 beacon->server_ip = attempt.endpoint.ToString(); 63 beacon->server_ip = attempt.endpoint.ToString();
54 else 64 else
55 beacon->server_ip = ""; 65 beacon->server_ip = "";
56 return true; 66 return beacon.Pass();
57 } 67 }
58 68
59 } // namespace 69 } // namespace
60 70
61 DomainReliabilityMonitor::DomainReliabilityMonitor( 71 DomainReliabilityMonitor::DomainReliabilityMonitor(
62 const std::string& upload_reporter_string, 72 const std::string& upload_reporter_string,
63 const scoped_refptr<base::SingleThreadTaskRunner>& pref_thread, 73 const scoped_refptr<base::SingleThreadTaskRunner>& pref_thread,
64 const scoped_refptr<base::SingleThreadTaskRunner>& network_thread) 74 const scoped_refptr<base::SingleThreadTaskRunner>& network_thread)
65 : time_(new ActualTime()), 75 : time_(new ActualTime()),
66 upload_reporter_string_(upload_reporter_string), 76 upload_reporter_string_(upload_reporter_string),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 FROM_HERE_WITH_EXPLICIT_FUNCTION( 155 FROM_HERE_WITH_EXPLICIT_FUNCTION(
146 "436671 DomainReliabilityMonitor::AddBakedInConfigs")); 156 "436671 DomainReliabilityMonitor::AddBakedInConfigs"));
147 157
148 DCHECK(OnNetworkThread()); 158 DCHECK(OnNetworkThread());
149 DCHECK(moved_to_network_thread_); 159 DCHECK(moved_to_network_thread_);
150 160
151 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) { 161 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) {
152 base::StringPiece json(kBakedInJsonConfigs[i]); 162 base::StringPiece json(kBakedInJsonConfigs[i]);
153 scoped_ptr<const DomainReliabilityConfig> config = 163 scoped_ptr<const DomainReliabilityConfig> config =
154 DomainReliabilityConfig::FromJSON(json); 164 DomainReliabilityConfig::FromJSON(json);
155 if (!config) 165 if (!config) {
166 DLOG(WARNING) << "Baked-in Domain Reliability config failed to parse: "
167 << json;
156 continue; 168 continue;
169 }
157 context_manager_.AddContextForConfig(config.Pass()); 170 context_manager_.AddContextForConfig(config.Pass());
158 } 171 }
172
173 std::vector<DomainReliabilityConfig*> google_configs;
174 GetAllGoogleConfigs(&google_configs);
175 for (auto google_config : google_configs)
176 context_manager_.AddContextForConfig(make_scoped_ptr(google_config));
159 } 177 }
160 178
161 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) { 179 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) {
162 DCHECK(OnNetworkThread()); 180 DCHECK(OnNetworkThread());
163 DCHECK(moved_to_network_thread_); 181 DCHECK(moved_to_network_thread_);
164 DCHECK(uploader_); 182 DCHECK(uploader_);
165 183
166 uploader_->set_discard_uploads(discard_uploads); 184 uploader_->set_discard_uploads(discard_uploads);
167 discard_uploads_set_ = true; 185 discard_uploads_set_ = true;
168 } 186 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 309
292 int response_code; 310 int response_code;
293 if (request.response_info.headers.get()) 311 if (request.response_info.headers.get())
294 response_code = request.response_info.headers->response_code(); 312 response_code = request.response_info.headers->response_code();
295 else 313 else
296 response_code = -1; 314 response_code = -1;
297 315
298 net::ConnectionAttempt url_request_attempt( 316 net::ConnectionAttempt url_request_attempt(
299 request.remote_endpoint, URLRequestStatusToNetError(request.status)); 317 request.remote_endpoint, URLRequestStatusToNetError(request.status));
300 318
301 DomainReliabilityBeacon beacon; 319 DomainReliabilityBeacon beacon_template;
302 beacon.protocol = GetDomainReliabilityProtocol( 320 beacon_template.protocol =
303 request.response_info.connection_info, 321 GetDomainReliabilityProtocol(request.response_info.connection_info,
304 request.response_info.ssl_info.is_valid()); 322 request.response_info.ssl_info.is_valid());
305 beacon.http_response_code = response_code; 323 beacon_template.http_response_code = response_code;
306 beacon.start_time = request.load_timing_info.request_start; 324 beacon_template.start_time = request.load_timing_info.request_start;
307 beacon.elapsed = time_->NowTicks() - beacon.start_time; 325 beacon_template.elapsed = time_->NowTicks() - beacon_template.start_time;
308 beacon.was_proxied = request.response_info.was_fetched_via_proxy; 326 beacon_template.was_proxied = request.response_info.was_fetched_via_proxy;
309 beacon.domain = request.url.host(); 327 beacon_template.url = request.url;
310 328
311 // This is not foolproof -- it's possible that we'll see the same error twice 329 // 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 330 // (e.g. an SSL error during connection on one attempt, and then an error
313 // that maps to the same code during a read). 331 // that maps to the same code during a read).
314 // TODO(ttuttle): Find a way for this code to reliably tell whether we 332 // TODO(ttuttle): Find a way for this code to reliably tell whether we
315 // eventually established a connection or not. 333 // eventually established a connection or not.
316 bool url_request_attempt_is_duplicate = false; 334 bool url_request_attempt_is_duplicate = false;
317 for (const auto& attempt : request.connection_attempts) { 335 for (const auto& attempt : request.connection_attempts) {
318 if (attempt.result == url_request_attempt.result) 336 if (attempt.result == url_request_attempt.result)
319 url_request_attempt_is_duplicate = true; 337 url_request_attempt_is_duplicate = true;
320 if (!UpdateBeaconFromAttempt(&beacon, attempt)) 338
321 continue; 339 scoped_ptr<DomainReliabilityBeacon> beacon =
322 context_manager_.RouteBeacon(request.url, beacon); 340 CreateBeaconFromAttempt(beacon_template, attempt);
341 if (beacon)
342 context_manager_.RouteBeacon(beacon.Pass());
323 } 343 }
324 344
325 if (url_request_attempt_is_duplicate) 345 if (url_request_attempt_is_duplicate)
326 return; 346 return;
327 if (!UpdateBeaconFromAttempt(&beacon, url_request_attempt)) 347
328 return; 348 scoped_ptr<DomainReliabilityBeacon> beacon =
329 context_manager_.RouteBeacon(request.url, beacon); 349 CreateBeaconFromAttempt(beacon_template, url_request_attempt);
350 if (beacon)
351 context_manager_.RouteBeacon(beacon.Pass());
330 } 352 }
331 353
332 base::WeakPtr<DomainReliabilityMonitor> 354 base::WeakPtr<DomainReliabilityMonitor>
333 DomainReliabilityMonitor::MakeWeakPtr() { 355 DomainReliabilityMonitor::MakeWeakPtr() {
334 return weak_factory_.GetWeakPtr(); 356 return weak_factory_.GetWeakPtr();
335 } 357 }
336 358
337 } // namespace domain_reliability 359 } // namespace domain_reliability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698