OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 #include "chrome/browser/net/http_server_properties_manager.h" | 4 #include "chrome/browser/net/http_server_properties_manager.h" |
5 | 5 |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 // Parse the preferences into a SpdySettingsMap. | 230 // Parse the preferences into a SpdySettingsMap. |
231 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; | 231 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; |
232 | 232 |
233 // Parse the preferences into a AlternateProtocolMap. | 233 // Parse the preferences into a AlternateProtocolMap. |
234 net::AlternateProtocolMap* alternate_protocol_map = | 234 net::AlternateProtocolMap* alternate_protocol_map = |
235 new net::AlternateProtocolMap; | 235 new net::AlternateProtocolMap; |
236 | 236 |
237 net::PipelineCapabilityMap* pipeline_capability_map = | 237 net::PipelineCapabilityMap* pipeline_capability_map = |
238 new net::PipelineCapabilityMap; | 238 new net::PipelineCapabilityMap; |
239 | 239 |
240 bool deleted_corrupted_prefs = false; | |
wtc
2012/01/11 03:26:41
This variable should be named detected_corrupted_p
ramant (doing other things)
2012/01/11 03:30:03
Done.
| |
240 const base::DictionaryValue& http_server_properties_dict = | 241 const base::DictionaryValue& http_server_properties_dict = |
241 *pref_service_->GetDictionary(prefs::kHttpServerProperties); | 242 *pref_service_->GetDictionary(prefs::kHttpServerProperties); |
242 for (base::DictionaryValue::key_iterator it = | 243 for (base::DictionaryValue::key_iterator it = |
243 http_server_properties_dict.begin_keys(); | 244 http_server_properties_dict.begin_keys(); |
244 it != http_server_properties_dict.end_keys(); ++it) { | 245 it != http_server_properties_dict.end_keys(); ++it) { |
245 // Get server's host/pair. | 246 // Get server's host/pair. |
246 const std::string& server_str = *it; | 247 const std::string& server_str = *it; |
247 net::HostPortPair server = net::HostPortPair::FromString(server_str); | 248 net::HostPortPair server = net::HostPortPair::FromString(server_str); |
248 if (server.host().empty()) { | 249 if (server.host().empty()) { |
249 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 250 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
250 NOTREACHED(); | 251 deleted_corrupted_prefs = true; |
251 continue; | 252 continue; |
252 } | 253 } |
253 | 254 |
254 base::DictionaryValue* server_pref_dict = NULL; | 255 base::DictionaryValue* server_pref_dict = NULL; |
255 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 256 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
256 server_str, &server_pref_dict)) { | 257 server_str, &server_pref_dict)) { |
257 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 258 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
258 NOTREACHED(); | 259 deleted_corrupted_prefs = true; |
259 continue; | 260 continue; |
260 } | 261 } |
261 | 262 |
262 // Get if server supports Spdy. | 263 // Get if server supports Spdy. |
263 bool supports_spdy = false; | 264 bool supports_spdy = false; |
264 if ((server_pref_dict->GetBoolean( | 265 if ((server_pref_dict->GetBoolean( |
265 "supports_spdy", &supports_spdy)) && supports_spdy) { | 266 "supports_spdy", &supports_spdy)) && supports_spdy) { |
266 spdy_servers->push_back(server_str); | 267 spdy_servers->push_back(server_str); |
267 } | 268 } |
268 | 269 |
269 // Get SpdySettings. | 270 // Get SpdySettings. |
270 DCHECK(!ContainsKey(*spdy_settings_map, server)); | 271 DCHECK(!ContainsKey(*spdy_settings_map, server)); |
271 base::ListValue* spdy_settings_list = NULL; | 272 base::ListValue* spdy_settings_list = NULL; |
272 if (server_pref_dict->GetListWithoutPathExpansion( | 273 if (server_pref_dict->GetListWithoutPathExpansion( |
273 "settings", &spdy_settings_list)) { | 274 "settings", &spdy_settings_list)) { |
274 spdy::SpdySettings spdy_settings; | 275 spdy::SpdySettings spdy_settings; |
275 | 276 |
276 for (base::ListValue::const_iterator list_it = | 277 for (base::ListValue::const_iterator list_it = |
277 spdy_settings_list->begin(); | 278 spdy_settings_list->begin(); |
278 list_it != spdy_settings_list->end(); ++list_it) { | 279 list_it != spdy_settings_list->end(); ++list_it) { |
279 if ((*list_it)->GetType() != Value::TYPE_DICTIONARY) { | 280 if ((*list_it)->GetType() != Value::TYPE_DICTIONARY) { |
280 DVLOG(1) << "Malformed SpdySettingsList for server: " << server_str; | 281 DVLOG(1) << "Malformed SpdySettingsList for server: " << server_str; |
281 NOTREACHED(); | 282 deleted_corrupted_prefs = true; |
282 continue; | 283 continue; |
283 } | 284 } |
284 | 285 |
285 const base::DictionaryValue* spdy_setting_dict = | 286 const base::DictionaryValue* spdy_setting_dict = |
286 static_cast<const base::DictionaryValue*>(*list_it); | 287 static_cast<const base::DictionaryValue*>(*list_it); |
287 | 288 |
288 int id = 0; | 289 int id = 0; |
289 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("id", &id)) { | 290 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("id", &id)) { |
290 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str; | 291 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str; |
291 NOTREACHED(); | 292 deleted_corrupted_prefs = true; |
292 continue; | 293 continue; |
293 } | 294 } |
294 | 295 |
295 int value = 0; | 296 int value = 0; |
296 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("value", | 297 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("value", |
297 &value)) { | 298 &value)) { |
298 DVLOG(1) << "Malformed value in SpdySettings for server: " << | 299 DVLOG(1) << "Malformed value in SpdySettings for server: " << |
299 server_str; | 300 server_str; |
300 NOTREACHED(); | 301 deleted_corrupted_prefs = true; |
301 continue; | 302 continue; |
302 } | 303 } |
303 | 304 |
304 spdy::SettingsFlagsAndId flags_and_id(0); | 305 spdy::SettingsFlagsAndId flags_and_id(0); |
305 flags_and_id.set_id(id); | 306 flags_and_id.set_id(id); |
306 flags_and_id.set_flags(spdy::SETTINGS_FLAG_PERSISTED); | 307 flags_and_id.set_flags(spdy::SETTINGS_FLAG_PERSISTED); |
307 | 308 |
308 spdy_settings.push_back(spdy::SpdySetting(flags_and_id, value)); | 309 spdy_settings.push_back(spdy::SpdySetting(flags_and_id, value)); |
309 } | 310 } |
310 | 311 |
(...skipping 14 matching lines...) Expand all Loading... | |
325 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 326 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
326 "alternate_protocol", &port_alternate_protocol_dict)) { | 327 "alternate_protocol", &port_alternate_protocol_dict)) { |
327 continue; | 328 continue; |
328 } | 329 } |
329 | 330 |
330 do { | 331 do { |
331 int port = 0; | 332 int port = 0; |
332 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( | 333 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( |
333 "port", &port) || (port > (1 << 16))) { | 334 "port", &port) || (port > (1 << 16))) { |
334 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 335 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
335 NOTREACHED(); | 336 deleted_corrupted_prefs = true; |
336 continue; | 337 continue; |
337 } | 338 } |
338 int protocol = 0; | 339 int protocol = 0; |
339 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( | 340 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( |
340 "protocol", &protocol) || (protocol < 0) || | 341 "protocol", &protocol) || (protocol < 0) || |
341 (protocol > net::NUM_ALTERNATE_PROTOCOLS)) { | 342 (protocol > net::NUM_ALTERNATE_PROTOCOLS)) { |
342 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 343 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
343 NOTREACHED(); | 344 deleted_corrupted_prefs = true; |
344 continue; | 345 continue; |
345 } | 346 } |
346 | 347 |
347 net::PortAlternateProtocolPair port_alternate_protocol; | 348 net::PortAlternateProtocolPair port_alternate_protocol; |
348 port_alternate_protocol.port = port; | 349 port_alternate_protocol.port = port; |
349 port_alternate_protocol.protocol = static_cast<net::AlternateProtocol>( | 350 port_alternate_protocol.protocol = static_cast<net::AlternateProtocol>( |
350 protocol); | 351 protocol); |
351 | 352 |
352 (*alternate_protocol_map)[server] = port_alternate_protocol; | 353 (*alternate_protocol_map)[server] = port_alternate_protocol; |
353 } while (false); | 354 } while (false); |
354 } | 355 } |
355 | 356 |
356 BrowserThread::PostTask( | 357 BrowserThread::PostTask( |
357 BrowserThread::IO, | 358 BrowserThread::IO, |
358 FROM_HERE, | 359 FROM_HERE, |
359 base::Bind(&HttpServerPropertiesManager:: | 360 base::Bind(&HttpServerPropertiesManager:: |
360 UpdateCacheFromPrefsOnIO, | 361 UpdateCacheFromPrefsOnIO, |
361 base::Unretained(this), | 362 base::Unretained(this), |
362 base::Owned(spdy_servers), | 363 base::Owned(spdy_servers), |
363 base::Owned(spdy_settings_map), | 364 base::Owned(spdy_settings_map), |
364 base::Owned(alternate_protocol_map), | 365 base::Owned(alternate_protocol_map), |
365 base::Owned(pipeline_capability_map))); | 366 base::Owned(pipeline_capability_map), |
367 deleted_corrupted_prefs)); | |
366 } | 368 } |
367 | 369 |
368 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO( | 370 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO( |
369 StringVector* spdy_servers, | 371 StringVector* spdy_servers, |
370 net::SpdySettingsMap* spdy_settings_map, | 372 net::SpdySettingsMap* spdy_settings_map, |
371 net::AlternateProtocolMap* alternate_protocol_map, | 373 net::AlternateProtocolMap* alternate_protocol_map, |
372 net::PipelineCapabilityMap* pipeline_capability_map) { | 374 net::PipelineCapabilityMap* pipeline_capability_map, |
375 bool deleted_corrupted_prefs) { | |
373 // Preferences have the master data because admins might have pushed new | 376 // Preferences have the master data because admins might have pushed new |
374 // preferences. Update the cached data with new data from preferences. | 377 // preferences. Update the cached data with new data from preferences. |
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
376 | 379 |
377 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 380 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
378 | 381 |
379 // Clear the cached data and use the new spdy_settings from preferences. | 382 // Clear the cached data and use the new spdy_settings from preferences. |
380 http_server_properties_impl_->InitializeSpdySettingsServers( | 383 http_server_properties_impl_->InitializeSpdySettingsServers( |
381 spdy_settings_map); | 384 spdy_settings_map); |
382 | 385 |
383 // Clear the cached data and use the new Alternate-Protocol server list from | 386 // Clear the cached data and use the new Alternate-Protocol server list from |
384 // preferences. | 387 // preferences. |
385 http_server_properties_impl_->InitializeAlternateProtocolServers( | 388 http_server_properties_impl_->InitializeAlternateProtocolServers( |
386 alternate_protocol_map); | 389 alternate_protocol_map); |
387 | 390 |
388 http_server_properties_impl_->InitializePipelineCapabilities( | 391 http_server_properties_impl_->InitializePipelineCapabilities( |
389 pipeline_capability_map); | 392 pipeline_capability_map); |
393 | |
394 // Update the prefs with what we have read (delete all corrupted prefs). | |
395 if (deleted_corrupted_prefs) | |
396 ScheduleUpdatePrefsOnIO(); | |
390 } | 397 } |
391 | 398 |
392 | 399 |
393 // | 400 // |
394 // Update Preferences with data from the cached data. | 401 // Update Preferences with data from the cached data. |
395 // | 402 // |
396 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { | 403 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { |
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
398 // Cancel pending updates, if any. | 405 // Cancel pending updates, if any. |
399 io_prefs_update_timer_->Stop(); | 406 io_prefs_update_timer_->Stop(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
615 std::string* pref_name = content::Details<std::string>(details).ptr(); | 622 std::string* pref_name = content::Details<std::string>(details).ptr(); |
616 if (*pref_name == prefs::kHttpServerProperties) { | 623 if (*pref_name == prefs::kHttpServerProperties) { |
617 if (!setting_prefs_) | 624 if (!setting_prefs_) |
618 ScheduleUpdateCacheOnUI(); | 625 ScheduleUpdateCacheOnUI(); |
619 } else { | 626 } else { |
620 NOTREACHED(); | 627 NOTREACHED(); |
621 } | 628 } |
622 } | 629 } |
623 | 630 |
624 } // namespace chrome_browser_net | 631 } // namespace chrome_browser_net |
OLD | NEW |