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

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

Issue 2466093002: Domain Reliability: Add more upload-related histograms. (Closed)
Patch Set: A couple of tweaks. Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_manager.h" 5 #include "components/domain_reliability/context_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/metrics/histogram_macros.h"
10
9 namespace domain_reliability { 11 namespace domain_reliability {
10 12
11 DomainReliabilityContextManager::DomainReliabilityContextManager( 13 DomainReliabilityContextManager::DomainReliabilityContextManager(
12 DomainReliabilityContext::Factory* context_factory) 14 DomainReliabilityContext::Factory* context_factory)
13 : context_factory_(context_factory) { 15 : context_factory_(context_factory) {
14 } 16 }
15 17
16 DomainReliabilityContextManager::~DomainReliabilityContextManager() { 18 DomainReliabilityContextManager::~DomainReliabilityContextManager() {
17 RemoveContexts( 19 RemoveContexts(
18 base::Callback<bool(const GURL&)>() /* no filter - delete everything */); 20 base::Callback<bool(const GURL&)>() /* no filter - delete everything */);
19 } 21 }
20 22
21 void DomainReliabilityContextManager::RouteBeacon( 23 void DomainReliabilityContextManager::RouteBeacon(
22 std::unique_ptr<DomainReliabilityBeacon> beacon) { 24 std::unique_ptr<DomainReliabilityBeacon> beacon) {
23 DomainReliabilityContext* context = GetContextForHost(beacon->url.host()); 25 DomainReliabilityContext* context = GetContextForHost(beacon->url.host());
24 if (!context) 26 if (!context)
25 return; 27 return;
26 28
27 context->OnBeacon(std::move(beacon)); 29 bool queued = context->OnBeacon(std::move(beacon));
30 if (!queued)
31 return;
32
33 base::TimeTicks now = base::TimeTicks::Now();
34 if (!last_routed_beacon_time_.is_null()) {
35 UMA_HISTOGRAM_LONG_TIMES("DomainReliability.BeaconIntervalGlobal",
36 now - last_routed_beacon_time_);
37 }
38 last_routed_beacon_time_ = now;
28 } 39 }
29 40
30 void DomainReliabilityContextManager::SetConfig( 41 void DomainReliabilityContextManager::SetConfig(
31 const GURL& origin, 42 const GURL& origin,
32 std::unique_ptr<DomainReliabilityConfig> config, 43 std::unique_ptr<DomainReliabilityConfig> config,
33 base::TimeDelta max_age) { 44 base::TimeDelta max_age) {
34 std::string key = origin.host(); 45 std::string key = origin.host();
35 46
36 if (!contexts_.count(key) && !removed_contexts_.count(key)) { 47 if (!contexts_.count(key) && !removed_contexts_.count(key)) {
37 LOG(WARNING) << "Ignoring NEL header for unknown origin " << origin.spec() 48 LOG(WARNING) << "Ignoring NEL header for unknown origin " << origin.spec()
38 << "."; 49 << ".";
39 return; 50 return;
40 } 51 }
41 52
42 if (contexts_.count(key)) { 53 if (contexts_.count(key)) {
43 // Currently, there is no easy way to change the config of a context, so 54 // Currently, there is no easy way to change the config of a context, so
44 // updating the config requires recreating the context, which loses 55 // updating the config requires recreating the context, which loses
45 // pending beacons and collector backoff state. Therefore, don't do so 56 // pending beacons and collector backoff state. Therefore, don't do so
46 // needlessly; make sure the config has actually changed before recreating 57 // needlessly; make sure the config has actually changed before recreating
47 // the context. 58 // the context.
48 if (contexts_[key]->config().Equals(*config)) { 59 bool config_same = contexts_[key]->config().Equals(*config);
60 UMA_HISTOGRAM_BOOLEAN("DomainReliability.SetConfigRecreatedContext",
61 !config_same);
62 if (!config_same) {
49 DVLOG(1) << "Ignoring unchanged NEL header for existing origin " 63 DVLOG(1) << "Ignoring unchanged NEL header for existing origin "
50 << origin.spec() << "."; 64 << origin.spec() << ".";
51 return; 65 return;
52 } 66 }
53 // TODO(juliatuttle): Make Context accept Config changes. 67 // TODO(juliatuttle): Make Context accept Config changes.
54 } 68 }
55 69
56 DVLOG(1) << "Adding/replacing context for existing origin " << origin.spec() 70 DVLOG(1) << "Adding/replacing context for existing origin " << origin.spec()
57 << "."; 71 << ".";
58 removed_contexts_.erase(key); 72 removed_contexts_.erase(key);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 context_it = contexts_.find(parent_host); 149 context_it = contexts_.find(parent_host);
136 if (context_it != contexts_.end() 150 if (context_it != contexts_.end()
137 && context_it->second->config().include_subdomains) { 151 && context_it->second->config().include_subdomains) {
138 return context_it->second; 152 return context_it->second;
139 } 153 }
140 154
141 return nullptr; 155 return nullptr;
142 } 156 }
143 157
144 } // namespace domain_reliability 158 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/context_manager.h ('k') | components/domain_reliability/uploader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698