Skip to content

Commit

Permalink
Save pipelining capabilities for the most used hosts between sessions.
Browse files Browse the repository at this point in the history
BUG=None
TEST=unit_tests


Review URL: http://codereview.chromium.org/8770035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113315 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
simonjam@chromium.org committed Dec 7, 2011
1 parent 12d264b commit acc32d1
Show file tree
Hide file tree
Showing 17 changed files with 373 additions and 112 deletions.
4 changes: 2 additions & 2 deletions base/memory/mru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ class MRUCacheBase {
// can keep them as you insert or delete things (as long as you don't delete
// the one you are pointing to) and they will still be valid.
iterator begin() { return ordering_.begin(); }
const_iterator begin() const { ordering_.begin(); }
const_iterator begin() const { return ordering_.begin(); }
iterator end() { return ordering_.end(); }
const_iterator end() const { return ordering_.end(); }

reverse_iterator rbegin() { return ordering_.rbegin(); }
const_reverse_iterator rbegin() const { ordering_.rbegin(); }
const_reverse_iterator rbegin() const { return ordering_.rbegin(); }
reverse_iterator rend() { return ordering_.rend(); }
const_reverse_iterator rend() const { return ordering_.rend(); }

Expand Down
98 changes: 87 additions & 11 deletions chrome/browser/net/http_server_properties_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,33 @@ HttpServerPropertiesManager::spdy_settings_map() const {
return http_server_properties_impl_->spdy_settings_map();
}

net::HttpPipelinedHostCapability
HttpServerPropertiesManager::GetPipelineCapability(
const net::HostPortPair& origin) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
return http_server_properties_impl_->GetPipelineCapability(origin);
}

void HttpServerPropertiesManager::SetPipelineCapability(
const net::HostPortPair& origin,
net::HttpPipelinedHostCapability capability) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
http_server_properties_impl_->SetPipelineCapability(origin, capability);
ScheduleUpdatePrefsOnIO();
}

void HttpServerPropertiesManager::ClearPipelineCapabilities() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
http_server_properties_impl_->ClearPipelineCapabilities();
ScheduleUpdatePrefsOnIO();
}

net::PipelineCapabilityMap
HttpServerPropertiesManager::GetPipelineCapabilityMap() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
return http_server_properties_impl_->GetPipelineCapabilityMap();
}

//
// Update the HttpServerPropertiesImpl's cache with data from preferences.
//
Expand Down Expand Up @@ -207,6 +234,9 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
net::AlternateProtocolMap* alternate_protocol_map =
new net::AlternateProtocolMap;

net::PipelineCapabilityMap* pipeline_capability_map =
new net::PipelineCapabilityMap;

const base::DictionaryValue& http_server_properties_dict =
*pref_service_->GetDictionary(prefs::kHttpServerProperties);
for (base::DictionaryValue::key_iterator it =
Expand Down Expand Up @@ -281,6 +311,14 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
(*spdy_settings_map)[server] = spdy_settings;
}

int pipeline_capability = net::PIPELINE_UNKNOWN;
if ((server_pref_dict->GetInteger(
"pipeline_capability", &pipeline_capability)) &&
pipeline_capability != net::PIPELINE_UNKNOWN) {
(*pipeline_capability_map)[server] =
static_cast<net::HttpPipelinedHostCapability>(pipeline_capability);
}

// Get alternate_protocol server.
DCHECK(!ContainsKey(*alternate_protocol_map, server));
base::DictionaryValue* port_alternate_protocol_dict = NULL;
Expand Down Expand Up @@ -323,13 +361,15 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
base::Unretained(this),
base::Owned(spdy_servers),
base::Owned(spdy_settings_map),
base::Owned(alternate_protocol_map)));
base::Owned(alternate_protocol_map),
base::Owned(pipeline_capability_map)));
}

void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
StringVector* spdy_servers,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map) {
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map) {
// Preferences have the master data because admins might have pushed new
// preferences. Update the cached data with new data from preferences.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
Expand All @@ -344,6 +384,9 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
// preferences.
http_server_properties_impl_->InitializeAlternateProtocolServers(
alternate_protocol_map);

http_server_properties_impl_->InitializePipelineCapabilities(
pipeline_capability_map);
}


Expand Down Expand Up @@ -381,6 +424,11 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() {
*alternate_protocol_map =
http_server_properties_impl_->alternate_protocol_map();

net::PipelineCapabilityMap* pipeline_capability_map =
new net::PipelineCapabilityMap;
*pipeline_capability_map =
http_server_properties_impl_->GetPipelineCapabilityMap();

// Update the preferences on the UI thread.
BrowserThread::PostTask(
BrowserThread::UI,
Expand All @@ -389,34 +437,39 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() {
ui_weak_ptr_,
base::Owned(spdy_server_list),
base::Owned(spdy_settings_map),
base::Owned(alternate_protocol_map)));
base::Owned(alternate_protocol_map),
base::Owned(pipeline_capability_map)));
}

