Chromium Code Reviews| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 const base::DictionaryValue& http_server_properties_dict = | 240 const base::DictionaryValue& http_server_properties_dict = |
| 241 *pref_service_->GetDictionary(prefs::kHttpServerProperties); | 241 *pref_service_->GetDictionary(prefs::kHttpServerProperties); |
| 242 for (base::DictionaryValue::key_iterator it = | 242 for (base::DictionaryValue::key_iterator it = |
| 243 http_server_properties_dict.begin_keys(); | 243 http_server_properties_dict.begin_keys(); |
| 244 it != http_server_properties_dict.end_keys(); ++it) { | 244 it != http_server_properties_dict.end_keys(); ++it) { |
| 245 // Get server's host/pair. | 245 // Get server's host/pair. |
| 246 const std::string& server_str = *it; | 246 const std::string& server_str = *it; |
| 247 net::HostPortPair server = net::HostPortPair::FromString(server_str); | 247 net::HostPortPair server = net::HostPortPair::FromString(server_str); |
| 248 if (server.host().empty()) { | 248 if (server.host().empty()) { |
| 249 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 249 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
| 250 NOTREACHED(); | |
| 251 continue; | 250 continue; |
| 252 } | 251 } |
| 253 | 252 |
| 254 base::DictionaryValue* server_pref_dict = NULL; | 253 base::DictionaryValue* server_pref_dict = NULL; |
| 255 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 254 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
| 256 server_str, &server_pref_dict)) { | 255 server_str, &server_pref_dict)) { |
| 257 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 256 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
| 258 NOTREACHED(); | |
| 259 continue; | 257 continue; |
| 260 } | 258 } |
| 261 | 259 |
| 262 // Get if server supports Spdy. | 260 // Get if server supports Spdy. |
| 263 bool supports_spdy = false; | 261 bool supports_spdy = false; |
| 264 if ((server_pref_dict->GetBoolean( | 262 if ((server_pref_dict->GetBoolean( |
| 265 "supports_spdy", &supports_spdy)) && supports_spdy) { | 263 "supports_spdy", &supports_spdy)) && supports_spdy) { |
| 266 spdy_servers->push_back(server_str); | 264 spdy_servers->push_back(server_str); |
| 267 } | 265 } |
| 268 | 266 |
| 269 // Get SpdySettings. | 267 // Get SpdySettings. |
| 270 DCHECK(!ContainsKey(*spdy_settings_map, server)); | 268 DCHECK(!ContainsKey(*spdy_settings_map, server)); |
| 271 base::ListValue* spdy_settings_list = NULL; | 269 base::ListValue* spdy_settings_list = NULL; |
| 272 if (server_pref_dict->GetListWithoutPathExpansion( | 270 if (server_pref_dict->GetListWithoutPathExpansion( |
| 273 "settings", &spdy_settings_list)) { | 271 "settings", &spdy_settings_list)) { |
| 274 spdy::SpdySettings spdy_settings; | 272 spdy::SpdySettings spdy_settings; |
| 275 | 273 |
| 276 for (base::ListValue::const_iterator list_it = | 274 for (base::ListValue::const_iterator list_it = |
| 277 spdy_settings_list->begin(); | 275 spdy_settings_list->begin(); |
| 278 list_it != spdy_settings_list->end(); ++list_it) { | 276 list_it != spdy_settings_list->end(); ++list_it) { |
| 279 if ((*list_it)->GetType() != Value::TYPE_DICTIONARY) { | 277 if ((*list_it)->GetType() != Value::TYPE_DICTIONARY) { |
| 280 DVLOG(1) << "Malformed SpdySettingsList for server: " << server_str; | 278 DVLOG(1) << "Malformed SpdySettingsList for server: " << server_str; |
| 281 NOTREACHED(); | |
| 282 continue; | 279 continue; |
| 283 } | 280 } |
| 284 | 281 |
| 285 const base::DictionaryValue* spdy_setting_dict = | 282 const base::DictionaryValue* spdy_setting_dict = |
| 286 static_cast<const base::DictionaryValue*>(*list_it); | 283 static_cast<const base::DictionaryValue*>(*list_it); |
| 287 | 284 |
| 288 int id = 0; | 285 int id = 0; |
| 289 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("id", &id)) { | 286 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("id", &id)) { |
| 290 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str; | 287 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str; |
| 291 NOTREACHED(); | |
| 292 continue; | 288 continue; |
| 293 } | 289 } |
| 294 | 290 |
| 295 int value = 0; | 291 int value = 0; |
| 296 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("value", | 292 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("value", |
| 297 &value)) { | 293 &value)) { |
| 298 DVLOG(1) << "Malformed value in SpdySettings for server: " << | 294 DVLOG(1) << "Malformed value in SpdySettings for server: " << |
| 299 server_str; | 295 server_str; |
| 300 NOTREACHED(); | |
| 301 continue; | 296 continue; |
| 302 } | 297 } |
| 303 | 298 |
| 304 spdy::SettingsFlagsAndId flags_and_id(0); | 299 spdy::SettingsFlagsAndId flags_and_id(0); |
| 305 flags_and_id.set_id(id); | 300 flags_and_id.set_id(id); |
| 306 flags_and_id.set_flags(spdy::SETTINGS_FLAG_PERSISTED); | 301 flags_and_id.set_flags(spdy::SETTINGS_FLAG_PERSISTED); |
| 307 | 302 |
| 308 spdy_settings.push_back(spdy::SpdySetting(flags_and_id, value)); | 303 spdy_settings.push_back(spdy::SpdySetting(flags_and_id, value)); |
| 309 } | 304 } |
| 310 | 305 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 325 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 320 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
| 326 "alternate_protocol", &port_alternate_protocol_dict)) { | 321 "alternate_protocol", &port_alternate_protocol_dict)) { |
| 327 continue; | 322 continue; |
| 328 } | 323 } |
| 329 | 324 |
| 330 do { | 325 do { |
| 331 int port = 0; | 326 int port = 0; |
| 332 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( | 327 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( |
| 333 "port", &port) || (port > (1 << 16))) { | 328 "port", &port) || (port > (1 << 16))) { |
| 334 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 329 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
| 335 NOTREACHED(); | |
| 336 continue; | 330 continue; |
| 337 } | 331 } |
| 338 int protocol = 0; | 332 int protocol = 0; |
| 339 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( | 333 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( |
| 340 "protocol", &protocol) || (protocol < 0) || | 334 "protocol", &protocol) || (protocol < 0) || |
| 341 (protocol > net::NUM_ALTERNATE_PROTOCOLS)) { | 335 (protocol > net::NUM_ALTERNATE_PROTOCOLS)) { |
| 342 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 336 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
| 343 NOTREACHED(); | |
| 344 continue; | 337 continue; |
| 345 } | 338 } |
| 346 | 339 |
| 347 net::PortAlternateProtocolPair port_alternate_protocol; | 340 net::PortAlternateProtocolPair port_alternate_protocol; |
| 348 port_alternate_protocol.port = port; | 341 port_alternate_protocol.port = port; |
| 349 port_alternate_protocol.protocol = static_cast<net::AlternateProtocol>( | 342 port_alternate_protocol.protocol = static_cast<net::AlternateProtocol>( |
| 350 protocol); | 343 protocol); |
| 351 | 344 |
| 352 (*alternate_protocol_map)[server] = port_alternate_protocol; | 345 (*alternate_protocol_map)[server] = port_alternate_protocol; |
| 353 } while (false); | 346 } while (false); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 380 http_server_properties_impl_->InitializeSpdySettingsServers( | 373 http_server_properties_impl_->InitializeSpdySettingsServers( |
| 381 spdy_settings_map); | 374 spdy_settings_map); |
| 382 | 375 |
| 383 // Clear the cached data and use the new Alternate-Protocol server list from | 376 // Clear the cached data and use the new Alternate-Protocol server list from |
| 384 // preferences. | 377 // preferences. |
| 385 http_server_properties_impl_->InitializeAlternateProtocolServers( | 378 http_server_properties_impl_->InitializeAlternateProtocolServers( |
| 386 alternate_protocol_map); | 379 alternate_protocol_map); |
| 387 | 380 |
| 388 http_server_properties_impl_->InitializePipelineCapabilities( | 381 http_server_properties_impl_->InitializePipelineCapabilities( |
| 389 pipeline_capability_map); | 382 pipeline_capability_map); |
| 383 | |
| 384 // Update the prefs with what we have read (delete all corrupted prefs). | |
| 385 ScheduleUpdatePrefsOnIO(); | |
|
wtc
2012/01/11 02:47:41
Is it possible to update the prefs only when we kn
ramant (doing other things)
2012/01/11 03:22:23
Many thanks for catching this.
Done.
| |
| 390 } | 386 } |
| 391 | 387 |
| 392 | 388 |
| 393 // | 389 // |
| 394 // Update Preferences with data from the cached data. | 390 // Update Preferences with data from the cached data. |
| 395 // | 391 // |
| 396 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { | 392 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { |
| 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 398 // Cancel pending updates, if any. | 394 // Cancel pending updates, if any. |
| 399 io_prefs_update_timer_->Stop(); | 395 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(); | 611 std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 616 if (*pref_name == prefs::kHttpServerProperties) { | 612 if (*pref_name == prefs::kHttpServerProperties) { |
| 617 if (!setting_prefs_) | 613 if (!setting_prefs_) |
| 618 ScheduleUpdateCacheOnUI(); | 614 ScheduleUpdateCacheOnUI(); |
| 619 } else { | 615 } else { |
| 620 NOTREACHED(); | 616 NOTREACHED(); |
| 621 } | 617 } |
| 622 } | 618 } |
| 623 | 619 |
| 624 } // namespace chrome_browser_net | 620 } // namespace chrome_browser_net |
| OLD | NEW |