diff options
author | yhirano@chromium.org <yhirano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 09:09:41 +0000 |
---|---|---|
committer | yhirano@chromium.org <yhirano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 09:09:41 +0000 |
commit | 03161c9270e3b216609d9bbe1bd5294a174ea399 (patch) | |
tree | 14183249a3f85f70293d7c8898757dddc2ed4c07 | |
parent | 09a58654a8c7b93329fa3be9ccb6710c11727fa3 (diff) | |
download | chromium_src-03161c9270e3b216609d9bbe1bd5294a174ea399.zip chromium_src-03161c9270e3b216609d9bbe1bd5294a174ea399.tar.gz chromium_src-03161c9270e3b216609d9bbe1bd5294a174ea399.tar.bz2 |
Revert 207763 "Merge https://src.chromium.org/viewvc/chrome?revi..."
> Merge https://src.chromium.org/viewvc/chrome?revision=205158&view=revision
>
> > SocketStream uses a weak ptr to URLRequestContext
> >
> > URLRequestContext can be destroyed while SocketStream is living, so we use WeakPtr to detect the destruction.
> > This is a workaround and this issue should be fixed in a better way in the future.
> >
> > Imported from https://codereview.chromium.org/15736021/ .
> >
> > TEST=net_unittests content_unittests
> > BUG=244746
> > R=mmenke
> TBR=mmenke@chromium.org
>
> Review URL: https://codereview.chromium.org/16874005
TBR=yhirano@chromium.org
Review URL: https://codereview.chromium.org/17368004
git-svn-id: svn://svn.chromium.org/chrome/branches/1500/src@207764 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 3 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 4 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 7 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_job.h | 4 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_unittest.cc | 62 | ||||
-rw-r--r-- | net/url_request/url_request_context.h | 3 |
6 files changed, 11 insertions, 72 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 4d5dd7b..cc2d371 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -298,7 +298,8 @@ ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( ChromeURLRequestContext::ChromeURLRequestContext( ContextType type, chrome_browser_net::LoadTimeStats* load_time_stats) - : load_time_stats_(load_time_stats) { + : weak_factory_(this), + load_time_stats_(load_time_stats) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (load_time_stats_) load_time_stats_->RegisterURLRequestContext(this, type); diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 86f09fc..db09992 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -41,13 +41,15 @@ class ChromeURLRequestContext : public net::URLRequestContext { virtual ~ChromeURLRequestContext(); base::WeakPtr<ChromeURLRequestContext> GetWeakPtr() { - return base::AsWeakPtr(this); + return weak_factory_.GetWeakPtr(); } // Copies the state from |other| into this context. void CopyFrom(ChromeURLRequestContext* other); private: + base::WeakPtrFactory<ChromeURLRequestContext> weak_factory_; + // --------------------------------------------------------------------------- // Important: When adding any new members below, consider whether they need to // be added to CopyFrom. diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 7c4b250..50386c3e 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -12,7 +12,6 @@ #include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" #include "net/base/address_list.h" #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" @@ -128,8 +127,8 @@ class NET_EXPORT SocketStream Delegate* delegate() const { return delegate_; } int max_pending_send_allowed() const { return max_pending_send_allowed_; } - URLRequestContext* context() const { return context_.get(); } - void set_context(URLRequestContext* context); + const URLRequestContext* context() const { return context_; } + void set_context(const URLRequestContext* context); BoundNetLog* net_log() { return &net_log_; } @@ -337,7 +336,7 @@ class NET_EXPORT SocketStream // sum of the size of buffers in |pending_write_bufs_| // exceeds this limit, SendData() fails. int max_pending_send_allowed_; - base::WeakPtr<URLRequestContext> context_; + const URLRequestContext* context_; UserDataMap user_data_; diff --git a/net/socket_stream/socket_stream_job.h b/net/socket_stream/socket_stream_job.h index 877f5ee..7c97aab 100644 --- a/net/socket_stream/socket_stream_job.h +++ b/net/socket_stream/socket_stream_job.h @@ -49,10 +49,10 @@ class NET_EXPORT SocketStreamJob virtual SocketStream::UserData* GetUserData(const void* key) const; virtual void SetUserData(const void* key, SocketStream::UserData* data); - URLRequestContext* context() const { + const URLRequestContext* context() const { return socket_->context(); } - void set_context(URLRequestContext* context) { + void set_context(const URLRequestContext* context) { socket_->set_context(context); } diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index bd183a0..aed80f2 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -924,66 +924,4 @@ TEST_F(SocketStreamTest, OnErrorDetachDelegate) { EXPECT_EQ(OK, test_callback.WaitForResult()); } -// A test for the WeakPtr workaround patch which should be deleted -// in the future. -TEST_F(SocketStreamTest, ContextDestroyedBeforeDoBeforeConnect) { - TestCompletionCallback test_callback; - - scoped_ptr<SocketStreamEventRecorder> delegate( - new SocketStreamEventRecorder(test_callback.callback())); - - scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext); - TestSocketStreamNetworkDelegate network_delegate; - network_delegate.SetBeforeConnectResult(OK); - context->set_network_delegate(&network_delegate); - - scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(context.get()); - - socket_stream->Connect(); - context.reset(); - - ASSERT_EQ(0U, delegate->GetSeenEvents().size()); - - test_callback.WaitForResult(); - - const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); - ASSERT_EQ(1U, events.size()); - - EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type); -} - -// A test for the WeakPtr workaround patch which should be deleted -// in the future. -TEST_F(SocketStreamTest, SocketStreamResetBeforeDoBeforeConnect) { - TestCompletionCallback test_callback; - - scoped_ptr<SocketStreamEventRecorder> delegate( - new SocketStreamEventRecorder(test_callback.callback())); - - scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext); - TestSocketStreamNetworkDelegate network_delegate; - network_delegate.SetBeforeConnectResult(OK); - context->set_network_delegate(&network_delegate); - - scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(context.get()); - - socket_stream->Connect(); - socket_stream = NULL; - context.reset(); - - ASSERT_EQ(0U, delegate->GetSeenEvents().size()); - test_callback.WaitForResult(); - - const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); - ASSERT_EQ(1U, events.size()); - - EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type); -} - } // namespace net diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index bfeaf70..f5dc635 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -47,8 +47,7 @@ class URLRequestThrottlerManager; // these member variables, since they may be shared. For the ones that aren't // shared, URLRequestContextStorage can be helpful in defining their storage. class NET_EXPORT URLRequestContext - : NON_EXPORTED_BASE(public base::NonThreadSafe), - public base::SupportsWeakPtr<URLRequestContext> { + : NON_EXPORTED_BASE(public base::NonThreadSafe) { public: URLRequestContext(); virtual ~URLRequestContext(); |