diff options
-rw-r--r-- | chrome/browser/io_thread.cc | 11 | ||||
-rw-r--r-- | chrome/browser/io_thread.h | 1 | ||||
-rw-r--r-- | net/http/http_network_session.cc | 1 | ||||
-rw-r--r-- | net/http/http_network_session.h | 1 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_common.cc | 3 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_common.h | 1 | ||||
-rw-r--r-- | net/url_request/url_request_test_util.cc | 2 | ||||
-rw-r--r-- | net/url_request/url_request_test_util.h | 11 | ||||
-rw-r--r-- | net/websockets/websocket_job.cc | 12 | ||||
-rw-r--r-- | net/websockets/websocket_job.h | 6 | ||||
-rw-r--r-- | net/websockets/websocket_job_test.cc | 50 | ||||
-rw-r--r-- | net/websockets/websocket_throttle_test.cc | 39 |
12 files changed, 76 insertions, 62 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 055f03c..cef70bc 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -77,7 +77,6 @@ #include "net/url_request/url_fetcher.h" #include "net/url_request/url_request_job_factory_impl.h" #include "net/url_request/url_request_throttler_manager.h" -#include "net/websockets/websocket_job.h" #include "url/url_constants.h" #if defined(ENABLE_CONFIGURATION_POLICY) @@ -756,11 +755,6 @@ void IOThread::InitializeNetworkOptions(const CommandLine& command_line) { std::string spdy_trial_group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName); - if (command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) { - // Enable WebSocket over SPDY. - net::WebSocketJob::set_websocket_over_spdy_enabled(true); - } - if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { globals_->trusted_spdy_proxy.set( command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy)); @@ -791,6 +785,9 @@ void IOThread::InitializeNetworkOptions(const CommandLine& command_line) { globals_->use_alternate_protocols.set(true); } } + + if (command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) + globals_->enable_websocket_over_spdy.set(true); } // TODO(rch): Make the client socket factory a per-network session @@ -965,6 +962,8 @@ void IOThread::InitializeNetworkSessionParams( globals_->forced_spdy_exclusions = params->forced_spdy_exclusions; globals_->use_alternate_protocols.CopyToIfSet( ¶ms->use_alternate_protocols); + globals_->enable_websocket_over_spdy.CopyToIfSet( + ¶ms->enable_websocket_over_spdy); globals_->enable_quic.CopyToIfSet(¶ms->enable_quic); globals_->enable_quic_https.CopyToIfSet(¶ms->enable_quic_https); diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index 8c991b7..9c83a17 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -167,6 +167,7 @@ class IOThread : public content::BrowserThreadDelegate { Optional<bool> force_spdy_always; std::set<net::HostPortPair> forced_spdy_exclusions; Optional<bool> use_alternate_protocols; + Optional<bool> enable_websocket_over_spdy; Optional<bool> enable_quic; Optional<bool> enable_quic_https; diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index 6d7129a..3db9ecb 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -81,6 +81,7 @@ HttpNetworkSession::Params::Params() force_spdy_over_ssl(true), force_spdy_always(false), use_alternate_protocols(false), + enable_websocket_over_spdy(false), enable_quic(false), enable_quic_https(false), enable_quic_port_selection(true), diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 42554c1..3dc9e6f 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -104,6 +104,7 @@ class NET_EXPORT HttpNetworkSession // Noe: Using this in the case of NPN for HTTP only results in the browser // trying SSL and then falling back to http. bool use_alternate_protocols; + bool enable_websocket_over_spdy; bool enable_quic; bool enable_quic_https; diff --git a/net/spdy/spdy_test_util_common.cc b/net/spdy/spdy_test_util_common.cc index 4f44b9c..6b8097e 100644 --- a/net/spdy/spdy_test_util_common.cc +++ b/net/spdy/spdy_test_util_common.cc @@ -361,6 +361,7 @@ SpdySessionDependencies::SpdySessionDependencies(NextProto protocol) force_spdy_over_ssl(false), force_spdy_always(false), use_alternate_protocols(false), + enable_websocket_over_spdy(false), net_log(NULL) { DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; @@ -394,6 +395,7 @@ SpdySessionDependencies::SpdySessionDependencies( force_spdy_over_ssl(false), force_spdy_always(false), use_alternate_protocols(false), + enable_websocket_over_spdy(false), net_log(NULL) { DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; } @@ -453,6 +455,7 @@ net::HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( params.force_spdy_over_ssl = session_deps->force_spdy_over_ssl; params.force_spdy_always = session_deps->force_spdy_always; params.use_alternate_protocols = session_deps->use_alternate_protocols; + params.enable_websocket_over_spdy = session_deps->enable_websocket_over_spdy; params.net_log = session_deps->net_log; return params; } diff --git a/net/spdy/spdy_test_util_common.h b/net/spdy/spdy_test_util_common.h index 6bc6acd..297dc29 100644 --- a/net/spdy/spdy_test_util_common.h +++ b/net/spdy/spdy_test_util_common.h @@ -223,6 +223,7 @@ struct SpdySessionDependencies { bool force_spdy_over_ssl; bool force_spdy_always; bool use_alternate_protocols; + bool enable_websocket_over_spdy; NetLog* net_log; }; diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc index 17ad311..e240082 100644 --- a/net/url_request/url_request_test_util.cc +++ b/net/url_request/url_request_test_util.cc @@ -95,6 +95,8 @@ void TestURLRequestContext::Init() { EXPECT_FALSE(client_socket_factory_); } else { HttpNetworkSession::Params params; + if (http_network_session_params_) + params = *http_network_session_params_; params.client_socket_factory = client_socket_factory(); params.host_resolver = host_resolver(); params.cert_verifier = cert_verifier(); diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h index 0b2f48c..ebd02c4 100644 --- a/net/url_request/url_request_test_util.h +++ b/net/url_request/url_request_test_util.h @@ -13,6 +13,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop_proxy.h" #include "base/path_service.h" #include "base/strings/string16.h" @@ -31,6 +32,7 @@ #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" #include "net/http/http_network_layer.h" +#include "net/http/http_network_session.h" #include "net/http/http_request_headers.h" #include "net/proxy/proxy_service.h" #include "net/ssl/ssl_config_service_defaults.h" @@ -66,9 +68,18 @@ class TestURLRequestContext : public URLRequestContext { client_socket_factory_ = factory; } + void set_http_network_session_params( + const HttpNetworkSession::Params& params) { + } + private: bool initialized_; + // Optional parameters to override default values. Note that values that + // point to other objects the TestURLRequestContext creates will be + // overwritten. + scoped_ptr<HttpNetworkSession::Params> http_network_session_params_; + // Not owned: ClientSocketFactory* client_socket_factory_; diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index cd8f09dd7..eb653fa 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -59,18 +59,11 @@ static base::LazyInstance<WebSocketJobInitSingleton> g_websocket_job_init = namespace net { -bool WebSocketJob::websocket_over_spdy_enabled_ = false; - // static void WebSocketJob::EnsureInit() { g_websocket_job_init.Get(); } -// static -void WebSocketJob::set_websocket_over_spdy_enabled(bool enabled) { - websocket_over_spdy_enabled_ = enabled; -} - WebSocketJob::WebSocketJob(SocketStream::Delegate* delegate) : delegate_(delegate), state_(INITIALIZED), @@ -579,16 +572,13 @@ int WebSocketJob::TrySpdyStream() { if (!socket_.get()) return ERR_FAILED; - if (!websocket_over_spdy_enabled_) - return OK; - // Check if we have a SPDY session available. HttpTransactionFactory* factory = socket_->context()->http_transaction_factory(); if (!factory) return OK; scoped_refptr<HttpNetworkSession> session = factory->GetSession(); - if (!session.get()) + if (!session.get() || !session->params().enable_websocket_over_spdy) return OK; SpdySessionPool* spdy_pool = session->spdy_session_pool(); PrivacyMode privacy_mode = socket_->privacy_mode(); diff --git a/net/websockets/websocket_job.h b/net/websockets/websocket_job.h index 119c4dc..2e90a24 100644 --- a/net/websockets/websocket_job.h +++ b/net/websockets/websocket_job.h @@ -49,10 +49,6 @@ class NET_EXPORT WebSocketJob static void EnsureInit(); - // Enable or Disable WebSocket over SPDY feature. - // This function is intended to be called before I/O thread starts. - static void set_websocket_over_spdy_enabled(bool enabled); - State state() const { return state_; } virtual void Connect() OVERRIDE; virtual bool SendData(const char* data, int len) OVERRIDE; @@ -124,8 +120,6 @@ class NET_EXPORT WebSocketJob void CloseInternal(); void SendPending(); - static bool websocket_over_spdy_enabled_; - SocketStream::Delegate* delegate_; State state_; bool waiting_; diff --git a/net/websockets/websocket_job_test.cc b/net/websockets/websocket_job_test.cc index 22fd6e7..7b87a87 100644 --- a/net/websockets/websocket_job_test.cc +++ b/net/websockets/websocket_job_test.cc @@ -274,11 +274,14 @@ class MockURLRequestContext : public URLRequestContext { class MockHttpTransactionFactory : public HttpTransactionFactory { public: - MockHttpTransactionFactory(NextProto next_proto, OrderedSocketData* data) { + MockHttpTransactionFactory(NextProto next_proto, + OrderedSocketData* data, + bool enable_websocket_over_spdy) { data_ = data; MockConnect connect_data(SYNCHRONOUS, OK); data_->set_connect_data(connect_data); session_deps_.reset(new SpdySessionDependencies(next_proto)); + session_deps_->enable_websocket_over_spdy = enable_websocket_over_spdy; session_deps_->socket_factory->AddSocketDataProvider(data_); http_session_ = SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); @@ -389,7 +392,9 @@ class DeletingSocketStreamDelegate : public SocketStream::Delegate { class WebSocketJobTest : public PlatformTest, public ::testing::WithParamInterface<NextProto> { public: - WebSocketJobTest() : spdy_util_(GetParam()) {} + WebSocketJobTest() + : spdy_util_(GetParam()), + enable_websocket_over_spdy_(false) {} virtual void SetUp() OVERRIDE { stream_type_ = STREAM_INVALID; @@ -416,6 +421,7 @@ class WebSocketJobTest : public PlatformTest, int WaitForResult() { return sync_test_callback_.WaitForResult(); } + protected: enum StreamType { STREAM_INVALID, @@ -444,8 +450,8 @@ class WebSocketJobTest : public PlatformTest, if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) { if (stream_type == STREAM_SPDY_WEBSOCKET) { - http_factory_.reset( - new MockHttpTransactionFactory(GetParam(), data_.get())); + http_factory_.reset(new MockHttpTransactionFactory( + GetParam(), data_.get(), enable_websocket_over_spdy_)); context_->set_http_transaction_factory(http_factory_.get()); } @@ -530,6 +536,9 @@ class WebSocketJobTest : public PlatformTest, scoped_ptr<MockHostResolver> host_resolver_; scoped_ptr<MockHttpTransactionFactory> http_factory_; + // Must be set before call to enable_websocket_over_spdy, defaults to false. + bool enable_websocket_over_spdy_; + static const char kHandshakeRequestWithoutCookie[]; static const char kHandshakeRequestWithCookie[]; static const char kHandshakeRequestWithFilteredCookie[]; @@ -711,7 +720,7 @@ INSTANTIATE_TEST_CASE_P( kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); TEST_P(WebSocketJobTest, DelayedCookies) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; GURL url("ws://example.com/demo"); GURL cookieUrl("http://example.com/demo"); CookieOptions cookie_options; @@ -1114,87 +1123,79 @@ void WebSocketJobTest::TestThrottlingLimit() { // Execute tests in both spdy-disabled mode and spdy-enabled mode. TEST_P(WebSocketJobTest, SimpleHandshake) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestSimpleHandshake(); } TEST_P(WebSocketJobTest, SlowHandshake) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestSlowHandshake(); } TEST_P(WebSocketJobTest, HandshakeWithCookie) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestHandshakeWithCookie(); } TEST_P(WebSocketJobTest, HandshakeWithCookieButNotAllowed) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestHandshakeWithCookieButNotAllowed(); } TEST_P(WebSocketJobTest, HSTSUpgrade) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestHSTSUpgrade(); } TEST_P(WebSocketJobTest, InvalidSendData) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestInvalidSendData(); } TEST_P(WebSocketJobTest, SimpleHandshakeSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestSimpleHandshake(); } TEST_P(WebSocketJobTest, SlowHandshakeSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestSlowHandshake(); } TEST_P(WebSocketJobTest, HandshakeWithCookieSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestHandshakeWithCookie(); } TEST_P(WebSocketJobTest, HandshakeWithCookieButNotAllowedSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestHandshakeWithCookieButNotAllowed(); } TEST_P(WebSocketJobTest, HSTSUpgradeSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestHSTSUpgrade(); } TEST_P(WebSocketJobTest, InvalidSendDataSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestInvalidSendData(); } TEST_P(WebSocketJobTest, ConnectByWebSocket) { - WebSocketJob::set_websocket_over_spdy_enabled(false); + enable_websocket_over_spdy_ = true; TestConnectByWebSocket(THROTTLING_OFF); } TEST_P(WebSocketJobTest, ConnectByWebSocketSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectByWebSocket(THROTTLING_OFF); } TEST_P(WebSocketJobTest, ConnectBySpdy) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestConnectBySpdy(SPDY_OFF, THROTTLING_OFF); } TEST_P(WebSocketJobTest, ConnectBySpdySpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectBySpdy(SPDY_ON, THROTTLING_OFF); } TEST_P(WebSocketJobTest, ThrottlingWebSocket) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestConnectByWebSocket(THROTTLING_ON); } @@ -1203,17 +1204,16 @@ TEST_P(WebSocketJobTest, ThrottlingMaxNumberOfThrottledJobLimit) { } TEST_P(WebSocketJobTest, ThrottlingWebSocketSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectByWebSocket(THROTTLING_ON); } TEST_P(WebSocketJobTest, ThrottlingSpdy) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestConnectBySpdy(SPDY_OFF, THROTTLING_ON); } TEST_P(WebSocketJobTest, ThrottlingSpdySpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectBySpdy(SPDY_ON, THROTTLING_ON); } diff --git a/net/websockets/websocket_throttle_test.cc b/net/websockets/websocket_throttle_test.cc index 7b33883..4d93001 100644 --- a/net/websockets/websocket_throttle_test.cc +++ b/net/websockets/websocket_throttle_test.cc @@ -16,20 +16,34 @@ #include "testing/platform_test.h" #include "url/gurl.h" -class DummySocketStreamDelegate : public net::SocketStream::Delegate { +namespace net { + +namespace { + +class DummySocketStreamDelegate : public SocketStream::Delegate { public: DummySocketStreamDelegate() {} virtual ~DummySocketStreamDelegate() {} virtual void OnConnected( - net::SocketStream* socket, int max_pending_send_allowed) OVERRIDE {} - virtual void OnSentData(net::SocketStream* socket, + SocketStream* socket, int max_pending_send_allowed) OVERRIDE {} + virtual void OnSentData(SocketStream* socket, int amount_sent) OVERRIDE {} - virtual void OnReceivedData(net::SocketStream* socket, + virtual void OnReceivedData(SocketStream* socket, const char* data, int len) OVERRIDE {} - virtual void OnClose(net::SocketStream* socket) OVERRIDE {} + virtual void OnClose(SocketStream* socket) OVERRIDE {} }; -namespace net { +class WebSocketThrottleTestContext : public TestURLRequestContext { + public: + explicit WebSocketThrottleTestContext(bool enable_websocket_over_spdy) + : TestURLRequestContext(true) { + HttpNetworkSession::Params params; + params.enable_websocket_over_spdy = enable_websocket_over_spdy; + Init(); + } +}; + +} // namespace class WebSocketThrottleTest : public PlatformTest { protected: @@ -60,11 +74,10 @@ class WebSocketThrottleTest : public PlatformTest { }; TEST_F(WebSocketThrottleTest, Throttle) { - TestURLRequestContext context; - DummySocketStreamDelegate delegate; // TODO(toyoshim): We need to consider both spdy-enabled and spdy-disabled // configuration. - WebSocketJob::set_websocket_over_spdy_enabled(true); + WebSocketThrottleTestContext context(true); + DummySocketStreamDelegate delegate; // For host1: 1.2.3.4, 1.2.3.5, 1.2.3.6 AddressList addr; @@ -273,9 +286,8 @@ TEST_F(WebSocketThrottleTest, Throttle) { } TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) { - TestURLRequestContext context; + WebSocketThrottleTestContext context(true); DummySocketStreamDelegate delegate; - WebSocketJob::set_websocket_over_spdy_enabled(true); // For localhost: 127.0.0.1, 127.0.0.1 AddressList addr; @@ -302,11 +314,10 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) { // A connection should not be blocked by another connection to the same IP // with a different port. TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) { - TestURLRequestContext context; + WebSocketThrottleTestContext context(false); DummySocketStreamDelegate delegate; IPAddressNumber localhost; ParseIPLiteralToNumber("127.0.0.1", &localhost); - WebSocketJob::set_websocket_over_spdy_enabled(false); // socket1: 127.0.0.1:80 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); @@ -345,4 +356,4 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) { base::MessageLoopForIO::current()->RunUntilIdle(); } -} +} // namespace net |