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

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: Fix memory leak in unittests 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 150 }
141 151
142 void DomainReliabilityMonitor::AddBakedInConfigs() { 152 void DomainReliabilityMonitor::AddBakedInConfigs() {
143 DCHECK(OnNetworkThread()); 153 DCHECK(OnNetworkThread());
144 DCHECK(moved_to_network_thread_); 154 DCHECK(moved_to_network_thread_);
145 155
146 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) { 156 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) {
147 base::StringPiece json(kBakedInJsonConfigs[i]); 157 base::StringPiece json(kBakedInJsonConfigs[i]);
148 scoped_ptr<const DomainReliabilityConfig> config = 158 scoped_ptr<const DomainReliabilityConfig> config =
149 DomainReliabilityConfig::FromJSON(json); 159 DomainReliabilityConfig::FromJSON(json);
150 if (!config) 160 if (!config) {
161 DLOG(WARNING) << "Baked-in Domain Reliability config failed to parse: "
162 << json;
151 continue; 163 continue;
164 }
152 context_manager_.AddContextForConfig(config.Pass()); 165 context_manager_.AddContextForConfig(config.Pass());
153 } 166 }
167
168 std::vector<DomainReliabilityConfig*> google_configs;
169 GetAllGoogleConfigs(&google_configs);
170 for (auto google_config : google_configs)
171 context_manager_.AddContextForConfig(make_scoped_ptr(google_config));
154 } 172 }
155 173
156 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) { 174 void DomainReliabilityMonitor::SetDiscardUploads(bool discard_uploads) {
157 DCHECK(OnNetworkThread()); 175 DCHECK(OnNetworkThread());
158 DCHECK(moved_to_network_thread_); 176 DCHECK(moved_to_network_thread_);
159 DCHECK(uploader_); 177 DCHECK(uploader_);
160 178
161 uploader_->set_discard_uploads(discard_uploads); 179 uploader_->set_discard_uploads(discard_uploads);
162 discard_uploads_set_ = true; 180 discard_uploads_set_ = true;
163 } 181 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 304
287 int response_code; 305 int response_code;
288 if (request.response_info.headers.get()) 306 if (request.response_info.headers.get())
289 response_code = request.response_info.headers->response_code(); 307 response_code = request.response_info.headers->response_code();
290 else 308 else
291 response_code = -1; 309 response_code = -1;
292 310
293 net::ConnectionAttempt url_request_attempt( 311 net::ConnectionAttempt url_request_attempt(
294 request.remote_endpoint, URLRequestStatusToNetError(request.status)); 312 request.remote_endpoint, URLRequestStatusToNetError(request.status));
295 313
296 DomainReliabilityBeacon beacon; 314 DomainReliabilityBeacon beacon_template;
297 beacon.protocol = GetDomainReliabilityProtocol( 315 beacon_template.protocol =
298 request.response_info.connection_info, 316 GetDomainReliabilityProtocol(request.response_info.connection_info,
299 request.response_info.ssl_info.is_valid()); 317 request.response_info.ssl_info.is_valid());
300 beacon.http_response_code = response_code; 318 beacon_template.http_response_code = response_code;
301 beacon.start_time = request.load_timing_info.request_start; 319 beacon_template.start_time = request.load_timing_info.request_start;
302 beacon.elapsed = time_->NowTicks() - beacon.start_time; 320 beacon_template.elapsed = time_->NowTicks() - beacon_template.start_time;
303 beacon.was_proxied = request.response_info.was_fetched_via_proxy; 321 beacon_template.was_proxied = request.response_info.was_fetched_via_proxy;
304 beacon.domain = request.url.host(); 322 beacon_template.url = request.url;
305 323
306 // This is not foolproof -- it's possible that we'll see the same error twice 324 // This is not foolproof -- it's possible that we'll see the same error twice
307 // (e.g. an SSL error during connection on one attempt, and then an error 325 // (e.g. an SSL error during connection on one attempt, and then an error
308 // that maps to the same code during a read). 326 // that maps to the same code during a read).
309 // TODO(ttuttle): Find a way for this code to reliably tell whether we 327 // TODO(ttuttle): Find a way for this code to reliably tell whether we
310 // eventually established a connection or not. 328 // eventually established a connection or not.
311 bool url_request_attempt_is_duplicate = false; 329 bool url_request_attempt_is_duplicate = false;
312 for (const auto& attempt : request.connection_attempts) { 330 for (const auto& attempt : request.connection_attempts) {
313 if (attempt.result == url_request_attempt.result) 331 if (attempt.result == url_request_attempt.result)
314 url_request_attempt_is_duplicate = true; 332 url_request_attempt_is_duplicate = true;
315 if (!UpdateBeaconFromAttempt(&beacon, attempt)) 333
316 continue; 334 scoped_ptr<DomainReliabilityBeacon> beacon =
317 context_manager_.RouteBeacon(request.url, beacon); 335 CreateBeaconFromAttempt(beacon_template, attempt);
336 if (beacon)
337 context_manager_.RouteBeacon(beacon.Pass());
318 } 338 }
319 339
320 if (url_request_attempt_is_duplicate) 340 if (url_request_attempt_is_duplicate)
321 return; 341 return;
322 if (!UpdateBeaconFromAttempt(&beacon, url_request_attempt)) 342
323 return; 343 scoped_ptr<DomainReliabilityBeacon> beacon =
324 context_manager_.RouteBeacon(request.url, beacon); 344 CreateBeaconFromAttempt(beacon_template, url_request_attempt);
345 if (beacon)
346 context_manager_.RouteBeacon(beacon.Pass());
325 } 347 }
326 348
327 base::WeakPtr<DomainReliabilityMonitor> 349 base::WeakPtr<DomainReliabilityMonitor>
328 DomainReliabilityMonitor::MakeWeakPtr() { 350 DomainReliabilityMonitor::MakeWeakPtr() {
329 return weak_factory_.GetWeakPtr(); 351 return weak_factory_.GetWeakPtr();
330 } 352 }
331 353
332 } // namespace domain_reliability 354 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/google_configs_unittest.cc ('k') | components/domain_reliability/monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698