OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http_server_properties_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "base/single_thread_task_runner.h" | |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/thread_task_runner_handle.h" | |
14 #include "base/values.h" | 16 #include "base/values.h" |
15 #include "chrome/browser/chrome_notification_types.h" | |
16 #include "chrome/common/pref_names.h" | |
17 #include "components/pref_registry/pref_registry_syncable.h" | |
18 #include "content/public/browser/browser_thread.h" | |
19 #include "content/public/browser/notification_details.h" | |
20 #include "content/public/browser/notification_source.h" | |
21 | 17 |
22 using content::BrowserThread; | 18 namespace net { |
23 | |
24 namespace chrome_browser_net { | |
25 | 19 |
26 namespace { | 20 namespace { |
27 | 21 |
28 // Time to wait before starting an update the http_server_properties_impl_ cache | 22 // Time to wait before starting an update the http_server_properties_impl_ cache |
29 // from preferences. Scheduling another update during this period will reset the | 23 // from preferences. Scheduling another update during this period will reset the |
30 // timer. | 24 // timer. |
31 const int64 kUpdateCacheDelayMs = 1000; | 25 const int64 kUpdateCacheDelayMs = 1000; |
32 | 26 |
33 // Time to wait before starting an update the preferences from the | 27 // Time to wait before starting an update the preferences from the |
34 // http_server_properties_impl_ cache. Scheduling another update during this | 28 // http_server_properties_impl_ cache. Scheduling another update during this |
(...skipping 20 matching lines...) Expand all Loading... | |
55 | 49 |
56 // Persist 300 MRU SupportsSpdyServerHostPortPairs. | 50 // Persist 300 MRU SupportsSpdyServerHostPortPairs. |
57 const int kMaxSupportsSpdyServerHostsToPersist = 300; | 51 const int kMaxSupportsSpdyServerHostsToPersist = 300; |
58 | 52 |
59 } // namespace | 53 } // namespace |
60 | 54 |
61 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
62 // HttpServerPropertiesManager | 56 // HttpServerPropertiesManager |
63 | 57 |
64 HttpServerPropertiesManager::HttpServerPropertiesManager( | 58 HttpServerPropertiesManager::HttpServerPropertiesManager( |
65 PrefService* pref_service) | 59 PrefService* pref_service, |
66 : pref_service_(pref_service), | 60 const char* pref_path, |
67 setting_prefs_(false) { | 61 scoped_refptr<base::SequencedTaskRunner> network_task_runner) |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 : pref_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
63 pref_service_(pref_service), | |
64 setting_prefs_(false), | |
65 path_(pref_path), | |
66 network_task_runner_(network_task_runner) { | |
69 DCHECK(pref_service); | 67 DCHECK(pref_service); |
70 ui_weak_ptr_factory_.reset( | 68 pref_weak_ptr_factory_.reset( |
71 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 69 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); |
72 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); | 70 pref_weak_ptr_ = pref_weak_ptr_factory_->GetWeakPtr(); |
73 ui_cache_update_timer_.reset( | 71 pref_cache_update_timer_.reset( |
74 new base::OneShotTimer<HttpServerPropertiesManager>); | 72 new base::OneShotTimer<HttpServerPropertiesManager>); |
75 pref_change_registrar_.Init(pref_service_); | 73 pref_change_registrar_.Init(pref_service_); |
76 pref_change_registrar_.Add( | 74 pref_change_registrar_.Add( |
77 prefs::kHttpServerProperties, | 75 path_, |
78 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, | 76 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, |
79 base::Unretained(this))); | 77 base::Unretained(this))); |
80 } | 78 } |
81 | 79 |
82 HttpServerPropertiesManager::~HttpServerPropertiesManager() { | 80 HttpServerPropertiesManager::~HttpServerPropertiesManager() { |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 81 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
84 io_weak_ptr_factory_.reset(); | 82 network_weak_ptr_factory_.reset(); |
85 } | 83 } |
86 | 84 |
87 void HttpServerPropertiesManager::InitializeOnIOThread() { | 85 void HttpServerPropertiesManager::InitializeOnNetworkThread() { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 86 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
89 io_weak_ptr_factory_.reset( | 87 network_weak_ptr_factory_.reset( |
90 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 88 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); |
91 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl()); | 89 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl()); |
92 | 90 |
93 io_prefs_update_timer_.reset( | 91 network_prefs_update_timer_.reset( |
94 new base::OneShotTimer<HttpServerPropertiesManager>); | 92 new base::OneShotTimer<HttpServerPropertiesManager>); |
95 | 93 |
96 BrowserThread::PostTask( | 94 pref_task_runner_->PostTask( |
97 BrowserThread::UI, | |
98 FROM_HERE, | 95 FROM_HERE, |
99 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI, | 96 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread, |
100 ui_weak_ptr_)); | 97 pref_weak_ptr_)); |
101 } | 98 } |
102 | 99 |
103 void HttpServerPropertiesManager::ShutdownOnUIThread() { | 100 void HttpServerPropertiesManager::ShutdownOnPrefThread() { |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
105 // Cancel any pending updates, and stop listening for pref change updates. | 102 // Cancel any pending updates, and stop listening for pref change updates. |
106 ui_cache_update_timer_->Stop(); | 103 pref_cache_update_timer_->Stop(); |
107 ui_weak_ptr_factory_.reset(); | 104 pref_weak_ptr_factory_.reset(); |
108 pref_change_registrar_.RemoveAll(); | 105 pref_change_registrar_.RemoveAll(); |
109 } | 106 } |
110 | 107 |
111 // static | 108 // static |
112 void HttpServerPropertiesManager::RegisterProfilePrefs( | |
113 user_prefs::PrefRegistrySyncable* prefs) { | |
114 prefs->RegisterDictionaryPref( | |
115 prefs::kHttpServerProperties, | |
116 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
117 } | |
118 | |
119 // static | |
120 void HttpServerPropertiesManager::SetVersion( | 109 void HttpServerPropertiesManager::SetVersion( |
121 base::DictionaryValue* http_server_properties_dict, | 110 base::DictionaryValue* http_server_properties_dict, |
122 int version_number) { | 111 int version_number) { |
123 if (version_number < 0) | 112 if (version_number < 0) |
124 version_number = kVersionNumber; | 113 version_number = kVersionNumber; |
125 DCHECK_LE(version_number, kVersionNumber); | 114 DCHECK_LE(version_number, kVersionNumber); |
126 if (version_number <= kVersionNumber) | 115 if (version_number <= kVersionNumber) |
127 http_server_properties_dict->SetInteger("version", version_number); | 116 http_server_properties_dict->SetInteger("version", version_number); |
128 } | 117 } |
129 | 118 |
130 // This is required for conformance with the HttpServerProperties interface. | 119 // This is required for conformance with the HttpServerProperties interface. |
131 base::WeakPtr<net::HttpServerProperties> | 120 base::WeakPtr<net::HttpServerProperties> |
132 HttpServerPropertiesManager::GetWeakPtr() { | 121 HttpServerPropertiesManager::GetWeakPtr() { |
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 122 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
134 return io_weak_ptr_factory_->GetWeakPtr(); | 123 return network_weak_ptr_factory_->GetWeakPtr(); |
135 } | 124 } |
136 | 125 |
137 void HttpServerPropertiesManager::Clear() { | 126 void HttpServerPropertiesManager::Clear() { |
138 Clear(base::Closure()); | 127 Clear(base::Closure()); |
139 } | 128 } |
140 | 129 |
141 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { | 130 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 131 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
143 | 132 |
144 http_server_properties_impl_->Clear(); | 133 http_server_properties_impl_->Clear(); |
145 UpdatePrefsFromCacheOnIO(completion); | 134 UpdatePrefsFromCacheOnNetworkThread(completion); |
146 } | 135 } |
147 | 136 |
148 bool HttpServerPropertiesManager::SupportsSpdy( | 137 bool HttpServerPropertiesManager::SupportsSpdy( |
149 const net::HostPortPair& server) { | 138 const net::HostPortPair& server) { |
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 139 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
151 return http_server_properties_impl_->SupportsSpdy(server); | 140 return http_server_properties_impl_->SupportsSpdy(server); |
152 } | 141 } |
153 | 142 |
154 void HttpServerPropertiesManager::SetSupportsSpdy( | 143 void HttpServerPropertiesManager::SetSupportsSpdy( |
155 const net::HostPortPair& server, | 144 const net::HostPortPair& server, |
156 bool support_spdy) { | 145 bool support_spdy) { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 146 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
158 | 147 |
159 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); | 148 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); |
160 ScheduleUpdatePrefsOnIO(); | 149 ScheduleUpdatePrefsOnNetworkThread(); |
161 } | 150 } |
162 | 151 |
163 bool HttpServerPropertiesManager::HasAlternateProtocol( | 152 bool HttpServerPropertiesManager::HasAlternateProtocol( |
164 const net::HostPortPair& server) { | 153 const net::HostPortPair& server) { |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 154 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
166 return http_server_properties_impl_->HasAlternateProtocol(server); | 155 return http_server_properties_impl_->HasAlternateProtocol(server); |
167 } | 156 } |
168 | 157 |
169 net::PortAlternateProtocolPair | 158 net::PortAlternateProtocolPair |
170 HttpServerPropertiesManager::GetAlternateProtocol( | 159 HttpServerPropertiesManager::GetAlternateProtocol( |
171 const net::HostPortPair& server) { | 160 const net::HostPortPair& server) { |
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 161 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
173 return http_server_properties_impl_->GetAlternateProtocol(server); | 162 return http_server_properties_impl_->GetAlternateProtocol(server); |
174 } | 163 } |
175 | 164 |
176 void HttpServerPropertiesManager::SetAlternateProtocol( | 165 void HttpServerPropertiesManager::SetAlternateProtocol( |
177 const net::HostPortPair& server, | 166 const net::HostPortPair& server, |
178 uint16 alternate_port, | 167 uint16 alternate_port, |
179 net::AlternateProtocol alternate_protocol) { | 168 net::AlternateProtocol alternate_protocol) { |
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 169 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
181 http_server_properties_impl_->SetAlternateProtocol( | 170 http_server_properties_impl_->SetAlternateProtocol( |
182 server, alternate_port, alternate_protocol); | 171 server, alternate_port, alternate_protocol); |
183 ScheduleUpdatePrefsOnIO(); | 172 ScheduleUpdatePrefsOnNetworkThread(); |
184 } | 173 } |
185 | 174 |
186 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( | 175 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( |
187 const net::HostPortPair& server) { | 176 const net::HostPortPair& server) { |
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 177 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
189 http_server_properties_impl_->SetBrokenAlternateProtocol(server); | 178 http_server_properties_impl_->SetBrokenAlternateProtocol(server); |
190 ScheduleUpdatePrefsOnIO(); | 179 ScheduleUpdatePrefsOnNetworkThread(); |
191 } | 180 } |
192 | 181 |
193 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( | 182 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( |
194 const net::HostPortPair& server) { | 183 const net::HostPortPair& server) { |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 184 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
196 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( | 185 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( |
197 server); | 186 server); |
198 } | 187 } |
199 | 188 |
200 void HttpServerPropertiesManager::ConfirmAlternateProtocol( | 189 void HttpServerPropertiesManager::ConfirmAlternateProtocol( |
201 const net::HostPortPair& server) { | 190 const net::HostPortPair& server) { |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 191 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
203 http_server_properties_impl_->ConfirmAlternateProtocol(server); | 192 http_server_properties_impl_->ConfirmAlternateProtocol(server); |
204 ScheduleUpdatePrefsOnIO(); | 193 ScheduleUpdatePrefsOnNetworkThread(); |
205 } | 194 } |
206 | 195 |
207 void HttpServerPropertiesManager::ClearAlternateProtocol( | 196 void HttpServerPropertiesManager::ClearAlternateProtocol( |
208 const net::HostPortPair& server) { | 197 const net::HostPortPair& server) { |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 198 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
210 http_server_properties_impl_->ClearAlternateProtocol(server); | 199 http_server_properties_impl_->ClearAlternateProtocol(server); |
211 ScheduleUpdatePrefsOnIO(); | 200 ScheduleUpdatePrefsOnNetworkThread(); |
212 } | 201 } |
213 | 202 |
214 const net::AlternateProtocolMap& | 203 const net::AlternateProtocolMap& |
215 HttpServerPropertiesManager::alternate_protocol_map() const { | 204 HttpServerPropertiesManager::alternate_protocol_map() const { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 205 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
217 return http_server_properties_impl_->alternate_protocol_map(); | 206 return http_server_properties_impl_->alternate_protocol_map(); |
218 } | 207 } |
219 | 208 |
220 void HttpServerPropertiesManager::SetAlternateProtocolExperiment( | 209 void HttpServerPropertiesManager::SetAlternateProtocolExperiment( |
221 net::AlternateProtocolExperiment experiment) { | 210 net::AlternateProtocolExperiment experiment) { |
222 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment); | 211 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment); |
223 } | 212 } |
224 | 213 |
225 net::AlternateProtocolExperiment | 214 net::AlternateProtocolExperiment |
226 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const { | 215 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const { |
227 return http_server_properties_impl_->GetAlternateProtocolExperiment(); | 216 return http_server_properties_impl_->GetAlternateProtocolExperiment(); |
228 } | 217 } |
229 | 218 |
230 const net::SettingsMap& | 219 const net::SettingsMap& HttpServerPropertiesManager::GetSpdySettings( |
231 HttpServerPropertiesManager::GetSpdySettings( | |
232 const net::HostPortPair& host_port_pair) { | 220 const net::HostPortPair& host_port_pair) { |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 221 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
234 return http_server_properties_impl_->GetSpdySettings(host_port_pair); | 222 return http_server_properties_impl_->GetSpdySettings(host_port_pair); |
235 } | 223 } |
236 | 224 |
237 bool HttpServerPropertiesManager::SetSpdySetting( | 225 bool HttpServerPropertiesManager::SetSpdySetting( |
238 const net::HostPortPair& host_port_pair, | 226 const net::HostPortPair& host_port_pair, |
239 net::SpdySettingsIds id, | 227 net::SpdySettingsIds id, |
240 net::SpdySettingsFlags flags, | 228 net::SpdySettingsFlags flags, |
241 uint32 value) { | 229 uint32 value) { |
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 230 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
243 bool persist = http_server_properties_impl_->SetSpdySetting( | 231 bool persist = http_server_properties_impl_->SetSpdySetting( |
244 host_port_pair, id, flags, value); | 232 host_port_pair, id, flags, value); |
245 if (persist) | 233 if (persist) |
246 ScheduleUpdatePrefsOnIO(); | 234 ScheduleUpdatePrefsOnNetworkThread(); |
247 return persist; | 235 return persist; |
248 } | 236 } |
249 | 237 |
250 void HttpServerPropertiesManager::ClearSpdySettings( | 238 void HttpServerPropertiesManager::ClearSpdySettings( |
251 const net::HostPortPair& host_port_pair) { | 239 const net::HostPortPair& host_port_pair) { |
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 240 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
253 http_server_properties_impl_->ClearSpdySettings(host_port_pair); | 241 http_server_properties_impl_->ClearSpdySettings(host_port_pair); |
254 ScheduleUpdatePrefsOnIO(); | 242 ScheduleUpdatePrefsOnNetworkThread(); |
255 } | 243 } |
256 | 244 |
257 void HttpServerPropertiesManager::ClearAllSpdySettings() { | 245 void HttpServerPropertiesManager::ClearAllSpdySettings() { |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 246 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
259 http_server_properties_impl_->ClearAllSpdySettings(); | 247 http_server_properties_impl_->ClearAllSpdySettings(); |
260 ScheduleUpdatePrefsOnIO(); | 248 ScheduleUpdatePrefsOnNetworkThread(); |
261 } | 249 } |
262 | 250 |
263 const net::SpdySettingsMap& | 251 const net::SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() |
264 HttpServerPropertiesManager::spdy_settings_map() const { | 252 const { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 253 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
266 return http_server_properties_impl_->spdy_settings_map(); | 254 return http_server_properties_impl_->spdy_settings_map(); |
267 } | 255 } |
268 | 256 |
269 void HttpServerPropertiesManager::SetServerNetworkStats( | 257 void HttpServerPropertiesManager::SetServerNetworkStats( |
270 const net::HostPortPair& host_port_pair, | 258 const net::HostPortPair& host_port_pair, |
271 NetworkStats stats) { | 259 NetworkStats stats) { |
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 260 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
273 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | 261 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); |
274 } | 262 } |
275 | 263 |
276 const HttpServerPropertiesManager::NetworkStats* | 264 const HttpServerPropertiesManager::NetworkStats* |
277 HttpServerPropertiesManager::GetServerNetworkStats( | 265 HttpServerPropertiesManager::GetServerNetworkStats( |
278 const net::HostPortPair& host_port_pair) const { | 266 const net::HostPortPair& host_port_pair) const { |
279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 267 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
280 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | 268 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); |
281 } | 269 } |
282 | 270 |
283 // | 271 // |
284 // Update the HttpServerPropertiesImpl's cache with data from preferences. | 272 // Update the HttpServerPropertiesImpl's cache with data from preferences. |
285 // | 273 // |
286 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() { | 274 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { |
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 275 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
288 // Cancel pending updates, if any. | 276 // Cancel pending updates, if any. |
289 ui_cache_update_timer_->Stop(); | 277 pref_cache_update_timer_->Stop(); |
290 StartCacheUpdateTimerOnUI( | 278 StartCacheUpdateTimerOnPrefThread( |
291 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); | 279 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); |
292 } | 280 } |
293 | 281 |
294 void HttpServerPropertiesManager::StartCacheUpdateTimerOnUI( | 282 void HttpServerPropertiesManager::StartCacheUpdateTimerOnPrefThread( |
295 base::TimeDelta delay) { | 283 base::TimeDelta delay) { |
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 284 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
297 ui_cache_update_timer_->Start( | 285 pref_cache_update_timer_->Start( |
298 FROM_HERE, delay, this, | 286 FROM_HERE, |
299 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI); | 287 delay, |
288 this, | |
289 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread); | |
300 } | 290 } |
301 | 291 |
302 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() { | 292 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { |
303 // The preferences can only be read on the UI thread. | 293 // The preferences can only be read on the UI thread. |
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 294 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
305 | 295 |
306 if (!pref_service_->HasPrefPath(prefs::kHttpServerProperties)) | 296 if (!pref_service_->HasPrefPath(path_)) |
307 return; | 297 return; |
308 | 298 |
309 bool detected_corrupted_prefs = false; | 299 bool detected_corrupted_prefs = false; |
310 const base::DictionaryValue& http_server_properties_dict = | 300 const base::DictionaryValue& http_server_properties_dict = |
311 *pref_service_->GetDictionary(prefs::kHttpServerProperties); | 301 *pref_service_->GetDictionary(path_); |
312 | 302 |
313 int version = kMissingVersion; | 303 int version = kMissingVersion; |
314 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion( | 304 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion("version", |
315 "version", &version)) { | 305 &version)) { |
316 DVLOG(1) << "Missing version. Clearing all properties."; | 306 DVLOG(1) << "Missing version. Clearing all properties."; |
317 return; | 307 return; |
318 } | 308 } |
319 | 309 |
320 // The properties for a given server is in | 310 // The properties for a given server is in |
321 // http_server_properties_dict["servers"][server]. | 311 // http_server_properties_dict["servers"][server]. |
322 const base::DictionaryValue* servers_dict = NULL; | 312 const base::DictionaryValue* servers_dict = NULL; |
323 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 313 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
324 "servers", &servers_dict)) { | 314 "servers", &servers_dict)) { |
325 DVLOG(1) << "Malformed http_server_properties for servers."; | 315 DVLOG(1) << "Malformed http_server_properties for servers."; |
326 return; | 316 return; |
327 } | 317 } |
328 | 318 |
329 // String is host/port pair of spdy server. | 319 // String is host/port pair of spdy server. |
330 scoped_ptr<StringVector> spdy_servers(new StringVector); | 320 scoped_ptr<StringVector> spdy_servers(new StringVector); |
331 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( | 321 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( |
332 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 322 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
333 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( | 323 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( |
334 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); | 324 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); |
(...skipping 28 matching lines...) Expand all Loading... | |
363 | 353 |
364 const base::DictionaryValue* server_pref_dict = NULL; | 354 const base::DictionaryValue* server_pref_dict = NULL; |
365 if (!it.value().GetAsDictionary(&server_pref_dict)) { | 355 if (!it.value().GetAsDictionary(&server_pref_dict)) { |
366 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 356 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
367 detected_corrupted_prefs = true; | 357 detected_corrupted_prefs = true; |
368 continue; | 358 continue; |
369 } | 359 } |
370 | 360 |
371 // Get if server supports Spdy. | 361 // Get if server supports Spdy. |
372 bool supports_spdy = false; | 362 bool supports_spdy = false; |
373 if ((server_pref_dict->GetBoolean( | 363 if ((server_pref_dict->GetBoolean("supports_spdy", &supports_spdy)) && |
374 "supports_spdy", &supports_spdy)) && supports_spdy) { | 364 supports_spdy) { |
375 spdy_servers->push_back(server_str); | 365 spdy_servers->push_back(server_str); |
376 } | 366 } |
377 | 367 |
378 // Get SpdySettings. | 368 // Get SpdySettings. |
379 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); | 369 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); |
380 const base::DictionaryValue* spdy_settings_dict = NULL; | 370 const base::DictionaryValue* spdy_settings_dict = NULL; |
381 if (server_pref_dict->GetDictionaryWithoutPathExpansion( | 371 if (server_pref_dict->GetDictionaryWithoutPathExpansion( |
382 "settings", &spdy_settings_dict)) { | 372 "settings", &spdy_settings_dict)) { |
383 net::SettingsMap settings_map; | 373 net::SettingsMap settings_map; |
384 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); | 374 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); |
385 !dict_it.IsAtEnd(); dict_it.Advance()) { | 375 !dict_it.IsAtEnd(); |
376 dict_it.Advance()) { | |
386 const std::string& id_str = dict_it.key(); | 377 const std::string& id_str = dict_it.key(); |
387 int id = 0; | 378 int id = 0; |
388 if (!base::StringToInt(id_str, &id)) { | 379 if (!base::StringToInt(id_str, &id)) { |
389 DVLOG(1) << "Malformed id in SpdySettings for server: " << | 380 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str; |
390 server_str; | |
391 NOTREACHED(); | 381 NOTREACHED(); |
392 continue; | 382 continue; |
393 } | 383 } |
394 int value = 0; | 384 int value = 0; |
395 if (!dict_it.value().GetAsInteger(&value)) { | 385 if (!dict_it.value().GetAsInteger(&value)) { |
396 DVLOG(1) << "Malformed value in SpdySettings for server: " << | 386 DVLOG(1) << "Malformed value in SpdySettings for server: " |
397 server_str; | 387 << server_str; |
398 NOTREACHED(); | 388 NOTREACHED(); |
399 continue; | 389 continue; |
400 } | 390 } |
401 net::SettingsFlagsAndValue flags_and_value( | 391 net::SettingsFlagsAndValue flags_and_value(net::SETTINGS_FLAG_PERSISTED, |
402 net::SETTINGS_FLAG_PERSISTED, value); | 392 value); |
403 settings_map[static_cast<net::SpdySettingsIds>(id)] = flags_and_value; | 393 settings_map[static_cast<net::SpdySettingsIds>(id)] = flags_and_value; |
404 } | 394 } |
405 spdy_settings_map->Put(server, settings_map); | 395 spdy_settings_map->Put(server, settings_map); |
406 } | 396 } |
407 | 397 |
408 // Get alternate_protocol server. | 398 // Get alternate_protocol server. |
409 DCHECK(alternate_protocol_map->Peek(server) == | 399 DCHECK(alternate_protocol_map->Peek(server) == |
410 alternate_protocol_map->end()); | 400 alternate_protocol_map->end()); |
411 const base::DictionaryValue* port_alternate_protocol_dict = NULL; | 401 const base::DictionaryValue* port_alternate_protocol_dict = NULL; |
412 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 402 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
413 "alternate_protocol", &port_alternate_protocol_dict)) { | 403 "alternate_protocol", &port_alternate_protocol_dict)) { |
414 continue; | 404 continue; |
415 } | 405 } |
416 | 406 |
417 if (count >= alternate_protocols_to_load) | 407 if (count >= alternate_protocols_to_load) |
418 continue; | 408 continue; |
419 do { | 409 do { |
420 int port = 0; | 410 int port = 0; |
421 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( | 411 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( |
422 "port", &port) || (port > (1 << 16))) { | 412 "port", &port) || |
413 (port > (1 << 16))) { | |
423 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 414 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
424 detected_corrupted_prefs = true; | 415 detected_corrupted_prefs = true; |
425 continue; | 416 continue; |
426 } | 417 } |
427 std::string protocol_str; | 418 std::string protocol_str; |
428 if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion( | 419 if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion( |
429 "protocol_str", &protocol_str)) { | 420 "protocol_str", &protocol_str)) { |
430 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 421 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
431 detected_corrupted_prefs = true; | 422 detected_corrupted_prefs = true; |
432 continue; | 423 continue; |
433 } | 424 } |
434 net::AlternateProtocol protocol = | 425 net::AlternateProtocol protocol = |
435 net::AlternateProtocolFromString(protocol_str); | 426 net::AlternateProtocolFromString(protocol_str); |
436 if (!net::IsAlternateProtocolValid(protocol)) { | 427 if (!net::IsAlternateProtocolValid(protocol)) { |
437 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 428 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
438 detected_corrupted_prefs = true; | 429 detected_corrupted_prefs = true; |
439 continue; | 430 continue; |
440 } | 431 } |
441 | 432 |
442 net::PortAlternateProtocolPair port_alternate_protocol; | 433 net::PortAlternateProtocolPair port_alternate_protocol; |
443 port_alternate_protocol.port = port; | 434 port_alternate_protocol.port = port; |
444 port_alternate_protocol.protocol = protocol; | 435 port_alternate_protocol.protocol = protocol; |
445 | 436 |
446 alternate_protocol_map->Put(server, port_alternate_protocol); | 437 alternate_protocol_map->Put(server, port_alternate_protocol); |
447 ++count; | 438 ++count; |
448 } while (false); | 439 } while (false); |
449 } | 440 } |
450 | 441 |
451 BrowserThread::PostTask( | 442 network_task_runner_->PostTask( |
452 BrowserThread::IO, | |
453 FROM_HERE, | 443 FROM_HERE, |
454 base::Bind(&HttpServerPropertiesManager:: | 444 base::Bind( |
455 UpdateCacheFromPrefsOnIO, | 445 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, |
456 base::Unretained(this), | 446 base::Unretained(this), |
457 base::Owned(spdy_servers.release()), | 447 base::Owned(spdy_servers.release()), |
458 base::Owned(spdy_settings_map.release()), | 448 base::Owned(spdy_settings_map.release()), |
459 base::Owned(alternate_protocol_map.release()), | 449 base::Owned(alternate_protocol_map.release()), |
460 alternate_protocol_experiment, | 450 alternate_protocol_experiment, |
461 detected_corrupted_prefs)); | 451 detected_corrupted_prefs)); |
462 } | 452 } |
463 | 453 |
464 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO( | 454 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( |
465 StringVector* spdy_servers, | 455 StringVector* spdy_servers, |
466 net::SpdySettingsMap* spdy_settings_map, | 456 net::SpdySettingsMap* spdy_settings_map, |
467 net::AlternateProtocolMap* alternate_protocol_map, | 457 net::AlternateProtocolMap* alternate_protocol_map, |
468 net::AlternateProtocolExperiment alternate_protocol_experiment, | 458 net::AlternateProtocolExperiment alternate_protocol_experiment, |
469 bool detected_corrupted_prefs) { | 459 bool detected_corrupted_prefs) { |
470 // Preferences have the master data because admins might have pushed new | 460 // Preferences have the master data because admins might have pushed new |
471 // preferences. Update the cached data with new data from preferences. | 461 // preferences. Update the cached data with new data from preferences. |
472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 462 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
473 | 463 |
474 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | 464 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); |
475 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 465 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
476 | 466 |
477 // Update the cached data and use the new spdy_settings from preferences. | 467 // Update the cached data and use the new spdy_settings from preferences. |
478 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | 468 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); |
479 http_server_properties_impl_->InitializeSpdySettingsServers( | 469 http_server_properties_impl_->InitializeSpdySettingsServers( |
480 spdy_settings_map); | 470 spdy_settings_map); |
481 | 471 |
482 // Update the cached data and use the new Alternate-Protocol server list from | 472 // Update the cached data and use the new Alternate-Protocol server list from |
483 // preferences. | 473 // preferences. |
484 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | 474 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", |
485 alternate_protocol_map->size()); | 475 alternate_protocol_map->size()); |
486 http_server_properties_impl_->InitializeAlternateProtocolServers( | 476 http_server_properties_impl_->InitializeAlternateProtocolServers( |
487 alternate_protocol_map); | 477 alternate_protocol_map); |
488 http_server_properties_impl_->SetAlternateProtocolExperiment( | 478 http_server_properties_impl_->SetAlternateProtocolExperiment( |
489 alternate_protocol_experiment); | 479 alternate_protocol_experiment); |
490 | 480 |
491 // Update the prefs with what we have read (delete all corrupted prefs). | 481 // Update the prefs with what we have read (delete all corrupted prefs). |
492 if (detected_corrupted_prefs) | 482 if (detected_corrupted_prefs) |
493 ScheduleUpdatePrefsOnIO(); | 483 ScheduleUpdatePrefsOnNetworkThread(); |
494 } | 484 } |
495 | 485 |
496 | |
497 // | 486 // |
498 // Update Preferences with data from the cached data. | 487 // Update Preferences with data from the cached data. |
499 // | 488 // |
500 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { | 489 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread() { |
501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 490 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
502 // Cancel pending updates, if any. | 491 // Cancel pending updates, if any. |
503 io_prefs_update_timer_->Stop(); | 492 network_prefs_update_timer_->Stop(); |
504 StartPrefsUpdateTimerOnIO( | 493 StartPrefsUpdateTimerOnNetworkThread( |
505 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs)); | 494 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs)); |
506 } | 495 } |
507 | 496 |
508 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO( | 497 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnNetworkThread( |
509 base::TimeDelta delay) { | 498 base::TimeDelta delay) { |
510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 499 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
511 // This is overridden in tests to post the task without the delay. | 500 // This is overridden in tests to post the task without the delay. |
512 io_prefs_update_timer_->Start( | 501 network_prefs_update_timer_->Start( |
513 FROM_HERE, delay, this, | 502 FROM_HERE, |
514 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO); | 503 delay, |
504 this, | |
505 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread); | |
515 } | 506 } |
516 | 507 |
517 // This is required so we can set this as the callback for a timer. | 508 // This is required so we can set this as the callback for a timer. |
518 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() { | 509 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() { |
519 UpdatePrefsFromCacheOnIO(base::Closure()); | 510 UpdatePrefsFromCacheOnNetworkThread(base::Closure()); |
520 } | 511 } |
521 | 512 |
522 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO( | 513 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( |
523 const base::Closure& completion) { | 514 const base::Closure& completion) { |
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 515 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
525 | 516 |
526 base::ListValue* spdy_server_list = new base::ListValue; | 517 base::ListValue* spdy_server_list = new base::ListValue; |
527 http_server_properties_impl_->GetSpdyServerList( | 518 http_server_properties_impl_->GetSpdyServerList( |
528 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); | 519 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); |
529 | 520 |
530 net::SpdySettingsMap* spdy_settings_map = | 521 net::SpdySettingsMap* spdy_settings_map = |
531 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist); | 522 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist); |
532 const net::SpdySettingsMap& main_map = | 523 const net::SpdySettingsMap& main_map = |
533 http_server_properties_impl_->spdy_settings_map(); | 524 http_server_properties_impl_->spdy_settings_map(); |
534 int count = 0; | 525 int count = 0; |
(...skipping 19 matching lines...) Expand all Loading... | |
554 if (!canonical_suffix.empty()) { | 545 if (!canonical_suffix.empty()) { |
555 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | 546 if (persisted_map.find(canonical_suffix) != persisted_map.end()) |
556 continue; | 547 continue; |
557 persisted_map[canonical_suffix] = true; | 548 persisted_map[canonical_suffix] = true; |
558 } | 549 } |
559 alternate_protocol_map->Put(server, it->second); | 550 alternate_protocol_map->Put(server, it->second); |
560 ++count; | 551 ++count; |
561 } | 552 } |
562 | 553 |
563 // Update the preferences on the UI thread. | 554 // Update the preferences on the UI thread. |
564 BrowserThread::PostTask( | 555 pref_task_runner_->PostTask( |
565 BrowserThread::UI, | |
566 FROM_HERE, | 556 FROM_HERE, |
567 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI, | 557 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnPrefThread, |
568 ui_weak_ptr_, | 558 pref_weak_ptr_, |
569 base::Owned(spdy_server_list), | 559 base::Owned(spdy_server_list), |
570 base::Owned(spdy_settings_map), | 560 base::Owned(spdy_settings_map), |
571 base::Owned(alternate_protocol_map), | 561 base::Owned(alternate_protocol_map), |
572 completion)); | 562 completion)); |
573 } | 563 } |
574 | 564 |
575 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 565 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
576 // and PortAlternateProtocolPair preferences for a server. This is used only in | 566 // and PortAlternateProtocolPair preferences for a server. This is used only in |
577 // UpdatePrefsOnUI. | 567 // UpdatePrefsOnUI. |
578 struct ServerPref { | 568 struct ServerPref { |
579 ServerPref() | 569 ServerPref() |
580 : supports_spdy(false), | 570 : supports_spdy(false), settings_map(NULL), alternate_protocol(NULL) {} |
581 settings_map(NULL), | |
582 alternate_protocol(NULL) { | |
583 } | |
584 ServerPref(bool supports_spdy, | 571 ServerPref(bool supports_spdy, |
585 const net::SettingsMap* settings_map, | 572 const net::SettingsMap* settings_map, |
586 const net::PortAlternateProtocolPair* alternate_protocol) | 573 const net::PortAlternateProtocolPair* alternate_protocol) |
587 : supports_spdy(supports_spdy), | 574 : supports_spdy(supports_spdy), |
588 settings_map(settings_map), | 575 settings_map(settings_map), |
589 alternate_protocol(alternate_protocol) { | 576 alternate_protocol(alternate_protocol) {} |
590 } | |
591 bool supports_spdy; | 577 bool supports_spdy; |
592 const net::SettingsMap* settings_map; | 578 const net::SettingsMap* settings_map; |
593 const net::PortAlternateProtocolPair* alternate_protocol; | 579 const net::PortAlternateProtocolPair* alternate_protocol; |
594 }; | 580 }; |
595 | 581 |
596 void HttpServerPropertiesManager::UpdatePrefsOnUI( | 582 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
597 base::ListValue* spdy_server_list, | 583 base::ListValue* spdy_server_list, |
598 net::SpdySettingsMap* spdy_settings_map, | 584 net::SpdySettingsMap* spdy_settings_map, |
599 net::AlternateProtocolMap* alternate_protocol_map, | 585 net::AlternateProtocolMap* alternate_protocol_map, |
600 const base::Closure& completion) { | 586 const base::Closure& completion) { |
601 | |
602 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; | 587 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; |
603 ServerPrefMap server_pref_map; | 588 ServerPrefMap server_pref_map; |
604 | 589 |
605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 590 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
606 | 591 |
607 // Add servers that support spdy to server_pref_map. | 592 // Add servers that support spdy to server_pref_map. |
608 std::string s; | 593 std::string s; |
609 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); | 594 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); |
610 list_it != spdy_server_list->end(); ++list_it) { | 595 list_it != spdy_server_list->end(); |
596 ++list_it) { | |
611 if ((*list_it)->GetAsString(&s)) { | 597 if ((*list_it)->GetAsString(&s)) { |
612 net::HostPortPair server = net::HostPortPair::FromString(s); | 598 net::HostPortPair server = net::HostPortPair::FromString(s); |
613 | 599 |
614 ServerPrefMap::iterator it = server_pref_map.find(server); | 600 ServerPrefMap::iterator it = server_pref_map.find(server); |
615 if (it == server_pref_map.end()) { | 601 if (it == server_pref_map.end()) { |
616 ServerPref server_pref(true, NULL, NULL); | 602 ServerPref server_pref(true, NULL, NULL); |
617 server_pref_map[server] = server_pref; | 603 server_pref_map[server] = server_pref; |
618 } else { | 604 } else { |
619 it->second.supports_spdy = true; | 605 it->second.supports_spdy = true; |
620 } | 606 } |
621 } | 607 } |
622 } | 608 } |
623 | 609 |
624 // Add servers that have SpdySettings to server_pref_map. | 610 // Add servers that have SpdySettings to server_pref_map. |
625 for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); | 611 for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
626 map_it != spdy_settings_map->end(); ++map_it) { | 612 map_it != spdy_settings_map->end(); |
613 ++map_it) { | |
627 const net::HostPortPair& server = map_it->first; | 614 const net::HostPortPair& server = map_it->first; |
628 | 615 |
629 ServerPrefMap::iterator it = server_pref_map.find(server); | 616 ServerPrefMap::iterator it = server_pref_map.find(server); |
630 if (it == server_pref_map.end()) { | 617 if (it == server_pref_map.end()) { |
631 ServerPref server_pref(false, &map_it->second, NULL); | 618 ServerPref server_pref(false, &map_it->second, NULL); |
632 server_pref_map[server] = server_pref; | 619 server_pref_map[server] = server_pref; |
633 } else { | 620 } else { |
634 it->second.settings_map = &map_it->second; | 621 it->second.settings_map = &map_it->second; |
635 } | 622 } |
636 } | 623 } |
637 | 624 |
638 // Add AlternateProtocol servers to server_pref_map. | 625 // Add AlternateProtocol servers to server_pref_map. |
639 for (net::AlternateProtocolMap::const_iterator map_it = | 626 for (net::AlternateProtocolMap::const_iterator map_it = |
640 alternate_protocol_map->begin(); | 627 alternate_protocol_map->begin(); |
641 map_it != alternate_protocol_map->end(); ++map_it) { | 628 map_it != alternate_protocol_map->end(); |
629 ++map_it) { | |
642 const net::HostPortPair& server = map_it->first; | 630 const net::HostPortPair& server = map_it->first; |
643 const net::PortAlternateProtocolPair& port_alternate_protocol = | 631 const net::PortAlternateProtocolPair& port_alternate_protocol = |
644 map_it->second; | 632 map_it->second; |
645 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | 633 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { |
646 continue; | 634 continue; |
647 } | 635 } |
648 | 636 |
649 ServerPrefMap::iterator it = server_pref_map.find(server); | 637 ServerPrefMap::iterator it = server_pref_map.find(server); |
650 if (it == server_pref_map.end()) { | 638 if (it == server_pref_map.end()) { |
651 ServerPref server_pref(false, NULL, &map_it->second); | 639 ServerPref server_pref(false, NULL, &map_it->second); |
652 server_pref_map[server] = server_pref; | 640 server_pref_map[server] = server_pref; |
653 } else { | 641 } else { |
654 it->second.alternate_protocol = &map_it->second; | 642 it->second.alternate_protocol = &map_it->second; |
655 } | 643 } |
656 } | 644 } |
657 | 645 |
658 // Persist the prefs::kHttpServerProperties. | 646 // Persist properties to the |path_|. |
659 base::DictionaryValue http_server_properties_dict; | 647 base::DictionaryValue http_server_properties_dict; |
660 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 648 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
661 for (ServerPrefMap::const_iterator map_it = | 649 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); |
662 server_pref_map.begin(); | 650 map_it != server_pref_map.end(); |
663 map_it != server_pref_map.end(); ++map_it) { | 651 ++map_it) { |
664 const net::HostPortPair& server = map_it->first; | 652 const net::HostPortPair& server = map_it->first; |
665 const ServerPref& server_pref = map_it->second; | 653 const ServerPref& server_pref = map_it->second; |
666 | 654 |
667 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 655 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
668 | 656 |
669 // Save supports_spdy. | 657 // Save supports_spdy. |
670 if (server_pref.supports_spdy) | 658 if (server_pref.supports_spdy) |
671 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); | 659 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); |
672 | 660 |
673 // Save SPDY settings. | 661 // Save SPDY settings. |
674 if (server_pref.settings_map) { | 662 if (server_pref.settings_map) { |
675 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue; | 663 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue; |
676 for (net::SettingsMap::const_iterator it = | 664 for (net::SettingsMap::const_iterator it = |
677 server_pref.settings_map->begin(); | 665 server_pref.settings_map->begin(); |
678 it != server_pref.settings_map->end(); ++it) { | 666 it != server_pref.settings_map->end(); |
667 ++it) { | |
679 net::SpdySettingsIds id = it->first; | 668 net::SpdySettingsIds id = it->first; |
680 uint32 value = it->second.second; | 669 uint32 value = it->second.second; |
681 std::string key = base::StringPrintf("%u", id); | 670 std::string key = base::StringPrintf("%u", id); |
682 spdy_settings_dict->SetInteger(key, value); | 671 spdy_settings_dict->SetInteger(key, value); |
683 } | 672 } |
684 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); | 673 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); |
685 } | 674 } |
686 | 675 |
687 // Save alternate_protocol. | 676 // Save alternate_protocol. |
688 if (server_pref.alternate_protocol) { | 677 if (server_pref.alternate_protocol) { |
689 base::DictionaryValue* port_alternate_protocol_dict = | 678 base::DictionaryValue* port_alternate_protocol_dict = |
690 new base::DictionaryValue; | 679 new base::DictionaryValue; |
691 const net::PortAlternateProtocolPair* port_alternate_protocol = | 680 const net::PortAlternateProtocolPair* port_alternate_protocol = |
692 server_pref.alternate_protocol; | 681 server_pref.alternate_protocol; |
693 port_alternate_protocol_dict->SetInteger( | 682 port_alternate_protocol_dict->SetInteger("port", |
694 "port", port_alternate_protocol->port); | 683 port_alternate_protocol->port); |
695 const char* protocol_str = | 684 const char* protocol_str = |
696 net::AlternateProtocolToString(port_alternate_protocol->protocol); | 685 net::AlternateProtocolToString(port_alternate_protocol->protocol); |
697 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); | 686 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); |
698 server_pref_dict->SetWithoutPathExpansion( | 687 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
699 "alternate_protocol", port_alternate_protocol_dict); | 688 port_alternate_protocol_dict); |
700 } | 689 } |
701 | 690 |
702 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); | 691 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); |
703 } | 692 } |
704 | 693 |
705 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); | 694 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); |
706 SetVersion(&http_server_properties_dict, kVersionNumber); | 695 SetVersion(&http_server_properties_dict, kVersionNumber); |
707 setting_prefs_ = true; | 696 setting_prefs_ = true; |
708 pref_service_->Set(prefs::kHttpServerProperties, | 697 pref_service_->Set(path_, http_server_properties_dict); |
709 http_server_properties_dict); | |
710 setting_prefs_ = false; | 698 setting_prefs_ = false; |
711 | 699 |
712 // Note that |completion| will be fired after we have written everything to | 700 // Note that |completion| will be fired after we have written everything to |
713 // the Preferences, but likely before these changes are serialized to disk. | 701 // the Preferences, but likely before these changes are serialized to disk. |
714 // This is not a problem though, as JSONPrefStore guarantees that this will | 702 // This is not a problem though, as JSONPrefStore guarantees that this will |
715 // happen, pretty soon, and even in the case we shut down immediately. | 703 // happen, pretty soon, and even in the case we shut down immediately. |
716 if (!completion.is_null()) | 704 if (!completion.is_null()) |
717 completion.Run(); | 705 completion.Run(); |
718 } | 706 } |
719 | 707 |
720 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 708 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 709 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
722 if (!setting_prefs_) | 710 if (!setting_prefs_) |
723 ScheduleUpdateCacheOnUI(); | 711 ScheduleUpdateCacheOnPrefThread(); |
724 } | 712 } |
725 | 713 |
726 } // namespace chrome_browser_net | 714 } // namespace chrome_browser_net |
droger
2014/07/09 12:26:08
Fix the comment.
mef
2014/07/09 12:44:50
Done.
| |
OLD | NEW |