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

Side by Side Diff: chrome/browser/net/nqe/ui_network_quality_estimator_service.cc

Issue 2622663002: NetworkQualityEstimator: Enable prefs writing by default (Closed)
Patch Set: Fix moar tests Created 3 years, 11 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 | « no previous file | chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc » ('j') | 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 "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" 5 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 25 matching lines...) Expand all
36 36
37 const auto it = network_quality_estimator_params.find(parameter_name); 37 const auto it = network_quality_estimator_params.find(parameter_name);
38 return it == network_quality_estimator_params.end() ? default_value 38 return it == network_quality_estimator_params.end() ? default_value
39 : it->second; 39 : it->second;
40 } 40 }
41 41
42 // Returns true if writing to the persistent cache has been enabled via field 42 // Returns true if writing to the persistent cache has been enabled via field
43 // trial. 43 // trial.
44 bool persistent_cache_writing_enabled() { 44 bool persistent_cache_writing_enabled() {
45 return GetStringValueForVariationParamWithDefaultValue( 45 return GetStringValueForVariationParamWithDefaultValue(
46 "persistent_cache_writing_enabled", "false") == "true"; 46 "persistent_cache_writing_enabled", "true") == "true";
47 } 47 }
48 48
49 // Returns true if reading from the persistent cache has been enabled via field 49 // Returns true if reading from the persistent cache has been enabled via field
50 // trial. 50 // trial.
51 bool persistent_cache_reading_enabled() { 51 bool persistent_cache_reading_enabled() {
52 return GetStringValueForVariationParamWithDefaultValue( 52 if (GetStringValueForVariationParamWithDefaultValue(
53 "persistent_cache_reading_enabled", "false") == "true"; 53 "persistent_cache_reading_enabled", "false") != "true") {
54 return false;
55 }
56 // If reading from prefs is enabled, then writing to prefs must be enabled
57 // too.
58 DCHECK(persistent_cache_writing_enabled());
59 return true;
54 } 60 }
55 61
56 // PrefDelegateImpl writes the provided dictionary value to the network quality 62 // PrefDelegateImpl writes the provided dictionary value to the network quality
57 // estimator prefs on the disk. 63 // estimator prefs on the disk.
58 class PrefDelegateImpl 64 class PrefDelegateImpl
59 : public net::NetworkQualitiesPrefsManager::PrefDelegate { 65 : public net::NetworkQualitiesPrefsManager::PrefDelegate {
60 public: 66 public:
61 // |pref_service| is used to read and write prefs from/to the disk. 67 // |pref_service| is used to read and write prefs from/to the disk.
62 explicit PrefDelegateImpl(PrefService* pref_service) 68 explicit PrefDelegateImpl(PrefService* pref_service)
63 : pref_service_(pref_service), path_(prefs::kNetworkQualities) { 69 : pref_service_(pref_service), path_(prefs::kNetworkQualities) {
64 DCHECK(pref_service_); 70 DCHECK(pref_service_);
65 } 71 }
66 ~PrefDelegateImpl() override {} 72 ~PrefDelegateImpl() override {}
67 73
68 void SetDictionaryValue(const base::DictionaryValue& value) override { 74 void SetDictionaryValue(const base::DictionaryValue& value) override {
69 DCHECK(thread_checker_.CalledOnValidThread()); 75 DCHECK(thread_checker_.CalledOnValidThread());
70 if (!persistent_cache_writing_enabled()) 76 if (!persistent_cache_writing_enabled())
71 return; 77 return;
72 78
73 pref_service_->Set(path_, value); 79 pref_service_->Set(path_, value);
74 UMA_HISTOGRAM_COUNTS_1000("NQE.Prefs.WriteCount", 1); 80 UMA_HISTOGRAM_EXACT_LINEAR("NQE.Prefs.WriteCount", 1, 2);
75 } 81 }
76 82
77 std::unique_ptr<base::DictionaryValue> GetDictionaryValue() override { 83 std::unique_ptr<base::DictionaryValue> GetDictionaryValue() override {
78 DCHECK(thread_checker_.CalledOnValidThread()); 84 DCHECK(thread_checker_.CalledOnValidThread());
79 if (!persistent_cache_reading_enabled()) 85 if (!persistent_cache_reading_enabled())
80 return base::WrapUnique(new base::DictionaryValue()); 86 return base::WrapUnique(new base::DictionaryValue());
81 UMA_HISTOGRAM_COUNTS_1000("NQE.Prefs.ReadCount", 1); 87 UMA_HISTOGRAM_EXACT_LINEAR("NQE.Prefs.ReadCount", 1, 2);
82 return pref_service_->GetDictionary(path_)->CreateDeepCopy(); 88 return pref_service_->GetDictionary(path_)->CreateDeepCopy();
83 } 89 }
84 90
85 private: 91 private:
86 PrefService* pref_service_; 92 PrefService* pref_service_;
87 93
88 // |path_| is the location of the network quality estimator prefs. 94 // |path_| is the location of the network quality estimator prefs.
89 const std::string path_; 95 const std::string path_;
90 96
91 base::ThreadChecker thread_checker_; 97 base::ThreadChecker thread_checker_;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 282
277 std::map<net::nqe::internal::NetworkID, 283 std::map<net::nqe::internal::NetworkID,
278 net::nqe::internal::CachedNetworkQuality> 284 net::nqe::internal::CachedNetworkQuality>
279 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const { 285 UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const {
280 if (!prefs_manager_) { 286 if (!prefs_manager_) {
281 return std::map<net::nqe::internal::NetworkID, 287 return std::map<net::nqe::internal::NetworkID,
282 net::nqe::internal::CachedNetworkQuality>(); 288 net::nqe::internal::CachedNetworkQuality>();
283 } 289 }
284 return prefs_manager_->ForceReadPrefsForTesting(); 290 return prefs_manager_->ForceReadPrefsForTesting();
285 } 291 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698