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 "chrome/browser/net/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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace chrome_browser_net { | 24 namespace chrome_browser_net { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Time to wait before starting an update the http_server_properties_impl_ cache | 28 // 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 | 29 // from preferences. Scheduling another update during this period will reset the |
30 // timer. | 30 // timer. |
31 const int64 kUpdateCacheDelayMs = 1000; | 31 const int64 kUpdateCacheDelayMs = 1000; |
32 | 32 |
33 // Time to wait before starting an update the preferences from the | |
34 // http_server_properties_impl_ cache. Scheduling another update during this | |
35 // period will reset the timer. | |
36 const int64 kUpdatePrefsDelayMs = 5000; | |
37 | |
38 // "version" 0 indicates, http_server_properties doesn't have "version" | 33 // "version" 0 indicates, http_server_properties doesn't have "version" |
39 // property. | 34 // property. |
40 const int kMissingVersion = 0; | 35 const int kMissingVersion = 0; |
41 | 36 |
42 // The version number of persisted http_server_properties. | 37 // The version number of persisted http_server_properties. |
43 const int kVersionNumber = 3; | 38 const int kVersionNumber = 3; |
44 | 39 |
45 typedef std::vector<std::string> StringVector; | 40 typedef std::vector<std::string> StringVector; |
46 | 41 |
47 // Load either 200 or 1000 servers based on a coin flip. | 42 // Load either 200 or 1000 servers based on a coin flip. |
48 const int k200AlternateProtocolHostsToLoad = 200; | 43 const int k200AlternateProtocolHostsToLoad = 200; |
49 const int k1000AlternateProtocolHostsToLoad = 1000; | 44 const int k1000AlternateProtocolHostsToLoad = 1000; |
50 // Persist 1000 MRU AlternateProtocolHostPortPairs. | 45 // Persist 1000 MRU AlternateProtocolHostPortPairs. |
51 const int kMaxAlternateProtocolHostsToPersist = 1000; | 46 const int kMaxAlternateProtocolHostsToPersist = 1000; |
52 | 47 |
53 // Persist 200 MRU SpdySettingsHostPortPairs. | 48 // Persist 200 MRU SpdySettingsHostPortPairs. |
54 const int kMaxSpdySettingsHostsToPersist = 200; | 49 const int kMaxSpdySettingsHostsToPersist = 200; |
55 | 50 |
56 // Persist 300 MRU SupportsSpdyServerHostPortPairs. | |
57 const int kMaxSupportsSpdyServerHostsToPersist = 300; | |
58 | |
59 } // namespace | 51 } // namespace |
60 | 52 |
61 //////////////////////////////////////////////////////////////////////////////// | 53 //////////////////////////////////////////////////////////////////////////////// |
62 // HttpServerPropertiesManager | 54 // HttpServerPropertiesManager |
63 | 55 |
64 HttpServerPropertiesManager::HttpServerPropertiesManager( | 56 HttpServerPropertiesManager::HttpServerPropertiesManager( |
65 PrefService* pref_service) | 57 PrefService* pref_service) |
66 : pref_service_(pref_service), | 58 : pref_service_(pref_service), |
67 setting_prefs_(false) { | 59 setting_prefs_(false) { |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
69 DCHECK(pref_service); | 61 DCHECK(pref_service); |
70 ui_weak_ptr_factory_.reset( | 62 ui_weak_ptr_factory_.reset( |
71 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 63 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); |
72 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); | 64 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); |
73 ui_cache_update_timer_.reset( | 65 ui_cache_update_timer_.reset( |
74 new base::OneShotTimer<HttpServerPropertiesManager>); | 66 new base::OneShotTimer<HttpServerPropertiesManager>); |
75 pref_change_registrar_.Init(pref_service_); | 67 pref_change_registrar_.Init(pref_service_); |
76 pref_change_registrar_.Add( | 68 pref_change_registrar_.Add( |
77 prefs::kHttpServerProperties, | 69 prefs::kHttpServerProperties, |
78 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, | 70 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, |
79 base::Unretained(this))); | 71 base::Unretained(this))); |
80 } | 72 } |
81 | 73 |
82 HttpServerPropertiesManager::~HttpServerPropertiesManager() { | 74 HttpServerPropertiesManager::~HttpServerPropertiesManager() { |
| 75 // Why does destruction happen on the IO thread? |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
84 io_weak_ptr_factory_.reset(); | |
85 } | 77 } |
86 | 78 |
87 void HttpServerPropertiesManager::InitializeOnIOThread() { | 79 void HttpServerPropertiesManager::InitializeOnIOThread() { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
89 io_weak_ptr_factory_.reset( | 81 ChromeHttpServerProperties::UpdateCallback io_callback = |
90 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 82 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnIO, |
91 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl()); | 83 ui_weak_ptr_); |
92 | 84 |
93 io_prefs_update_timer_.reset( | 85 http_server_properties_impl_.reset( |
94 new base::OneShotTimer<HttpServerPropertiesManager>); | 86 new ChromeHttpServerProperties(io_callback)); |
95 | 87 |
96 BrowserThread::PostTask( | 88 BrowserThread::PostTask( |
97 BrowserThread::UI, | 89 BrowserThread::UI, |
98 FROM_HERE, | 90 FROM_HERE, |
99 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI, | 91 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI, |
100 ui_weak_ptr_)); | 92 ui_weak_ptr_)); |
101 } | 93 } |
102 | 94 |
103 void HttpServerPropertiesManager::ShutdownOnUIThread() { | 95 void HttpServerPropertiesManager::ShutdownOnUIThread() { |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
105 // Cancel any pending updates, and stop listening for pref change updates. | 97 // Cancel any pending updates, and stop listening for pref change updates. |
106 ui_cache_update_timer_->Stop(); | 98 ui_cache_update_timer_->Stop(); |
107 ui_weak_ptr_factory_.reset(); | 99 ui_weak_ptr_factory_.reset(); |
108 pref_change_registrar_.RemoveAll(); | 100 pref_change_registrar_.RemoveAll(); |
109 } | 101 } |
110 | 102 |
| 103 net::HttpServerProperties* HttpServerPropertiesManager::http_server_properties()
{ |
| 104 return http_server_properties_impl_.get(); |
| 105 } |
| 106 |
| 107 |
111 // static | 108 // static |
112 void HttpServerPropertiesManager::RegisterProfilePrefs( | 109 void HttpServerPropertiesManager::RegisterProfilePrefs( |
113 user_prefs::PrefRegistrySyncable* prefs) { | 110 user_prefs::PrefRegistrySyncable* prefs) { |
114 prefs->RegisterDictionaryPref( | 111 prefs->RegisterDictionaryPref( |
115 prefs::kHttpServerProperties, | 112 prefs::kHttpServerProperties, |
116 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 113 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
117 } | 114 } |
118 | 115 |
119 // static | 116 // static |
120 void HttpServerPropertiesManager::SetVersion( | 117 void HttpServerPropertiesManager::SetVersion( |
121 base::DictionaryValue* http_server_properties_dict, | 118 base::DictionaryValue* http_server_properties_dict, |
122 int version_number) { | 119 int version_number) { |
123 if (version_number < 0) | 120 if (version_number < 0) |
124 version_number = kVersionNumber; | 121 version_number = kVersionNumber; |
125 DCHECK_LE(version_number, kVersionNumber); | 122 DCHECK_LE(version_number, kVersionNumber); |
126 if (version_number <= kVersionNumber) | 123 if (version_number <= kVersionNumber) |
127 http_server_properties_dict->SetInteger("version", version_number); | 124 http_server_properties_dict->SetInteger("version", version_number); |
128 } | 125 } |
129 | 126 |
130 // This is required for conformance with the HttpServerProperties interface. | |
131 base::WeakPtr<net::HttpServerProperties> | |
132 HttpServerPropertiesManager::GetWeakPtr() { | |
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
134 return io_weak_ptr_factory_->GetWeakPtr(); | |
135 } | |
136 | |
137 void HttpServerPropertiesManager::Clear() { | |
138 Clear(base::Closure()); | |
139 } | |
140 | |
141 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { | |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
143 | |
144 http_server_properties_impl_->Clear(); | |
145 UpdatePrefsFromCacheOnIO(completion); | |
146 } | |
147 | |
148 bool HttpServerPropertiesManager::SupportsSpdy( | |
149 const net::HostPortPair& server) { | |
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
151 return http_server_properties_impl_->SupportsSpdy(server); | |
152 } | |
153 | |
154 void HttpServerPropertiesManager::SetSupportsSpdy( | |
155 const net::HostPortPair& server, | |
156 bool support_spdy) { | |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
158 | |
159 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); | |
160 ScheduleUpdatePrefsOnIO(); | |
161 } | |
162 | |
163 bool HttpServerPropertiesManager::HasAlternateProtocol( | |
164 const net::HostPortPair& server) { | |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
166 return http_server_properties_impl_->HasAlternateProtocol(server); | |
167 } | |
168 | |
169 net::PortAlternateProtocolPair | |
170 HttpServerPropertiesManager::GetAlternateProtocol( | |
171 const net::HostPortPair& server) { | |
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
173 return http_server_properties_impl_->GetAlternateProtocol(server); | |
174 } | |
175 | |
176 void HttpServerPropertiesManager::SetAlternateProtocol( | |
177 const net::HostPortPair& server, | |
178 uint16 alternate_port, | |
179 net::AlternateProtocol alternate_protocol) { | |
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
181 http_server_properties_impl_->SetAlternateProtocol( | |
182 server, alternate_port, alternate_protocol); | |
183 ScheduleUpdatePrefsOnIO(); | |
184 } | |
185 | |
186 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( | |
187 const net::HostPortPair& server) { | |
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
189 http_server_properties_impl_->SetBrokenAlternateProtocol(server); | |
190 ScheduleUpdatePrefsOnIO(); | |
191 } | |
192 | |
193 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( | |
194 const net::HostPortPair& server) { | |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
196 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( | |
197 server); | |
198 } | |
199 | |
200 void HttpServerPropertiesManager::ConfirmAlternateProtocol( | |
201 const net::HostPortPair& server) { | |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
203 http_server_properties_impl_->ConfirmAlternateProtocol(server); | |
204 ScheduleUpdatePrefsOnIO(); | |
205 } | |
206 | |
207 void HttpServerPropertiesManager::ClearAlternateProtocol( | |
208 const net::HostPortPair& server) { | |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
210 http_server_properties_impl_->ClearAlternateProtocol(server); | |
211 ScheduleUpdatePrefsOnIO(); | |
212 } | |
213 | |
214 const net::AlternateProtocolMap& | |
215 HttpServerPropertiesManager::alternate_protocol_map() const { | |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
217 return http_server_properties_impl_->alternate_protocol_map(); | |
218 } | |
219 | |
220 void HttpServerPropertiesManager::SetAlternateProtocolExperiment( | |
221 net::AlternateProtocolExperiment experiment) { | |
222 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment); | |
223 } | |
224 | |
225 net::AlternateProtocolExperiment | |
226 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const { | |
227 return http_server_properties_impl_->GetAlternateProtocolExperiment(); | |
228 } | |
229 | |
230 const net::SettingsMap& | |
231 HttpServerPropertiesManager::GetSpdySettings( | |
232 const net::HostPortPair& host_port_pair) { | |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
234 return http_server_properties_impl_->GetSpdySettings(host_port_pair); | |
235 } | |
236 | |
237 bool HttpServerPropertiesManager::SetSpdySetting( | |
238 const net::HostPortPair& host_port_pair, | |
239 net::SpdySettingsIds id, | |
240 net::SpdySettingsFlags flags, | |
241 uint32 value) { | |
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
243 bool persist = http_server_properties_impl_->SetSpdySetting( | |
244 host_port_pair, id, flags, value); | |
245 if (persist) | |
246 ScheduleUpdatePrefsOnIO(); | |
247 return persist; | |
248 } | |
249 | |
250 void HttpServerPropertiesManager::ClearSpdySettings( | |
251 const net::HostPortPair& host_port_pair) { | |
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
253 http_server_properties_impl_->ClearSpdySettings(host_port_pair); | |
254 ScheduleUpdatePrefsOnIO(); | |
255 } | |
256 | |
257 void HttpServerPropertiesManager::ClearAllSpdySettings() { | |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
259 http_server_properties_impl_->ClearAllSpdySettings(); | |
260 ScheduleUpdatePrefsOnIO(); | |
261 } | |
262 | |
263 const net::SpdySettingsMap& | |
264 HttpServerPropertiesManager::spdy_settings_map() const { | |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
266 return http_server_properties_impl_->spdy_settings_map(); | |
267 } | |
268 | |
269 void HttpServerPropertiesManager::SetServerNetworkStats( | |
270 const net::HostPortPair& host_port_pair, | |
271 NetworkStats stats) { | |
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
273 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | |
274 } | |
275 | |
276 const HttpServerPropertiesManager::NetworkStats* | |
277 HttpServerPropertiesManager::GetServerNetworkStats( | |
278 const net::HostPortPair& host_port_pair) const { | |
279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
280 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | |
281 } | |
282 | |
283 // | 127 // |
284 // Update the HttpServerPropertiesImpl's cache with data from preferences. | 128 // Update the HttpServerPropertiesImpl's cache with data from preferences. |
285 // | 129 // |
286 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() { | 130 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() { |
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
288 // Cancel pending updates, if any. | 132 // Cancel pending updates, if any. |
289 ui_cache_update_timer_->Stop(); | 133 ui_cache_update_timer_->Stop(); |
290 StartCacheUpdateTimerOnUI( | 134 StartCacheUpdateTimerOnUI( |
291 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); | 135 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); |
292 } | 136 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 port_alternate_protocol.protocol = protocol; | 288 port_alternate_protocol.protocol = protocol; |
445 | 289 |
446 alternate_protocol_map->Put(server, port_alternate_protocol); | 290 alternate_protocol_map->Put(server, port_alternate_protocol); |
447 ++count; | 291 ++count; |
448 } while (false); | 292 } while (false); |
449 } | 293 } |
450 | 294 |
451 BrowserThread::PostTask( | 295 BrowserThread::PostTask( |
452 BrowserThread::IO, | 296 BrowserThread::IO, |
453 FROM_HERE, | 297 FROM_HERE, |
454 base::Bind(&HttpServerPropertiesManager:: | 298 base::Bind(&ChromeHttpServerProperties:: |
455 UpdateCacheFromPrefsOnIO, | 299 UpdateCacheFromPrefsOnIO, |
456 base::Unretained(this), | 300 base::Unretained(http_server_properties_impl_.get()), |
457 base::Owned(spdy_servers.release()), | 301 base::Owned(spdy_servers.release()), |
458 base::Owned(spdy_settings_map.release()), | 302 base::Owned(spdy_settings_map.release()), |
459 base::Owned(alternate_protocol_map.release()), | 303 base::Owned(alternate_protocol_map.release()), |
460 alternate_protocol_experiment, | 304 alternate_protocol_experiment, |
461 detected_corrupted_prefs)); | 305 detected_corrupted_prefs)); |
462 } | 306 } |
463 | 307 |
464 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO( | |
465 StringVector* spdy_servers, | |
466 net::SpdySettingsMap* spdy_settings_map, | |
467 net::AlternateProtocolMap* alternate_protocol_map, | |
468 net::AlternateProtocolExperiment alternate_protocol_experiment, | |
469 bool detected_corrupted_prefs) { | |
470 // Preferences have the master data because admins might have pushed new | |
471 // preferences. Update the cached data with new data from preferences. | |
472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
473 | |
474 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | |
475 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | |
476 | |
477 // Update the cached data and use the new spdy_settings from preferences. | |
478 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | |
479 http_server_properties_impl_->InitializeSpdySettingsServers( | |
480 spdy_settings_map); | |
481 | |
482 // Update the cached data and use the new Alternate-Protocol server list from | |
483 // preferences. | |
484 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | |
485 alternate_protocol_map->size()); | |
486 http_server_properties_impl_->InitializeAlternateProtocolServers( | |
487 alternate_protocol_map); | |
488 http_server_properties_impl_->SetAlternateProtocolExperiment( | |
489 alternate_protocol_experiment); | |
490 | |
491 // Update the prefs with what we have read (delete all corrupted prefs). | |
492 if (detected_corrupted_prefs) | |
493 ScheduleUpdatePrefsOnIO(); | |
494 } | |
495 | |
496 | |
497 // | |
498 // Update Preferences with data from the cached data. | |
499 // | |
500 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { | |
501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
502 // Cancel pending updates, if any. | |
503 io_prefs_update_timer_->Stop(); | |
504 StartPrefsUpdateTimerOnIO( | |
505 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs)); | |
506 } | |
507 | |
508 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO( | |
509 base::TimeDelta delay) { | |
510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
511 // This is overridden in tests to post the task without the delay. | |
512 io_prefs_update_timer_->Start( | |
513 FROM_HERE, delay, this, | |
514 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO); | |
515 } | |
516 | |
517 // This is required so we can set this as the callback for a timer. | |
518 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() { | |
519 UpdatePrefsFromCacheOnIO(base::Closure()); | |
520 } | |
521 | |
522 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO( | |
523 const base::Closure& completion) { | |
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
525 | |
526 base::ListValue* spdy_server_list = new base::ListValue; | |
527 http_server_properties_impl_->GetSpdyServerList( | |
528 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); | |
529 | |
530 net::SpdySettingsMap* spdy_settings_map = | |
531 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist); | |
532 const net::SpdySettingsMap& main_map = | |
533 http_server_properties_impl_->spdy_settings_map(); | |
534 int count = 0; | |
535 for (net::SpdySettingsMap::const_iterator it = main_map.begin(); | |
536 it != main_map.end() && count < kMaxSpdySettingsHostsToPersist; | |
537 ++it, ++count) { | |
538 spdy_settings_map->Put(it->first, it->second); | |
539 } | |
540 | |
541 net::AlternateProtocolMap* alternate_protocol_map = | |
542 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist); | |
543 const net::AlternateProtocolMap& map = | |
544 http_server_properties_impl_->alternate_protocol_map(); | |
545 count = 0; | |
546 typedef std::map<std::string, bool> CanonicalHostPersistedMap; | |
547 CanonicalHostPersistedMap persisted_map; | |
548 for (net::AlternateProtocolMap::const_iterator it = map.begin(); | |
549 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; | |
550 ++it) { | |
551 const net::HostPortPair& server = it->first; | |
552 std::string canonical_suffix = | |
553 http_server_properties_impl_->GetCanonicalSuffix(server); | |
554 if (!canonical_suffix.empty()) { | |
555 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | |
556 continue; | |
557 persisted_map[canonical_suffix] = true; | |
558 } | |
559 alternate_protocol_map->Put(server, it->second); | |
560 ++count; | |
561 } | |
562 | |
563 // Update the preferences on the UI thread. | |
564 BrowserThread::PostTask( | |
565 BrowserThread::UI, | |
566 FROM_HERE, | |
567 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI, | |
568 ui_weak_ptr_, | |
569 base::Owned(spdy_server_list), | |
570 base::Owned(spdy_settings_map), | |
571 base::Owned(alternate_protocol_map), | |
572 completion)); | |
573 } | |
574 | |
575 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 308 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
576 // and PortAlternateProtocolPair preferences for a server. This is used only in | 309 // and PortAlternateProtocolPair preferences for a server. This is used only in |
577 // UpdatePrefsOnUI. | 310 // UpdatePrefsOnUI. |
578 struct ServerPref { | 311 struct ServerPref { |
579 ServerPref() | 312 ServerPref() |
580 : supports_spdy(false), | 313 : supports_spdy(false), |
581 settings_map(NULL), | 314 settings_map(NULL), |
582 alternate_protocol(NULL) { | 315 alternate_protocol(NULL) { |
583 } | 316 } |
584 ServerPref(bool supports_spdy, | 317 ServerPref(bool supports_spdy, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 setting_prefs_ = false; | 443 setting_prefs_ = false; |
711 | 444 |
712 // Note that |completion| will be fired after we have written everything to | 445 // Note that |completion| will be fired after we have written everything to |
713 // the Preferences, but likely before these changes are serialized to disk. | 446 // the Preferences, but likely before these changes are serialized to disk. |
714 // This is not a problem though, as JSONPrefStore guarantees that this will | 447 // 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. | 448 // happen, pretty soon, and even in the case we shut down immediately. |
716 if (!completion.is_null()) | 449 if (!completion.is_null()) |
717 completion.Run(); | 450 completion.Run(); |
718 } | 451 } |
719 | 452 |
| 453 // static |
| 454 void HttpServerPropertiesManager::UpdatePrefsOnIO( |
| 455 base::WeakPtr<HttpServerPropertiesManager> ui_weak_ptr, |
| 456 base::ListValue* spdy_server_list, |
| 457 net::SpdySettingsMap* spdy_settings_map, |
| 458 net::AlternateProtocolMap* alternate_protocol_map, |
| 459 const base::Closure& completion) { |
| 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 461 BrowserThread::PostTask( |
| 462 BrowserThread::UI, |
| 463 FROM_HERE, |
| 464 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI, |
| 465 ui_weak_ptr, |
| 466 spdy_server_list, |
| 467 spdy_settings_map, |
| 468 alternate_protocol_map, |
| 469 completion)); |
| 470 } |
| 471 |
720 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 472 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
722 if (!setting_prefs_) | 474 if (!setting_prefs_) |
723 ScheduleUpdateCacheOnUI(); | 475 ScheduleUpdateCacheOnUI(); |
724 } | 476 } |
725 | 477 |
726 } // namespace chrome_browser_net | 478 } // namespace chrome_browser_net |
OLD | NEW |