diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-14 21:33:58 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-14 21:33:58 +0000 |
commit | e91ac22d99252095839ca7c82c092972bd56445e (patch) | |
tree | 0054d7c65bd3ec21de4b2c776220788849b21e6a /net | |
parent | 30d170b85b632ffe2babc4e0955b2b09851540dc (diff) | |
download | chromium_src-e91ac22d99252095839ca7c82c092972bd56445e.zip chromium_src-e91ac22d99252095839ca7c82c092972bd56445e.tar.gz chromium_src-e91ac22d99252095839ca7c82c092972bd56445e.tar.bz2 |
Remove BindStateHolder and have Bind() return a Callback<> object directly.
This removes some complexity and also fixes a bug where if you call Bind() with the result of Bind(), the resulting Callback would only be valid during the first call. Ouch.
BUG=none
TEST=new unittests
Review URL: http://codereview.chromium.org/8738001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/completion_callback.cc | 14 | ||||
-rw-r--r-- | net/base/completion_callback.h | 7 | ||||
-rw-r--r-- | net/base/cookie_monster_unittest.cc | 2 | ||||
-rw-r--r-- | net/base/cookie_store_test_helpers.cc | 2 | ||||
-rw-r--r-- | net/base/cookie_store_test_helpers.h | 2 | ||||
-rw-r--r-- | net/http/http_proxy_client_socket.cc | 3 | ||||
-rw-r--r-- | net/net.gyp | 1 | ||||
-rw-r--r-- | net/socket/socket_test_util.cc | 5 | ||||
-rw-r--r-- | net/socket/web_socket_server_socket.cc | 3 | ||||
-rw-r--r-- | net/spdy/spdy_proxy_client_socket_unittest.cc | 4 |
10 files changed, 31 insertions, 12 deletions
diff --git a/net/base/completion_callback.cc b/net/base/completion_callback.cc new file mode 100644 index 0000000..e19e327 --- /dev/null +++ b/net/base/completion_callback.cc @@ -0,0 +1,14 @@ +// 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. + +#include "net/base/completion_callback.h" + +namespace net { + +void OldCompletionCallbackAdapter(OldCompletionCallback* old_callback, + int rv) { + old_callback->Run(rv); +} + +} // namespace net diff --git a/net/base/completion_callback.h b/net/base/completion_callback.h index cea6be3..2042994 100644 --- a/net/base/completion_callback.h +++ b/net/base/completion_callback.h @@ -60,6 +60,13 @@ class CancelableOldCompletionCallback : bool is_canceled_; }; +// Helper function for using OldCompletionCallback objects with +// the newer CompletionCallback APIs. +// +// This is a transitional function and should be removed when +// OldCompletionCallbackAdapter is deleted. +void OldCompletionCallbackAdapter(OldCompletionCallback* old_callback, int rv); + } // namespace net #endif // NET_BASE_COMPLETION_CALLBACK_H__ diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc index 87df99c..59580e6 100644 --- a/net/base/cookie_monster_unittest.cc +++ b/net/base/cookie_monster_unittest.cc @@ -145,7 +145,7 @@ class GetCookieStringCallback : public CookieCallback { explicit GetCookieStringCallback(Thread* run_in_thread) : CookieCallback(run_in_thread) {} - void Run(std::string cookie) { + void Run(const std::string& cookie) { cookie_ = cookie; CallbackEpilogue(); } diff --git a/net/base/cookie_store_test_helpers.cc b/net/base/cookie_store_test_helpers.cc index 0d50de3..7a69117 100644 --- a/net/base/cookie_store_test_helpers.cc +++ b/net/base/cookie_store_test_helpers.cc @@ -33,7 +33,7 @@ void DelayedCookieMonster::SetCookiesInternalCallback(bool result) { } void DelayedCookieMonster::GetCookiesWithOptionsInternalCallback( - std::string cookie) { + const std::string& cookie) { cookie_ = cookie; did_run_ = true; } diff --git a/net/base/cookie_store_test_helpers.h b/net/base/cookie_store_test_helpers.h index ba8c6c8..14b353b 100644 --- a/net/base/cookie_store_test_helpers.h +++ b/net/base/cookie_store_test_helpers.h @@ -70,7 +70,7 @@ class DelayedCookieMonster : public CookieStore { void SetCookiesInternalCallback(bool result); - void GetCookiesWithOptionsInternalCallback(std::string cookie); + void GetCookiesWithOptionsInternalCallback(const std::string& cookie); // Invoke the original callbacks. diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc index 4b03ba8..b0ddc32 100644 --- a/net/http/http_proxy_client_socket.cc +++ b/net/http/http_proxy_client_socket.cc @@ -73,8 +73,7 @@ int HttpProxyClientSocket::RestartWithAuth(OldCompletionCallback* callback) { rv = DoLoop(OK); if (rv == ERR_IO_PENDING) if (callback) { - user_callback_ = base::Bind(&OldCompletionCallback::Run<int>, - base::Unretained(callback)); + user_callback_ = base::Bind(&OldCompletionCallbackAdapter, callback); } return rv; } diff --git a/net/net.gyp b/net/net.gyp index 040c1e0..a62ec23 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -72,6 +72,7 @@ 'base/cert_verifier.h', 'base/cert_verify_result.cc', 'base/cert_verify_result.h', + 'base/completion_callback.cc', 'base/completion_callback.h', 'base/connection_type_histograms.cc', 'base/connection_type_histograms.h', diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index ff8bc50..37c0316 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -1481,8 +1481,7 @@ int MockTransportClientSocketPool::RequestSocket( AddressList(), net_log.net_log(), net::NetLog::Source()); CompletionCallback cb; if (callback) { - cb = base::Bind(&OldCompletionCallback::Run<int>, - base::Unretained(callback)); + cb = base::Bind(&OldCompletionCallbackAdapter, callback); } MockConnectJob* job = new MockConnectJob(socket, handle, cb); job_list_.push_back(job); @@ -1491,7 +1490,7 @@ int MockTransportClientSocketPool::RequestSocket( } void MockTransportClientSocketPool::CancelRequest(const std::string& group_name, - ClientSocketHandle* handle) { + ClientSocketHandle* handle) { std::vector<MockConnectJob*>::iterator i; for (i = job_list_.begin(); i != job_list_.end(); ++i) { if ((*i)->CancelHandle(handle)) { diff --git a/net/socket/web_socket_server_socket.cc b/net/socket/web_socket_server_socket.cc index 08b7788..899bb3e 100644 --- a/net/socket/web_socket_server_socket.cc +++ b/net/socket/web_socket_server_socket.cc @@ -321,8 +321,7 @@ class WebSocketServerSocketImpl : public net::WebSocketServerSocket { phase_ = PHASE_HANDSHAKE; net::CompletionCallback cb; if (callback) { - cb = base::Bind(&net::OldCompletionCallback::Run<int>, - base::Unretained(callback)); + cb = base::Bind(&net::OldCompletionCallbackAdapter, callback); } pending_reqs_.push_front(PendingReq( PendingReq::TYPE_READ_METADATA, fill_handshake_buf_.get(), diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc index d7d2626..c21080f 100644 --- a/net/spdy/spdy_proxy_client_socket_unittest.cc +++ b/net/spdy/spdy_proxy_client_socket_unittest.cc @@ -1276,8 +1276,8 @@ TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); ASSERT_EQ(ERR_IO_PENDING, sock_->Read(read_buf, kLen1, - base::Bind(&DeleteSockCallback::Run<int>, - base::Unretained(&read_callback)))); + base::Bind(&OldCompletionCallbackAdapter, + &read_callback))); scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1)); EXPECT_EQ(ERR_IO_PENDING, sock_->Write(write_buf, write_buf->size(), |