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

Side by Side Diff: chrome/browser/net/http_server_properties_manager.cc

Issue 9802003: SPDY - persist SPDY settings. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #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"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 http_server_properties_impl_->SetBrokenAlternateProtocol(server); 133 http_server_properties_impl_->SetBrokenAlternateProtocol(server);
134 ScheduleUpdatePrefsOnIO(); 134 ScheduleUpdatePrefsOnIO();
135 } 135 }
136 136
137 const net::AlternateProtocolMap& 137 const net::AlternateProtocolMap&
138 HttpServerPropertiesManager::alternate_protocol_map() const { 138 HttpServerPropertiesManager::alternate_protocol_map() const {
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
140 return http_server_properties_impl_->alternate_protocol_map(); 140 return http_server_properties_impl_->alternate_protocol_map();
141 } 141 }
142 142
143 const net::SpdySettings& 143 const net::SettingsMap&
144 HttpServerPropertiesManager::GetSpdySettings( 144 HttpServerPropertiesManager::GetSpdySettings(
145 const net::HostPortPair& host_port_pair) const { 145 const net::HostPortPair& host_port_pair) const {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
147 return http_server_properties_impl_->GetSpdySettings(host_port_pair); 147 return http_server_properties_impl_->GetSpdySettings(host_port_pair);
148 } 148 }
149 149
150 // Saves settings for a host. 150 bool HttpServerPropertiesManager::SetSpdySetting(
151 bool HttpServerPropertiesManager::SetSpdySettings(
152 const net::HostPortPair& host_port_pair, 151 const net::HostPortPair& host_port_pair,
153 const net::SpdySettings& settings) { 152 net::SpdySettingsIds id,
153 net::SpdySettingsFlags flags,
154 uint32 value) {
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
155 bool persist = http_server_properties_impl_->SetSpdySettings( 156 bool persist = http_server_properties_impl_->SetSpdySetting(
156 host_port_pair, settings); 157 host_port_pair, id, flags, value);
157 if (persist) 158 if (persist)
158 ScheduleUpdatePrefsOnIO(); 159 ScheduleUpdatePrefsOnIO();
159 return persist; 160 return persist;
160 }
161
162 bool HttpServerPropertiesManager::SetSpdySetting(
163 const net::HostPortPair& host_port_pair,
164 const net::SpdySetting& setting) {
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
166 bool persist = http_server_properties_impl_->SetSpdySetting(
167 host_port_pair, setting);
168 if (persist)
169 ScheduleUpdatePrefsOnIO();
170 return persist;
171 } 161 }
172 162
173 void HttpServerPropertiesManager::ClearSpdySettings() { 163 void HttpServerPropertiesManager::ClearSpdySettings() {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
175 http_server_properties_impl_->ClearSpdySettings(); 165 http_server_properties_impl_->ClearSpdySettings();
176 ScheduleUpdatePrefsOnIO(); 166 ScheduleUpdatePrefsOnIO();
177 } 167 }
178 168
179 const net::SpdySettingsMap& 169 const net::SpdySettingsMap&
180 HttpServerPropertiesManager::spdy_settings_map() const { 170 HttpServerPropertiesManager::spdy_settings_map() const {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 continue; 261 continue;
272 } 262 }
273 263
274 // Get if server supports Spdy. 264 // Get if server supports Spdy.
275 bool supports_spdy = false; 265 bool supports_spdy = false;
276 if ((server_pref_dict->GetBoolean( 266 if ((server_pref_dict->GetBoolean(
277 "supports_spdy", &supports_spdy)) && supports_spdy) { 267 "supports_spdy", &supports_spdy)) && supports_spdy) {
278 spdy_servers->push_back(server_str); 268 spdy_servers->push_back(server_str);
279 } 269 }
280 270
281 // TODO(rtenneti): Implement reading of SpdySettings. 271 // Get SpdySettings.
282 DCHECK(!ContainsKey(*spdy_settings_map, server)); 272 DCHECK(!ContainsKey(*spdy_settings_map, server));
273 base::ListValue* spdy_settings_list = NULL;
274 if (server_pref_dict->GetListWithoutPathExpansion(
275 "settings", &spdy_settings_list)) {
276 net::SettingsMap settings_map;
277
278 for (base::ListValue::const_iterator list_it =
279 spdy_settings_list->begin();
280 list_it != spdy_settings_list->end(); ++list_it) {
281 if ((*list_it)->GetType() != Value::TYPE_DICTIONARY) {
282 DVLOG(1) << "Malformed SpdySettingsList for server: " << server_str;
283 NOTREACHED();
284 continue;
285 }
286
287 const base::DictionaryValue* spdy_setting_dict =
288 static_cast<const base::DictionaryValue*>(*list_it);
289
290 int id = 0;
291 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("id", &id)) {
292 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str;
293 NOTREACHED();
294 continue;
295 }
296
297 int value = 0;
298 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("value",
299 &value)) {
300 DVLOG(1) << "Malformed value in SpdySettings for server: " <<
301 server_str;
302 NOTREACHED();
303 continue;
304 }
305
306 net::SettingsFlagsAndValue flags_and_value(
307 net::SETTINGS_FLAG_PERSISTED, value);
308 settings_map[static_cast<net::SpdySettingsIds>(id)] = flags_and_value;
309 }
310
311 (*spdy_settings_map)[server] = settings_map;
312 }
283 313
284 int pipeline_capability = net::PIPELINE_UNKNOWN; 314 int pipeline_capability = net::PIPELINE_UNKNOWN;
285 if ((server_pref_dict->GetInteger( 315 if ((server_pref_dict->GetInteger(
286 "pipeline_capability", &pipeline_capability)) && 316 "pipeline_capability", &pipeline_capability)) &&
287 pipeline_capability != net::PIPELINE_UNKNOWN) { 317 pipeline_capability != net::PIPELINE_UNKNOWN) {
288 (*pipeline_capability_map)[server] = 318 (*pipeline_capability_map)[server] =
289 static_cast<net::HttpPipelinedHostCapability>(pipeline_capability); 319 static_cast<net::HttpPipelinedHostCapability>(pipeline_capability);
290 } 320 }
291 321
292 // Get alternate_protocol server. 322 // Get alternate_protocol server.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 base::Owned(alternate_protocol_map), 446 base::Owned(alternate_protocol_map),
417 base::Owned(pipeline_capability_map))); 447 base::Owned(pipeline_capability_map)));
418 } 448 }
419 449
420 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 450 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
421 // PortAlternateProtocolPair, and |pipeline_capability| preferences for a 451 // PortAlternateProtocolPair, and |pipeline_capability| preferences for a
422 // server. This is used only in UpdatePrefsOnUI. 452 // server. This is used only in UpdatePrefsOnUI.
423 struct ServerPref { 453 struct ServerPref {
424 ServerPref() 454 ServerPref()
425 : supports_spdy(false), 455 : supports_spdy(false),
426 settings(NULL), 456 settings_map(NULL),
427 alternate_protocol(NULL), 457 alternate_protocol(NULL),
428 pipeline_capability(net::PIPELINE_UNKNOWN) { 458 pipeline_capability(net::PIPELINE_UNKNOWN) {
429 } 459 }
430 ServerPref(bool supports_spdy, 460 ServerPref(bool supports_spdy,
431 const net::SpdySettings* settings, 461 const net::SettingsMap* settings_map,
432 const net::PortAlternateProtocolPair* alternate_protocol) 462 const net::PortAlternateProtocolPair* alternate_protocol)
433 : supports_spdy(supports_spdy), 463 : supports_spdy(supports_spdy),
434 settings(settings), 464 settings_map(settings_map),
435 alternate_protocol(alternate_protocol), 465 alternate_protocol(alternate_protocol),
436 pipeline_capability(net::PIPELINE_UNKNOWN) { 466 pipeline_capability(net::PIPELINE_UNKNOWN) {
437 } 467 }
438 bool supports_spdy; 468 bool supports_spdy;
439 const net::SpdySettings* settings; 469 const net::SettingsMap* settings_map;
440 const net::PortAlternateProtocolPair* alternate_protocol; 470 const net::PortAlternateProtocolPair* alternate_protocol;
441 net::HttpPipelinedHostCapability pipeline_capability; 471 net::HttpPipelinedHostCapability pipeline_capability;
442 }; 472 };
443 473
444 void HttpServerPropertiesManager::UpdatePrefsOnUI( 474 void HttpServerPropertiesManager::UpdatePrefsOnUI(
445 base::ListValue* spdy_server_list, 475 base::ListValue* spdy_server_list,
446 net::SpdySettingsMap* spdy_settings_map, 476 net::SpdySettingsMap* spdy_settings_map,
447 net::AlternateProtocolMap* alternate_protocol_map, 477 net::AlternateProtocolMap* alternate_protocol_map,
448 net::PipelineCapabilityMap* pipeline_capability_map) { 478 net::PipelineCapabilityMap* pipeline_capability_map) {
449 479
(...skipping 23 matching lines...) Expand all
473 for (net::SpdySettingsMap::iterator map_it = 503 for (net::SpdySettingsMap::iterator map_it =
474 spdy_settings_map->begin(); 504 spdy_settings_map->begin();
475 map_it != spdy_settings_map->end(); ++map_it) { 505 map_it != spdy_settings_map->end(); ++map_it) {
476 const net::HostPortPair& server = map_it->first; 506 const net::HostPortPair& server = map_it->first;
477 507
478 ServerPrefMap::iterator it = server_pref_map.find(server); 508 ServerPrefMap::iterator it = server_pref_map.find(server);
479 if (it == server_pref_map.end()) { 509 if (it == server_pref_map.end()) {
480 ServerPref server_pref(false, &map_it->second, NULL); 510 ServerPref server_pref(false, &map_it->second, NULL);
481 server_pref_map[server] = server_pref; 511 server_pref_map[server] = server_pref;
482 } else { 512 } else {
483 it->second.settings = &map_it->second; 513 it->second.settings_map = &map_it->second;
484 } 514 }
485 } 515 }
486 516
487 // Add AlternateProtocol servers to server_pref_map. 517 // Add AlternateProtocol servers to server_pref_map.
488 for (net::AlternateProtocolMap::const_iterator map_it = 518 for (net::AlternateProtocolMap::const_iterator map_it =
489 alternate_protocol_map->begin(); 519 alternate_protocol_map->begin();
490 map_it != alternate_protocol_map->end(); ++map_it) { 520 map_it != alternate_protocol_map->end(); ++map_it) {
491 const net::HostPortPair& server = map_it->first; 521 const net::HostPortPair& server = map_it->first;
492 const net::PortAlternateProtocolPair& port_alternate_protocol = 522 const net::PortAlternateProtocolPair& port_alternate_protocol =
493 map_it->second; 523 map_it->second;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 server_pref_map.begin(); 558 server_pref_map.begin();
529 map_it != server_pref_map.end(); ++map_it) { 559 map_it != server_pref_map.end(); ++map_it) {
530 const net::HostPortPair& server = map_it->first; 560 const net::HostPortPair& server = map_it->first;
531 const ServerPref& server_pref = map_it->second; 561 const ServerPref& server_pref = map_it->second;
532 562
533 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 563 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
534 564
535 // Save supports_spdy. 565 // Save supports_spdy.
536 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); 566 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy);
537 567
538 // TODO(rtenneti): Implement save SpdySettings. 568 // Save SPDY settings.
569 if (server_pref.settings_map) {
570 base::ListValue* spdy_settings_list = new ListValue();
571 for (net::SettingsMap::const_iterator it =
572 server_pref.settings_map->begin();
573 it != server_pref.settings_map->end(); ++it) {
574 net::SpdySettingsIds id = it->first;
575 uint32 value = it->second.second;
576 base::DictionaryValue* spdy_setting_dict = new base::DictionaryValue;
577 spdy_setting_dict->SetInteger("id", id);
578 spdy_setting_dict->SetInteger("value", value);
579 spdy_settings_list->Append(spdy_setting_dict);
580 }
581 server_pref_dict->Set("settings", spdy_settings_list);
582 }
539 583
540 // Save alternate_protocol. 584 // Save alternate_protocol.
541 if (server_pref.alternate_protocol) { 585 if (server_pref.alternate_protocol) {
542 base::DictionaryValue* port_alternate_protocol_dict = 586 base::DictionaryValue* port_alternate_protocol_dict =
543 new base::DictionaryValue; 587 new base::DictionaryValue;
544 const net::PortAlternateProtocolPair* port_alternate_protocol = 588 const net::PortAlternateProtocolPair* port_alternate_protocol =
545 server_pref.alternate_protocol; 589 server_pref.alternate_protocol;
546 port_alternate_protocol_dict->SetInteger( 590 port_alternate_protocol_dict->SetInteger(
547 "port", port_alternate_protocol->port); 591 "port", port_alternate_protocol->port);
548 port_alternate_protocol_dict->SetInteger( 592 port_alternate_protocol_dict->SetInteger(
(...skipping 28 matching lines...) Expand all
577 std::string* pref_name = content::Details<std::string>(details).ptr(); 621 std::string* pref_name = content::Details<std::string>(details).ptr();
578 if (*pref_name == prefs::kHttpServerProperties) { 622 if (*pref_name == prefs::kHttpServerProperties) {
579 if (!setting_prefs_) 623 if (!setting_prefs_)
580 ScheduleUpdateCacheOnUI(); 624 ScheduleUpdateCacheOnUI();
581 } else { 625 } else {
582 NOTREACHED(); 626 NOTREACHED();
583 } 627 }
584 } 628 }
585 629
586 } // namespace chrome_browser_net 630 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/http_server_properties_manager.h ('k') | chrome/browser/net/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698