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

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

Issue 8770035: Save pipelining capabilities for the most used hosts between sessions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 http_server_properties_impl_->ClearSpdySettings(); 164 http_server_properties_impl_->ClearSpdySettings();
165 ScheduleUpdatePrefsOnIO(); 165 ScheduleUpdatePrefsOnIO();
166 } 166 }
167 167
168 const net::SpdySettingsMap& 168 const net::SpdySettingsMap&
169 HttpServerPropertiesManager::spdy_settings_map() const { 169 HttpServerPropertiesManager::spdy_settings_map() const {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
171 return http_server_properties_impl_->spdy_settings_map(); 171 return http_server_properties_impl_->spdy_settings_map();
172 } 172 }
173 173
174 net::HttpPipelinedHost::Capability
175 HttpServerPropertiesManager::GetPipelineCapability(
176 const net::HostPortPair& origin) {
177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
178 return http_server_properties_impl_->GetPipelineCapability(origin);
179 }
180
181 void HttpServerPropertiesManager::SetPipelineCapability(
182 const net::HostPortPair& origin,
183 net::HttpPipelinedHost::Capability capability) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
185 http_server_properties_impl_->SetPipelineCapability(origin, capability);
186 ScheduleUpdatePrefsOnIO();
187 }
188
189 void HttpServerPropertiesManager::ClearPipelineCapabilities() {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
191 http_server_properties_impl_->ClearPipelineCapabilities();
192 ScheduleUpdatePrefsOnIO();
193 }
194
195 net::PipelineCapabilityMap
196 HttpServerPropertiesManager::GetPipelineCapabilityMap() const {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
198 return http_server_properties_impl_->GetPipelineCapabilityMap();
199 }
200
174 // 201 //
175 // Update the HttpServerPropertiesImpl's cache with data from preferences. 202 // Update the HttpServerPropertiesImpl's cache with data from preferences.
176 // 203 //
177 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() { 204 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() {
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
179 // Cancel pending updates, if any. 206 // Cancel pending updates, if any.
180 ui_cache_update_timer_->Stop(); 207 ui_cache_update_timer_->Stop();
181 StartCacheUpdateTimerOnUI( 208 StartCacheUpdateTimerOnUI(
182 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); 209 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs));
183 } 210 }
(...skipping 16 matching lines...) Expand all
200 // String is host/port pair of spdy server. 227 // String is host/port pair of spdy server.
201 StringVector* spdy_servers = new StringVector; 228 StringVector* spdy_servers = new StringVector;
202 229
203 // Parse the preferences into a SpdySettingsMap. 230 // Parse the preferences into a SpdySettingsMap.
204 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; 231 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap;
205 232
206 // Parse the preferences into a AlternateProtocolMap. 233 // Parse the preferences into a AlternateProtocolMap.
207 net::AlternateProtocolMap* alternate_protocol_map = 234 net::AlternateProtocolMap* alternate_protocol_map =
208 new net::AlternateProtocolMap; 235 new net::AlternateProtocolMap;
209 236
237 net::PipelineCapabilityMap* pipeline_capability_map =
238 new net::PipelineCapabilityMap;
239
210 const base::DictionaryValue& http_server_properties_dict = 240 const base::DictionaryValue& http_server_properties_dict =
211 *pref_service_->GetDictionary(prefs::kHttpServerProperties); 241 *pref_service_->GetDictionary(prefs::kHttpServerProperties);
212 for (base::DictionaryValue::key_iterator it = 242 for (base::DictionaryValue::key_iterator it =
213 http_server_properties_dict.begin_keys(); 243 http_server_properties_dict.begin_keys();
214 it != http_server_properties_dict.end_keys(); ++it) { 244 it != http_server_properties_dict.end_keys(); ++it) {
215 // Get server's host/pair. 245 // Get server's host/pair.
216 const std::string& server_str = *it; 246 const std::string& server_str = *it;
217 net::HostPortPair server = net::HostPortPair::FromString(server_str); 247 net::HostPortPair server = net::HostPortPair::FromString(server_str);
218 if (server.host().empty()) { 248 if (server.host().empty()) {
219 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 249 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 spdy::SettingsFlagsAndId flags_and_id(0); 304 spdy::SettingsFlagsAndId flags_and_id(0);
275 flags_and_id.set_id(id); 305 flags_and_id.set_id(id);
276 flags_and_id.set_flags(spdy::SETTINGS_FLAG_PERSISTED); 306 flags_and_id.set_flags(spdy::SETTINGS_FLAG_PERSISTED);
277 307
278 spdy_settings.push_back(spdy::SpdySetting(flags_and_id, value)); 308 spdy_settings.push_back(spdy::SpdySetting(flags_and_id, value));
279 } 309 }
280 310
281 (*spdy_settings_map)[server] = spdy_settings; 311 (*spdy_settings_map)[server] = spdy_settings;
282 } 312 }
283 313
314 int pipeline_capability = 0;
mmenke 2011/12/02 21:52:10 Use net::HttpPipelinedHost::UNKNOWN to be a little
James Simonsen 2011/12/03 03:16:00 Done.
315 if ((server_pref_dict->GetInteger(
316 "pipeline_capability", &pipeline_capability)) && pipeline_capability) {
mmenke 2011/12/02 21:52:10 pipeline_capability != net::HttpPipelinedHost::UNK
James Simonsen 2011/12/03 03:16:00 Done.
317 (*pipeline_capability_map)[server] =
318 static_cast<net::HttpPipelinedHost::Capability>(pipeline_capability);
319 }
320
284 // Get alternate_protocol server. 321 // Get alternate_protocol server.
285 DCHECK(!ContainsKey(*alternate_protocol_map, server)); 322 DCHECK(!ContainsKey(*alternate_protocol_map, server));
286 base::DictionaryValue* port_alternate_protocol_dict = NULL; 323 base::DictionaryValue* port_alternate_protocol_dict = NULL;
287 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( 324 if (!server_pref_dict->GetDictionaryWithoutPathExpansion(
288 "alternate_protocol", &port_alternate_protocol_dict)) { 325 "alternate_protocol", &port_alternate_protocol_dict)) {
289 continue; 326 continue;
290 } 327 }
291 328
292 do { 329 do {
293 int port = 0; 330 int port = 0;
(...skipping 22 matching lines...) Expand all
316 } 353 }
317 354
318 BrowserThread::PostTask( 355 BrowserThread::PostTask(
319 BrowserThread::IO, 356 BrowserThread::IO,
320 FROM_HERE, 357 FROM_HERE,
321 base::Bind(&HttpServerPropertiesManager:: 358 base::Bind(&HttpServerPropertiesManager::
322 UpdateCacheFromPrefsOnIO, 359 UpdateCacheFromPrefsOnIO,
323 base::Unretained(this), 360 base::Unretained(this),
324 base::Owned(spdy_servers), 361 base::Owned(spdy_servers),
325 base::Owned(spdy_settings_map), 362 base::Owned(spdy_settings_map),
326 base::Owned(alternate_protocol_map))); 363 base::Owned(alternate_protocol_map),
364 base::Owned(pipeline_capability_map)));
327 } 365 }
328 366
329 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO( 367 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
330 StringVector* spdy_servers, 368 StringVector* spdy_servers,
331 net::SpdySettingsMap* spdy_settings_map, 369 net::SpdySettingsMap* spdy_settings_map,
332 net::AlternateProtocolMap* alternate_protocol_map) { 370 net::AlternateProtocolMap* alternate_protocol_map,
371 net::PipelineCapabilityMap* pipeline_capability_map) {
333 // Preferences have the master data because admins might have pushed new 372 // Preferences have the master data because admins might have pushed new
334 // preferences. Update the cached data with new data from preferences. 373 // preferences. Update the cached data with new data from preferences.
335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
336 375
337 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); 376 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
338 377
339 // Clear the cached data and use the new spdy_settings from preferences. 378 // Clear the cached data and use the new spdy_settings from preferences.
340 http_server_properties_impl_->InitializeSpdySettingsServers( 379 http_server_properties_impl_->InitializeSpdySettingsServers(
341 spdy_settings_map); 380 spdy_settings_map);
342 381
343 // Clear the cached data and use the new Alternate-Protocol server list from 382 // Clear the cached data and use the new Alternate-Protocol server list from
344 // preferences. 383 // preferences.
345 http_server_properties_impl_->InitializeAlternateProtocolServers( 384 http_server_properties_impl_->InitializeAlternateProtocolServers(
346 alternate_protocol_map); 385 alternate_protocol_map);
386
387 http_server_properties_impl_->InitializePipelineCapabilities(
388 pipeline_capability_map);
347 } 389 }
348 390
349 391
350 // 392 //
351 // Update Preferences with data from the cached data. 393 // Update Preferences with data from the cached data.
352 // 394 //
353 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { 395 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() {
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
355 // Cancel pending updates, if any. 397 // Cancel pending updates, if any.
356 io_prefs_update_timer_->Stop(); 398 io_prefs_update_timer_->Stop();
(...skipping 17 matching lines...) Expand all
374 http_server_properties_impl_->GetSpdyServerList(spdy_server_list); 416 http_server_properties_impl_->GetSpdyServerList(spdy_server_list);
375 417
376 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; 418 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap;
377 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map(); 419 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map();
378 420
379 net::AlternateProtocolMap* alternate_protocol_map = 421 net::AlternateProtocolMap* alternate_protocol_map =
380 new net::AlternateProtocolMap; 422 new net::AlternateProtocolMap;
381 *alternate_protocol_map = 423 *alternate_protocol_map =
382 http_server_properties_impl_->alternate_protocol_map(); 424 http_server_properties_impl_->alternate_protocol_map();
383 425
426 net::PipelineCapabilityMap* pipeline_capability_map =
427 new net::PipelineCapabilityMap;
428 *pipeline_capability_map =
429 http_server_properties_impl_->GetPipelineCapabilityMap();
430
384 // Update the preferences on the UI thread. 431 // Update the preferences on the UI thread.
385 BrowserThread::PostTask( 432 BrowserThread::PostTask(
386 BrowserThread::UI, 433 BrowserThread::UI,
387 FROM_HERE, 434 FROM_HERE,
388 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI, 435 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI,
389 ui_weak_ptr_, 436 ui_weak_ptr_,
390 base::Owned(spdy_server_list), 437 base::Owned(spdy_server_list),
391 base::Owned(spdy_settings_map), 438 base::Owned(spdy_settings_map),
392 base::Owned(alternate_protocol_map))); 439 base::Owned(alternate_protocol_map),
440 base::Owned(pipeline_capability_map)));
393 } 441 }
394 442
395 // A local or temporary data structure to hold supports_spdy, SpdySettings and 443 // A local or temporary data structure to hold supports_spdy, SpdySettings and
mmenke 2011/12/02 21:52:10 While you're here, mind replacing supports_spdy wi
James Simonsen 2011/12/03 03:16:00 Done.
396 // PortAlternateProtocolPair preferences for a server. This is used only in 444 // PortAlternateProtocolPair preferences for a server. This is used only in
397 // UpdatePrefsOnUI. 445 // UpdatePrefsOnUI.
mmenke 2011/12/02 21:52:10 Update comment.
James Simonsen 2011/12/03 03:16:00 Done.
398 struct ServerPref { 446 struct ServerPref {
399 ServerPref() 447 ServerPref()
400 : supports_spdy(false), 448 : supports_spdy(false),
401 settings(NULL), 449 settings(NULL),
402 alternate_protocol(NULL) { 450 alternate_protocol(NULL),
451 pipeline_capability(net::HttpPipelinedHost::UNKNOWN) {
403 } 452 }
404 ServerPref(bool supports_spdy, 453 ServerPref(bool supports_spdy,
405 const spdy::SpdySettings* settings, 454 const spdy::SpdySettings* settings,
406 const net::PortAlternateProtocolPair* alternate_protocol) 455 const net::PortAlternateProtocolPair* alternate_protocol)
407 : supports_spdy(supports_spdy), 456 : supports_spdy(supports_spdy),
408 settings(settings), 457 settings(settings),
409 alternate_protocol(alternate_protocol) { 458 alternate_protocol(alternate_protocol),
459 pipeline_capability(net::HttpPipelinedHost::UNKNOWN) {
410 } 460 }
411 bool supports_spdy; 461 bool supports_spdy;
412 const spdy::SpdySettings* settings; 462 const spdy::SpdySettings* settings;
413 const net::PortAlternateProtocolPair* alternate_protocol; 463 const net::PortAlternateProtocolPair* alternate_protocol;
464 net::HttpPipelinedHost::Capability pipeline_capability;
414 }; 465 };
415 466
416 void HttpServerPropertiesManager::UpdatePrefsOnUI( 467 void HttpServerPropertiesManager::UpdatePrefsOnUI(
417 base::ListValue* spdy_server_list, 468 base::ListValue* spdy_server_list,
418 net::SpdySettingsMap* spdy_settings_map, 469 net::SpdySettingsMap* spdy_settings_map,
419 net::AlternateProtocolMap* alternate_protocol_map) { 470 net::AlternateProtocolMap* alternate_protocol_map,
471 net::PipelineCapabilityMap* pipeline_capability_map) {
420 472
421 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; 473 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
422 ServerPrefMap server_pref_map; 474 ServerPrefMap server_pref_map;
423 475
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
425 477
426 // Add servers that support spdy to server_pref_map. 478 // Add servers that support spdy to server_pref_map.
427 std::string s; 479 std::string s;
428 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); 480 for (base::ListValue::const_iterator list_it = spdy_server_list->begin();
429 list_it != spdy_server_list->end(); ++list_it) { 481 list_it != spdy_server_list->end(); ++list_it) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 521
470 ServerPrefMap::iterator it = server_pref_map.find(server); 522 ServerPrefMap::iterator it = server_pref_map.find(server);
471 if (it == server_pref_map.end()) { 523 if (it == server_pref_map.end()) {
472 ServerPref server_pref(false, NULL, &map_it->second); 524 ServerPref server_pref(false, NULL, &map_it->second);
473 server_pref_map[server] = server_pref; 525 server_pref_map[server] = server_pref;
474 } else { 526 } else {
475 it->second.alternate_protocol = &map_it->second; 527 it->second.alternate_protocol = &map_it->second;
476 } 528 }
477 } 529 }
478 530
531 for (net::PipelineCapabilityMap::const_iterator map_it =
532 pipeline_capability_map->begin();
mmenke 2011/12/02 21:52:10 Could you indent this 4 more spaces, to make it cl
James Simonsen 2011/12/03 03:16:00 Done.
533 map_it != pipeline_capability_map->end(); ++map_it) {
534 const net::HostPortPair& server = map_it->first;
535 const net::HttpPipelinedHost::Capability& pipeline_capability =
536 map_it->second;
537
538 ServerPrefMap::iterator it = server_pref_map.find(server);
539 if (it == server_pref_map.end()) {
540 ServerPref server_pref;
541 server_pref.pipeline_capability = pipeline_capability;
542 server_pref_map[server] = server_pref;
543 } else {
544 it->second.pipeline_capability = pipeline_capability;
545 }
546 }
547
479 // Persist the prefs::kHttpServerProperties. 548 // Persist the prefs::kHttpServerProperties.
480 base::DictionaryValue http_server_properties_dict; 549 base::DictionaryValue http_server_properties_dict;
481 for (ServerPrefMap::const_iterator map_it = 550 for (ServerPrefMap::const_iterator map_it =
482 server_pref_map.begin(); 551 server_pref_map.begin();
483 map_it != server_pref_map.end(); ++map_it) { 552 map_it != server_pref_map.end(); ++map_it) {
484 const net::HostPortPair& server = map_it->first; 553 const net::HostPortPair& server = map_it->first;
485 const ServerPref& server_pref = map_it->second; 554 const ServerPref& server_pref = map_it->second;
486 555
487 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 556 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
488 557
(...skipping 22 matching lines...) Expand all
511 new base::DictionaryValue; 580 new base::DictionaryValue;
512 const net::PortAlternateProtocolPair* port_alternate_protocol = 581 const net::PortAlternateProtocolPair* port_alternate_protocol =
513 server_pref.alternate_protocol; 582 server_pref.alternate_protocol;
514 port_alternate_protocol_dict->SetInteger( 583 port_alternate_protocol_dict->SetInteger(
515 "port", port_alternate_protocol->port); 584 "port", port_alternate_protocol->port);
516 port_alternate_protocol_dict->SetInteger( 585 port_alternate_protocol_dict->SetInteger(
517 "protocol", port_alternate_protocol->protocol); 586 "protocol", port_alternate_protocol->protocol);
518 server_pref_dict->SetWithoutPathExpansion( 587 server_pref_dict->SetWithoutPathExpansion(
519 "alternate_protocol", port_alternate_protocol_dict); 588 "alternate_protocol", port_alternate_protocol_dict);
520 } 589 }
590
591 if (server_pref.pipeline_capability != net::HttpPipelinedHost::UNKNOWN) {
592 server_pref_dict->SetInteger("pipeline_capability",
593 server_pref.pipeline_capability);
594 }
595
521 http_server_properties_dict.SetWithoutPathExpansion( 596 http_server_properties_dict.SetWithoutPathExpansion(
522 server.ToString(), server_pref_dict); 597 server.ToString(), server_pref_dict);
mmenke 2011/12/02 21:52:10 Mind fixing the indentation in this old code while
James Simonsen 2011/12/03 03:16:00 Done.
523 } 598 }
524 599
525 setting_prefs_ = true; 600 setting_prefs_ = true;
526 pref_service_->Set(prefs::kHttpServerProperties, 601 pref_service_->Set(prefs::kHttpServerProperties,
527 http_server_properties_dict); 602 http_server_properties_dict);
528 setting_prefs_ = false; 603 setting_prefs_ = false;
529 } 604 }
530 605
531 void HttpServerPropertiesManager::Observe( 606 void HttpServerPropertiesManager::Observe(
532 int type, 607 int type,
533 const content::NotificationSource& source, 608 const content::NotificationSource& source,
534 const content::NotificationDetails& details) { 609 const content::NotificationDetails& details) {
535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
536 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); 611 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED);
537 PrefService* prefs = content::Source<PrefService>(source).ptr(); 612 PrefService* prefs = content::Source<PrefService>(source).ptr();
538 DCHECK(prefs == pref_service_); 613 DCHECK(prefs == pref_service_);
539 std::string* pref_name = content::Details<std::string>(details).ptr(); 614 std::string* pref_name = content::Details<std::string>(details).ptr();
540 if (*pref_name == prefs::kHttpServerProperties) { 615 if (*pref_name == prefs::kHttpServerProperties) {
541 if (!setting_prefs_) 616 if (!setting_prefs_)
542 ScheduleUpdateCacheOnUI(); 617 ScheduleUpdateCacheOnUI();
543 } else { 618 } else {
544 NOTREACHED(); 619 NOTREACHED();
545 } 620 }
546 } 621 }
547 622
548 } // namespace chrome_browser_net 623 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698