summaryrefslogtreecommitdiffstats
path: root/net/socket_stream
diff options
context:
space:
mode:
authorpeter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-12 18:23:05 +0000
committerpeter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-12 18:23:05 +0000
commita8030a22c88436615550267e26b539382dd5fe8b (patch)
treed25b01d04058e18309329edef8cfb1d059690429 /net/socket_stream
parent26ca33d393dbd3d3b8763d1659f906f52d2e0289 (diff)
downloadchromium_src-a8030a22c88436615550267e26b539382dd5fe8b.zip
chromium_src-a8030a22c88436615550267e26b539382dd5fe8b.tar.gz
chromium_src-a8030a22c88436615550267e26b539382dd5fe8b.tar.bz2
Revert 256579 "Allow the content browser client to specify a spe..."
This broke the Android builders. The try-bots on the CL did point out the compile errors, but it was committed manually anyway. Logs: http://build.chromium.org/p/chromium.linux/builders/Android%20Clang%20Builder%20%28dbg%29/builds/30977/steps/compile/logs/stdio > Allow the content browser client to specify a special cookie store to be > used for a given render process id. This special cookie store will then > be used for renderer messages pertaining to cookies, url fetches in net, > and websockets. If the special cookie store is NULL, a default cookie store > will be used. > > R=erikwright@chromium.org, jam@chromium.org, lambroslambrou@chromium.org, mmenke@chromium.org, tyoshino@chromium.org > > Review URL: https://codereview.chromium.org/188693003 TBR=tburkard@chromium.org Review URL: https://codereview.chromium.org/197463003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256583 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream')
-rw-r--r--net/socket_stream/socket_stream.cc56
-rw-r--r--net/socket_stream/socket_stream.h15
-rw-r--r--net/socket_stream/socket_stream_job.cc12
-rw-r--r--net/socket_stream/socket_stream_job.h16
-rw-r--r--net/socket_stream/socket_stream_job_manager.cc10
-rw-r--r--net/socket_stream/socket_stream_job_manager.h3
-rw-r--r--net/socket_stream/socket_stream_unittest.cc81
7 files changed, 83 insertions, 110 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index 5aacd4a..1682ddc 100644
--- a/net/socket_stream/socket_stream.cc
+++ b/net/socket_stream/socket_stream.cc
@@ -87,13 +87,11 @@ void SocketStream::ResponseHeaders::Realloc(size_t new_size) {
SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; }
-SocketStream::SocketStream(const GURL& url, Delegate* delegate,
- URLRequestContext* context,
- CookieStore* cookie_store)
+SocketStream::SocketStream(const GURL& url, Delegate* delegate)
: delegate_(delegate),
url_(url),
max_pending_send_allowed_(kMaxPendingSendAllowed),
- context_(context),
+ context_(NULL),
next_state_(STATE_NONE),
factory_(ClientSocketFactory::GetDefaultFactory()),
proxy_mode_(kDirectConnection),
@@ -110,24 +108,12 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate,
waiting_for_write_completion_(false),
closing_(false),
server_closed_(false),
- metrics_(new SocketStreamMetrics(url)),
- cookie_store_(cookie_store) {
+ metrics_(new SocketStreamMetrics(url)) {
DCHECK(base::MessageLoop::current())
<< "The current base::MessageLoop must exist";
DCHECK(base::MessageLoopForIO::IsCurrent())
<< "The current base::MessageLoop must be TYPE_IO";
DCHECK(delegate_);
-
- if (context_) {
- if (!cookie_store_)
- cookie_store_ = context_->cookie_store();
-
- net_log_ = BoundNetLog::Make(
- context->net_log(),
- NetLog::SOURCE_SOCKET_STREAM);
-
- net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
- }
}
SocketStream::UserData* SocketStream::GetUserData(
@@ -146,20 +132,28 @@ bool SocketStream::is_secure() const {
return url_.SchemeIs("wss");
}
-void SocketStream::DetachContext() {
- if (!context_)
- return;
+void SocketStream::set_context(URLRequestContext* context) {
+ const URLRequestContext* prev_context = context_;
- if (pac_request_) {
- context_->proxy_service()->CancelPacRequest(pac_request_);
- pac_request_ = NULL;
- }
+ context_ = context;
- net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE);
- net_log_ = BoundNetLog();
+ if (prev_context != context) {
+ if (prev_context && pac_request_) {
+ prev_context->proxy_service()->CancelPacRequest(pac_request_);
+ pac_request_ = NULL;
+ }
+
+ net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE);
+ net_log_ = BoundNetLog();
- context_ = NULL;
- cookie_store_ = NULL;
+ if (context) {
+ net_log_ = BoundNetLog::Make(
+ context->net_log(),
+ NetLog::SOURCE_SOCKET_STREAM);
+
+ net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
+ }
+ }
}
void SocketStream::CheckPrivacyMode() {
@@ -324,7 +318,7 @@ void SocketStream::ContinueDespiteError() {
}
SocketStream::~SocketStream() {
- DetachContext();
+ set_context(NULL);
DCHECK(!delegate_);
DCHECK(!pac_request_);
}
@@ -1348,8 +1342,4 @@ int SocketStream::HandleCertificateError(int result) {
return ERR_IO_PENDING;
}
-CookieStore* SocketStream::cookie_store() const {
- return cookie_store_;
-}
-
} // namespace net
diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h
index cfc764d..b86f20a 100644
--- a/net/socket_stream/socket_stream.h
+++ b/net/socket_stream/socket_stream.h
@@ -19,7 +19,6 @@
#include "net/base/net_export.h"
#include "net/base/net_log.h"
#include "net/base/privacy_mode.h"
-#include "net/cookies/cookie_store.h"
#include "net/proxy/proxy_service.h"
#include "net/ssl/ssl_config_service.h"
#include "net/url_request/url_request.h"
@@ -115,8 +114,7 @@ class NET_EXPORT SocketStream
virtual ~Delegate() {}
};
- SocketStream(const GURL& url, Delegate* delegate, URLRequestContext* context,
- CookieStore* cookie_store);
+ SocketStream(const GURL& url, Delegate* delegate);
// The user data allows the clients to associate data with this job.
// Multiple user data values can be stored under different keys.
@@ -132,6 +130,9 @@ class NET_EXPORT SocketStream
int max_pending_send_allowed() const { return max_pending_send_allowed_; }
URLRequestContext* context() { return context_; }
+ // There're some asynchronous operations and members that are constructed from
+ // |context|. Be careful when you use this for the second time or more.
+ void set_context(URLRequestContext* context);
const SSLConfig& server_ssl_config() const { return server_ssl_config_; }
PrivacyMode privacy_mode() const { return privacy_mode_; }
@@ -161,9 +162,6 @@ class NET_EXPORT SocketStream
// back.
virtual void DetachDelegate();
- // Detach the context.
- virtual void DetachContext();
-
const ProxyServer& proxy_server() const;
// Sets an alternative ClientSocketFactory. Doesn't take ownership of
@@ -182,8 +180,6 @@ class NET_EXPORT SocketStream
// actions on alert dialog or browser cached such kinds of user actions.
void ContinueDespiteError();
- CookieStore* cookie_store() const;
-
protected:
friend class base::RefCountedThreadSafe<SocketStream>;
virtual ~SocketStream();
@@ -393,9 +389,6 @@ class NET_EXPORT SocketStream
scoped_ptr<SocketStreamMetrics> metrics_;
- // Cookie store to use for this socket stream.
- scoped_refptr<CookieStore> cookie_store_;
-
DISALLOW_COPY_AND_ASSIGN(SocketStream);
};
diff --git a/net/socket_stream/socket_stream_job.cc b/net/socket_stream/socket_stream_job.cc
index f2de823..9c13a8f 100644
--- a/net/socket_stream/socket_stream_job.cc
+++ b/net/socket_stream/socket_stream_job.cc
@@ -24,9 +24,7 @@ SocketStreamJob* SocketStreamJob::CreateSocketStreamJob(
const GURL& url,
SocketStream::Delegate* delegate,
TransportSecurityState* sts,
- SSLConfigService* ssl,
- URLRequestContext* context,
- CookieStore* cookie_store) {
+ SSLConfigService* ssl) {
GURL socket_url(url);
TransportSecurityState::DomainState domain_state;
if (url.scheme() == "ws" && sts && sts->GetDomainState(
@@ -38,8 +36,7 @@ SocketStreamJob* SocketStreamJob::CreateSocketStreamJob(
url_parse::Component(0, strlen(kNewScheme)));
socket_url = url.ReplaceComponents(replacements);
}
- return SocketStreamJobManager::GetInstance()->CreateJob(
- socket_url, delegate, context, cookie_store);
+ return SocketStreamJobManager::GetInstance()->CreateJob(socket_url, delegate);
}
SocketStreamJob::SocketStreamJob() {}
@@ -85,11 +82,6 @@ void SocketStreamJob::DetachDelegate() {
socket_->DetachDelegate();
}
-void SocketStreamJob::DetachContext() {
- if (socket_.get())
- socket_->DetachContext();
-}
-
SocketStreamJob::~SocketStreamJob() {}
} // namespace net
diff --git a/net/socket_stream/socket_stream_job.h b/net/socket_stream/socket_stream_job.h
index 9fc27d9..d12e73a 100644
--- a/net/socket_stream/socket_stream_job.h
+++ b/net/socket_stream/socket_stream_job.h
@@ -15,7 +15,6 @@ class GURL;
namespace net {
-class CookieStore;
class SSLConfigService;
class SSLInfo;
class TransportSecurityState;
@@ -31,9 +30,7 @@ class NET_EXPORT SocketStreamJob
public:
// Callback function implemented by protocol handlers to create new jobs.
typedef SocketStreamJob* (ProtocolFactory)(const GURL& url,
- SocketStream::Delegate* delegate,
- URLRequestContext* context,
- CookieStore* cookie_store);
+ SocketStream::Delegate* delegate);
static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
ProtocolFactory* factory);
@@ -42,9 +39,7 @@ class NET_EXPORT SocketStreamJob
const GURL& url,
SocketStream::Delegate* delegate,
TransportSecurityState* sts,
- SSLConfigService* ssl,
- URLRequestContext* context,
- CookieStore* cookie_store);
+ SSLConfigService* ssl);
SocketStreamJob();
void InitSocketStream(SocketStream* socket) {
@@ -57,8 +52,9 @@ class NET_EXPORT SocketStreamJob
URLRequestContext* context() const {
return socket_.get() ? socket_->context() : 0;
}
- CookieStore* cookie_store() const {
- return socket_.get() ? socket_->cookie_store() : 0;
+ void set_context(URLRequestContext* context) {
+ if (socket_.get())
+ socket_->set_context(context);
}
virtual void Connect();
@@ -77,8 +73,6 @@ class NET_EXPORT SocketStreamJob
virtual void DetachDelegate();
- virtual void DetachContext();
-
protected:
friend class WebSocketJobTest;
friend class base::RefCountedThreadSafe<SocketStreamJob>;
diff --git a/net/socket_stream/socket_stream_job_manager.cc b/net/socket_stream/socket_stream_job_manager.cc
index 6418be4..7f66a4a 100644
--- a/net/socket_stream/socket_stream_job_manager.cc
+++ b/net/socket_stream/socket_stream_job_manager.cc
@@ -20,14 +20,12 @@ SocketStreamJobManager* SocketStreamJobManager::GetInstance() {
}
SocketStreamJob* SocketStreamJobManager::CreateJob(
- const GURL& url, SocketStream::Delegate* delegate,
- URLRequestContext* context, CookieStore* cookie_store) const {
+ const GURL& url, SocketStream::Delegate* delegate) const {
// If url is invalid, create plain SocketStreamJob, which will close
// the socket immediately.
if (!url.is_valid()) {
SocketStreamJob* job = new SocketStreamJob();
- job->InitSocketStream(new SocketStream(url, delegate, context,
- cookie_store));
+ job->InitSocketStream(new SocketStream(url, delegate));
return job;
}
@@ -36,12 +34,12 @@ SocketStreamJob* SocketStreamJobManager::CreateJob(
base::AutoLock locked(lock_);
FactoryMap::const_iterator found = factories_.find(scheme);
if (found != factories_.end()) {
- SocketStreamJob* job = found->second(url, delegate, context, cookie_store);
+ SocketStreamJob* job = found->second(url, delegate);
if (job)
return job;
}
SocketStreamJob* job = new SocketStreamJob();
- job->InitSocketStream(new SocketStream(url, delegate, context, cookie_store));
+ job->InitSocketStream(new SocketStream(url, delegate));
return job;
}
diff --git a/net/socket_stream/socket_stream_job_manager.h b/net/socket_stream/socket_stream_job_manager.h
index 2363fb5..aa0cd40 100644
--- a/net/socket_stream/socket_stream_job_manager.h
+++ b/net/socket_stream/socket_stream_job_manager.h
@@ -22,8 +22,7 @@ class SocketStreamJobManager {
static SocketStreamJobManager* GetInstance();
SocketStreamJob* CreateJob(
- const GURL& url, SocketStream::Delegate* delegate,
- URLRequestContext* context, CookieStore* cookie_store) const;
+ const GURL& url, SocketStream::Delegate* delegate) const;
SocketStreamJob::ProtocolFactory* RegisterProtocolFactory(
const std::string& scheme, SocketStreamJob::ProtocolFactory* factory);
diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc
index 069f92e..4a6a9e2 100644
--- a/net/socket_stream/socket_stream_unittest.cc
+++ b/net/socket_stream/socket_stream_unittest.cc
@@ -318,7 +318,7 @@ class SocketStreamTest : public PlatformTest {
virtual void DoCloseFlushPendingWriteTestWithSetContextNull(
SocketStreamEvent* event) {
- event->socket->DetachContext();
+ event->socket->set_context(NULL);
// handshake response received.
for (size_t i = 0; i < messages_.size(); i++) {
std::vector<char> frame;
@@ -400,8 +400,9 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) {
TestURLRequestContext context;
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
MockWrite data_writes[] = {
MockWrite(SocketStreamTest::kWebSocketHandshakeRequest),
@@ -452,16 +453,16 @@ TEST_F(SocketStreamTest, ResolveFailure) {
scoped_ptr<SocketStreamEventRecorder> delegate(
new SocketStreamEventRecorder(test_callback.callback()));
+ scoped_refptr<SocketStream> socket_stream(
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
// Make resolver fail.
TestURLRequestContext context;
scoped_ptr<MockHostResolver> mock_host_resolver(
new MockHostResolver());
mock_host_resolver->rules()->AddSimulatedFailure("example.com");
context.set_host_resolver(mock_host_resolver.get());
-
- scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ socket_stream->set_context(&context);
// No read/write on socket is expected.
StaticSocketDataProvider data_provider(NULL, 0, NULL, 0);
@@ -492,8 +493,9 @@ TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) {
TestURLRequestContext context;
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
DelayedSocketData data_provider(1, NULL, 0, NULL, 0);
@@ -564,12 +566,12 @@ TEST_F(SocketStreamTest, BasicAuthProxy) {
&SocketStreamEventRecorder::DoRestartWithAuth,
base::Unretained(delegate.get())));
- TestURLRequestContextWithProxy context("myproxy:70");
-
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ TestURLRequestContextWithProxy context("myproxy:70");
+ socket_stream->set_context(&context);
socket_stream->SetClientSocketFactory(&mock_socket_factory);
socket_stream->Connect();
@@ -616,6 +618,9 @@ TEST_F(SocketStreamTest, BasicAuthProxyWithAuthCache) {
delegate->SetOnConnected(base::Bind(&SocketStreamEventRecorder::DoClose,
base::Unretained(delegate.get())));
+ scoped_refptr<SocketStream> socket_stream(
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
TestURLRequestContextWithProxy context("myproxy:70");
HttpAuthCache* auth_cache =
context.http_transaction_factory()->GetSession()->http_auth_cache();
@@ -627,10 +632,7 @@ TEST_F(SocketStreamTest, BasicAuthProxyWithAuthCache) {
ASCIIToUTF16("bar")),
"/");
- scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
-
+ socket_stream->set_context(&context);
socket_stream->SetClientSocketFactory(&mock_socket_factory);
socket_stream->Connect();
@@ -673,6 +675,9 @@ TEST_F(SocketStreamTest, WSSBasicAuthProxyWithAuthCache) {
delegate->SetOnConnected(base::Bind(&SocketStreamEventRecorder::DoClose,
base::Unretained(delegate.get())));
+ scoped_refptr<SocketStream> socket_stream(
+ new SocketStream(GURL("wss://example.com/demo"), delegate.get()));
+
TestURLRequestContextWithProxy context("myproxy:70");
HttpAuthCache* auth_cache =
context.http_transaction_factory()->GetSession()->http_auth_cache();
@@ -684,10 +689,7 @@ TEST_F(SocketStreamTest, WSSBasicAuthProxyWithAuthCache) {
ASCIIToUTF16("bar")),
"/");
- scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("wss://example.com/demo"), delegate.get(),
- &context, NULL));
-
+ socket_stream->set_context(&context);
socket_stream->SetClientSocketFactory(&mock_socket_factory);
socket_stream->Connect();
@@ -719,8 +721,9 @@ TEST_F(SocketStreamTest, IOPending) {
TestURLRequestContext context;
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
MockWrite data_writes[] = {
MockWrite(SocketStreamTest::kWebSocketHandshakeRequest),
@@ -780,8 +783,9 @@ TEST_F(SocketStreamTest, SwitchToSpdy) {
TestURLRequestContext context;
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
socket_stream->Connect();
@@ -807,8 +811,9 @@ TEST_F(SocketStreamTest, SwitchAfterPending) {
TestURLRequestContext context;
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
socket_stream->Connect();
io_test_callback_.WaitForResult();
@@ -860,9 +865,9 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) {
base::Unretained(delegate.get())));
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+ socket_stream->set_context(&context);
socket_stream->SetClientSocketFactory(&mock_socket_factory);
socket_stream->Connect();
@@ -911,9 +916,9 @@ TEST_F(SocketStreamTest, SecureProxyConnect) {
base::Unretained(delegate.get())));
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+ socket_stream->set_context(&context);
socket_stream->SetClientSocketFactory(&mock_socket_factory);
socket_stream->Connect();
@@ -943,8 +948,9 @@ TEST_F(SocketStreamTest, BeforeConnectFailed) {
context.set_network_delegate(&network_delegate);
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
socket_stream->Connect();
@@ -975,8 +981,8 @@ TEST_F(SocketStreamTest, OnErrorDetachDelegate) {
TestURLRequestContext context;
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://localhost:9998/echo"), delegate,
- &context, NULL));
+ new SocketStream(GURL("ws://localhost:9998/echo"), delegate));
+ socket_stream->set_context(&context);
socket_stream->SetClientSocketFactory(&mock_socket_factory);
delegate->set_socket_stream(socket_stream);
// The delegate pointer will become invalid during the test. Set it to NULL to
@@ -995,8 +1001,7 @@ TEST_F(SocketStreamTest, NullContextSocketStreamShouldNotCrash) {
new SocketStreamEventRecorder(test_callback.callback()));
TestURLRequestContext context;
scoped_refptr<SocketStream> socket_stream(
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(),
- &context, NULL));
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
delegate->SetOnStartOpenConnection(base::Bind(
&SocketStreamTest::DoIOPending, base::Unretained(this)));
delegate->SetOnConnected(base::Bind(
@@ -1005,6 +1010,8 @@ TEST_F(SocketStreamTest, NullContextSocketStreamShouldNotCrash) {
&SocketStreamTest::DoCloseFlushPendingWriteTestWithSetContextNull,
base::Unretained(this)));
+ socket_stream->set_context(&context);
+
MockWrite data_writes[] = {
MockWrite(SocketStreamTest::kWebSocketHandshakeRequest),
};