summaryrefslogtreecommitdiffstats
path: root/net
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
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')
-rw-r--r--net/proxy/proxy_script_fetcher_impl.cc2
-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
-rw-r--r--net/url_request/url_fetcher_core.cc2
-rw-r--r--net/url_request/url_request.cc82
-rw-r--r--net/url_request/url_request.h24
-rw-r--r--net/url_request/url_request_context.cc6
-rw-r--r--net/url_request/url_request_context.h6
-rw-r--r--net/url_request/url_request_http_job.cc9
-rw-r--r--net/url_request/url_request_job.cc6
-rw-r--r--net/url_request/url_request_job.h4
-rw-r--r--net/websockets/websocket_job.cc13
-rw-r--r--net/websockets/websocket_job_test.cc15
-rw-r--r--net/websockets/websocket_throttle_test.cc27
19 files changed, 155 insertions, 234 deletions
diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc
index 0887d8c..705bbbf 100644
--- a/net/proxy/proxy_script_fetcher_impl.cc
+++ b/net/proxy/proxy_script_fetcher_impl.cc
@@ -135,7 +135,7 @@ int ProxyScriptFetcherImpl::Fetch(
}
cur_request_ =
- url_request_context_->CreateRequest(url, DEFAULT_PRIORITY, this, NULL);
+ url_request_context_->CreateRequest(url, DEFAULT_PRIORITY, this);
cur_request_->set_method("GET");
// Make sure that the PAC script is downloaded using a direct connection,
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),
};
diff --git a/net/url_request/url_fetcher_core.cc b/net/url_request/url_fetcher_core.cc
index eb45ecf..eea2e81 100644
--- a/net/url_request/url_fetcher_core.cc
+++ b/net/url_request/url_fetcher_core.cc
@@ -507,7 +507,7 @@ void URLFetcherCore::StartURLRequest() {
g_registry.Get().AddURLFetcherCore(this);
current_response_bytes_ = 0;
request_ = request_context_getter_->GetURLRequestContext()->CreateRequest(
- original_url_, DEFAULT_PRIORITY, this, NULL);
+ original_url_, DEFAULT_PRIORITY, this);
request_->set_stack_trace(stack_trace_);
int flags = request_->load_flags() | load_flags_;
if (!g_interception_enabled)
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index e2be4c2..531e8e8 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -209,17 +209,38 @@ URLRequest::URLRequest(const GURL& url,
RequestPriority priority,
Delegate* delegate,
const URLRequestContext* context)
- : identifier_(GenerateURLRequestIdentifier()) {
- Init(url, priority, delegate, context, NULL);
-}
+ : context_(context),
+ network_delegate_(context->network_delegate()),
+ net_log_(BoundNetLog::Make(context->net_log(),
+ NetLog::SOURCE_URL_REQUEST)),
+ url_chain_(1, url),
+ method_("GET"),
+ referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
+ load_flags_(LOAD_NORMAL),
+ delegate_(delegate),
+ is_pending_(false),
+ is_redirecting_(false),
+ redirect_limit_(kMaxRedirects),
+ priority_(priority),
+ identifier_(GenerateURLRequestIdentifier()),
+ calling_delegate_(false),
+ use_blocked_by_as_load_param_(false),
+ before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete,
+ base::Unretained(this))),
+ has_notified_completion_(false),
+ received_response_content_length_(0),
+ creation_time_(base::TimeTicks::Now()),
+ notified_before_network_start_(false) {
+ SIMPLE_STATS_COUNTER("URLRequestCount");
-URLRequest::URLRequest(const GURL& url,
- RequestPriority priority,
- Delegate* delegate,
- const URLRequestContext* context,
- CookieStore* cookie_store)
- : identifier_(GenerateURLRequestIdentifier()) {
- Init(url, priority, delegate, context, cookie_store);
+ // Sanity check out environment.
+ DCHECK(base::MessageLoop::current())
+ << "The current base::MessageLoop must exist";
+
+ CHECK(context);
+ context->url_requests()->insert(this);
+
+ net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
}
URLRequest::~URLRequest() {
@@ -263,47 +284,6 @@ void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) {
interceptor);
}
-void URLRequest::Init(const GURL& url,
- RequestPriority priority,
- Delegate* delegate,
- const URLRequestContext* context,
- CookieStore* cookie_store) {
- context_ = context;
- network_delegate_ = context->network_delegate();
- net_log_ = BoundNetLog::Make(context->net_log(), NetLog::SOURCE_URL_REQUEST);
- url_chain_.push_back(url);
- method_ = "GET";
- referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
- load_flags_ = LOAD_NORMAL;
- delegate_ = delegate;
- is_pending_ = false;
- is_redirecting_ = false;
- redirect_limit_ = kMaxRedirects;
- priority_ = priority;
- calling_delegate_ = false;
- use_blocked_by_as_load_param_ =false;
- before_request_callback_ = base::Bind(&URLRequest::BeforeRequestComplete,
- base::Unretained(this));
- has_notified_completion_ = false;
- received_response_content_length_ = 0;
- creation_time_ = base::TimeTicks::Now();
- notified_before_network_start_ = false;
-
- SIMPLE_STATS_COUNTER("URLRequestCount");
-
- // Sanity check out environment.
- DCHECK(base::MessageLoop::current())
- << "The current base::MessageLoop must exist";
-
- CHECK(context);
- context->url_requests()->insert(this);
- cookie_store_ = cookie_store;
- if (cookie_store_ == NULL)
- cookie_store_ = context->cookie_store();
-
- net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
-}
-
void URLRequest::EnableChunkedUpload() {
DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked());
if (!upload_data_stream_) {
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index f4e8c40..7c8e1a9 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -25,7 +25,6 @@
#include "net/base/request_priority.h"
#include "net/base/upload_progress.h"
#include "net/cookies/canonical_cookie.h"
-#include "net/cookies/cookie_store.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_info.h"
#include "net/url_request/url_request_status.h"
@@ -292,20 +291,11 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
virtual ~Delegate() {}
};
- // TODO(tburkard): we should get rid of this constructor, and have each
- // creator of a URLRequest specifically list the cookie store to be used.
- // For now, this constructor will use the cookie store in |context|.
URLRequest(const GURL& url,
RequestPriority priority,
Delegate* delegate,
const URLRequestContext* context);
- URLRequest(const GURL& url,
- RequestPriority priority,
- Delegate* delegate,
- const URLRequestContext* context,
- CookieStore* cookie_store);
-
// If destroyed after Start() has been called but while IO is pending,
// then the request will be effectively canceled and the delegate
// will not have any more of its methods called.
@@ -701,8 +691,6 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
// Allow the URLRequestJob class to set our status too
void set_status(const URLRequestStatus& value) { status_ = value; }
- CookieStore* cookie_store() const { return cookie_store_; }
-
// Allow the URLRequestJob to redirect this request. Returns OK if
// successful, otherwise an error code is returned.
int Redirect(const GURL& location, int http_status_code);
@@ -742,15 +730,6 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
static void RegisterRequestInterceptor(Interceptor* interceptor);
static void UnregisterRequestInterceptor(Interceptor* interceptor);
- // Initializes the URLRequest. Code shared between the two constructors.
- // TODO(tburkard): This can ultimately be folded into a single constructor
- // again.
- void Init(const GURL& url,
- RequestPriority priotity,
- Delegate* delegate,
- const URLRequestContext* context,
- CookieStore* cookie_store);
-
// Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest
// handler. If |blocked| is true, the request is blocked and an error page is
// returned indicating so. This should only be called after Start is called
@@ -916,9 +895,6 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
// Keeps track of whether or not OnBeforeNetworkStart has been called yet.
bool notified_before_network_start_;
- // The cookie store to be used for this request.
- scoped_refptr<CookieStore> cookie_store_;
-
DISALLOW_COPY_AND_ASSIGN(URLRequest);
};
diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc
index d6a4d2f..3542b16 100644
--- a/net/url_request/url_request_context.cc
+++ b/net/url_request/url_request_context.cc
@@ -73,10 +73,8 @@ const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams(
scoped_ptr<URLRequest> URLRequestContext::CreateRequest(
const GURL& url,
RequestPriority priority,
- URLRequest::Delegate* delegate,
- CookieStore* cookie_store) const {
- return scoped_ptr<URLRequest>(
- new URLRequest(url, priority, delegate, this, cookie_store));
+ URLRequest::Delegate* delegate) const {
+ return scoped_ptr<URLRequest>(new URLRequest(url, priority, delegate, this));
}
void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h
index a05c9ae..5bb5b51 100644
--- a/net/url_request/url_request_context.h
+++ b/net/url_request/url_request_context.h
@@ -58,13 +58,9 @@ class NET_EXPORT URLRequestContext
// May return NULL if this context doesn't have an associated network session.
const HttpNetworkSession::Params* GetNetworkSessionParams() const;
- // Creates a URLRequest. |cookie_store| optionally specifies a cookie store
- // to be used rather than the one represented by the context, or NULL
- // otherwise.
scoped_ptr<URLRequest> CreateRequest(const GURL& url,
RequestPriority priority,
- URLRequest::Delegate* delegate,
- CookieStore* cookie_store) const;
+ URLRequest::Delegate* delegate) const;
NetLog* net_log() const {
return net_log_;
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 044e5f0..82ef633 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -539,7 +539,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
if (!request_)
return;
- CookieStore* cookie_store = GetCookieStore();
+ CookieStore* cookie_store = request_->context()->cookie_store();
if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) {
net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
if (cookie_monster) {
@@ -558,7 +558,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
void URLRequestHttpJob::DoLoadCookies() {
CookieOptions options;
options.set_include_httponly();
- GetCookieStore()->GetCookiesWithOptionsAsync(
+ request_->context()->cookie_store()->GetCookiesWithOptionsAsync(
request_->url(), options,
base::Bind(&URLRequestHttpJob::OnCookiesLoaded,
weak_factory_.GetWeakPtr()));
@@ -638,7 +638,8 @@ void URLRequestHttpJob::SaveNextCookie() {
new SharedBoolean(true);
if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) &&
- GetCookieStore() && response_cookies_.size() > 0) {
+ request_->context()->cookie_store() &&
+ response_cookies_.size() > 0) {
CookieOptions options;
options.set_include_httponly();
options.set_server_time(response_date_);
@@ -656,7 +657,7 @@ void URLRequestHttpJob::SaveNextCookie() {
if (CanSetCookie(
response_cookies_[response_cookies_save_index_], &options)) {
callback_pending->data = true;
- GetCookieStore()->SetCookieWithOptionsAsync(
+ request_->context()->cookie_store()->SetCookieWithOptionsAsync(
request_->url(), response_cookies_[response_cookies_save_index_],
options, callback);
}
diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc
index c4b34c2..78f704a 100644
--- a/net/url_request/url_request_job.cc
+++ b/net/url_request/url_request_job.cc
@@ -286,12 +286,6 @@ bool URLRequestJob::CanEnablePrivacyMode() const {
return request_->CanEnablePrivacyMode();
}
-CookieStore* URLRequestJob::GetCookieStore() const {
- DCHECK(request_);
-
- return request_->cookie_store();
-}
-
void URLRequestJob::NotifyBeforeNetworkStart(bool* defer) {
if (!request_)
return;
diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h
index 9bb763e..3194ef6 100644
--- a/net/url_request/url_request_job.h
+++ b/net/url_request/url_request_job.h
@@ -26,7 +26,6 @@ namespace net {
class AuthChallengeInfo;
class AuthCredentials;
class CookieOptions;
-class CookieStore;
class Filter;
class HttpRequestHeaders;
class HttpResponseInfo;
@@ -239,9 +238,6 @@ class NET_EXPORT URLRequestJob
// Delegates to URLRequest::Delegate.
bool CanEnablePrivacyMode() const;
- // Returns the cookie store to be used for the request.
- CookieStore* GetCookieStore() const;
-
// Notifies the job that the network is about to be used.
void NotifyBeforeNetworkStart(bool* defer);
diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc
index 63e65a4..b0f5be8 100644
--- a/net/websockets/websocket_job.cc
+++ b/net/websockets/websocket_job.cc
@@ -36,10 +36,9 @@ const char* const kSetCookieHeaders[] = {
};
net::SocketStreamJob* WebSocketJobFactory(
- const GURL& url, net::SocketStream::Delegate* delegate,
- net::URLRequestContext* context, net::CookieStore* cookie_store) {
+ const GURL& url, net::SocketStream::Delegate* delegate) {
net::WebSocketJob* job = new net::WebSocketJob(delegate);
- job->InitSocketStream(new net::SocketStream(url, job, context, cookie_store));
+ job->InitSocketStream(new net::SocketStream(url, job));
return job;
}
@@ -371,11 +370,11 @@ void WebSocketJob::AddCookieHeaderAndSend() {
if (socket_.get() && delegate_ && state_ == CONNECTING) {
handshake_request_->RemoveHeaders(kCookieHeaders,
arraysize(kCookieHeaders));
- if (allow && socket_->cookie_store()) {
+ if (allow && socket_->context()->cookie_store()) {
// Add cookies, including HttpOnly cookies.
CookieOptions cookie_options;
cookie_options.set_include_httponly();
- socket_->cookie_store()->GetCookiesWithOptionsAsync(
+ socket_->context()->cookie_store()->GetCookiesWithOptionsAsync(
GetURLForCookies(), cookie_options,
base::Bind(&WebSocketJob::LoadCookieCallback,
weak_ptr_factory_.GetWeakPtr()));
@@ -506,7 +505,7 @@ void WebSocketJob::SaveNextCookie() {
callback_pending_ = false;
save_next_cookie_running_ = true;
- if (socket_->cookie_store()) {
+ if (socket_->context()->cookie_store()) {
GURL url_for_cookies = GetURLForCookies();
CookieOptions options;
@@ -527,7 +526,7 @@ void WebSocketJob::SaveNextCookie() {
continue;
callback_pending_ = true;
- socket_->cookie_store()->SetCookieWithOptionsAsync(
+ socket_->context()->cookie_store()->SetCookieWithOptionsAsync(
url_for_cookies, cookie, options,
base::Bind(&WebSocketJob::OnCookieSaved,
weak_ptr_factory_.GetWeakPtr()));
diff --git a/net/websockets/websocket_job_test.cc b/net/websockets/websocket_job_test.cc
index 3d7d424..31bd9d6 100644
--- a/net/websockets/websocket_job_test.cc
+++ b/net/websockets/websocket_job_test.cc
@@ -41,9 +41,8 @@ namespace {
class MockSocketStream : public SocketStream {
public:
- MockSocketStream(const GURL& url, SocketStream::Delegate* delegate,
- URLRequestContext* context, CookieStore* cookie_store)
- : SocketStream(url, delegate, context, cookie_store) {}
+ MockSocketStream(const GURL& url, SocketStream::Delegate* delegate)
+ : SocketStream(url, delegate) {}
virtual void Connect() OVERRIDE {}
virtual bool SendData(const char* data, int len) OVERRIDE {
@@ -365,8 +364,7 @@ class WebSocketJobTest : public PlatformTest,
websocket_ = new WebSocketJob(delegate);
if (stream_type == STREAM_MOCK_SOCKET)
- socket_ = new MockSocketStream(url, websocket_.get(), context_.get(),
- NULL);
+ socket_ = new MockSocketStream(url, websocket_.get());
if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) {
if (stream_type == STREAM_SPDY_WEBSOCKET) {
@@ -382,7 +380,7 @@ class WebSocketJobTest : public PlatformTest,
host_resolver_.reset(new MockHostResolver);
context_->set_host_resolver(host_resolver_.get());
- socket_ = new SocketStream(url, websocket_.get(), context_.get(), NULL);
+ socket_ = new SocketStream(url, websocket_.get());
socket_factory_.reset(new MockClientSocketFactory);
DCHECK(data_.get());
socket_factory_->AddSocketDataProvider(data_.get());
@@ -390,6 +388,7 @@ class WebSocketJobTest : public PlatformTest,
}
websocket_->InitSocketStream(socket_.get());
+ websocket_->set_context(context_.get());
// MockHostResolver resolves all hosts to 127.0.0.1; however, when we create
// a WebSocketJob purely to block another one in a throttling test, we don't
// perform a real connect. In that case, the following address is used
@@ -739,14 +738,14 @@ void WebSocketJobTest::TestHSTSUpgrade() {
scoped_refptr<SocketStreamJob> job =
SocketStreamJob::CreateSocketStreamJob(
url, &delegate, context_->transport_security_state(),
- context_->ssl_config_service(), NULL, NULL);
+ context_->ssl_config_service());
EXPECT_TRUE(GetSocket(job.get())->is_secure());
job->DetachDelegate();
url = GURL("ws://donotupgrademe.com/");
job = SocketStreamJob::CreateSocketStreamJob(
url, &delegate, context_->transport_security_state(),
- context_->ssl_config_service(), NULL, NULL);
+ context_->ssl_config_service());
EXPECT_FALSE(GetSocket(job.get())->is_secure());
job->DetachDelegate();
}
diff --git a/net/websockets/websocket_throttle_test.cc b/net/websockets/websocket_throttle_test.cc
index 7b33883..14237b9 100644
--- a/net/websockets/websocket_throttle_test.cc
+++ b/net/websockets/websocket_throttle_test.cc
@@ -73,7 +73,8 @@ TEST_F(WebSocketThrottleTest, Throttle) {
addr.push_back(MakeAddr(1, 2, 3, 6));
scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s1(
- new SocketStream(GURL("ws://host1/"), w1.get(), &context, NULL));
+ new SocketStream(GURL("ws://host1/"), w1.get()));
+ s1->set_context(&context);
w1->InitSocketStream(s1.get());
WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr);
@@ -93,7 +94,8 @@ TEST_F(WebSocketThrottleTest, Throttle) {
addr.push_back(MakeAddr(1, 2, 3, 4));
scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s2(
- new SocketStream(GURL("ws://host2/"), w2.get(), &context, NULL));
+ new SocketStream(GURL("ws://host2/"), w2.get()));
+ s2->set_context(&context);
w2->InitSocketStream(s2.get());
WebSocketThrottleTest::MockSocketStreamConnect(s2.get(), addr);
@@ -113,7 +115,8 @@ TEST_F(WebSocketThrottleTest, Throttle) {
addr.push_back(MakeAddr(1, 2, 3, 5));
scoped_refptr<WebSocketJob> w3(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s3(
- new SocketStream(GURL("ws://host3/"), w3.get(), &context, NULL));
+ new SocketStream(GURL("ws://host3/"), w3.get()));
+ s3->set_context(&context);
w3->InitSocketStream(s3.get());
WebSocketThrottleTest::MockSocketStreamConnect(s3.get(), addr);
@@ -133,7 +136,8 @@ TEST_F(WebSocketThrottleTest, Throttle) {
addr.push_back(MakeAddr(1, 2, 3, 6));
scoped_refptr<WebSocketJob> w4(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s4(
- new SocketStream(GURL("ws://host4/"), w4.get(), &context, NULL));
+ new SocketStream(GURL("ws://host4/"), w4.get()));
+ s4->set_context(&context);
w4->InitSocketStream(s4.get());
WebSocketThrottleTest::MockSocketStreamConnect(s4.get(), addr);
@@ -152,7 +156,8 @@ TEST_F(WebSocketThrottleTest, Throttle) {
addr.push_back(MakeAddr(1, 2, 3, 6));
scoped_refptr<WebSocketJob> w5(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s5(
- new SocketStream(GURL("ws://host5/"), w5.get(), &context, NULL));
+ new SocketStream(GURL("ws://host5/"), w5.get()));
+ s5->set_context(&context);
w5->InitSocketStream(s5.get());
WebSocketThrottleTest::MockSocketStreamConnect(s5.get(), addr);
@@ -171,7 +176,8 @@ TEST_F(WebSocketThrottleTest, Throttle) {
addr.push_back(MakeAddr(1, 2, 3, 6));
scoped_refptr<WebSocketJob> w6(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s6(
- new SocketStream(GURL("ws://host6/"), w6.get(), &context, NULL));
+ new SocketStream(GURL("ws://host6/"), w6.get()));
+ s6->set_context(&context);
w6->InitSocketStream(s6.get());
WebSocketThrottleTest::MockSocketStreamConnect(s6.get(), addr);
@@ -283,7 +289,8 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) {
addr.push_back(MakeAddr(127, 0, 0, 1));
scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s1(
- new SocketStream(GURL("ws://localhost/"), w1.get(), &context, NULL));
+ new SocketStream(GURL("ws://localhost/"), w1.get()));
+ s1->set_context(&context);
w1->InitSocketStream(s1.get());
WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr);
@@ -311,7 +318,8 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) {
// socket1: 127.0.0.1:80
scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s1(
- new SocketStream(GURL("ws://localhost:80/"), w1.get(), &context, NULL));
+ new SocketStream(GURL("ws://localhost:80/"), w1.get()));
+ s1->set_context(&context);
w1->InitSocketStream(s1.get());
MockSocketStreamConnect(s1.get(),
AddressList::CreateFromIPAddress(localhost, 80));
@@ -324,7 +332,8 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) {
// socket2: 127.0.0.1:81
scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate));
scoped_refptr<SocketStream> s2(
- new SocketStream(GURL("ws://localhost:81/"), w2.get(), &context, NULL));
+ new SocketStream(GURL("ws://localhost:81/"), w2.get()));
+ s2->set_context(&context);
w2->InitSocketStream(s2.get());
MockSocketStreamConnect(s2.get(),
AddressList::CreateFromIPAddress(localhost, 81));