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

Side by Side Diff: net/nqe/network_quality_store.cc

Issue 2731333003: Record UMA only when network quality is eligible for caching (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « net/nqe/network_quality_store.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "net/nqe/network_quality_store.h" 5 #include "net/nqe/network_quality_store.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "net/base/network_change_notifier.h" 9 #include "net/base/network_change_notifier.h"
10 10
(...skipping 17 matching lines...) Expand all
28 DCHECK(thread_checker_.CalledOnValidThread()); 28 DCHECK(thread_checker_.CalledOnValidThread());
29 } 29 }
30 30
31 void NetworkQualityStore::Add( 31 void NetworkQualityStore::Add(
32 const nqe::internal::NetworkID& network_id, 32 const nqe::internal::NetworkID& network_id,
33 const nqe::internal::CachedNetworkQuality& cached_network_quality) { 33 const nqe::internal::CachedNetworkQuality& cached_network_quality) {
34 DCHECK(thread_checker_.CalledOnValidThread()); 34 DCHECK(thread_checker_.CalledOnValidThread());
35 DCHECK_LE(cached_network_qualities_.size(), 35 DCHECK_LE(cached_network_qualities_.size(),
36 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); 36 static_cast<size_t>(kMaximumNetworkQualityCacheSize));
37 37
38 // If the network name is unavailable, caching should not be performed. If 38 if (!EligibleForCaching(network_id))
39 // |disable_offline_check_| is set to true, cache the network quality even if
40 // the network is set to offline.
41 if (network_id.type != NetworkChangeNotifier::CONNECTION_ETHERNET &&
42 network_id.id.empty() &&
43 (network_id.type != NetworkChangeNotifier::CONNECTION_NONE ||
44 !disable_offline_check_)) {
45 return; 39 return;
46 }
47 40
48 // Remove the entry from the map, if it is already present. 41 // Remove the entry from the map, if it is already present.
49 cached_network_qualities_.erase(network_id); 42 cached_network_qualities_.erase(network_id);
50 43
51 if (cached_network_qualities_.size() == kMaximumNetworkQualityCacheSize) { 44 if (cached_network_qualities_.size() == kMaximumNetworkQualityCacheSize) {
52 // Remove the oldest entry. 45 // Remove the oldest entry.
53 CachedNetworkQualities::iterator oldest_entry_iterator = 46 CachedNetworkQualities::iterator oldest_entry_iterator =
54 cached_network_qualities_.begin(); 47 cached_network_qualities_.begin();
55 48
56 for (CachedNetworkQualities::iterator it = 49 for (CachedNetworkQualities::iterator it =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 FROM_HERE, base::Bind(&NetworkQualityStore::NotifyCacheObserverIfPresent, 90 FROM_HERE, base::Bind(&NetworkQualityStore::NotifyCacheObserverIfPresent,
98 weak_ptr_factory_.GetWeakPtr(), observer)); 91 weak_ptr_factory_.GetWeakPtr(), observer));
99 } 92 }
100 93
101 void NetworkQualityStore::RemoveNetworkQualitiesCacheObserver( 94 void NetworkQualityStore::RemoveNetworkQualitiesCacheObserver(
102 NetworkQualitiesCacheObserver* observer) { 95 NetworkQualitiesCacheObserver* observer) {
103 DCHECK(thread_checker_.CalledOnValidThread()); 96 DCHECK(thread_checker_.CalledOnValidThread());
104 network_qualities_cache_observer_list_.RemoveObserver(observer); 97 network_qualities_cache_observer_list_.RemoveObserver(observer);
105 } 98 }
106 99
100 bool NetworkQualityStore::EligibleForCaching(
101 const NetworkID& network_id) const {
102 DCHECK(thread_checker_.CalledOnValidThread());
103
104 // If the network name is unavailable, caching should not be performed. If
RyanSturm 2017/03/09 00:01:55 This comment seems unnecessary. It describes the c
tbansal1 2017/03/09 00:24:00 Done.
105 // |disable_offline_check_| is set to true, cache the network quality even if
106 // the network is set to offline.
107 return network_id.type == NetworkChangeNotifier::CONNECTION_ETHERNET ||
108 !network_id.id.empty() ||
109 (network_id.type == NetworkChangeNotifier::CONNECTION_NONE &&
110 disable_offline_check_);
111 }
112
107 void NetworkQualityStore::DisableOfflineCheckForTesting( 113 void NetworkQualityStore::DisableOfflineCheckForTesting(
108 bool disable_offline_check) { 114 bool disable_offline_check) {
109 DCHECK(thread_checker_.CalledOnValidThread()); 115 DCHECK(thread_checker_.CalledOnValidThread());
110 disable_offline_check_ = disable_offline_check; 116 disable_offline_check_ = disable_offline_check;
111 } 117 }
112 118
113 void NetworkQualityStore::NotifyCacheObserverIfPresent( 119 void NetworkQualityStore::NotifyCacheObserverIfPresent(
114 NetworkQualitiesCacheObserver* observer) const { 120 NetworkQualitiesCacheObserver* observer) const {
115 DCHECK(thread_checker_.CalledOnValidThread()); 121 DCHECK(thread_checker_.CalledOnValidThread());
116 122
117 if (!network_qualities_cache_observer_list_.HasObserver(observer)) 123 if (!network_qualities_cache_observer_list_.HasObserver(observer))
118 return; 124 return;
119 for (const auto it : cached_network_qualities_) 125 for (const auto it : cached_network_qualities_)
120 observer->OnChangeInCachedNetworkQuality(it.first, it.second); 126 observer->OnChangeInCachedNetworkQuality(it.first, it.second);
121 } 127 }
122 128
123 } // namespace internal 129 } // namespace internal
124 130
125 } // namespace nqe 131 } // namespace nqe
126 132
127 } // namespace net 133 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_store.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698