// A local or temporary data structure to hold supports_spdy, SpdySettings and
// PortAlternateProtocolPair preferences for a server. This is used only in
// UpdatePrefsOnUI.
// A local or temporary data structure to hold |supports_spdy|, SpdySettings,
// PortAlternateProtocolPair, and |pipeline_capability| preferences for a
// server. This is used only in UpdatePrefsOnUI.
struct ServerPref {
ServerPref()
: supports_spdy(false),
settings(NULL),
alternate_protocol(NULL) {
alternate_protocol(NULL),
pipeline_capability(net::PIPELINE_UNKNOWN) {
}
ServerPref(bool supports_spdy,
const spdy::SpdySettings* settings,
const net::PortAlternateProtocolPair* alternate_protocol)
: supports_spdy(supports_spdy),
settings(settings),
alternate_protocol(alternate_protocol) {
alternate_protocol(alternate_protocol),
pipeline_capability(net::PIPELINE_UNKNOWN) {
}
bool supports_spdy;
const spdy::SpdySettings* settings;
const net::PortAlternateProtocolPair* alternate_protocol;
net::HttpPipelinedHostCapability pipeline_capability;
};

void HttpServerPropertiesManager::UpdatePrefsOnUI(
base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map) {
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map) {

typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
ServerPrefMap server_pref_map;
Expand Down Expand Up @@ -476,6 +529,23 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
}
}

for (net::PipelineCapabilityMap::const_iterator map_it =
pipeline_capability_map->begin();
map_it != pipeline_capability_map->end(); ++map_it) {
const net::HostPortPair& server = map_it->first;
const net::HttpPipelinedHostCapability& pipeline_capability =
map_it->second;

ServerPrefMap::iterator it = server_pref_map.find(server);
if (it == server_pref_map.end()) {
ServerPref server_pref;
server_pref.pipeline_capability = pipeline_capability;
server_pref_map[server] = server_pref;
} else {
it->second.pipeline_capability = pipeline_capability;
}
}

// Persist the prefs::kHttpServerProperties.
base::DictionaryValue http_server_properties_dict;
for (ServerPrefMap::const_iterator map_it =
Expand Down Expand Up @@ -518,8 +588,14 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
server_pref_dict->SetWithoutPathExpansion(
"alternate_protocol", port_alternate_protocol_dict);
}
http_server_properties_dict.SetWithoutPathExpansion(
server.ToString(), server_pref_dict);

if (server_pref.pipeline_capability != net::PIPELINE_UNKNOWN) {
server_pref_dict->SetInteger("pipeline_capability",
server_pref.pipeline_capability);
}

http_server_properties_dict.SetWithoutPathExpansion(server.ToString(),
server_pref_dict);
}

setting_prefs_ = true;
Expand Down
18 changes: 16 additions & 2 deletions chrome/browser/net/http_server_properties_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "content/public/browser/notification_observer.h"
#include "net/base/host_port_pair.h"
#include "net/http/http_pipelined_host_capability.h"
#include "net/http/http_server_properties.h"
#include "net/http/http_server_properties_impl.h"

Expand Down Expand Up @@ -122,6 +123,17 @@ class HttpServerPropertiesManager
// Returns all SpdySettings mappings.
virtual const net::SpdySettingsMap& spdy_settings_map() const OVERRIDE;

virtual net::HttpPipelinedHostCapability GetPipelineCapability(
const net::HostPortPair& origin) OVERRIDE;

virtual void SetPipelineCapability(
const net::HostPortPair& origin,
net::HttpPipelinedHostCapability capability) OVERRIDE;

virtual void ClearPipelineCapabilities() OVERRIDE;

virtual net::PipelineCapabilityMap GetPipelineCapabilityMap() const OVERRIDE;

protected:
// --------------------
// SPDY related methods
Expand All @@ -145,7 +157,8 @@ class HttpServerPropertiesManager
void UpdateCacheFromPrefsOnIO(
std::vector<std::string>* spdy_servers,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map);
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map);

// These are used to delay updating the preferences when cached data in
// |http_server_properties_impl_| is changing, and execute only one update per
Expand All @@ -167,7 +180,8 @@ class HttpServerPropertiesManager
void UpdatePrefsOnUI(
base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map);
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map);

