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

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: Merged 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::HttpPipelinedHostCapability
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::HttpPipelinedHostCapability 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 = net::PIPELINE_UNKNOWN;
315 if ((server_pref_dict->GetInteger(
316 "pipeline_capability", &pipeline_capability)) &&
317 pipeline_capability != net::PIPELINE_UNKNOWN) {
318 (*pipeline_capability_map)[server] =
319 static_cast<net::HttpPipelinedHostCapability>(pipeline_capability);
320 }
321
284 // Get alternate_protocol server. 322 // Get alternate_protocol server.
285 DCHECK(!ContainsKey(*alternate_protocol_map, server)); 323 DCHECK(!ContainsKey(*alternate_protocol_map, server));
286 base::DictionaryValue* port_alternate_protocol_dict = NULL; 324 base::DictionaryValue* port_alternate_protocol_dict = NULL;
287 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( 325 if (!server_pref_dict->GetDictionaryWithoutPathExpansion(
288 "alternate_protocol", &port_alternate_protocol_dict)) { 326 "alternate_protocol", &port_alternate_protocol_dict)) {
289 continue; 327 continue;
290 } 328 }
291 329
292 do { 330 do {
293 int port = 0; 331 int port = 0;
(...skipping 22 matching lines...) Expand all
316 } 354 }
317 355
318 BrowserThread::PostTask( 356 BrowserThread::PostTask(
319 BrowserThread::IO, 357 BrowserThread::IO,
320 FROM_HERE, 358 FROM_HERE,
321 base::Bind(&HttpServerPropertiesManager:: 359 base::Bind(&HttpServerPropertiesManager::
322 UpdateCacheFromPrefsOnIO, 360 UpdateCacheFromPrefsOnIO,
323 base::Unretained(this), 361 base::Unretained(this),
324 base::Owned(spdy_servers), 362 base::Owned(spdy_servers),
325 base::Owned(spdy_settings_map), 363 base::Owned(spdy_settings_map),
326 base::Owned(alternate_protocol_map))); 364 base::Owned(alternate_protocol_map),
365 base::Owned(pipeline_capability_map)));
327 } 366 }
328 367
329 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO( 368 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
330 StringVector* spdy_servers, 369 StringVector* spdy_servers,
331 net::SpdySettingsMap* spdy_settings_map, 370 net::SpdySettingsMap* spdy_settings_map,
332 net::AlternateProtocolMap* alternate_protocol_map) { 371 net::AlternateProtocolMap* alternate_protocol_map,
372 net::PipelineCapabilityMap* pipeline_capability_map) {
333 // Preferences have the master data because admins might have pushed new 373 // Preferences have the master data because admins might have pushed new
334 // preferences. Update the cached data with new data from preferences. 374 // preferences. Update the cached data with new data from preferences.
335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
336 376
337 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); 377 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
338 378
339 // Clear the cached data and use the new spdy_settings from preferences. 379 // Clear the cached data and use the new spdy_settings from preferences.
340 http_server_properties_impl_->InitializeSpdySettingsServers( 380 http_server_properties_impl_->InitializeSpdySettingsServers(
341 spdy_settings_map); 381 spdy_settings_map);
342 382
343 // Clear the cached data and use the new Alternate-Protocol server list from 383 // Clear the cached data and use the new Alternate-Protocol server list from
344 // preferences. 384 // preferences.
345 http_server_properties_impl_->InitializeAlternateProtocolServers( 385 http_server_properties_impl_->InitializeAlternateProtocolServers(
346 alternate_protocol_map); 386 alternate_protocol_map);
387
388 http_server_properties_impl_->InitializePipelineCapabilities(
389 pipeline_capability_map);
347 } 390 }
348 391
349 392
350 // 393 //
351 // Update Preferences with data from the cached data. 394 // Update Preferences with data from the cached data.
352 // 395 //
353 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { 396 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() {
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
355 // Cancel pending updates, if any. 398 // Cancel pending updates, if any.
356 io_prefs_update_timer_->Stop(); 399 io_prefs_update_timer_->Stop();
(...skipping 17 matching lines...) Expand all
374 http_server_properties_impl_->GetSpdyServerList(spdy_server_list); 417 http_server_properties_impl_->GetSpdyServerList(spdy_server_list);
375 418
376 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; 419 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap;
377 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map(); 420 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map();
378 421
379 net::AlternateProtocolMap* alternate_protocol_map = 422 net::AlternateProtocolMap* alternate_protocol_map =
380 new net::AlternateProtocolMap; 423 new net::AlternateProtocolMap;
381 *alternate_protocol_map = 424 *alternate_protocol_map =
382 http_server_properties_impl_->alternate_protocol_map(); 425 http_server_properties_impl_->alternate_protocol_map();
383 426
427 net::PipelineCapabilityMap* pipeline_capability_map =
428 new net::PipelineCapabilityMap;
429 *pipeline_capability_map =
430 http_server_properties_impl_->GetPipelineCapabilityMap();
431
384 // Update the preferences on the UI thread. 432 // Update the preferences on the UI thread.
385 BrowserThread::PostTask( 433 BrowserThread::PostTask(
386 BrowserThread::UI, 434 BrowserThread::UI,
387 FROM_HERE, 435 FROM_HERE,
388 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI, 436 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI,
389 ui_weak_ptr_, 437 ui_weak_ptr_,
390 base::Owned(spdy_server_list), 438 base::Owned(spdy_server_list),
391 base::Owned(spdy_settings_map), 439 base::Owned(spdy_settings_map),
392 base::Owned(alternate_protocol_map))); 440 base::Owned(alternate_protocol_map),
441 base::Owned(pipeline_capability_map)));
393 } 442 }
394 443
395 // A local or temporary data structure to hold supports_spdy, SpdySettings and 444 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
396 // PortAlternateProtocolPair preferences for a server. This is used only in 445 // PortAlternateProtocolPair, and |pipeline_capability| preferences for a
397 // UpdatePrefsOnUI. 446 // server. This is used only in UpdatePrefsOnUI.
398 struct ServerPref { 447 struct ServerPref {
399 ServerPref() 448 ServerPref()
400 : supports_spdy(false), 449 : supports_spdy(false),
401 settings(NULL), 450 settings(NULL),
402 alternate_protocol(NULL) { 451 alternate_protocol(NULL),
452 pipeline_capability(net::PIPELINE_UNKNOWN) {
403 } 453 }
404 ServerPref(bool supports_spdy, 454 ServerPref(bool supports_spdy,
405 const spdy::SpdySettings* settings, 455 const spdy::SpdySettings* settings,
406 const net::PortAlternateProtocolPair* alternate_protocol) 456 const net::PortAlternateProtocolPair* alternate_protocol)
407 : supports_spdy(supports_spdy), 457 : supports_spdy(supports_spdy),
408 settings(settings), 458 settings(settings),
409 alternate_protocol(alternate_protocol) { 459 alternate_protocol(alternate_protocol),
460 pipeline_capability(net::PIPELINE_UNKNOWN) {
410 } 461 }
411 bool supports_spdy; 462 bool supports_spdy;
412 const spdy::SpdySettings* settings; 463 const spdy::SpdySettings* settings;
413 const net::PortAlternateProtocolPair* alternate_protocol; 464 const net::PortAlternateProtocolPair* alternate_protocol;
465 net::HttpPipelinedHostCapability pipeline_capability;
414 }; 466 };
415 467
416 void HttpServerPropertiesManager::UpdatePrefsOnUI( 468 void HttpServerPropertiesManager::UpdatePrefsOnUI(
417 base::ListValue* spdy_server_list, 469 base::ListValue* spdy_server_list,
418 net::SpdySettingsMap* spdy_settings_map, 470 net::SpdySettingsMap* spdy_settings_map,
419 net::AlternateProtocolMap* alternate_protocol_map) { 471 net::AlternateProtocolMap* alternate_protocol_map,
472 net::PipelineCapabilityMap* pipeline_capability_map) {
420 473
421 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; 474 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
422 ServerPrefMap server_pref_map; 475 ServerPrefMap server_pref_map;
423 476
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
425 478
426 // Add servers that support spdy to server_pref_map. 479 // Add servers that support spdy to server_pref_map.
427 std::string s; 480 std::string s;
428 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); 481 for (base::ListValue::const_iterator list_it = spdy_server_list->begin();
429 list_it != spdy_server_list->end(); ++list_it) { 482 list_it != spdy_server_list->end(); ++list_it) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 522
470 ServerPrefMap::iterator it = server_pref_map.find(server); 523 ServerPrefMap::iterator it = server_pref_map.find(server);
471 if (it == server_pref_map.end()) { 524 if (it == server_pref_map.end()) {
472 ServerPref server_pref(false, NULL, &map_it->second); 525 ServerPref server_pref(false, NULL, &map_it->second);
473 server_pref_map[server] = server_pref; 526 server_pref_map[server] = server_pref;
474 } else { 527 } else {
475 it->second.alternate_protocol = &map_it->second; 528 it->second.alternate_protocol = &map_it->second;
476 } 529 }
477 } 530 }
478 531
532 for (net::PipelineCapabilityMap::const_iterator map_it =
533 pipeline_capability_map->begin();
534 map_it != pipeline_capability_map->end(); ++map_it) {
535 const net::HostPortPair& server = map_it->first;
536 const net::HttpPipelinedHostCapability& pipeline_capability =
537 map_it->second;
538
539 ServerPrefMap::iterator it = server_pref_map.find(server);
540 if (it == server_pref_map.end()) {
541 ServerPref server_pref;
542 server_pref.pipeline_capability = pipeline_capability;
543 server_pref_map[server] = server_pref;
544 } else {
545 it->second.pipeline_capability = pipeline_capability;
546 }
547 }
548
479 // Persist the prefs::kHttpServerProperties. 549 // Persist the prefs::kHttpServerProperties.
480 base::DictionaryValue http_server_properties_dict; 550 base::DictionaryValue http_server_properties_dict;
481 for (ServerPrefMap::const_iterator map_it = 551 for (ServerPrefMap::const_iterator map_it =
482 server_pref_map.begin(); 552 server_pref_map.begin();
483 map_it != server_pref_map.end(); ++map_it) { 553 map_it != server_pref_map.end(); ++map_it) {
484 const net::HostPortPair& server = map_it->first; 554 const net::HostPortPair& server = map_it->first;
485 const ServerPref& server_pref = map_it->second; 555 const ServerPref& server_pref = map_it->second;
486 556
487 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 557 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
488 558
(...skipping 22 matching lines...) Expand all
511 new base::DictionaryValue; 581 new base::DictionaryValue;
512 const net::PortAlternateProtocolPair* port_alternate_protocol = 582 const net::PortAlternateProtocolPair* port_alternate_protocol =
513 server_pref.alternate_protocol; 583 server_pref.alternate_protocol;
514 port_alternate_protocol_dict->SetInteger( 584 port_alternate_protocol_dict->SetInteger(
515 "port", port_alternate_protocol->port); 585 "port", port_alternate_protocol->port);
516 port_alternate_protocol_dict->SetInteger( 586 port_alternate_protocol_dict->SetInteger(
517 "protocol", port_alternate_protocol->protocol); 587 "protocol", port_alternate_protocol->protocol);
518 server_pref_dict->SetWithoutPathExpansion( 588 server_pref_dict->SetWithoutPathExpansion(
519 "alternate_protocol", port_alternate_protocol_dict); 589 "alternate_protocol", port_alternate_protocol_dict);
520 } 590 }
521 http_server_properties_dict.SetWithoutPathExpansion( 591
522 server.ToString(), server_pref_dict); 592 if (server_pref.pipeline_capability != net::PIPELINE_UNKNOWN) {
593 server_pref_dict->SetInteger("pipeline_capability",
594 server_pref.pipeline_capability);
595 }
596
597 http_server_properties_dict.SetWithoutPathExpansion(server.ToString(),
598 server_pref_dict);
523 } 599 }
524 600
525 setting_prefs_ = true; 601 setting_prefs_ = true;
526 pref_service_->Set(prefs::kHttpServerProperties, 602 pref_service_->Set(prefs::kHttpServerProperties,
527 http_server_properties_dict); 603 http_server_properties_dict);
528 setting_prefs_ = false; 604 setting_prefs_ = false;
529 } 605 }
530 606
531 void HttpServerPropertiesManager::Observe( 607 void HttpServerPropertiesManager::Observe(
532 int type, 608 int type,
533 const content::NotificationSource& source, 609 const content::NotificationSource& source,
534 const content::NotificationDetails& details) { 610 const content::NotificationDetails& details) {
535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
536 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); 612 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED);
537 PrefService* prefs = content::Source<PrefService>(source).ptr(); 613 PrefService* prefs = content::Source<PrefService>(source).ptr();
538 DCHECK(prefs == pref_service_); 614 DCHECK(prefs == pref_service_);
539 std::string* pref_name = content::Details<std::string>(details).ptr(); 615 std::string* pref_name = content::Details<std::string>(details).ptr();
540 if (*pref_name == prefs::kHttpServerProperties) { 616 if (*pref_name == prefs::kHttpServerProperties) {
541 if (!setting_prefs_) 617 if (!setting_prefs_)
542 ScheduleUpdateCacheOnUI(); 618 ScheduleUpdateCacheOnUI();
543 } else { 619 } else {
544 NOTREACHED(); 620 NOTREACHED();
545 } 621 }
546 } 622 }
547 623
548 } // namespace chrome_browser_net 624 } // 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