summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-10 22:09:58 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-10 22:09:58 +0000
commit2de5530222ed163c8c2f3ebae925b3673fb3ec76 (patch)
tree627b59a6fdb49bfc7511263abb3189223578f76e
parent3054f1ba755f9919a55789a6a204ee5169e02640 (diff)
downloadchromium_src-2de5530222ed163c8c2f3ebae925b3673fb3ec76.zip
chromium_src-2de5530222ed163c8c2f3ebae925b3673fb3ec76.tar.gz
chromium_src-2de5530222ed163c8c2f3ebae925b3673fb3ec76.tar.bz2
base::Bind: Cleanup in test_shell.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8215002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104796 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/appcache/appcache_dispatcher_host.cc36
-rw-r--r--content/browser/appcache/appcache_dispatcher_host.h6
-rw-r--r--webkit/appcache/appcache_backend_impl.cc6
-rw-r--r--webkit/appcache/appcache_backend_impl.h6
-rw-r--r--webkit/appcache/appcache_host.cc75
-rw-r--r--webkit/appcache/appcache_host.h27
-rw-r--r--webkit/appcache/appcache_host_unittest.cc38
-rw-r--r--webkit/tools/test_shell/layout_test_controller.cc12
-rw-r--r--webkit/tools/test_shell/layout_test_controller.h3
-rw-r--r--webkit/tools/test_shell/mac/webwidget_host.mm2
-rw-r--r--webkit/tools/test_shell/notification_presenter.cc5
-rw-r--r--webkit/tools/test_shell/simple_appcache_system.cc127
-rw-r--r--webkit/tools/test_shell/simple_file_writer.cc31
-rw-r--r--webkit/tools/test_shell/simple_resource_loader_bridge.cc74
-rw-r--r--webkit/tools/test_shell/simple_socket_stream_bridge.cc25
-rw-r--r--webkit/tools/test_shell/test_shell_devtools_agent.cc17
-rw-r--r--webkit/tools/test_shell/test_shell_devtools_agent.h3
-rw-r--r--webkit/tools/test_shell/test_shell_devtools_client.cc12
-rw-r--r--webkit/tools/test_shell/test_shell_devtools_client.h3
-rw-r--r--webkit/tools/test_shell/test_webview_delegate_gtk.cc6
-rw-r--r--webkit/tools/test_shell/webwidget_host.cc7
-rw-r--r--webkit/tools/test_shell/webwidget_host.h3
-rw-r--r--webkit/tools/test_shell/webwidget_host_gtk.cc2
-rw-r--r--webkit/tools/test_shell/webwidget_host_win.cc2
24 files changed, 288 insertions, 240 deletions
diff --git a/content/browser/appcache/appcache_dispatcher_host.cc b/content/browser/appcache/appcache_dispatcher_host.cc
index 3f2447a..16c9026 100644
--- a/content/browser/appcache/appcache_dispatcher_host.cc
+++ b/content/browser/appcache/appcache_dispatcher_host.cc
@@ -4,7 +4,8 @@
#include "content/browser/appcache/appcache_dispatcher_host.h"
-#include "base/callback.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/user_metrics.h"
#include "content/common/appcache_messages.h"
@@ -24,12 +25,15 @@ void AppCacheDispatcherHost::OnChannelConnected(int32 peer_pid) {
if (appcache_service_.get()) {
backend_impl_.Initialize(
appcache_service_.get(), &frontend_proxy_, process_id_);
- get_status_callback_.reset(
- NewCallback(this, &AppCacheDispatcherHost::GetStatusCallback));
- start_update_callback_.reset(
- NewCallback(this, &AppCacheDispatcherHost::StartUpdateCallback));
- swap_cache_callback_.reset(
- NewCallback(this, &AppCacheDispatcherHost::SwapCacheCallback));
+ get_status_callback_ =
+ base::Bind(&AppCacheDispatcherHost::GetStatusCallback,
+ base::Unretained(this));
+ start_update_callback_ =
+ base::Bind(&AppCacheDispatcherHost::StartUpdateCallback,
+ base::Unretained(this));
+ swap_cache_callback_ =
+ base::Bind(&AppCacheDispatcherHost::SwapCacheCallback,
+ base::Unretained(this));
}
}
@@ -140,8 +144,7 @@ void AppCacheDispatcherHost::OnGetResourceList(
backend_impl_.GetResourceList(host_id, params);
}
-void AppCacheDispatcherHost::OnGetStatus(int host_id,
- IPC::Message* reply_msg) {
+void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) {
if (pending_reply_msg_.get()) {
BadMessageReceived();
delete reply_msg;
@@ -150,8 +153,8 @@ void AppCacheDispatcherHost::OnGetStatus(int host_id,
pending_reply_msg_.reset(reply_msg);
if (appcache_service_.get()) {
- if (!backend_impl_.GetStatusWithCallback(
- host_id, get_status_callback_.get(), reply_msg)) {
+ if (!backend_impl_.GetStatusWithCallback(host_id, get_status_callback_,
+ reply_msg)) {
BadMessageReceived();
}
return;
@@ -170,8 +173,8 @@ void AppCacheDispatcherHost::OnStartUpdate(int host_id,
pending_reply_msg_.reset(reply_msg);
if (appcache_service_.get()) {
- if (!backend_impl_.StartUpdateWithCallback(
- host_id, start_update_callback_.get(), reply_msg)) {
+ if (!backend_impl_.StartUpdateWithCallback(host_id, start_update_callback_,
+ reply_msg)) {
BadMessageReceived();
}
return;
@@ -180,8 +183,7 @@ void AppCacheDispatcherHost::OnStartUpdate(int host_id,
StartUpdateCallback(false, reply_msg);
}
-void AppCacheDispatcherHost::OnSwapCache(int host_id,
- IPC::Message* reply_msg) {
+void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) {
if (pending_reply_msg_.get()) {
BadMessageReceived();
delete reply_msg;
@@ -190,8 +192,8 @@ void AppCacheDispatcherHost::OnSwapCache(int host_id,
pending_reply_msg_.reset(reply_msg);
if (appcache_service_.get()) {
- if (!backend_impl_.SwapCacheWithCallback(
- host_id, swap_cache_callback_.get(), reply_msg)) {
+ if (!backend_impl_.SwapCacheWithCallback(host_id, swap_cache_callback_,
+ reply_msg)) {
BadMessageReceived();
}
return;
diff --git a/content/browser/appcache/appcache_dispatcher_host.h b/content/browser/appcache/appcache_dispatcher_host.h
index a2fe1fc..5ed331b 100644
--- a/content/browser/appcache/appcache_dispatcher_host.h
+++ b/content/browser/appcache/appcache_dispatcher_host.h
@@ -64,9 +64,9 @@ class AppCacheDispatcherHost : public BrowserMessageFilter {
AppCacheFrontendProxy frontend_proxy_;
appcache::AppCacheBackendImpl backend_impl_;
- scoped_ptr<appcache::GetStatusCallback> get_status_callback_;
- scoped_ptr<appcache::StartUpdateCallback> start_update_callback_;
- scoped_ptr<appcache::SwapCacheCallback> swap_cache_callback_;
+ appcache::GetStatusCallback get_status_callback_;
+ appcache::StartUpdateCallback start_update_callback_;
+ appcache::SwapCacheCallback swap_cache_callback_;
scoped_ptr<IPC::Message> pending_reply_msg_;
// The corresponding ChildProcessHost object's id().
diff --git a/webkit/appcache/appcache_backend_impl.cc b/webkit/appcache/appcache_backend_impl.cc
index 44b3c47..9b132f4 100644
--- a/webkit/appcache/appcache_backend_impl.cc
+++ b/webkit/appcache/appcache_backend_impl.cc
@@ -110,7 +110,7 @@ bool AppCacheBackendImpl::MarkAsForeignEntry(
}
bool AppCacheBackendImpl::GetStatusWithCallback(
- int host_id, GetStatusCallback* callback, void* callback_param) {
+ int host_id, const GetStatusCallback& callback, void* callback_param) {
AppCacheHost* host = GetHost(host_id);
if (!host)
return false;
@@ -120,7 +120,7 @@ bool AppCacheBackendImpl::GetStatusWithCallback(
}
bool AppCacheBackendImpl::StartUpdateWithCallback(
- int host_id, StartUpdateCallback* callback, void* callback_param) {
+ int host_id, const StartUpdateCallback& callback, void* callback_param) {
AppCacheHost* host = GetHost(host_id);
if (!host)
return false;
@@ -130,7 +130,7 @@ bool AppCacheBackendImpl::StartUpdateWithCallback(
}
bool AppCacheBackendImpl::SwapCacheWithCallback(
- int host_id, SwapCacheCallback* callback, void* callback_param) {
+ int host_id, const SwapCacheCallback& callback, void* callback_param) {
AppCacheHost* host = GetHost(host_id);
if (!host)
return false;
diff --git a/webkit/appcache/appcache_backend_impl.h b/webkit/appcache/appcache_backend_impl.h
index 67e7e99..0f81791 100644
--- a/webkit/appcache/appcache_backend_impl.h
+++ b/webkit/appcache/appcache_backend_impl.h
@@ -41,11 +41,11 @@ class APPCACHE_EXPORT AppCacheBackendImpl {
bool SelectCacheForSharedWorker(int host_id, int64 appcache_id);
bool MarkAsForeignEntry(int host_id, const GURL& document_url,
int64 cache_document_was_loaded_from);
- bool GetStatusWithCallback(int host_id, GetStatusCallback* callback,
+ bool GetStatusWithCallback(int host_id, const GetStatusCallback& callback,
void* callback_param);
- bool StartUpdateWithCallback(int host_id, StartUpdateCallback* callback,
+ bool StartUpdateWithCallback(int host_id, const StartUpdateCallback& callback,
void* callback_param);
- bool SwapCacheWithCallback(int host_id, SwapCacheCallback* callback,
+ bool SwapCacheWithCallback(int host_id, const SwapCacheCallback& callback,
void* callback_param);
// Returns a pointer to a registered host. The backend retains ownership.
diff --git a/webkit/appcache/appcache_host.cc b/webkit/appcache/appcache_host.cc
index ddc9bd2..dd9f9fb 100644
--- a/webkit/appcache/appcache_host.cc
+++ b/webkit/appcache/appcache_host.cc
@@ -41,8 +41,7 @@ AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend,
pending_main_resource_cache_id_(kNoCacheId),
pending_selected_cache_id_(kNoCacheId),
frontend_(frontend), service_(service),
- pending_get_status_callback_(NULL), pending_start_update_callback_(NULL),
- pending_swap_cache_callback_(NULL), pending_callback_param_(NULL),
+ pending_callback_param_(NULL),
main_resource_was_fallback_(false), main_resource_blocked_(false),
associated_cache_info_pending_(false) {
}
@@ -69,9 +68,9 @@ void AppCacheHost::RemoveObserver(Observer* observer) {
void AppCacheHost::SelectCache(const GURL& document_url,
const int64 cache_document_was_loaded_from,
const GURL& manifest_url) {
- DCHECK(!pending_start_update_callback_ &&
- !pending_swap_cache_callback_ &&
- !pending_get_status_callback_ &&
+ DCHECK(pending_start_update_callback_.is_null() &&
+ pending_swap_cache_callback_.is_null() &&
+ pending_get_status_callback_.is_null() &&
!is_selection_pending());
origin_in_use_ = document_url.GetOrigin();
@@ -125,9 +124,9 @@ void AppCacheHost::SelectCache(const GURL& document_url,
void AppCacheHost::SelectCacheForWorker(int parent_process_id,
int parent_host_id) {
- DCHECK(!pending_start_update_callback_ &&
- !pending_swap_cache_callback_ &&
- !pending_get_status_callback_ &&
+ DCHECK(pending_start_update_callback_.is_null() &&
+ pending_swap_cache_callback_.is_null() &&
+ pending_get_status_callback_.is_null() &&
!is_selection_pending());
parent_process_id_ = parent_process_id;
@@ -136,9 +135,9 @@ void AppCacheHost::SelectCacheForWorker(int parent_process_id,
}
void AppCacheHost::SelectCacheForSharedWorker(int64 appcache_id) {
- DCHECK(!pending_start_update_callback_ &&
- !pending_swap_cache_callback_ &&
- !pending_get_status_callback_ &&
+ DCHECK(pending_start_update_callback_.is_null() &&
+ pending_swap_cache_callback_.is_null() &&
+ pending_get_status_callback_.is_null() &&
!is_selection_pending());
if (appcache_id != kNoCacheId) {
@@ -158,11 +157,11 @@ void AppCacheHost::MarkAsForeignEntry(const GURL& document_url,
SelectCache(document_url, kNoCacheId, GURL());
}
-void AppCacheHost::GetStatusWithCallback(GetStatusCallback* callback,
+void AppCacheHost::GetStatusWithCallback(const GetStatusCallback& callback,
void* callback_param) {
- DCHECK(!pending_start_update_callback_ &&
- !pending_swap_cache_callback_ &&
- !pending_get_status_callback_);
+ DCHECK(pending_start_update_callback_.is_null() &&
+ pending_swap_cache_callback_.is_null() &&
+ pending_get_status_callback_.is_null());
pending_get_status_callback_ = callback;
pending_callback_param_ = callback_param;
@@ -173,20 +172,18 @@ void AppCacheHost::GetStatusWithCallback(GetStatusCallback* callback,
}
void AppCacheHost::DoPendingGetStatus() {
- DCHECK(pending_get_status_callback_);
+ DCHECK_EQ(false, pending_get_status_callback_.is_null());
- pending_get_status_callback_->Run(
- GetStatus(), pending_callback_param_);
-
- pending_get_status_callback_ = NULL;
+ pending_get_status_callback_.Run(GetStatus(), pending_callback_param_);
+ pending_get_status_callback_.Reset();
pending_callback_param_ = NULL;
}
-void AppCacheHost::StartUpdateWithCallback(StartUpdateCallback* callback,
+void AppCacheHost::StartUpdateWithCallback(const StartUpdateCallback& callback,
void* callback_param) {
- DCHECK(!pending_start_update_callback_ &&
- !pending_swap_cache_callback_ &&
- !pending_get_status_callback_);
+ DCHECK(pending_start_update_callback_.is_null() &&
+ pending_swap_cache_callback_.is_null() &&
+ pending_get_status_callback_.is_null());
pending_start_update_callback_ = callback;
pending_callback_param_ = callback_param;
@@ -197,7 +194,7 @@ void AppCacheHost::StartUpdateWithCallback(StartUpdateCallback* callback,
}
void AppCacheHost::DoPendingStartUpdate() {
- DCHECK(pending_start_update_callback_);
+ DCHECK_EQ(false, pending_start_update_callback_.is_null());
// 6.9.8 Application cache API
bool success = false;
@@ -209,18 +206,16 @@ void AppCacheHost::DoPendingStartUpdate() {
}
}
- pending_start_update_callback_->Run(
- success, pending_callback_param_);
-
- pending_start_update_callback_ = NULL;
+ pending_start_update_callback_.Run(success, pending_callback_param_);
+ pending_start_update_callback_.Reset();
pending_callback_param_ = NULL;
}
-void AppCacheHost::SwapCacheWithCallback(SwapCacheCallback* callback,
+void AppCacheHost::SwapCacheWithCallback(const SwapCacheCallback& callback,
void* callback_param) {
- DCHECK(!pending_start_update_callback_ &&
- !pending_swap_cache_callback_ &&
- !pending_get_status_callback_);
+ DCHECK(pending_start_update_callback_.is_null() &&
+ pending_swap_cache_callback_.is_null() &&
+ pending_get_status_callback_.is_null());
pending_swap_cache_callback_ = callback;
pending_callback_param_ = callback_param;
@@ -231,7 +226,7 @@ void AppCacheHost::SwapCacheWithCallback(SwapCacheCallback* callback,
}
void AppCacheHost::DoPendingSwapCache() {
- DCHECK(pending_swap_cache_callback_);
+ DCHECK_EQ(false, pending_swap_cache_callback_.is_null());
// 6.9.8 Application cache API
bool success = false;
@@ -247,10 +242,8 @@ void AppCacheHost::DoPendingSwapCache() {
}
}
- pending_swap_cache_callback_->Run(
- success, pending_callback_param_);
-
- pending_swap_cache_callback_ = NULL;
+ pending_swap_cache_callback_.Run(success, pending_callback_param_);
+ pending_swap_cache_callback_.Reset();
pending_callback_param_ = NULL;
}
@@ -403,11 +396,11 @@ void AppCacheHost::FinishCacheSelection(
}
// Respond to pending callbacks now that we have a selection.
- if (pending_get_status_callback_)
+ if (!pending_get_status_callback_.is_null())
DoPendingGetStatus();
- else if (pending_start_update_callback_)
+ else if (!pending_start_update_callback_.is_null())
DoPendingStartUpdate();
- else if (pending_swap_cache_callback_)
+ else if (!pending_swap_cache_callback_.is_null())
DoPendingSwapCache();
FOR_EACH_OBSERVER(Observer, observers_, OnCacheSelectionComplete(this));
diff --git a/webkit/appcache/appcache_host.h b/webkit/appcache/appcache_host.h
index f04b4ef..c94a1b3 100644
--- a/webkit/appcache/appcache_host.h
+++ b/webkit/appcache/appcache_host.h
@@ -27,9 +27,9 @@ class AppCache;
class AppCacheFrontend;
class AppCacheRequestHandler;
-typedef Callback2<Status, void*>::Type GetStatusCallback;
-typedef Callback2<bool, void*>::Type StartUpdateCallback;
-typedef Callback2<bool, void*>::Type SwapCacheCallback;
+typedef base::Callback<void(Status, void*)> GetStatusCallback;
+typedef base::Callback<void(bool, void*)> StartUpdateCallback;
+typedef base::Callback<void(bool, void*)> SwapCacheCallback;
// Server-side representation of an application cache host.
class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate,
@@ -65,11 +65,11 @@ class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate,
void SelectCacheForSharedWorker(int64 appcache_id);
void MarkAsForeignEntry(const GURL& document_url,
int64 cache_document_was_loaded_from);
- void GetStatusWithCallback(GetStatusCallback* callback,
+ void GetStatusWithCallback(const GetStatusCallback& callback,
void* callback_param);
- void StartUpdateWithCallback(StartUpdateCallback* callback,
+ void StartUpdateWithCallback(const StartUpdateCallback& callback,
void* callback_param);
- void SwapCacheWithCallback(SwapCacheCallback* callback,
+ void SwapCacheWithCallback(const SwapCacheCallback& callback,
void* callback_param);
// Called prior to the main resource load. When the system contains multiple
@@ -219,14 +219,13 @@ class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate,
// Our central service object.
AppCacheService* service_;
- // Since these are synchronous scriptable api calls in the client,
- // there can only be one type of callback pending.
- // Also, we have to wait until we have a cache selection prior
- // to responding to these calls, as cache selection involves
- // async loading of a cache or a group from storage.
- GetStatusCallback* pending_get_status_callback_;
- StartUpdateCallback* pending_start_update_callback_;
- SwapCacheCallback* pending_swap_cache_callback_;
+ // Since these are synchronous scriptable API calls in the client, there can
+ // only be one type of callback pending. Also, we have to wait until we have a
+ // cache selection prior to responding to these calls, as cache selection
+ // involves async loading of a cache or a group from storage.
+ GetStatusCallback pending_get_status_callback_;
+ StartUpdateCallback pending_start_update_callback_;
+ SwapCacheCallback pending_swap_cache_callback_;
void* pending_callback_param_;
// True if a fallback resource was delivered as the main resource.
diff --git a/webkit/appcache/appcache_host_unittest.cc b/webkit/appcache/appcache_host_unittest.cc
index 4621628..f439059 100644
--- a/webkit/appcache/appcache_host_unittest.cc
+++ b/webkit/appcache/appcache_host_unittest.cc
@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/callback.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -19,12 +20,15 @@ namespace appcache {
class AppCacheHostTest : public testing::Test {
public:
AppCacheHostTest() {
- get_status_callback_.reset(
- NewCallback(this, &AppCacheHostTest::GetStatusCallback));
- start_update_callback_.reset(
- NewCallback(this, &AppCacheHostTest::StartUpdateCallback));
- swap_cache_callback_.reset(
- NewCallback(this, &AppCacheHostTest::SwapCacheCallback));
+ get_status_callback_ =
+ base::Bind(&AppCacheHostTest::GetStatusCallback,
+ base::Unretained(this));
+ start_update_callback_ =
+ base::Bind(&AppCacheHostTest::StartUpdateCallback,
+ base::Unretained(this));
+ swap_cache_callback_ =
+ base::Bind(&AppCacheHostTest::SwapCacheCallback,
+ base::Unretained(this));
}
class MockFrontend : public AppCacheFrontend {
@@ -135,9 +139,9 @@ class AppCacheHostTest : public testing::Test {
MockFrontend mock_frontend_;
// Mock callbacks we expect to receive from the 'host'
- scoped_ptr<appcache::GetStatusCallback> get_status_callback_;
- scoped_ptr<appcache::StartUpdateCallback> start_update_callback_;
- scoped_ptr<appcache::SwapCacheCallback> swap_cache_callback_;
+ appcache::GetStatusCallback get_status_callback_;
+ appcache::StartUpdateCallback start_update_callback_;
+ appcache::SwapCacheCallback swap_cache_callback_;
Status last_status_result_;
bool last_swap_result_;
@@ -157,20 +161,18 @@ TEST_F(AppCacheHostTest, Basic) {
// See that the callbacks are delivered immediately
// and respond as if there is no cache selected.
last_status_result_ = OBSOLETE;
- host.GetStatusWithCallback(get_status_callback_.get(),
- reinterpret_cast<void*>(1));
+ host.GetStatusWithCallback(get_status_callback_, reinterpret_cast<void*>(1));
EXPECT_EQ(UNCACHED, last_status_result_);
EXPECT_EQ(reinterpret_cast<void*>(1), last_callback_param_);
last_start_result_ = true;
- host.StartUpdateWithCallback(start_update_callback_.get(),
+ host.StartUpdateWithCallback(start_update_callback_,
reinterpret_cast<void*>(2));
EXPECT_FALSE(last_start_result_);
EXPECT_EQ(reinterpret_cast<void*>(2), last_callback_param_);
last_swap_result_ = true;
- host.SwapCacheWithCallback(swap_cache_callback_.get(),
- reinterpret_cast<void*>(3));
+ host.SwapCacheWithCallback(swap_cache_callback_, reinterpret_cast<void*>(3));
EXPECT_FALSE(last_swap_result_);
EXPECT_EQ(reinterpret_cast<void*>(3), last_callback_param_);
}
@@ -283,8 +285,7 @@ TEST_F(AppCacheHostTest, FailedCacheLoad) {
// The callback should not occur until we finish cache selection.
last_status_result_ = OBSOLETE;
last_callback_param_ = reinterpret_cast<void*>(-1);
- host.GetStatusWithCallback(get_status_callback_.get(),
- reinterpret_cast<void*>(1));
+ host.GetStatusWithCallback(get_status_callback_, reinterpret_cast<void*>(1));
EXPECT_EQ(OBSOLETE, last_status_result_);
EXPECT_EQ(reinterpret_cast<void*>(-1), last_callback_param_);
@@ -315,8 +316,7 @@ TEST_F(AppCacheHostTest, FailedGroupLoad) {
// The callback should not occur until we finish cache selection.
last_status_result_ = OBSOLETE;
last_callback_param_ = reinterpret_cast<void*>(-1);
- host.GetStatusWithCallback(get_status_callback_.get(),
- reinterpret_cast<void*>(1));
+ host.GetStatusWithCallback(get_status_callback_, reinterpret_cast<void*>(1));
EXPECT_EQ(OBSOLETE, last_status_result_);
EXPECT_EQ(reinterpret_cast<void*>(-1), last_callback_param_);
diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc
index 4b3fda1..c295aef 100644
--- a/webkit/tools/test_shell/layout_test_controller.cc
+++ b/webkit/tools/test_shell/layout_test_controller.cc
@@ -10,6 +10,7 @@
#include "base/base64.h"
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
@@ -69,7 +70,7 @@ bool LayoutTestController::stop_provisional_frame_loads_ = false;
LayoutTestController::WorkQueue LayoutTestController::work_queue_;
LayoutTestController::LayoutTestController(TestShell* shell) :
- ALLOW_THIS_IN_INITIALIZER_LIST(timeout_factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
// Set static shell_ variable since we can't do it in an initializer list.
// We also need to be careful not to assign shell_ to new windows which are
// temporary.
@@ -151,9 +152,10 @@ void LayoutTestController::waitUntilDone(
if (!is_debugger_present) {
// TODO(ojan): Use base::OneShotTimer. For some reason, using OneShotTimer
// seems to cause layout test failures on the try bots.
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- timeout_factory_.NewRunnableMethod(
- &LayoutTestController::notifyDoneTimedOut),
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&LayoutTestController::notifyDoneTimedOut,
+ weak_factory_.GetWeakPtr()),
shell_->GetLayoutTestTimeout());
}
@@ -164,7 +166,7 @@ void LayoutTestController::waitUntilDone(
void LayoutTestController::notifyDone(
const CppArgumentList& args, CppVariant* result) {
// Test didn't timeout. Kill the timeout timer.
- timeout_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
completeNotifyDone(false);
result->SetNull();
diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h
index 3ada264..5e82b01 100644
--- a/webkit/tools/test_shell/layout_test_controller.h
+++ b/webkit/tools/test_shell/layout_test_controller.h
@@ -16,6 +16,7 @@
#include <queue>
+#include "base/memory/weak_ptr.h"
#include "base/timer.h"
#include "base/string16.h"
#include "webkit/glue/cpp_bound_class.h"
@@ -108,7 +109,7 @@ class LayoutTestController : public CppBoundClass {
// Used for test timeouts.
// TODO(ojan): Use base::OneShotTimer.
- ScopedRunnableMethodFactory<LayoutTestController> timeout_factory_;
+ base::WeakPtrFactory<LayoutTestController> weak_factory_;
// Non-owning pointer. The LayoutTestController is owned by the host.
static TestShell* shell_;
diff --git a/webkit/tools/test_shell/mac/webwidget_host.mm b/webkit/tools/test_shell/mac/webwidget_host.mm
index 47a9d07..be13e98 100644
--- a/webkit/tools/test_shell/mac/webwidget_host.mm
+++ b/webkit/tools/test_shell/mac/webwidget_host.mm
@@ -150,7 +150,7 @@ WebWidgetHost::WebWidgetHost()
webwidget_(NULL),
scroll_dx_(0),
scroll_dy_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
set_painting(false);
}
diff --git a/webkit/tools/test_shell/notification_presenter.cc b/webkit/tools/test_shell/notification_presenter.cc
index 1628f47..b5f7234 100644
--- a/webkit/tools/test_shell/notification_presenter.cc
+++ b/webkit/tools/test_shell/notification_presenter.cc
@@ -4,6 +4,7 @@
#include "webkit/tools/test_shell/notification_presenter.h"
+#include "base/bind.h"
#include "base/message_loop.h"
#include "base/task.h"
#include "googleurl/src/gurl.h"
@@ -74,8 +75,8 @@ bool TestNotificationPresenter::show(const WebNotification& notification) {
WebNotification event_target(notification);
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableFunction(&DeferredDisplayDispatch, event_target));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&DeferredDisplayDispatch, event_target));
return true;
}
diff --git a/webkit/tools/test_shell/simple_appcache_system.cc b/webkit/tools/test_shell/simple_appcache_system.cc
index 6a8d454..95d7acf 100644
--- a/webkit/tools/test_shell/simple_appcache_system.cc
+++ b/webkit/tools/test_shell/simple_appcache_system.cc
@@ -7,6 +7,8 @@
#include <string>
#include <vector>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/task.h"
#include "base/synchronization/waitable_event.h"
@@ -38,9 +40,10 @@ class SimpleFrontendProxy
if (!system_)
return;
if (system_->is_io_thread()) {
- system_->ui_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleFrontendProxy::OnCacheSelected,
- host_id, info));
+ system_->ui_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleFrontendProxy::OnCacheSelected, this, host_id,
+ info));
} else if (system_->is_ui_thread()) {
system_->frontend_impl_.OnCacheSelected(host_id, info);
} else {
@@ -53,8 +56,10 @@ class SimpleFrontendProxy
if (!system_)
return;
if (system_->is_io_thread())
- system_->ui_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleFrontendProxy::OnStatusChanged, host_ids, status));
+ system_->ui_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleFrontendProxy::OnStatusChanged, this, host_ids,
+ status));
else if (system_->is_ui_thread())
system_->frontend_impl_.OnStatusChanged(host_ids, status);
else
@@ -66,8 +71,10 @@ class SimpleFrontendProxy
if (!system_)
return;
if (system_->is_io_thread())
- system_->ui_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleFrontendProxy::OnEventRaised, host_ids, event_id));
+ system_->ui_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleFrontendProxy::OnEventRaised, this, host_ids,
+ event_id));
else if (system_->is_ui_thread())
system_->frontend_impl_.OnEventRaised(host_ids, event_id);
else
@@ -80,9 +87,10 @@ class SimpleFrontendProxy
if (!system_)
return;
if (system_->is_io_thread())
- system_->ui_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleFrontendProxy::OnProgressEventRaised,
- host_ids, url, num_total, num_complete));
+ system_->ui_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleFrontendProxy::OnProgressEventRaised, this,
+ host_ids, url, num_total, num_complete));
else if (system_->is_ui_thread())
system_->frontend_impl_.OnProgressEventRaised(
host_ids, url, num_total, num_complete);
@@ -95,9 +103,10 @@ class SimpleFrontendProxy
if (!system_)
return;
if (system_->is_io_thread())
- system_->ui_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleFrontendProxy::OnErrorEventRaised,
- host_ids, message));
+ system_->ui_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleFrontendProxy::OnErrorEventRaised, this, host_ids,
+ message));
else if (system_->is_ui_thread())
system_->frontend_impl_.OnErrorEventRaised(
host_ids, message);
@@ -111,9 +120,10 @@ class SimpleFrontendProxy
if (!system_)
return;
if (system_->is_io_thread())
- system_->ui_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleFrontendProxy::OnLogMessage,
- host_id, log_level, message));
+ system_->ui_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleFrontendProxy::OnLogMessage, this, host_id,
+ log_level, message));
else if (system_->is_ui_thread())
system_->frontend_impl_.OnLogMessage(
host_id, log_level, message);
@@ -141,18 +151,22 @@ class SimpleBackendProxy
public:
explicit SimpleBackendProxy(SimpleAppCacheSystem* appcache_system)
: system_(appcache_system), event_(true, false) {
- get_status_callback_.reset(
- NewCallback(this, &SimpleBackendProxy::GetStatusCallback));
- start_update_callback_.reset(
- NewCallback(this, &SimpleBackendProxy::StartUpdateCallback));
- swap_cache_callback_.reset(
- NewCallback(this, &SimpleBackendProxy::SwapCacheCallback));
+ get_status_callback_ =
+ base::Bind(&SimpleBackendProxy::GetStatusCallback,
+ base::Unretained(this));
+ start_update_callback_ =
+ base::Bind(&SimpleBackendProxy::StartUpdateCallback,
+ base::Unretained(this));
+ swap_cache_callback_=
+ base::Bind(&SimpleBackendProxy::SwapCacheCallback,
+ base::Unretained(this));
}
virtual void RegisterHost(int host_id) {
if (system_->is_ui_thread()) {
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::RegisterHost, host_id));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleBackendProxy::RegisterHost, this, host_id));
} else if (system_->is_io_thread()) {
system_->backend_impl_->RegisterHost(host_id);
} else {
@@ -162,8 +176,9 @@ class SimpleBackendProxy
virtual void UnregisterHost(int host_id) {
if (system_->is_ui_thread()) {
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::UnregisterHost, host_id));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleBackendProxy::UnregisterHost, this, host_id));
} else if (system_->is_io_thread()) {
system_->backend_impl_->UnregisterHost(host_id);
} else {
@@ -173,9 +188,10 @@ class SimpleBackendProxy
virtual void SetSpawningHostId(int host_id, int spawning_host_id) {
if (system_->is_ui_thread()) {
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::SetSpawningHostId,
- host_id, spawning_host_id));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleBackendProxy::SetSpawningHostId, this, host_id,
+ spawning_host_id));
} else if (system_->is_io_thread()) {
system_->backend_impl_->SetSpawningHostId(host_id, spawning_host_id);
} else {
@@ -188,9 +204,11 @@ class SimpleBackendProxy
const int64 cache_document_was_loaded_from,
const GURL& manifest_url) {
if (system_->is_ui_thread()) {
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::SelectCache, host_id, document_url,
- cache_document_was_loaded_from, manifest_url));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleBackendProxy::SelectCache, this, host_id,
+ document_url, cache_document_was_loaded_from,
+ manifest_url));
} else if (system_->is_io_thread()) {
system_->backend_impl_->SelectCache(host_id, document_url,
cache_document_was_loaded_from,
@@ -204,9 +222,10 @@ class SimpleBackendProxy
int host_id,
std::vector<appcache::AppCacheResourceInfo>* resource_infos) {
if (system_->is_ui_thread()) {
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::GetResourceList,
- host_id, resource_infos));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleBackendProxy::GetResourceList, this, host_id,
+ resource_infos));
} else if (system_->is_io_thread()) {
system_->backend_impl_->GetResourceList(host_id, resource_infos);
} else {
@@ -230,9 +249,10 @@ class SimpleBackendProxy
virtual void MarkAsForeignEntry(int host_id, const GURL& document_url,
int64 cache_document_was_loaded_from) {
if (system_->is_ui_thread()) {
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::MarkAsForeignEntry, host_id, document_url,
- cache_document_was_loaded_from));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleBackendProxy::MarkAsForeignEntry, this, host_id,
+ document_url, cache_document_was_loaded_from));
} else if (system_->is_io_thread()) {
system_->backend_impl_->MarkAsForeignEntry(
host_id, document_url,
@@ -246,12 +266,13 @@ class SimpleBackendProxy
if (system_->is_ui_thread()) {
status_result_ = appcache::UNCACHED;
event_.Reset();
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::GetStatus, host_id));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &SimpleBackendProxy::GetStatus, host_id));
event_.Wait();
} else if (system_->is_io_thread()) {
system_->backend_impl_->GetStatusWithCallback(
- host_id, get_status_callback_.get(), NULL);
+ host_id, get_status_callback_, NULL);
} else {
NOTREACHED();
}
@@ -262,12 +283,13 @@ class SimpleBackendProxy
if (system_->is_ui_thread()) {
bool_result_ = false;
event_.Reset();
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::StartUpdate, host_id));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &SimpleBackendProxy::StartUpdate, host_id));
event_.Wait();
} else if (system_->is_io_thread()) {
system_->backend_impl_->StartUpdateWithCallback(
- host_id, start_update_callback_.get(), NULL);
+ host_id, start_update_callback_, NULL);
} else {
NOTREACHED();
}
@@ -278,12 +300,13 @@ class SimpleBackendProxy
if (system_->is_ui_thread()) {
bool_result_ = false;
event_.Reset();
- system_->io_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SimpleBackendProxy::SwapCache, host_id));
+ system_->io_message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &SimpleBackendProxy::SwapCache, host_id));
event_.Wait();
} else if (system_->is_io_thread()) {
system_->backend_impl_->SwapCacheWithCallback(
- host_id, swap_cache_callback_.get(), NULL);
+ host_id, swap_cache_callback_, NULL);
} else {
NOTREACHED();
}
@@ -318,9 +341,9 @@ class SimpleBackendProxy
base::WaitableEvent event_;
bool bool_result_;
appcache::Status status_result_;
- scoped_ptr<appcache::GetStatusCallback> get_status_callback_;
- scoped_ptr<appcache::StartUpdateCallback> start_update_callback_;
- scoped_ptr<appcache::SwapCacheCallback> swap_cache_callback_;
+ appcache::GetStatusCallback get_status_callback_;
+ appcache::StartUpdateCallback start_update_callback_;
+ appcache::SwapCacheCallback swap_cache_callback_;
};
@@ -356,8 +379,8 @@ SimpleAppCacheSystem::~SimpleAppCacheSystem() {
// We pump a task thru the db thread to ensure any tasks previously
// scheduled on that thread have been performed prior to return.
base::WaitableEvent event(false, false);
- db_thread_.message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(&SignalEvent, &event));
+ db_thread_.message_loop()->PostTask(
+ FROM_HERE, base::Bind(&SignalEvent, &event));
event.Wait();
}
}
diff --git a/webkit/tools/test_shell/simple_file_writer.cc b/webkit/tools/test_shell/simple_file_writer.cc
index 8c07ccd..5956696 100644
--- a/webkit/tools/test_shell/simple_file_writer.cc
+++ b/webkit/tools/test_shell/simple_file_writer.cc
@@ -4,6 +4,7 @@
#include "webkit/tools/test_shell/simple_file_writer.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop_proxy.h"
#include "net/url_request/url_request_context.h"
@@ -45,8 +46,9 @@ class SimpleFileWriter::IOThreadProxy
void Truncate(const GURL& path, int64 offset) {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &IOThreadProxy::Truncate, path, offset));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadProxy::Truncate, this, path, offset));
return;
}
DCHECK(!operation_);
@@ -56,8 +58,9 @@ class SimpleFileWriter::IOThreadProxy
void Write(const GURL& path, const GURL& blob_url, int64 offset) {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &IOThreadProxy::Write, path, blob_url, offset));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadProxy::Write, this, path, blob_url, offset));
return;
}
DCHECK(request_context_);
@@ -68,8 +71,9 @@ class SimpleFileWriter::IOThreadProxy
void Cancel() {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &IOThreadProxy::Cancel));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadProxy::Cancel, this));
return;
}
if (!operation_) {
@@ -132,8 +136,9 @@ class SimpleFileWriter::IOThreadProxy
void DidSucceed() {
if (!main_thread_->BelongsToCurrentThread()) {
- main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &IOThreadProxy::DidSucceed));
+ main_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadProxy::DidSucceed, this));
return;
}
if (simple_writer_)
@@ -142,8 +147,9 @@ class SimpleFileWriter::IOThreadProxy
void DidFail(base::PlatformFileError error_code) {
if (!main_thread_->BelongsToCurrentThread()) {
- main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &IOThreadProxy::DidFail, error_code));
+ main_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadProxy::DidFail, this, error_code));
return;
}
if (simple_writer_)
@@ -152,8 +158,9 @@ class SimpleFileWriter::IOThreadProxy
void DidWrite(int64 bytes, bool complete) {
if (!main_thread_->BelongsToCurrentThread()) {
- main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &IOThreadProxy::DidWrite, bytes, complete));
+ main_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadProxy::DidWrite, this, bytes, complete));
return;
}
if (simple_writer_)
diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
index 73fd0cb..1da0692 100644
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
@@ -206,14 +206,16 @@ class RequestProxy : public net::URLRequest::Delegate,
ConvertRequestParamsForFileOverHTTPIfNeeded(params);
// proxy over to the io thread
- g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::AsyncStart, params));
+ g_io_thread->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::AsyncStart, this, params));
}
void Cancel() {
// proxy over to the io thread
- g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::AsyncCancel));
+ g_io_thread->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::AsyncCancel, this));
}
protected:
@@ -237,9 +239,11 @@ class RequestProxy : public net::URLRequest::Delegate,
if (peer_ && peer_->OnReceivedRedirect(new_url, info,
&has_new_first_party_for_cookies,
&new_first_party_for_cookies)) {
- g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::AsyncFollowDeferredRedirect,
- has_new_first_party_for_cookies, new_first_party_for_cookies));
+ g_io_thread->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::AsyncFollowDeferredRedirect, this,
+ has_new_first_party_for_cookies,
+ new_first_party_for_cookies));
} else {
Cancel();
}
@@ -265,8 +269,9 @@ class RequestProxy : public net::URLRequest::Delegate,
// peer could generate new requests in reponse to the received data, which
// when run on the io thread, could race against this function in doing
// another InvokeLater. See bug 769249.
- g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::AsyncReadData));
+ g_io_thread->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::AsyncReadData, this));
peer_->OnReceivedData(buf_copy.get(), bytes_read, -1);
}
@@ -276,8 +281,9 @@ class RequestProxy : public net::URLRequest::Delegate,
return;
// Continue reading more data, see the comment in NotifyReceivedData.
- g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::AsyncReadData));
+ g_io_thread->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::AsyncReadData, this));
peer_->OnDownloadedData(bytes_read);
}
@@ -391,26 +397,30 @@ class RequestProxy : public net::URLRequest::Delegate,
const ResourceResponseInfo& info,
bool* defer_redirect) {
*defer_redirect = true; // See AsyncFollowDeferredRedirect
- owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::NotifyReceivedRedirect, new_url, info));
+ owner_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::NotifyReceivedRedirect, this, new_url, info));
}
virtual void OnReceivedResponse(
const ResourceResponseInfo& info) {
- owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::NotifyReceivedResponse, info));
+ owner_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::NotifyReceivedResponse, this, info));
}
virtual void OnReceivedData(int bytes_read) {
if (download_to_file_) {
file_stream_.Write(buf_->data(), bytes_read, NULL);
- owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::NotifyDownloadedData, bytes_read));
+ owner_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read));
return;
}
- owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::NotifyReceivedData, bytes_read));
+ owner_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read));
}
virtual void OnCompletedRequest(const net::URLRequestStatus& status,
@@ -418,12 +428,10 @@ class RequestProxy : public net::URLRequest::Delegate,
const base::Time& complete_time) {
if (download_to_file_)
file_stream_.Close();
- owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this,
- &RequestProxy::NotifyCompletedRequest,
- status,
- security_info,
- complete_time));
+ owner_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::NotifyCompletedRequest, this, status,
+ security_info, complete_time));
}
// --------------------------------------------------------------------------
@@ -545,8 +553,10 @@ class RequestProxy : public net::URLRequest::Delegate,
bool too_much_time_passed = time_since_last > kOneSecond;
if (is_finished || enough_new_progress || too_much_time_passed) {
- owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RequestProxy::NotifyUploadProgress, position, size));
+ owner_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestProxy::NotifyUploadProgress, this, position,
+ size));
last_upload_ticks_ = base::TimeTicks::Now();
last_upload_position_ = position;
}
@@ -964,8 +974,9 @@ void SimpleResourceLoaderBridge::SetCookie(const GURL& url,
}
scoped_refptr<CookieSetter> cookie_setter(new CookieSetter());
- g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- cookie_setter.get(), &CookieSetter::Set, url, cookie));
+ g_io_thread->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&CookieSetter::Set, cookie_setter.get(), url, cookie));
}
// static
@@ -980,8 +991,9 @@ std::string SimpleResourceLoaderBridge::GetCookies(
scoped_refptr<CookieGetter> getter(new CookieGetter());
- g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- getter.get(), &CookieGetter::Get, url));
+ g_io_thread->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&CookieGetter::Get, getter.get(), url));
return getter->GetResult();
}
diff --git a/webkit/tools/test_shell/simple_socket_stream_bridge.cc b/webkit/tools/test_shell/simple_socket_stream_bridge.cc
index 14b652b..b1174d3 100644
--- a/webkit/tools/test_shell/simple_socket_stream_bridge.cc
+++ b/webkit/tools/test_shell/simple_socket_stream_bridge.cc
@@ -7,6 +7,7 @@
#include "webkit/tools/test_shell/simple_socket_stream_bridge.h"
#include "base/atomicops.h"
+#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
#include "googleurl/src/gurl.h"
@@ -94,8 +95,7 @@ void WebSocketStreamHandleBridgeImpl::Connect(const GURL& url) {
AddRef(); // Released in DoOnClose().
g_io_thread->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoConnect,
- url));
+ base::Bind(&WebSocketStreamHandleBridgeImpl::DoConnect, this, url));
if (delegate_)
delegate_->WillOpenStream(handle_, url);
}
@@ -105,8 +105,8 @@ bool WebSocketStreamHandleBridgeImpl::Send(
DCHECK(g_io_thread);
g_io_thread->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoSend,
- new std::vector<char>(data)));
+ base::Bind(&WebSocketStreamHandleBridgeImpl::DoSend, this,
+ new std::vector<char>(data)));
return true;
}
@@ -114,7 +114,7 @@ void WebSocketStreamHandleBridgeImpl::Close() {
DCHECK(g_io_thread);
g_io_thread->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoClose));
+ base::Bind(&WebSocketStreamHandleBridgeImpl::DoClose, this));
}
void WebSocketStreamHandleBridgeImpl::OnConnected(
@@ -122,8 +122,8 @@ void WebSocketStreamHandleBridgeImpl::OnConnected(
base::subtle::NoBarrier_AtomicIncrement(&num_pending_tasks_, 1);
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoOnConnected,
- max_pending_send_allowed));
+ base::Bind(&WebSocketStreamHandleBridgeImpl::DoOnConnected, this,
+ max_pending_send_allowed));
}
void WebSocketStreamHandleBridgeImpl::OnSentData(
@@ -131,8 +131,8 @@ void WebSocketStreamHandleBridgeImpl::OnSentData(
base::subtle::NoBarrier_AtomicIncrement(&num_pending_tasks_, 1);
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoOnSentData,
- amount_sent));
+ base::Bind(&WebSocketStreamHandleBridgeImpl::DoOnSentData, this,
+ amount_sent));
}
void WebSocketStreamHandleBridgeImpl::OnReceivedData(
@@ -140,9 +140,8 @@ void WebSocketStreamHandleBridgeImpl::OnReceivedData(
base::subtle::NoBarrier_AtomicIncrement(&num_pending_tasks_, 1);
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &WebSocketStreamHandleBridgeImpl::DoOnReceivedData,
- new std::vector<char>(data, data + len)));
+ base::Bind(&WebSocketStreamHandleBridgeImpl::DoOnReceivedData, this,
+ new std::vector<char>(data, data + len)));
}
void WebSocketStreamHandleBridgeImpl::OnClose(net::SocketStream* socket) {
@@ -152,7 +151,7 @@ void WebSocketStreamHandleBridgeImpl::OnClose(net::SocketStream* socket) {
socket_id_ = kNoSocketId;
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoOnClose));
+ base::Bind(&WebSocketStreamHandleBridgeImpl::DoOnClose, this));
}
void WebSocketStreamHandleBridgeImpl::DoConnect(const GURL& url) {
diff --git a/webkit/tools/test_shell/test_shell_devtools_agent.cc b/webkit/tools/test_shell/test_shell_devtools_agent.cc
index 0571e64..836916f 100644
--- a/webkit/tools/test_shell/test_shell_devtools_agent.cc
+++ b/webkit/tools/test_shell/test_shell_devtools_agent.cc
@@ -4,6 +4,7 @@
#include "webkit/tools/test_shell/test_shell_devtools_agent.h"
+#include "base/bind.h"
#include "base/message_loop.h"
#include "grit/webkit_chromium_resources.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
@@ -52,7 +53,7 @@ void TestShellDevToolsAgent::DispatchMessageLoop() {
}
TestShellDevToolsAgent::TestShellDevToolsAgent()
- : ALLOW_THIS_IN_INITIALIZER_LIST(call_method_factory_(this)),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
dev_tools_client_(NULL) {
static int dev_tools_agent_counter;
routing_id_ = ++dev_tools_agent_counter;
@@ -90,11 +91,10 @@ WebKit::WebDevToolsAgentClient::WebKitClientMessageLoop*
}
void TestShellDevToolsAgent::AsyncCall(const TestShellDevToolsCallArgs &args) {
- MessageLoop::current()->PostDelayedTask(
+ MessageLoop::current()->PostTask(
FROM_HERE,
- call_method_factory_.NewRunnableMethod(&TestShellDevToolsAgent::Call,
- args),
- 0);
+ base::Bind(&TestShellDevToolsAgent::Call, weak_factory_.GetWeakPtr(),
+ args));
}
void TestShellDevToolsAgent::Call(const TestShellDevToolsCallArgs &args) {
@@ -134,11 +134,10 @@ void TestShellDevToolsAgent::detach() {
}
void TestShellDevToolsAgent::frontendLoaded() {
- MessageLoop::current()->PostDelayedTask(
+ MessageLoop::current()->PostTask(
FROM_HERE,
- call_method_factory_.NewRunnableMethod(
- &TestShellDevToolsAgent::DelayedFrontendLoaded),
- 0);
+ base::Bind(&TestShellDevToolsAgent::DelayedFrontendLoaded,
+ weak_factory_.GetWeakPtr()));
}
bool TestShellDevToolsAgent::evaluateInWebInspector(
diff --git a/webkit/tools/test_shell/test_shell_devtools_agent.h b/webkit/tools/test_shell/test_shell_devtools_agent.h
index ee45ed6..9258442 100644
--- a/webkit/tools/test_shell/test_shell_devtools_agent.h
+++ b/webkit/tools/test_shell/test_shell_devtools_agent.h
@@ -5,6 +5,7 @@
#ifndef TEST_SHELL_DEVTOOLS_AGENT_H_
#define TEST_SHELL_DEVTOOLS_AGENT_H_
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgentClient.h"
@@ -51,7 +52,7 @@ class TestShellDevToolsAgent : public WebKit::WebDevToolsAgentClient {
static void DispatchMessageLoop();
WebKit::WebDevToolsAgent* GetWebAgent();
- ScopedRunnableMethodFactory<TestShellDevToolsAgent> call_method_factory_;
+ base::WeakPtrFactory<TestShellDevToolsAgent> weak_factory_;
TestShellDevToolsClient* dev_tools_client_;
int routing_id_;
WebKit::WebDevToolsAgent* web_dev_tools_agent_;
diff --git a/webkit/tools/test_shell/test_shell_devtools_client.cc b/webkit/tools/test_shell/test_shell_devtools_client.cc
index 320e7e2..b8d5664 100644
--- a/webkit/tools/test_shell/test_shell_devtools_client.cc
+++ b/webkit/tools/test_shell/test_shell_devtools_client.cc
@@ -14,6 +14,7 @@
#include "webkit/tools/test_shell/test_shell_devtools_callargs.h"
#include "webkit/tools/test_shell/test_shell_devtools_client.h"
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop.h"
@@ -25,7 +26,7 @@ using WebKit::WebView;
TestShellDevToolsClient::TestShellDevToolsClient(TestShellDevToolsAgent *agent,
WebView* web_view)
- : ALLOW_THIS_IN_INITIALIZER_LIST(call_method_factory_(this)),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
dev_tools_agent_(agent),
web_view_(web_view) {
web_tools_frontend_.reset(WebDevToolsFrontend::create(web_view_, this,
@@ -36,7 +37,7 @@ TestShellDevToolsClient::TestShellDevToolsClient(TestShellDevToolsAgent *agent,
TestShellDevToolsClient::~TestShellDevToolsClient() {
// It is a chance that page will be destroyed at detach step of
// dev_tools_agent_ and we should clean pending requests a bit earlier.
- call_method_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
if (dev_tools_agent_)
dev_tools_agent_->detach();
}
@@ -74,9 +75,10 @@ void TestShellDevToolsClient::undockWindow() {
}
void TestShellDevToolsClient::AsyncCall(const TestShellDevToolsCallArgs &args) {
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- call_method_factory_.NewRunnableMethod(&TestShellDevToolsClient::Call,
- args), 0);
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&TestShellDevToolsClient::Call, weak_factory_.GetWeakPtr(),
+ args));
}
void TestShellDevToolsClient::Call(const TestShellDevToolsCallArgs &args) {
diff --git a/webkit/tools/test_shell/test_shell_devtools_client.h b/webkit/tools/test_shell/test_shell_devtools_client.h
index af8f41b..b9ef290 100644
--- a/webkit/tools/test_shell/test_shell_devtools_client.h
+++ b/webkit/tools/test_shell/test_shell_devtools_client.h
@@ -6,6 +6,7 @@
#define TEST_SHELL_DEVTOOLS_CLIENT_H_
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontendClient.h"
@@ -44,7 +45,7 @@ class TestShellDevToolsClient: public WebKit::WebDevToolsFrontendClient {
private:
void Call(const TestShellDevToolsCallArgs& args);
- ScopedRunnableMethodFactory<TestShellDevToolsClient> call_method_factory_;
+ base::WeakPtrFactory<TestShellDevToolsClient> weak_factory_;
TestShellDevToolsAgent* dev_tools_agent_;
WebKit::WebView* web_view_;
scoped_ptr<WebKit::WebDevToolsFrontend> web_tools_frontend_;
diff --git a/webkit/tools/test_shell/test_webview_delegate_gtk.cc b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
index ab60381..6adfa0c 100644
--- a/webkit/tools/test_shell/test_webview_delegate_gtk.cc
+++ b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
@@ -9,6 +9,7 @@
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
+#include "base/bind.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "net/base/net_errors.h"
@@ -104,8 +105,9 @@ void TestWebViewDelegate::show(WebNavigationPolicy policy) {
void TestWebViewDelegate::closeWidgetSoon() {
if (this == shell_->delegate()) {
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
- &gtk_widget_destroy, GTK_WIDGET(shell_->mainWnd())));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&gtk_widget_destroy, GTK_WIDGET(shell_->mainWnd())));
} else if (this == shell_->popup_delegate()) {
shell_->ClosePopup();
}
diff --git a/webkit/tools/test_shell/webwidget_host.cc b/webkit/tools/test_shell/webwidget_host.cc
index 59cf80b..32b399b 100644
--- a/webkit/tools/test_shell/webwidget_host.cc
+++ b/webkit/tools/test_shell/webwidget_host.cc
@@ -4,9 +4,12 @@
#include "webkit/tools/test_shell/webwidget_host.h"
+#include "base/bind.h"
#include "base/message_loop.h"
void WebWidgetHost::ScheduleAnimation() {
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- factory_.NewRunnableMethod(&WebWidgetHost::ScheduleComposite), 10);
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&WebWidgetHost::ScheduleComposite, weak_factory_.GetWeakPtr()),
+ 10);
}
diff --git a/webkit/tools/test_shell/webwidget_host.h b/webkit/tools/test_shell/webwidget_host.h
index b16ba7e..130c81c 100644
--- a/webkit/tools/test_shell/webwidget_host.h
+++ b/webkit/tools/test_shell/webwidget_host.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "skia/ext/platform_canvas.h"
#include "ui/gfx/native_widget_types.h"
@@ -153,7 +154,7 @@ class WebWidgetHost {
#endif
private:
- ScopedRunnableMethodFactory<WebWidgetHost> factory_;
+ base::WeakPtrFactory<WebWidgetHost> weak_factory_;
};
#endif // WEBKIT_TOOLS_TEST_SHELL_WEBWIDGET_HOST_H_
diff --git a/webkit/tools/test_shell/webwidget_host_gtk.cc b/webkit/tools/test_shell/webwidget_host_gtk.cc
index 6480b38..bfd3835 100644
--- a/webkit/tools/test_shell/webwidget_host_gtk.cc
+++ b/webkit/tools/test_shell/webwidget_host_gtk.cc
@@ -328,7 +328,7 @@ WebWidgetHost::WebWidgetHost()
webwidget_(NULL),
scroll_dx_(0),
scroll_dy_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
set_painting(false);
}
diff --git a/webkit/tools/test_shell/webwidget_host_win.cc b/webkit/tools/test_shell/webwidget_host_win.cc
index 0d06d6c..c149994 100644
--- a/webkit/tools/test_shell/webwidget_host_win.cc
+++ b/webkit/tools/test_shell/webwidget_host_win.cc
@@ -201,7 +201,7 @@ WebWidgetHost::WebWidgetHost()
track_mouse_leave_(false),
scroll_dx_(0),
scroll_dy_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
set_painting(false);
}