private:
// Callback for preference changes.
Expand Down
61 changes: 57 additions & 4 deletions chrome/browser/net/http_server_properties_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {

MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void());
MOCK_METHOD0(UpdatePrefsFromCacheOnIO, void());
MOCK_METHOD3(UpdateCacheFromPrefsOnIO,
MOCK_METHOD4(UpdateCacheFromPrefsOnIO,
void(std::vector<std::string>* spdy_servers,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map));
MOCK_METHOD3(UpdatePrefsOnUI,
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map));
MOCK_METHOD4(UpdatePrefsOnUI,
void(base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map));
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map));

private:
DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager);
Expand Down Expand Up @@ -152,6 +154,9 @@ TEST_F(HttpServerPropertiesManagerTest,
server_pref_dict->SetWithoutPathExpansion(
"alternate_protocol", alternate_protocol);

// Set pipeline capability for www.google.com:80.
server_pref_dict->SetInteger("pipeline_capability", net::PIPELINE_CAPABLE);

// Set the server preference for www.google.com:80.
base::DictionaryValue* http_server_properties_dict =
new base::DictionaryValue;
Expand Down Expand Up @@ -181,6 +186,9 @@ TEST_F(HttpServerPropertiesManagerTest,
server_pref_dict1->SetWithoutPathExpansion(
"alternate_protocol", alternate_protocol1);

// Set pipelining capability for mail.google.com:80
server_pref_dict1->SetInteger("pipeline_capability", net::PIPELINE_INCAPABLE);

// Set the server preference for mail.google.com:80.
http_server_properties_dict->SetWithoutPathExpansion(
"mail.google.com:80", server_pref_dict1);
Expand Down Expand Up @@ -238,6 +246,14 @@ TEST_F(HttpServerPropertiesManagerTest,
net::HostPortPair::FromString("mail.google.com:80"));
EXPECT_EQ(444, port_alternate_protocol.port);
EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol);

// Verify pipeline capability.
EXPECT_EQ(net::PIPELINE_CAPABLE,
http_server_props_manager_->GetPipelineCapability(
net::HostPortPair::FromString("www.google.com:80")));
EXPECT_EQ(net::PIPELINE_INCAPABLE,
http_server_props_manager_->GetPipelineCapability(
net::HostPortPair::FromString("mail.google.com:80")));
}

TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
Expand Down Expand Up @@ -306,6 +322,33 @@ TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) {
EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol);
}

TEST_F(HttpServerPropertiesManagerTest, PipelineCapability) {
ExpectPrefsUpdate();

net::HostPortPair known_pipeliner("pipeline.com", 8080);
net::HostPortPair bad_pipeliner("wordpress.com", 80);
EXPECT_EQ(net::PIPELINE_UNKNOWN,
http_server_props_manager_->GetPipelineCapability(known_pipeliner));
EXPECT_EQ(net::PIPELINE_UNKNOWN,
http_server_props_manager_->GetPipelineCapability(bad_pipeliner));

// Post an update task to the IO thread. SetPipelineCapability calls
// ScheduleUpdatePrefsOnIO.
http_server_props_manager_->SetPipelineCapability(known_pipeliner,
net::PIPELINE_CAPABLE);
http_server_props_manager_->SetPipelineCapability(bad_pipeliner,
net::PIPELINE_INCAPABLE);

// Run the task.
loop_.RunAllPending();

EXPECT_EQ(net::PIPELINE_CAPABLE,
http_server_props_manager_->GetPipelineCapability(known_pipeliner));
EXPECT_EQ(net::PIPELINE_INCAPABLE,
http_server_props_manager_->GetPipelineCapability(bad_pipeliner));
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
}

TEST_F(HttpServerPropertiesManagerTest, Clear) {
ExpectPrefsUpdate();

Expand All @@ -321,6 +364,10 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
spdy_settings.push_back(std::make_pair(id1, 31337));
http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings);

net::HostPortPair known_pipeliner("pipeline.com", 8080);
http_server_props_manager_->SetPipelineCapability(known_pipeliner,
net::PIPELINE_CAPABLE);

// Run the task.
loop_.RunAllPending();

Expand All @@ -337,6 +384,9 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags());
EXPECT_EQ(31337U, spdy_setting1_ret.second);

EXPECT_EQ(net::PIPELINE_CAPABLE,
http_server_props_manager_->GetPipelineCapability(known_pipeliner));

Mock::VerifyAndClearExpectations(http_server_props_manager_.get());

ExpectPrefsUpdate();
Expand All @@ -354,6 +404,9 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
http_server_props_manager_->GetSpdySettings(spdy_server_mail);
EXPECT_EQ(0U, spdy_settings1_ret.size());

EXPECT_EQ(net::PIPELINE_UNKNOWN,
http_server_props_manager_->GetPipelineCapability(known_pipeliner));

Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
}

Expand Down
Loading

0 comments on commit acc32d1

Please sign in to comment.