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/context.h" | 5 #include "components/domain_reliability/context.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
14 #include "base/rand_util.h" | |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "components/domain_reliability/dispatcher.h" | 16 #include "components/domain_reliability/dispatcher.h" |
16 #include "components/domain_reliability/uploader.h" | 17 #include "components/domain_reliability/uploader.h" |
17 #include "components/domain_reliability/util.h" | 18 #include "components/domain_reliability/util.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
20 | 21 |
21 using base::DictionaryValue; | 22 using base::DictionaryValue; |
22 using base::ListValue; | 23 using base::ListValue; |
23 using base::Value; | 24 using base::Value; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 weak_factory_(this) { | 63 weak_factory_(this) { |
63 } | 64 } |
64 | 65 |
65 DomainReliabilityContext::~DomainReliabilityContext() { | 66 DomainReliabilityContext::~DomainReliabilityContext() { |
66 ClearBeacons(); | 67 ClearBeacons(); |
67 } | 68 } |
68 | 69 |
69 void DomainReliabilityContext::OnBeacon( | 70 void DomainReliabilityContext::OnBeacon( |
70 scoped_ptr<DomainReliabilityBeacon> beacon) { | 71 scoped_ptr<DomainReliabilityBeacon> beacon) { |
71 bool success = (beacon->status == "ok"); | 72 bool success = (beacon->status == "ok"); |
72 | 73 double sample_rate = config().GetSampleRate(success); |
73 bool reported = config().DecideIfShouldReportRequest(success); | 74 bool report = base::RandDouble() < sample_rate; |
jkarlin
2015/12/09 11:46:22
nit: s/report/should_report/
report sounds like a
Deprecated (see juliatuttle)
2015/12/10 17:04:23
Done, and same for evicted => should_evict.
| |
74 UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", reported); | 75 UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", report); |
75 if (!reported) { | 76 if (!report) { |
76 // If the beacon isn't queued to be reported, it definitely cannot evict | 77 // If the beacon isn't queued to be reported, it definitely cannot evict |
77 // an older beacon. (This histogram is also logged below based on whether | 78 // an older beacon. (This histogram is also logged below based on whether |
78 // an older beacon was actually evicted.) | 79 // an older beacon was actually evicted.) |
79 LogOnBeaconDidEvictHistogram(false); | 80 LogOnBeaconDidEvictHistogram(false); |
80 return; | 81 return; |
81 } | 82 } |
83 beacon->sample_rate = sample_rate; | |
82 | 84 |
83 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.ReportedBeaconError", | 85 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.ReportedBeaconError", |
84 -beacon->chrome_error); | 86 -beacon->chrome_error); |
85 if (!beacon->server_ip.empty()) { | 87 if (!beacon->server_ip.empty()) { |
86 UMA_HISTOGRAM_SPARSE_SLOWLY( | 88 UMA_HISTOGRAM_SPARSE_SLOWLY( |
87 "DomainReliability.ReportedBeaconError_HasServerIP", | 89 "DomainReliability.ReportedBeaconError_HasServerIP", |
88 -beacon->chrome_error); | 90 -beacon->chrome_error); |
89 } | 91 } |
90 // TODO(ttuttle): Histogram HTTP response code? | 92 // TODO(ttuttle): Histogram HTTP response code? |
91 | 93 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 delete beacons_.front(); | 246 delete beacons_.front(); |
245 beacons_.pop_front(); | 247 beacons_.pop_front(); |
246 | 248 |
247 // If that just removed a beacon counted in uploading_beacons_size_, decrement | 249 // If that just removed a beacon counted in uploading_beacons_size_, decrement |
248 // that. | 250 // that. |
249 if (uploading_beacons_size_ > 0) | 251 if (uploading_beacons_size_ > 0) |
250 --uploading_beacons_size_; | 252 --uploading_beacons_size_; |
251 } | 253 } |
252 | 254 |
253 } // namespace domain_reliability | 255 } // namespace domain_reliability |
OLD | NEW |