Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 if (contexts_[key]->config().Equals(*config)) { |
| 49 DVLOG(1) << "Ignoring unchanged NEL header for existing origin " | 60 DVLOG(1) << "Ignoring unchanged NEL header for existing origin " |
| 50 << origin.spec() << "."; | 61 << origin.spec() << "."; |
| 62 UMA_HISTOGRAM_BOOLEAN("DomainReliability.SetConfigRecreatedContext", | |
| 63 false); | |
| 51 return; | 64 return; |
| 65 } else { | |
| 66 UMA_HISTOGRAM_BOOLEAN("DomainReliability.SetConfigRecreatedContext", | |
| 67 true); | |
|
Alexei Svitkine (slow)
2016/11/01 14:49:46
Please refactor the code to avoid having two macro
Julia Tuttle
2016/11/01 15:52:47
Done.
| |
| 52 } | 68 } |
| 53 // TODO(juliatuttle): Make Context accept Config changes. | 69 // TODO(juliatuttle): Make Context accept Config changes. |
| 54 } | 70 } |
| 55 | 71 |
| 56 DVLOG(1) << "Adding/replacing context for existing origin " << origin.spec() | |
|
Julia Tuttle
2016/10/31 23:32:05
Note to self: Put this back.
Julia Tuttle
2016/11/01 15:52:47
Done.
| |
| 57 << "."; | |
| 58 removed_contexts_.erase(key); | 72 removed_contexts_.erase(key); |
| 59 config->origin = origin; | 73 config->origin = origin; |
| 60 AddContextForConfig(std::move(config)); | 74 AddContextForConfig(std::move(config)); |
| 61 } | 75 } |
| 62 | 76 |
| 63 void DomainReliabilityContextManager::ClearConfig(const GURL& origin) { | 77 void DomainReliabilityContextManager::ClearConfig(const GURL& origin) { |
| 64 std::string key = origin.host(); | 78 std::string key = origin.host(); |
| 65 | 79 |
| 66 if (contexts_.count(key)) { | 80 if (contexts_.count(key)) { |
| 67 DVLOG(1) << "Removing context for existing origin " << origin.spec() << "."; | 81 DVLOG(1) << "Removing context for existing origin " << origin.spec() << "."; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |