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

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

Issue 2894863002: Rename TaskRunner::RunsTasksOnCurrentThread() in //net (Closed)
Patch Set: for Requirements Created 3 years, 7 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
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_qualities_prefs_manager.h" 5 #include "net/nqe/network_qualities_prefs_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 DCHECK(pref_delegate_); 71 DCHECK(pref_delegate_);
72 DCHECK(pref_task_runner_); 72 DCHECK(pref_task_runner_);
73 DCHECK_GE(kMaxCacheSize, prefs_->size()); 73 DCHECK_GE(kMaxCacheSize, prefs_->size());
74 74
75 pref_weak_ptr_ = pref_weak_ptr_factory_.GetWeakPtr(); 75 pref_weak_ptr_ = pref_weak_ptr_factory_.GetWeakPtr();
76 } 76 }
77 77
78 NetworkQualitiesPrefsManager::~NetworkQualitiesPrefsManager() { 78 NetworkQualitiesPrefsManager::~NetworkQualitiesPrefsManager() {
79 if (!network_task_runner_) 79 if (!network_task_runner_)
80 return; 80 return;
81 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 81 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
82 if (network_quality_estimator_) 82 if (network_quality_estimator_)
83 network_quality_estimator_->RemoveNetworkQualitiesCacheObserver(this); 83 network_quality_estimator_->RemoveNetworkQualitiesCacheObserver(this);
84 } 84 }
85 85
86 void NetworkQualitiesPrefsManager::InitializeOnNetworkThread( 86 void NetworkQualitiesPrefsManager::InitializeOnNetworkThread(
87 NetworkQualityEstimator* network_quality_estimator) { 87 NetworkQualityEstimator* network_quality_estimator) {
88 DCHECK(!network_task_runner_); 88 DCHECK(!network_task_runner_);
89 DCHECK(network_quality_estimator); 89 DCHECK(network_quality_estimator);
90 90
91 network_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 91 network_task_runner_ = base::ThreadTaskRunnerHandle::Get();
92 network_quality_estimator_ = network_quality_estimator; 92 network_quality_estimator_ = network_quality_estimator;
93 network_quality_estimator_->AddNetworkQualitiesCacheObserver(this); 93 network_quality_estimator_->AddNetworkQualitiesCacheObserver(this);
94 94
95 // Notify network quality estimator of the read prefs. 95 // Notify network quality estimator of the read prefs.
96 network_quality_estimator_->OnPrefsRead(read_prefs_startup_); 96 network_quality_estimator_->OnPrefsRead(read_prefs_startup_);
97 } 97 }
98 98
99 void NetworkQualitiesPrefsManager::OnChangeInCachedNetworkQuality( 99 void NetworkQualitiesPrefsManager::OnChangeInCachedNetworkQuality(
100 const nqe::internal::NetworkID& network_id, 100 const nqe::internal::NetworkID& network_id,
101 const nqe::internal::CachedNetworkQuality& cached_network_quality) { 101 const nqe::internal::CachedNetworkQuality& cached_network_quality) {
102 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 102 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
103 103
104 // Notify |this| on the pref thread. 104 // Notify |this| on the pref thread.
105 pref_task_runner_->PostTask( 105 pref_task_runner_->PostTask(
106 FROM_HERE, 106 FROM_HERE,
107 base::Bind(&NetworkQualitiesPrefsManager:: 107 base::Bind(&NetworkQualitiesPrefsManager::
108 OnChangeInCachedNetworkQualityOnPrefThread, 108 OnChangeInCachedNetworkQualityOnPrefThread,
109 pref_weak_ptr_, network_id, cached_network_quality)); 109 pref_weak_ptr_, network_id, cached_network_quality));
110 } 110 }
111 111
112 void NetworkQualitiesPrefsManager::ShutdownOnPrefThread() { 112 void NetworkQualitiesPrefsManager::ShutdownOnPrefThread() {
Ryan Sleevi 2017/05/22 17:22:14 OnPrefSequence
Yeol Park 2017/05/23 05:26:33 Done.
113 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 113 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence());
114 pref_weak_ptr_factory_.InvalidateWeakPtrs(); 114 pref_weak_ptr_factory_.InvalidateWeakPtrs();
115 pref_delegate_.reset(); 115 pref_delegate_.reset();
116 } 116 }
117 117
118 void NetworkQualitiesPrefsManager::ClearPrefs() { 118 void NetworkQualitiesPrefsManager::ClearPrefs() {
119 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 119 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence());
120 prefs_->Clear(); 120 prefs_->Clear();
121 DCHECK_EQ(0u, prefs_->size()); 121 DCHECK_EQ(0u, prefs_->size());
122 pref_delegate_->SetDictionaryValue(*prefs_); 122 pref_delegate_->SetDictionaryValue(*prefs_);
123 } 123 }
124 124
125 void NetworkQualitiesPrefsManager::OnChangeInCachedNetworkQualityOnPrefThread( 125 void NetworkQualitiesPrefsManager::OnChangeInCachedNetworkQualityOnPrefThread(
Ryan Sleevi 2017/05/22 17:22:14 OnPrefSequence
Yeol Park 2017/05/23 05:26:33 Done.
126 const nqe::internal::NetworkID& network_id, 126 const nqe::internal::NetworkID& network_id,
127 const nqe::internal::CachedNetworkQuality& cached_network_quality) { 127 const nqe::internal::CachedNetworkQuality& cached_network_quality) {
128 // The prefs can only be written on the pref thread. 128 // The prefs can only be written on the pref thread.
129 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 129 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence());
130 DCHECK_GE(kMaxCacheSize, prefs_->size()); 130 DCHECK_GE(kMaxCacheSize, prefs_->size());
131 131
132 std::string network_id_string = network_id.ToString(); 132 std::string network_id_string = network_id.ToString();
133 133
134 // If the network ID contains a period, then return early since the dictionary 134 // If the network ID contains a period, then return early since the dictionary
135 // prefs cannot contain period in the path. 135 // prefs cannot contain period in the path.
136 if (network_id_string.find(".") != std::string::npos) 136 if (network_id_string.find(".") != std::string::npos)
137 return; 137 return;
138 138
139 prefs_->SetString(network_id_string, 139 prefs_->SetString(network_id_string,
(...skipping 23 matching lines...) Expand all
163 index_to_delete--; 163 index_to_delete--;
164 } 164 }
165 } 165 }
166 DCHECK_GE(kMaxCacheSize, prefs_->size()); 166 DCHECK_GE(kMaxCacheSize, prefs_->size());
167 167
168 // Notify the pref delegate so that it updates the prefs on the disk. 168 // Notify the pref delegate so that it updates the prefs on the disk.
169 pref_delegate_->SetDictionaryValue(*prefs_); 169 pref_delegate_->SetDictionaryValue(*prefs_);
170 } 170 }
171 171
172 ParsedPrefs NetworkQualitiesPrefsManager::ForceReadPrefsForTesting() const { 172 ParsedPrefs NetworkQualitiesPrefsManager::ForceReadPrefsForTesting() const {
173 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 173 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence());
174 std::unique_ptr<base::DictionaryValue> value( 174 std::unique_ptr<base::DictionaryValue> value(
175 pref_delegate_->GetDictionaryValue()); 175 pref_delegate_->GetDictionaryValue());
176 return ConvertDictionaryValueToMap(value.get()); 176 return ConvertDictionaryValueToMap(value.get());
177 } 177 }
178 178
179 } // namespace net 179 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698