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

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 spdy::SpdySettings& 143 const spdy::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 spdy::SpdySettings& settings) { 152 uint32 id,
153 const spdy::SettingsFlagsAndValue& flags_and_value) {
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
155 bool persist = http_server_properties_impl_->SetSpdySettings( 155 bool persist = http_server_properties_impl_->SetSpdySetting(
156 host_port_pair, settings); 156 host_port_pair, id, flags_and_value);
157 if (persist) 157 if (persist)
158 ScheduleUpdatePrefsOnIO(); 158 ScheduleUpdatePrefsOnIO();
159 return persist; 159 return persist;
160 }
161
162 bool HttpServerPropertiesManager::SetSpdySetting(
163 const net::HostPortPair& host_port_pair,
164 const spdy::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 } 160 }
172 161
173 void HttpServerPropertiesManager::ClearSpdySettings() { 162 void HttpServerPropertiesManager::ClearSpdySettings() {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
175 http_server_properties_impl_->ClearSpdySettings(); 164 http_server_properties_impl_->ClearSpdySettings();
176 ScheduleUpdatePrefsOnIO(); 165 ScheduleUpdatePrefsOnIO();
177 } 166 }
178 167
179 const net::SpdySettingsMap& 168 const net::SpdySettingsMap&
180 HttpServerPropertiesManager::spdy_settings_map() const { 169 HttpServerPropertiesManager::spdy_settings_map() const {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 continue; 260 continue;
272 } 261 }
273 262
274 // Get if server supports Spdy. 263 // Get if server supports Spdy.
275 bool supports_spdy = false; 264 bool supports_spdy = false;
276 if ((server_pref_dict->GetBoolean( 265 if ((server_pref_dict->GetBoolean(
277 "supports_spdy", &supports_spdy)) && supports_spdy) { 266 "supports_spdy", &supports_spdy)) && supports_spdy) {
278 spdy_servers->push_back(server_str); 267 spdy_servers->push_back(server_str);
279 } 268 }
280 269
281 // TODO(rtenneti): Implement reading of SpdySettings. 270 // Get SpdySettings.
282 DCHECK(!ContainsKey(*spdy_settings_map, server)); 271 DCHECK(!ContainsKey(*spdy_settings_map, server));
272 base::ListValue* spdy_settings_list = NULL;
273 if (server_pref_dict->GetListWithoutPathExpansion(
274 "settings", &spdy_settings_list)) {
275 spdy::SettingsMap settings_map;
276
277 for (base::ListValue::const_iterator list_it =
278 spdy_settings_list->begin();
279 list_it != spdy_settings_list->end(); ++list_it) {
280 if ((*list_it)->GetType() != Value::TYPE_DICTIONARY) {
Ryan Hamilton 2012/03/21 16:24:41 Do I understand correctly that we're persisting th
ramant (doing other things) 2012/03/23 04:11:25 Correct. Didn't change the format in this CL. Th
Ryan Hamilton 2012/03/23 15:25:38 Sounds good.
281 DVLOG(1) << "Malformed SpdySettingsList for server: " << server_str;
282 NOTREACHED();
283 continue;
284 }
285
286 const base::DictionaryValue* spdy_setting_dict =
287 static_cast<const base::DictionaryValue*>(*list_it);
288
289 int id = 0;
290 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("id", &id)) {
291 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str;
292 NOTREACHED();
293 continue;
294 }
295
296 int value = 0;
297 if (!spdy_setting_dict->GetIntegerWithoutPathExpansion("value",
298 &value)) {
299 DVLOG(1) << "Malformed value in SpdySettings for server: " <<
300 server_str;
301 NOTREACHED();
302 continue;
303 }
304
305 spdy::SettingsFlagsAndValue flags_and_value(
306 spdy::SETTINGS_FLAG_PERSISTED, value);
307 settings_map[id] = flags_and_value;
308 }
309
310 (*spdy_settings_map)[server] = settings_map;
311 }
283 312
284 int pipeline_capability = net::PIPELINE_UNKNOWN; 313 int pipeline_capability = net::PIPELINE_UNKNOWN;
285 if ((server_pref_dict->GetInteger( 314 if ((server_pref_dict->GetInteger(
286 "pipeline_capability", &pipeline_capability)) && 315 "pipeline_capability", &pipeline_capability)) &&
287 pipeline_capability != net::PIPELINE_UNKNOWN) { 316 pipeline_capability != net::PIPELINE_UNKNOWN) {
288 (*pipeline_capability_map)[server] = 317 (*pipeline_capability_map)[server] =
289 static_cast<net::HttpPipelinedHostCapability>(pipeline_capability); 318 static_cast<net::HttpPipelinedHostCapability>(pipeline_capability);
290 } 319 }
291 320
292 // Get alternate_protocol server. 321 // Get alternate_protocol server.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 base::Owned(alternate_protocol_map), 445 base::Owned(alternate_protocol_map),
417 base::Owned(pipeline_capability_map))); 446 base::Owned(pipeline_capability_map)));
418 } 447 }
419 448
420 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 449 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
421 // PortAlternateProtocolPair, and |pipeline_capability| preferences for a 450 // PortAlternateProtocolPair, and |pipeline_capability| preferences for a
422 // server. This is used only in UpdatePrefsOnUI. 451 // server. This is used only in UpdatePrefsOnUI.
423 struct ServerPref { 452 struct ServerPref {
424 ServerPref() 453 ServerPref()
425 : supports_spdy(false), 454 : supports_spdy(false),
426 settings(NULL), 455 settings_map(NULL),
427 alternate_protocol(NULL), 456 alternate_protocol(NULL),
428 pipeline_capability(net::PIPELINE_UNKNOWN) { 457 pipeline_capability(net::PIPELINE_UNKNOWN) {
429 } 458 }
430 ServerPref(bool supports_spdy, 459 ServerPref(bool supports_spdy,
431 const spdy::SpdySettings* settings, 460 const spdy::SettingsMap* settings_map,
432 const net::PortAlternateProtocolPair* alternate_protocol) 461 const net::PortAlternateProtocolPair* alternate_protocol)
433 : supports_spdy(supports_spdy), 462 : supports_spdy(supports_spdy),
434 settings(settings), 463 settings_map(settings_map),
435 alternate_protocol(alternate_protocol), 464 alternate_protocol(alternate_protocol),
436 pipeline_capability(net::PIPELINE_UNKNOWN) { 465 pipeline_capability(net::PIPELINE_UNKNOWN) {
437 } 466 }
438 bool supports_spdy; 467 bool supports_spdy;
439 const spdy::SpdySettings* settings; 468 const spdy::SettingsMap* settings_map;
440 const net::PortAlternateProtocolPair* alternate_protocol; 469 const net::PortAlternateProtocolPair* alternate_protocol;
441 net::HttpPipelinedHostCapability pipeline_capability; 470 net::HttpPipelinedHostCapability pipeline_capability;
442 }; 471 };
443 472
444 void HttpServerPropertiesManager::UpdatePrefsOnUI( 473 void HttpServerPropertiesManager::UpdatePrefsOnUI(
445 base::ListValue* spdy_server_list, 474 base::ListValue* spdy_server_list,
446 net::SpdySettingsMap* spdy_settings_map, 475 net::SpdySettingsMap* spdy_settings_map,
447 net::AlternateProtocolMap* alternate_protocol_map, 476 net::AlternateProtocolMap* alternate_protocol_map,
448 net::PipelineCapabilityMap* pipeline_capability_map) { 477 net::PipelineCapabilityMap* pipeline_capability_map) {
449 478
(...skipping 23 matching lines...) Expand all
473 for (net::SpdySettingsMap::iterator map_it = 502 for (net::SpdySettingsMap::iterator map_it =
474 spdy_settings_map->begin(); 503 spdy_settings_map->begin();
475 map_it != spdy_settings_map->end(); ++map_it) { 504 map_it != spdy_settings_map->end(); ++map_it) {
476 const net::HostPortPair& server = map_it->first; 505 const net::HostPortPair& server = map_it->first;
477 506
478 ServerPrefMap::iterator it = server_pref_map.find(server); 507 ServerPrefMap::iterator it = server_pref_map.find(server);
479 if (it == server_pref_map.end()) { 508 if (it == server_pref_map.end()) {
480 ServerPref server_pref(false, &map_it->second, NULL); 509 ServerPref server_pref(false, &map_it->second, NULL);
481 server_pref_map[server] = server_pref; 510 server_pref_map[server] = server_pref;
482 } else { 511 } else {
483 it->second.settings = &map_it->second; 512 it->second.settings_map = &map_it->second;
484 } 513 }
485 } 514 }
486 515
487 // Add AlternateProtocol servers to server_pref_map. 516 // Add AlternateProtocol servers to server_pref_map.
488 for (net::AlternateProtocolMap::const_iterator map_it = 517 for (net::AlternateProtocolMap::const_iterator map_it =
489 alternate_protocol_map->begin(); 518 alternate_protocol_map->begin();
490 map_it != alternate_protocol_map->end(); ++map_it) { 519 map_it != alternate_protocol_map->end(); ++map_it) {
491 const net::HostPortPair& server = map_it->first; 520 const net::HostPortPair& server = map_it->first;
492 const net::PortAlternateProtocolPair& port_alternate_protocol = 521 const net::PortAlternateProtocolPair& port_alternate_protocol =
493 map_it->second; 522 map_it->second;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 server_pref_map.begin(); 557 server_pref_map.begin();
529 map_it != server_pref_map.end(); ++map_it) { 558 map_it != server_pref_map.end(); ++map_it) {
530 const net::HostPortPair& server = map_it->first; 559 const net::HostPortPair& server = map_it->first;
531 const ServerPref& server_pref = map_it->second; 560 const ServerPref& server_pref = map_it->second;
532 561
533 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 562 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
534 563
535 // Save supports_spdy. 564 // Save supports_spdy.
536 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); 565 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy);
537 566
538 // TODO(rtenneti): Implement save SpdySettings. 567 // Save SPDY settings.
568 if (server_pref.settings_map) {
569 base::ListValue* spdy_settings_list = new ListValue();
Ryan Hamilton 2012/03/21 16:24:41 Do you need to worry about reading old values? Di
ramant (doing other things) 2012/03/23 04:11:25 The format for spdy_settings is same as before. Fo
570 for (spdy::SettingsMap::const_iterator it =
571 server_pref.settings_map->begin();
572 it != server_pref.settings_map->end(); ++it) {
573 uint32 id = it->first;
574 uint32 value = it->second.second;
575 base::DictionaryValue* spdy_setting_dict = new base::DictionaryValue;
576 spdy_setting_dict->SetInteger("id", id);
577 spdy_setting_dict->SetInteger("value", value);
578 spdy_settings_list->Append(spdy_setting_dict);
579 }
580 server_pref_dict->Set("settings", spdy_settings_list);
581 }
539 582
540 // Save alternate_protocol. 583 // Save alternate_protocol.
541 if (server_pref.alternate_protocol) { 584 if (server_pref.alternate_protocol) {
542 base::DictionaryValue* port_alternate_protocol_dict = 585 base::DictionaryValue* port_alternate_protocol_dict =
543 new base::DictionaryValue; 586 new base::DictionaryValue;
544 const net::PortAlternateProtocolPair* port_alternate_protocol = 587 const net::PortAlternateProtocolPair* port_alternate_protocol =
545 server_pref.alternate_protocol; 588 server_pref.alternate_protocol;
546 port_alternate_protocol_dict->SetInteger( 589 port_alternate_protocol_dict->SetInteger(
547 "port", port_alternate_protocol->port); 590 "port", port_alternate_protocol->port);
548 port_alternate_protocol_dict->SetInteger( 591 port_alternate_protocol_dict->SetInteger(
(...skipping 28 matching lines...) Expand all
577 std::string* pref_name = content::Details<std::string>(details).ptr(); 620 std::string* pref_name = content::Details<std::string>(details).ptr();
578 if (*pref_name == prefs::kHttpServerProperties) { 621 if (*pref_name == prefs::kHttpServerProperties) {
579 if (!setting_prefs_) 622 if (!setting_prefs_)
580 ScheduleUpdateCacheOnUI(); 623 ScheduleUpdateCacheOnUI();
581 } else { 624 } else {
582 NOTREACHED(); 625 NOTREACHED();
583 } 626 }
584 } 627 }
585 628
586 } // namespace chrome_browser_net 629 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698