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

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: Add new configs Created 5 years, 2 months 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 12 matching lines...) Expand all
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).
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;
156 continue; 166 continue;
167 }
157 context_manager_.AddContextForConfig(config.Pass()); 168 context_manager_.AddContextForConfig(config.Pass());
158 } 169 }
170
171 GoogleConfigs google_configs = GoogleConfigs::GetAllConfigs();
172 while (google_configs.HasMoreConfigs())
173 context_manager_.AddContextForConfig(google_configs.GetNextConfig());
davidben 2015/10/20 23:35:54 Since you're calling AddContextForConfig which sti
Deprecated (see juliatuttle) 2015/10/26 19:08:41 Yeah, it is. What's the best way to convey a vect
159 } 174 }
160 175
161 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) { 176 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) {
162 DCHECK(OnNetworkThread()); 177 DCHECK(OnNetworkThread());
163 DCHECK(moved_to_network_thread_); 178 DCHECK(moved_to_network_thread_);
164 DCHECK(uploader_); 179 DCHECK(uploader_);
165 180
166 uploader_->set_discard_uploads(discard_uploads); 181 uploader_->set_discard_uploads(discard_uploads);
167 discard_uploads_set_ = true; 182 discard_uploads_set_ = true;
168 } 183 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 306
292 int response_code; 307 int response_code;
293 if (request.response_info.headers.get()) 308 if (request.response_info.headers.get())
294 response_code = request.response_info.headers->response_code(); 309 response_code = request.response_info.headers->response_code();
295 else 310 else
296 response_code = -1; 311 response_code = -1;
297 312
298 net::ConnectionAttempt url_request_attempt( 313 net::ConnectionAttempt url_request_attempt(
299 request.remote_endpoint, URLRequestStatusToNetError(request.status)); 314 request.remote_endpoint, URLRequestStatusToNetError(request.status));
300 315
301 DomainReliabilityBeacon beacon; 316 DomainReliabilityBeacon beacon_template;
302 beacon.protocol = GetDomainReliabilityProtocol( 317 beacon_template.protocol =
303 request.response_info.connection_info, 318 GetDomainReliabilityProtocol(request.response_info.connection_info,
304 request.response_info.ssl_info.is_valid()); 319 request.response_info.ssl_info.is_valid());
305 beacon.http_response_code = response_code; 320 beacon_template.http_response_code = response_code;
306 beacon.start_time = request.load_timing_info.request_start; 321 beacon_template.start_time = request.load_timing_info.request_start;
307 beacon.elapsed = time_->NowTicks() - beacon.start_time; 322 beacon_template.elapsed = time_->NowTicks() - beacon_template.start_time;
308 beacon.was_proxied = request.response_info.was_fetched_via_proxy; 323 beacon_template.was_proxied = request.response_info.was_fetched_via_proxy;
309 beacon.domain = request.url.host(); 324 beacon_template.url = request.url;
310 325
311 // This is not foolproof -- it's possible that we'll see the same error twice 326 // 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 327 // (e.g. an SSL error during connection on one attempt, and then an error
313 // that maps to the same code during a read). 328 // that maps to the same code during a read).
314 // TODO(ttuttle): Find a way for this code to reliably tell whether we 329 // TODO(ttuttle): Find a way for this code to reliably tell whether we
315 // eventually established a connection or not. 330 // eventually established a connection or not.
316 bool url_request_attempt_is_duplicate = false; 331 bool url_request_attempt_is_duplicate = false;
317 for (const auto& attempt : request.connection_attempts) { 332 for (const auto& attempt : request.connection_attempts) {
318 if (attempt.result == url_request_attempt.result) 333 if (attempt.result == url_request_attempt.result)
319 url_request_attempt_is_duplicate = true; 334 url_request_attempt_is_duplicate = true;
320 if (!UpdateBeaconFromAttempt(&beacon, attempt)) 335
321 continue; 336 scoped_ptr<DomainReliabilityBeacon> beacon =
322 context_manager_.RouteBeacon(request.url, beacon); 337 CreateBeaconFromAttempt(beacon_template, attempt);
338 if (beacon)
339 context_manager_.RouteBeacon(beacon.Pass());
323 } 340 }
324 341
325 if (url_request_attempt_is_duplicate) 342 if (url_request_attempt_is_duplicate)
326 return; 343 return;
327 if (!UpdateBeaconFromAttempt(&beacon, url_request_attempt)) 344
328 return; 345 scoped_ptr<DomainReliabilityBeacon> beacon =
329 context_manager_.RouteBeacon(request.url, beacon); 346 CreateBeaconFromAttempt(beacon_template, url_request_attempt);
347 if (beacon)
348 context_manager_.RouteBeacon(beacon.Pass());
330 } 349 }
331 350
332 base::WeakPtr<DomainReliabilityMonitor> 351 base::WeakPtr<DomainReliabilityMonitor>
333 DomainReliabilityMonitor::MakeWeakPtr() { 352 DomainReliabilityMonitor::MakeWeakPtr() {
334 return weak_factory_.GetWeakPtr(); 353 return weak_factory_.GetWeakPtr();
335 } 354 }
336 355
337 } // namespace domain_reliability 356 } // namespace domain_reliability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698