Commit fc3ff06f authored by thakis@chromium.org's avatar thakis@chromium.org

Revert 113315 (speculative revert for http://crbug.com/106657)

- Save pipelining capabilities for the most used hosts between sessions.

BUG=None
TEST=unit_tests


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

TBR=simonjam@chromium.org
Review URL: http://codereview.chromium.org/8833003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113338 0039d316-1c4b-4281-b951-d872f2087c98
parent 14153a2e
......@@ -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 { return ordering_.begin(); }
const_iterator begin() const { 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 { return ordering_.rbegin(); }
const_reverse_iterator rbegin() const { ordering_.rbegin(); }
reverse_iterator rend() { return ordering_.rend(); }
const_reverse_iterator rend() const { return ordering_.rend(); }
......
......@@ -171,33 +171,6 @@ 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.
//
......@@ -234,9 +207,6 @@ 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 =
......@@ -311,14 +281,6 @@ 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;
......@@ -361,15 +323,13 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
base::Unretained(this),
base::Owned(spdy_servers),
base::Owned(spdy_settings_map),
base::Owned(alternate_protocol_map),
base::Owned(pipeline_capability_map)));
base::Owned(alternate_protocol_map)));
}
void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
StringVector* spdy_servers,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map) {
net::AlternateProtocolMap* alternate_protocol_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));
......@@ -384,9 +344,6 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
// preferences.
http_server_properties_impl_->InitializeAlternateProtocolServers(
alternate_protocol_map);
http_server_properties_impl_->InitializePipelineCapabilities(
pipeline_capability_map);
}
......@@ -424,11 +381,6 @@ 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,
......@@ -437,39 +389,34 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() {
ui_weak_ptr_,
base::Owned(spdy_server_list),
base::Owned(spdy_settings_map),
base::Owned(alternate_protocol_map),
base::Owned(pipeline_capability_map)));
base::Owned(alternate_protocol_map)));
}
// 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.
// A local or temporary data structure to hold supports_spdy, SpdySettings and
// PortAlternateProtocolPair preferences for a server. This is used only in
// UpdatePrefsOnUI.
struct ServerPref {
ServerPref()
: supports_spdy(false),
settings(NULL),
alternate_protocol(NULL),
pipeline_capability(net::PIPELINE_UNKNOWN) {
alternate_protocol(NULL) {
}
ServerPref(bool supports_spdy,
const spdy::SpdySettings* settings,
const net::PortAlternateProtocolPair* alternate_protocol)
: supports_spdy(supports_spdy),
settings(settings),
alternate_protocol(alternate_protocol),
pipeline_capability(net::PIPELINE_UNKNOWN) {
alternate_protocol(alternate_protocol) {
}
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::PipelineCapabilityMap* pipeline_capability_map) {
net::AlternateProtocolMap* alternate_protocol_map) {
typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
ServerPrefMap server_pref_map;
......@@ -529,23 +476,6 @@ 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 =
......@@ -588,14 +518,8 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
server_pref_dict->SetWithoutPathExpansion(
"alternate_protocol", port_alternate_protocol_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);
http_server_properties_dict.SetWithoutPathExpansion(
server.ToString(), server_pref_dict);
}
setting_prefs_ = true;
......
......@@ -17,7 +17,6 @@
#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"
......@@ -123,17 +122,6 @@ 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
......@@ -157,8 +145,7 @@ class HttpServerPropertiesManager
void UpdateCacheFromPrefsOnIO(
std::vector<std::string>* spdy_servers,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map);
net::AlternateProtocolMap* alternate_protocol_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
......@@ -180,8 +167,7 @@ class HttpServerPropertiesManager
void UpdatePrefsOnUI(
base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map);
net::AlternateProtocolMap* alternate_protocol_map);
private:
// Callback for preference changes.
......
......@@ -60,16 +60,14 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {
MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void());
MOCK_METHOD0(UpdatePrefsFromCacheOnIO, void());
MOCK_METHOD4(UpdateCacheFromPrefsOnIO,
MOCK_METHOD3(UpdateCacheFromPrefsOnIO,
void(std::vector<std::string>* spdy_servers,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map));
MOCK_METHOD4(UpdatePrefsOnUI,
net::AlternateProtocolMap* alternate_protocol_map));
MOCK_METHOD3(UpdatePrefsOnUI,
void(base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map,
net::PipelineCapabilityMap* pipeline_capability_map));
net::AlternateProtocolMap* alternate_protocol_map));
private:
DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager);
......@@ -154,9 +152,6 @@ 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;
......@@ -186,9 +181,6 @@ 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);
......@@ -246,14 +238,6 @@ 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) {
......@@ -322,33 +306,6 @@ 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();
......@@ -364,10 +321,6 @@ 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();
......@@ -384,9 +337,6 @@ 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();
......@@ -404,9 +354,6 @@ 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());
}
......
......@@ -6,15 +6,14 @@
#define NET_HTTP_HTTP_PIPELINED_HOST_H_
#pragma once
#include "net/base/host_port_pair.h"
#include "net/base/net_export.h"
#include "net/http/http_pipelined_connection.h"
#include "net/http/http_pipelined_host_capability.h"
namespace net {
class BoundNetLog;
class ClientSocketHandle;
class HostPortPair;
class HttpPipelinedStream;
class ProxyInfo;
struct SSLConfig;
......@@ -24,6 +23,14 @@ struct SSLConfig;
// assigns requests to the least loaded pipelined connection.
class NET_EXPORT_PRIVATE HttpPipelinedHost {
public:
enum Capability {
UNKNOWN,
INCAPABLE,
CAPABLE,
PROBABLY_CAPABLE, // We are using pipelining, but haven't processed enough
// requests to record this host as known to be capable.
};
class Delegate {
public:
// Called when a pipelined host has no outstanding requests on any of its
......@@ -35,9 +42,8 @@ class NET_EXPORT_PRIVATE HttpPipelinedHost {
virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) = 0;
// Called when a host determines if pipelining can be used.
virtual void OnHostDeterminedCapability(
HttpPipelinedHost* host,
HttpPipelinedHostCapability capability) = 0;
virtual void OnHostDeterminedCapability(HttpPipelinedHost* host,
Capability capability) = 0;
};
class Factory {
......@@ -48,7 +54,7 @@ class NET_EXPORT_PRIVATE HttpPipelinedHost {
virtual HttpPipelinedHost* CreateNewHost(
Delegate* delegate, const HostPortPair& origin,
HttpPipelinedConnection::Factory* factory,
HttpPipelinedHostCapability capability) = 0;
Capability capability) = 0;
};
virtual ~HttpPipelinedHost() {}
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_HTTP_HTTP_PIPELINED_HOST_CAPABILITY_H_
#define NET_HTTP_HTTP_PIPELINED_HOST_CAPABILITY_H_
#pragma once
namespace net {
// These values are serialized in Preferences. Do not change these values and
// only add new ones at the end.
enum HttpPipelinedHostCapability {
PIPELINE_UNKNOWN = 0,
PIPELINE_INCAPABLE = 1,
PIPELINE_CAPABLE = 2,
PIPELINE_PROBABLY_CAPABLE = 3, // We are using pipelining, but haven't
// processed enough requests to record this
// host as known to be capable.
};
} // namespace net
#endif // NET_HTTP_HTTP_PIPELINED_HOST_CAPABILITY_H_
......@@ -34,7 +34,7 @@ HttpPipelinedHostImpl::HttpPipelinedHostImpl(
HttpPipelinedHost::Delegate* delegate,
const HostPortPair& origin,
HttpPipelinedConnection::Factory* factory,
HttpPipelinedHostCapability capability)
Capability capability)
: delegate_(delegate),
origin_(origin),
factory_(factory),
......@@ -54,7 +54,7 @@ HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline(
const ProxyInfo& used_proxy_info,
const BoundNetLog& net_log,
bool was_npn_negotiated) {
if (capability_ == PIPELINE_INCAPABLE) {
if (capability_ == INCAPABLE) {
return NULL;
}
HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline(
......@@ -124,21 +124,21 @@ void HttpPipelinedHostImpl::OnPipelineFeedback(
switch (feedback) {
case HttpPipelinedConnection::OK:
++pipelines_[pipeline].num_successes;
if (capability_ == PIPELINE_UNKNOWN) {
capability_ = PIPELINE_PROBABLY_CAPABLE;
if (capability_ == UNKNOWN) {
capability_ = PROBABLY_CAPABLE;
NotifyAllPipelinesHaveCapacity();
} else if (capability_ == PIPELINE_PROBABLY_CAPABLE &&
} else if (capability_ == PROBABLY_CAPABLE &&
pipelines_[pipeline].num_successes >=
kNumKnownSuccessesThreshold) {
capability_ = PIPELINE_CAPABLE;
delegate_->OnHostDeterminedCapability(this, PIPELINE_CAPABLE);
capability_ = CAPABLE;
delegate_->OnHostDeterminedCapability(this, CAPABLE);
}
break;
case HttpPipelinedConnection::PIPELINE_SOCKET_ERROR:
case HttpPipelinedConnection::OLD_HTTP_VERSION:
capability_ = PIPELINE_INCAPABLE;
delegate_->OnHostDeterminedCapability(this, PIPELINE_INCAPABLE);
capability_ = INCAPABLE;
delegate_->OnHostDeterminedCapability(this, INCAPABLE);
break;
case HttpPipelinedConnection::MUST_CLOSE_CONNECTION:
......@@ -149,15 +149,15 @@ void HttpPipelinedHostImpl::OnPipelineFeedback(
int HttpPipelinedHostImpl::GetPipelineCapacity() const {
int capacity = 0;
switch (capability_) {
case PIPELINE_CAPABLE:
case PIPELINE_PROBABLY_CAPABLE:
case CAPABLE:
case PROBABLY_CAPABLE:
capacity = max_pipeline_depth();
break;
case PIPELINE_INCAPABLE:
case INCAPABLE:
CHECK(false);
case PIPELINE_UNKNOWN:
case UNKNOWN:
capacity = 1;
break;
......@@ -169,7 +169,7 @@ int HttpPipelinedHostImpl::GetPipelineCapacity() const {
bool HttpPipelinedHostImpl::CanPipelineAcceptRequests(
HttpPipelinedConnection* pipeline) const {
return capability_ != PIPELINE_INCAPABLE &&
return capability_ != INCAPABLE &&
pipeline->usable() &&
pipeline->active() &&
pipeline->depth() < GetPipelineCapacity();
......
......@@ -15,7 +15,6 @@
#include "net/base/net_export.h"
#include "net/http/http_pipelined_connection.h"
#include "net/http/http_pipelined_host.h"
#include "net/http/http_pipelined_host_capability.h"
namespace net {
......@@ -35,7 +34,7 @@ class NET_EXPORT_PRIVATE HttpPipelinedHostImpl
HttpPipelinedHostImpl(HttpPipelinedHost::Delegate* delegate,
const HostPortPair& origin,
HttpPipelinedConnection::Factory* factory,
HttpPipelinedHostCapability capability);
Capability capability);
virtual ~HttpPipelinedHostImpl();
// HttpPipelinedHost interface
......@@ -99,7 +98,7 @@ class NET_EXPORT_PRIVATE HttpPipelinedHostImpl
const HostPortPair origin_;
PipelineInfoMap pipelines_;
scoped_ptr<HttpPipelinedConnection::Factory> factory_;
HttpPipelinedHostCapability capability_;
Capability capability_;
DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostImpl);
};
......
......@@ -32,7 +32,7 @@ class MockHostDelegate : public HttpPipelinedHost::Delegate {
MOCK_METHOD1(OnHostHasAdditionalCapacity, void(HttpPipelinedHost* host));
MOCK_METHOD2(OnHostDeterminedCapability,
void(HttpPipelinedHost* host,
HttpPipelinedHostCapability capability));
HttpPipelinedHost::Capability capability));
};
class MockPipelineFactory : public HttpPipelinedConnection::Factory {
......@@ -83,10 +83,10 @@ class HttpPipelinedHostImplTest : public testing::Test {
: origin_("host", 123),
factory_(new MockPipelineFactory), // Owned by host_.
host_(new HttpPipelinedHostImpl(&delegate_, origin_, factory_,
PIPELINE_CAPABLE)) {
HttpPipelinedHost::CAPABLE)) {
}
void SetCapability(HttpPipelinedHostCapability capability) {
void SetCapability(HttpPipelinedHost::Capability capability) {
factory_ = new MockPipelineFactory;
host_.reset(new HttpPipelinedHostImpl(
&delegate_, origin_, factory_, capability));
......@@ -200,7 +200,7 @@ TEST_F(HttpPipelinedHostImplTest, PicksLeastLoadedPipeline) {
}
TEST_F(HttpPipelinedHostImplTest, OpensUpOnPipelineSuccess) {
SetCapability(PIPELINE_UNKNOWN);
SetCapability(HttpPipelinedHost::UNKNOWN);
MockPipeline* pipeline = AddTestPipeline(1, true, true);
EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
......@@ -219,7 +219,7 @@ TEST_F(HttpPipelinedHostImplTest, OpensUpOnPipelineSuccess) {
}
TEST_F(HttpPipelinedHostImplTest, OpensAllPipelinesOnPipelineSuccess) {
SetCapability(PIPELINE_UNKNOWN);
SetCapability(HttpPipelinedHost::UNKNOWN);
MockPipeline* pipeline1 = AddTestPipeline(1, false, true);
MockPipeline* pipeline2 = AddTestPipeline(1, true, true);
......@@ -240,14 +240,15 @@ TEST_F(HttpPipelinedHostImplTest, OpensAllPipelinesOnPipelineSuccess) {
}
TEST_F(HttpPipelinedHostImplTest, ShutsDownOnOldVersion) {
SetCapability(PIPELINE_UNKNOWN);
SetCapability(HttpPipelinedHost::UNKNOWN);
MockPipeline* pipeline = AddTestPipeline(1, true, true);
EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
.Times(0);
EXPECT_CALL(delegate_,
OnHostDeterminedCapability(host_.get(), PIPELINE_INCAPABLE))
OnHostDeterminedCapability(host_.get(),
HttpPipelinedHost::INCAPABLE))
.Times(1);
host_->OnPipelineFeedback(pipeline,
HttpPipelinedConnection::OLD_HTTP_VERSION);
......@@ -258,7 +259,7 @@ TEST_F(HttpPipelinedHostImplTest, ShutsDownOnOldVersion) {
}
TEST_F(HttpPipelinedHostImplTest, ConnectionCloseHasNoEffect) {
SetCapability(PIPELINE_UNKNOWN);
SetCapability(HttpPipelinedHost::UNKNOWN);
MockPipeline* pipeline = AddTestPipeline(1, true, true);
EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
......@@ -275,13 +276,14 @@ TEST_F(HttpPipelinedHostImplTest, ConnectionCloseHasNoEffect) {
}
TEST_F(HttpPipelinedHostImplTest, SuccessesLeadToCapable) {
SetCapability(PIPELINE_UNKNOWN);
SetCapability(HttpPipelinedHost::UNKNOWN);
MockPipeline* pipeline = AddTestPipeline(1, true, true);
EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
.Times(1);
EXPECT_CALL(delegate_,
OnHostDeterminedCapability(host_.get(), PIPELINE_CAPABLE))
OnHostDeterminedCapability(host_.get(),
HttpPipelinedHost::CAPABLE))
.Times(1);
host_->OnPipelineFeedback(pipeline, HttpPipelinedConnection::OK);
......
......@@ -6,29 +6,31 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "net/http/http_pipelined_host_capability.h"
#include "net/http/http_pipelined_host_impl.h"
#include "net/http/http_server_properties.h"
namespace net {
// TODO(simonjam): Run experiments with different values of this to see what
// value is good at avoiding evictions without eating too much memory. Until
// then, this is just a bad guess.
static const int kNumHostsToRemember = 200;
class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory {
public:
virtual HttpPipelinedHost* CreateNewHost(
HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin,
HttpPipelinedConnection::Factory* factory,
HttpPipelinedHostCapability capability) OVERRIDE {
HttpPipelinedHost::Capability capability) OVERRIDE {
return new HttpPipelinedHostImpl(delegate, origin, factory, capability);
}
};
HttpPipelinedHostPool::HttpPipelinedHostPool(
Delegate* delegate,
HttpPipelinedHost::Factory* factory,
HttpServerProperties* http_server_properties)
HttpPipelinedHost::Factory* factory)
: delegate_(delegate),
factory_(factory),
http_server_properties_(http_server_properties) {
known_capability_map_(kNumHostsToRemember) {
if (!factory) {
factory_.reset(new HttpPipelinedHostImplFactory);
}
......@@ -40,9 +42,8 @@ HttpPipelinedHostPool::~HttpPipelinedHostPool() {
bool HttpPipelinedHostPool::IsHostEligibleForPipelining(
const HostPortPair& origin) {
HttpPipelinedHostCapability capability =
http_server_properties_->GetPipelineCapability(origin);
return capability != PIPELINE_INCAPABLE;
HttpPipelinedHost::Capability capability = GetHostCapability(origin);
return capability != HttpPipelinedHost::INCAPABLE;
}
HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline(
......@@ -89,9 +90,8 @@ HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost(
return NULL;
}
HttpPipelinedHostCapability capability =
http_server_properties_->GetPipelineCapability(origin);
if (capability == PIPELINE_INCAPABLE) {
HttpPipelinedHost::Capability capability = GetHostCapability(origin);
if (capability == HttpPipelinedHost::INCAPABLE) {
return NULL;
}
......@@ -115,8 +115,22 @@ void HttpPipelinedHostPool::OnHostHasAdditionalCapacity(
void HttpPipelinedHostPool::OnHostDeterminedCapability(
HttpPipelinedHost* host,
HttpPipelinedHostCapability capability) {
http_server_properties_->SetPipelineCapability(host->origin(), capability);
HttpPipelinedHost::Capability capability) {
CapabilityMap::iterator known_it = known_capability_map_.Get(host->origin());
if (known_it == known_capability_map_.end() ||
known_it->second != HttpPipelinedHost::INCAPABLE) {
known_capability_map_.Put(host->origin(), capability);
}
}
HttpPipelinedHost::Capability HttpPipelinedHostPool::GetHostCapability(
const HostPortPair& origin) {
HttpPipelinedHost::Capability capability = HttpPipelinedHost::UNKNOWN;
CapabilityMap::const_iterator it = known_capability_map_.Get(origin);
if (it != known_capability_map_.end()) {
capability = it->second;
}
return capability;
}
} // namespace net
......@@ -10,15 +10,14 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/memory/mru_cache.h"
#include "base/memory/scoped_ptr.h"
#include "net/http/http_pipelined_host.h"
#include "net/http/http_pipelined_host_capability.h"
namespace net {
class HostPortPair;
class HttpPipelinedStream;
class HttpServerProperties;
// Manages all of the pipelining state for specific host with active pipelined
// HTTP requests. Manages connection jobs, constructs pipelined streams, and
......@@ -35,8 +34,7 @@ class NET_EXPORT_PRIVATE HttpPipelinedHostPool
};
HttpPipelinedHostPool(Delegate* delegate,
HttpPipelinedHost::Factory* factory,
HttpServerProperties* http_server_properties_);
HttpPipelinedHost::Factory* factory);
virtual ~HttpPipelinedHostPool();
// Returns true if pipelining might work for |origin|. Generally, this returns
......@@ -69,18 +67,22 @@ class NET_EXPORT_PRIVATE HttpPipelinedHostPool
virtual void OnHostDeterminedCapability(
HttpPipelinedHost* host,
HttpPipelinedHostCapability capability) OVERRIDE;
HttpPipelinedHost::Capability capability) OVERRIDE;
private:
typedef base::MRUCache<HostPortPair,
HttpPipelinedHost::Capability> CapabilityMap;
typedef std::map<const HostPortPair, HttpPipelinedHost*> HostMap;
HttpPipelinedHost* GetPipelinedHost(const HostPortPair& origin,
bool create_if_not_found);
HttpPipelinedHost::Capability GetHostCapability(const HostPortPair& origin);
Delegate* delegate_;
scoped_ptr<HttpPipelinedHost::Factory> factory_;
HostMap host_map_;
HttpServerProperties* http_server_properties_;
CapabilityMap known_capability_map_;
DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostPool);
};
......
......@@ -7,8 +7,6 @@
#include "base/memory/scoped_ptr.h"
#include "net/base/ssl_config_service.h"
#include "net/http/http_pipelined_host.h"
#include "net/http/http_pipelined_host_capability.h"
#include "net/http/http_server_properties_impl.h"
#include "net/proxy/proxy_info.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -38,7 +36,7 @@ class MockHostFactory : public HttpPipelinedHost::Factory {
MOCK_METHOD4(CreateNewHost, HttpPipelinedHost*(
HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin,
HttpPipelinedConnection::Factory* factory,
HttpPipelinedHostCapability capability));
HttpPipelinedHost::Capability capability));
};
class MockHost : public HttpPipelinedHost {
......@@ -68,9 +66,7 @@ class HttpPipelinedHostPoolTest : public testing::Test {
: origin_("host", 123),
factory_(new MockHostFactory), // Owned by pool_.
host_(new MockHost(origin_)), // Owned by pool_.
http_server_properties_(new HttpServerPropertiesImpl),
pool_(new HttpPipelinedHostPool(&delegate_, factory_,
http_server_properties_.get())),
pool_(new HttpPipelinedHostPool(&delegate_, factory_)),
was_npn_negotiated_(false) {
}
......@@ -92,7 +88,6 @@ class HttpPipelinedHostPoolTest : public testing::Test {
MockPoolDelegate delegate_;
MockHostFactory* factory_;
MockHost* host_;
scoped_ptr<HttpServerPropertiesImpl> http_server_properties_;
scoped_ptr<HttpPipelinedHostPool> pool_;
const SSLConfig ssl_config_;
......@@ -104,7 +99,7 @@ class HttpPipelinedHostPoolTest : public testing::Test {
TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) {
EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_));
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_UNKNOWN))
HttpPipelinedHost::UNKNOWN))
.Times(1)
.WillOnce(Return(host_));
......@@ -114,16 +109,16 @@ TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) {
TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) {
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_UNKNOWN))
HttpPipelinedHost::UNKNOWN))
.Times(1)
.WillOnce(Return(host_));
CreateDummyStream();
pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE);
pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::INCAPABLE);
pool_->OnHostIdle(host_);
EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_));
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_INCAPABLE))
HttpPipelinedHost::INCAPABLE))
.Times(0);
EXPECT_EQ(NULL,
pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection,
......@@ -133,18 +128,18 @@ TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) {
TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) {
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_UNKNOWN))
HttpPipelinedHost::UNKNOWN))
.Times(1)
.WillOnce(Return(host_));
CreateDummyStream();
pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::CAPABLE);
pool_->OnHostIdle(host_);
EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_));
host_ = new MockHost(origin_);
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_CAPABLE))
HttpPipelinedHost::CAPABLE))
.Times(1)
.WillOnce(Return(host_));
CreateDummyStream();
......@@ -153,21 +148,21 @@ TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) {
TEST_F(HttpPipelinedHostPoolTest, IncapableIsSticky) {
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_UNKNOWN))
HttpPipelinedHost::UNKNOWN))
.Times(1)
.WillOnce(Return(host_));
CreateDummyStream();
pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE);
pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::CAPABLE);
pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::INCAPABLE);
pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::CAPABLE);
pool_->OnHostIdle(host_);
EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_));
}
TEST_F(HttpPipelinedHostPoolTest, RemainsUnknownWithoutFeedback) {
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_UNKNOWN))
HttpPipelinedHost::UNKNOWN))
.Times(1)
.WillOnce(Return(host_));
......@@ -177,7 +172,7 @@ TEST_F(HttpPipelinedHostPoolTest, RemainsUnknownWithoutFeedback) {
host_ = new MockHost(origin_);
EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _,
PIPELINE_UNKNOWN))
HttpPipelinedHost::UNKNOWN))
.Times(1)
.WillOnce(Return(host_));
......@@ -185,14 +180,6 @@ TEST_F(HttpPipelinedHostPoolTest, RemainsUnknownWithoutFeedback) {
pool_->OnHostIdle(host_);
}
TEST_F(HttpPipelinedHostPoolTest, PopulatesServerProperties) {
EXPECT_EQ(PIPELINE_UNKNOWN,
http_server_properties_->GetPipelineCapability(host_->origin()));
pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
EXPECT_EQ(PIPELINE_CAPABLE,
http_server_properties_->GetPipelineCapability(host_->origin()));
}
} // anonymous namespace
} // namespace net
......@@ -10,7 +10,6 @@
#include "base/basictypes.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_export.h"
#include "net/http/http_pipelined_host_capability.h"
#include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this.
namespace net {
......@@ -36,8 +35,6 @@ struct NET_EXPORT PortAlternateProtocolPair {
typedef std::map<HostPortPair, PortAlternateProtocolPair> AlternateProtocolMap;
typedef std::map<HostPortPair, spdy::SpdySettings> SpdySettingsMap;
typedef std::map<HostPortPair,
HttpPipelinedHostCapability> PipelineCapabilityMap;
extern const char kAlternateProtocolHeader[];
extern const char* const kAlternateProtocolStrings[NUM_ALTERNATE_PROTOCOLS];
......@@ -98,17 +95,6 @@ class NET_EXPORT HttpServerProperties {
// Returns all persistent SpdySettings.
virtual const SpdySettingsMap& spdy_settings_map() const = 0;
virtual HttpPipelinedHostCapability GetPipelineCapability(
const HostPortPair& origin) = 0;
virtual void SetPipelineCapability(
const HostPortPair& origin,
HttpPipelinedHostCapability capability) = 0;
virtual void ClearPipelineCapabilities() = 0;
virtual PipelineCapabilityMap GetPipelineCapabilityMap() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
};
......
......@@ -8,18 +8,10 @@
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
#include "base/stringprintf.h"
#include "net/http/http_pipelined_host_capability.h"
namespace net {
// TODO(simonjam): Run experiments with different values of this to see what
// value is good at avoiding evictions without eating too much memory. Until
// then, this is just a bad guess.
static const int kDefaultNumHostsToRemember = 200;
HttpServerPropertiesImpl::HttpServerPropertiesImpl()
: pipeline_capability_map_(
new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)) {
HttpServerPropertiesImpl::HttpServerPropertiesImpl() {
}
HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
......@@ -56,21 +48,6 @@ void HttpServerPropertiesImpl::InitializeSpdySettingsServers(
spdy_settings_map_.swap(*spdy_settings_map);
}
void HttpServerPropertiesImpl::InitializePipelineCapabilities(
const PipelineCapabilityMap* pipeline_capability_map) {
PipelineCapabilityMap::const_iterator it;
pipeline_capability_map_->Clear();
for (it = pipeline_capability_map->begin();
it != pipeline_capability_map->end(); ++it) {
pipeline_capability_map_->Put(it->first, it->second);
}
}
void HttpServerPropertiesImpl::SetNumPipelinedHostsToRemember(int max_size) {
DCHECK(pipeline_capability_map_->empty());
pipeline_capability_map_.reset(new CachedPipelineCapabilityMap(max_size));
}
void HttpServerPropertiesImpl::GetSpdyServerList(
base::ListValue* spdy_server_list) const {
DCHECK(CalledOnValidThread());
......@@ -117,7 +94,6 @@ void HttpServerPropertiesImpl::Clear() {
spdy_servers_table_.clear();
alternate_protocol_map_.clear();
spdy_settings_map_.clear();
pipeline_capability_map_->Clear();
}
bool HttpServerPropertiesImpl::SupportsSpdy(
......@@ -263,41 +239,4 @@ HttpServerPropertiesImpl::spdy_settings_map() const {
return spdy_settings_map_;
}
HttpPipelinedHostCapability HttpServerPropertiesImpl::GetPipelineCapability(
const HostPortPair& origin) {
HttpPipelinedHostCapability capability = PIPELINE_UNKNOWN;
CachedPipelineCapabilityMap::const_iterator it =
pipeline_capability_map_->Get(origin);
if (it != pipeline_capability_map_->end()) {
capability = it->second;
}
return capability;
}
void HttpServerPropertiesImpl::SetPipelineCapability(
const HostPortPair& origin,
HttpPipelinedHostCapability capability) {
CachedPipelineCapabilityMap::iterator it =
pipeline_capability_map_->Peek(origin);
if (it == pipeline_capability_map_->end() ||
it->second != PIPELINE_INCAPABLE) {
pipeline_capability_map_->Put(origin, capability);
}
}
void HttpServerPropertiesImpl::ClearPipelineCapabilities() {
pipeline_capability_map_->Clear();
}
PipelineCapabilityMap
HttpServerPropertiesImpl::GetPipelineCapabilityMap() const {
PipelineCapabilityMap result;
CachedPipelineCapabilityMap::const_iterator it;
for (it = pipeline_capability_map_->begin();
it != pipeline_capability_map_->end(); ++it) {
result[it->first] = it->second;
}
return result;
}
} // namespace net
......@@ -12,12 +12,10 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/hash_tables.h"
#include "base/memory/mru_cache.h"
#include "base/threading/non_thread_safe.h"
#include "base/values.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_export.h"
#include "net/http/http_pipelined_host_capability.h"
#include "net/http/http_server_properties.h"
namespace base {
......@@ -44,11 +42,6 @@ class NET_EXPORT HttpServerPropertiesImpl
void InitializeSpdySettingsServers(SpdySettingsMap* spdy_settings_map);
// Initializes |pipeline_capability_map_| with the servers (host/port) from
// |pipeline_capability_map| that either support HTTP pipelining or not.
void InitializePipelineCapabilities(
const PipelineCapabilityMap* pipeline_capability_map);
// Get the list of servers (host/port) that support SPDY.
void GetSpdyServerList(base::ListValue* spdy_server_list) const;
......@@ -63,12 +56,6 @@ class NET_EXPORT HttpServerPropertiesImpl
static void ForceAlternateProtocol(const PortAlternateProtocolPair& pair);
static void DisableForcedAlternateProtocol();
// Changes the number of host/port pairs we remember pipelining capability
// for. A larger number means we're more likely to be able to pipeline
// immediately if a host is known good, but uses more memory. This function
// can only be called if |pipeline_capability_map_| is empty.
void SetNumPipelinedHostsToRemember(int max_size);
// -----------------------------
// HttpServerProperties methods:
// -----------------------------
......@@ -119,20 +106,7 @@ class NET_EXPORT HttpServerPropertiesImpl
// Returns all persistent SpdySettings.
virtual const SpdySettingsMap& spdy_settings_map() const OVERRIDE;
virtual HttpPipelinedHostCapability GetPipelineCapability(
const HostPortPair& origin) OVERRIDE;
virtual void SetPipelineCapability(
const HostPortPair& origin,
HttpPipelinedHostCapability capability) OVERRIDE;
virtual void ClearPipelineCapabilities() OVERRIDE;
virtual PipelineCapabilityMap GetPipelineCapabilityMap() const OVERRIDE;
private:
typedef base::MRUCache<
HostPortPair, HttpPipelinedHostCapability> CachedPipelineCapabilityMap;
// |spdy_servers_table_| has flattened representation of servers (host/port
// pair) that either support or not support SPDY protocol.
typedef base::hash_map<std::string, bool> SpdyServerHostPortTable;
......@@ -140,7 +114,6 @@ class NET_EXPORT HttpServerPropertiesImpl
AlternateProtocolMap alternate_protocol_map_;
SpdySettingsMap spdy_settings_map_;
scoped_ptr<CachedPipelineCapabilityMap> pipeline_capability_map_;
DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl);
};
......
......@@ -37,8 +37,7 @@ GURL UpgradeUrlToHttps(const GURL& original_url, int port) {
HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session)
: session_(session),
http_pipelined_host_pool_(this, NULL,
session_->http_server_properties()) {}
http_pipelined_host_pool_(this, NULL) {}
HttpStreamFactoryImpl::~HttpStreamFactoryImpl() {
DCHECK(request_map_.empty());
......
......@@ -436,7 +436,6 @@
'http/http_pipelined_connection_impl.cc',
'http/http_pipelined_connection_impl.h',
'http/http_pipelined_host.h',
'http/http_pipelined_host_capability.h',
'http/http_pipelined_host_impl.cc',
'http/http_pipelined_host_impl.h',
'http/http_pipelined_host_pool.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment