summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/message_loop.cc6
-rw-r--r--base/message_loop.h10
-rw-r--r--base/message_loop_helpers.h73
-rw-r--r--base/message_loop_proxy.cc7
-rw-r--r--base/message_loop_proxy.h11
-rw-r--r--chrome/browser/browsing_data_quota_helper.h3
-rw-r--r--chrome/browser/browsing_data_remover.h3
-rw-r--r--chrome/browser/chromeos/login/screen_locker.h5
-rw-r--r--chrome/browser/chromeos/web_socket_proxy.cc3
-rw-r--r--chrome/browser/ui/views/browser_actions_container.h3
-rw-r--r--chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.h4
-rw-r--r--content/renderer/webplugin_delegate_proxy.h3
-rw-r--r--net/url_request/url_request_context_getter.h4
-rw-r--r--webkit/plugins/npapi/webplugin_delegate_impl.h4
-rw-r--r--webkit/plugins/ppapi/ppapi_webplugin_impl.h4
-rw-r--r--webkit/plugins/webview_plugin.h4
16 files changed, 127 insertions, 20 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 32b4061..10be720 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -770,6 +770,12 @@ bool MessageLoop::DoIdleWork() {
return false;
}
+void MessageLoop::DeleteSoonInternal(const tracked_objects::Location& from_here,
+ void(*deleter)(const void*),
+ const void* object) {
+ PostNonNestableTask(from_here, base::Bind(deleter, object));
+}
+
//------------------------------------------------------------------------------
// MessageLoop::AutoRunState
diff --git a/base/message_loop.h b/base/message_loop.h
index 18333e2..573e712 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -14,6 +14,7 @@
#include "base/callback_forward.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
+#include "base/message_loop_helpers.h"
#include "base/message_loop_proxy.h"
#include "base/message_pump.h"
#include "base/observer_list.h"
@@ -228,7 +229,8 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// from RefCountedThreadSafe<T>!
template <class T>
void DeleteSoon(const tracked_objects::Location& from_here, const T* object) {
- PostNonNestableTask(from_here, new DeleteTask<T>(object));
+ base::subtle::DeleteHelperInternal<T, void>::DeleteOnMessageLoop(
+ this, from_here, object);
}
// A variant on PostTask that releases the given reference counted object
@@ -552,6 +554,12 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
private:
+ template <class T, class R> friend class base::subtle::DeleteHelperInternal;
+
+ void DeleteSoonInternal(const tracked_objects::Location& from_here,
+ void(*deleter)(const void*),
+ const void* object);
+
DISALLOW_COPY_AND_ASSIGN(MessageLoop);
};
diff --git a/base/message_loop_helpers.h b/base/message_loop_helpers.h
new file mode 100644
index 0000000..151128c
--- /dev/null
+++ b/base/message_loop_helpers.h
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef BASE_MESSAGE_LOOP_HELPERS_H_
+#define BASE_MESSAGE_LOOP_HELPERS_H_
+#pragma once
+
+#include "base/basictypes.h"
+
+namespace tracked_objects {
+class Location;
+}
+
+namespace base {
+
+namespace subtle {
+template <class T, class R> class DeleteHelperInternal;
+}
+
+// This is a template helper which uses a function indirection to erase T from
+// the function signature while still remembering it so we can call the correct
+// destructor. We use this trick so we don't need to include bind.h in a
+// header file. We also embed the function in a class to make it easier for
+// users of DeleteSoon to declare the helper as a friend.
+template <class T>
+class DeleteHelper {
+ private:
+ // TODO(dcheng): Move the return type back to a function template parameter.
+ template <class T2, class R> friend class subtle::DeleteHelperInternal;
+
+ static void DoDelete(const void* object) {
+ delete reinterpret_cast<const T*>(object);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(DeleteHelper);
+};
+
+namespace subtle {
+
+// An internal MessageLoop-like class helper for DeleteHelper. We don't want to
+// expose DoDelete directly since the void* argument makes it possible to pass
+// an object of the wrong type to delete. Instead, we force callers to go
+// through DeleteHelperInternal for type safety. MessageLoop-like classes which
+// expose a DeleteSoon method should friend this class and implement a
+// DeleteSoonInternal method with the following signature:
+// bool(const tracked_objects::Location&,
+// void(*deleter)(const void*),
+// void* object)
+// An implementation of DeleteSoonInternal should simply create a base::Closure
+// from (deleter, object) and return the result of posting the task.
+template <class T, class ReturnType>
+class DeleteHelperInternal {
+ public:
+ template <class MessageLoopType>
+ static ReturnType DeleteOnMessageLoop(
+ MessageLoopType* message_loop,
+ const tracked_objects::Location& from_here,
+ const T* object) {
+ return message_loop->DeleteSoonInternal(from_here,
+ &DeleteHelper<T>::DoDelete,
+ object);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DeleteHelperInternal);
+};
+
+} // namespace subtle
+
+} // namespace base
+
+#endif // BASE_MESSAGE_LOOP_HELPERS_H_
diff --git a/base/message_loop_proxy.cc b/base/message_loop_proxy.cc
index f9b4ad8..63837d7 100644
--- a/base/message_loop_proxy.cc
+++ b/base/message_loop_proxy.cc
@@ -49,4 +49,11 @@ void MessageLoopProxy::OnDestruct() const {
delete this;
}
+bool MessageLoopProxy::DeleteSoonInternal(
+ const tracked_objects::Location& from_here,
+ void(*deleter)(const void*),
+ const void* object) {
+ return PostNonNestableTask(from_here, base::Bind(deleter, object));
+}
+
} // namespace base
diff --git a/base/message_loop_proxy.h b/base/message_loop_proxy.h
index aac11b9..738f39f 100644
--- a/base/message_loop_proxy.h
+++ b/base/message_loop_proxy.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
+#include "base/message_loop_helpers.h"
#include "base/task.h"
namespace tracked_objects {
@@ -121,8 +122,9 @@ class BASE_EXPORT MessageLoopProxy
template <class T>
bool DeleteSoon(const tracked_objects::Location& from_here,
- T* object) {
- return PostNonNestableTask(from_here, new DeleteTask<T>(object));
+ const T* object) {
+ return base::subtle::DeleteHelperInternal<T, bool>::DeleteOnMessageLoop(
+ this, from_here, object);
}
template <class T>
bool ReleaseSoon(const tracked_objects::Location& from_here,
@@ -135,6 +137,7 @@ class BASE_EXPORT MessageLoopProxy
static scoped_refptr<MessageLoopProxy> current();
protected:
+ template <class T, class R> friend class subtle::DeleteHelperInternal;
friend class RefCountedThreadSafe<MessageLoopProxy, MessageLoopProxyTraits>;
friend struct MessageLoopProxyTraits;
@@ -144,6 +147,10 @@ class BASE_EXPORT MessageLoopProxy
// Called when the proxy is about to be deleted. Subclasses can override this
// to provide deletion on specific threads.
virtual void OnDestruct() const;
+
+ bool DeleteSoonInternal(const tracked_objects::Location& from_here,
+ void(*deleter)(const void*),
+ const void* object);
};
struct MessageLoopProxyTraits {
diff --git a/chrome/browser/browsing_data_quota_helper.h b/chrome/browser/browsing_data_quota_helper.h
index 3632855..b330bee 100644
--- a/chrome/browser/browsing_data_quota_helper.h
+++ b/chrome/browser/browsing_data_quota_helper.h
@@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
+#include "base/message_loop_helpers.h"
#include "base/message_loop_proxy.h"
#include "base/time.h"
#include "content/public/browser/browser_thread.h"
@@ -73,7 +74,7 @@ class BrowsingDataQuotaHelper
virtual ~BrowsingDataQuotaHelper();
private:
- friend class DeleteTask<const BrowsingDataQuotaHelper>;
+ friend class base::DeleteHelper<BrowsingDataQuotaHelper>;
friend struct BrowsingDataQuotaHelperDeleter;
scoped_refptr<base::MessageLoopProxy> io_thread_;
diff --git a/chrome/browser/browsing_data_remover.h b/chrome/browser/browsing_data_remover.h
index c445597..9bc68d9 100644
--- a/chrome/browser/browsing_data_remover.h
+++ b/chrome/browser/browsing_data_remover.h
@@ -9,6 +9,7 @@
#include <set>
#include "base/memory/ref_counted.h"
+#include "base/message_loop_helpers.h"
#include "base/observer_list.h"
#include "base/synchronization/waitable_event_watcher.h"
#include "base/time.h"
@@ -142,7 +143,7 @@ class BrowsingDataRemover : public content::NotificationObserver,
// BrowsingDataRemover deletes itself (using DeleteTask) and is not supposed
// to be deleted by other objects so make destructor private and DeleteTask
// a friend.
- friend class DeleteTask<BrowsingDataRemover>;
+ friend class base::DeleteHelper<BrowsingDataRemover>;
virtual ~BrowsingDataRemover();
// content::NotificationObserver method. Callback when TemplateURLService has
diff --git a/chrome/browser/chromeos/login/screen_locker.h b/chrome/browser/chromeos/login/screen_locker.h
index 3b47a4b..730c95c 100644
--- a/chrome/browser/chromeos/login/screen_locker.h
+++ b/chrome/browser/chromeos/login/screen_locker.h
@@ -8,8 +8,9 @@
#include <string>
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/task.h"
+#include "base/message_loop_helpers.h"
#include "base/time.h"
#include "chrome/browser/chromeos/login/login_status_consumer.h"
#include "chrome/browser/chromeos/login/screen_locker_delegate.h"
@@ -97,7 +98,7 @@ class ScreenLocker : public LoginStatusConsumer {
static test::ScreenLockerTester* GetTester();
private:
- friend class DeleteTask<ScreenLocker>;
+ friend class base::DeleteHelper<ScreenLocker>;
friend class test::ScreenLockerTester;
friend class test::ScreenLockerViewsTester;
friend class test::WebUIScreenLockerTester;
diff --git a/chrome/browser/chromeos/web_socket_proxy.cc b/chrome/browser/chromeos/web_socket_proxy.cc
index bf1aa28..1ab9548 100644
--- a/chrome/browser/chromeos/web_socket_proxy.cc
+++ b/chrome/browser/chromeos/web_socket_proxy.cc
@@ -32,6 +32,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
+#include "base/message_loop_helpers.h"
#include "base/sha1.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
@@ -800,7 +801,7 @@ class SSLChan : public MessageLoopForIO::Watcher {
MessageLoopForIO::FileDescriptorWatcher read_pipe_controller_;
MessageLoopForIO::FileDescriptorWatcher write_pipe_controller_;
- friend class DeleteTask<SSLChan>;
+ friend class base::DeleteHelper<SSLChan>;
DISALLOW_COPY_AND_ASSIGN(SSLChan);
};
diff --git a/chrome/browser/ui/views/browser_actions_container.h b/chrome/browser/ui/views/browser_actions_container.h
index ca47cbb..8a5d0ab 100644
--- a/chrome/browser/ui/views/browser_actions_container.h
+++ b/chrome/browser/ui/views/browser_actions_container.h
@@ -13,6 +13,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
+#include "base/message_loop_helpers.h"
#include "chrome/browser/extensions/extension_context_menu_model.h"
#include "chrome/browser/extensions/extension_toolbar_model.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
@@ -140,7 +141,7 @@ class BrowserActionButton : public views::MenuButton,
content::NotificationRegistrar registrar_;
- friend class DeleteTask<BrowserActionButton>;
+ friend class base::DeleteHelper<BrowserActionButton>;
DISALLOW_COPY_AND_ASSIGN(BrowserActionButton);
};
diff --git a/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.h b/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.h
index b2ad2dd..15cfee3 100644
--- a/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.h
+++ b/chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.h
@@ -11,7 +11,7 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
-#include "base/task.h"
+#include "base/message_loop_helpers.h"
#include "ui/views/controls/menu/menu_delegate.h"
class BrowserActionsContainer;
@@ -111,7 +111,7 @@ class BrowserActionOverflowMenuController : public views::MenuDelegate {
// Whether this controller is being used for drop.
bool for_drop_;
- friend class DeleteTask<BrowserActionOverflowMenuController>;
+ friend class base::DeleteHelper<BrowserActionOverflowMenuController>;
DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController);
};
diff --git a/content/renderer/webplugin_delegate_proxy.h b/content/renderer/webplugin_delegate_proxy.h
index d89fd40..9d76001 100644
--- a/content/renderer/webplugin_delegate_proxy.h
+++ b/content/renderer/webplugin_delegate_proxy.h
@@ -12,6 +12,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/message_loop_helpers.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_message.h"
@@ -132,7 +133,7 @@ class WebPluginDelegateProxy
gfx::PluginWindowHandle GetPluginWindowHandle();
protected:
- template<class WebPluginDelegateProxy> friend class DeleteTask;
+ friend class base::DeleteHelper<WebPluginDelegateProxy>;
virtual ~WebPluginDelegateProxy();
private:
diff --git a/net/url_request/url_request_context_getter.h b/net/url_request/url_request_context_getter.h
index 88421f4..a2475dd 100644
--- a/net/url_request/url_request_context_getter.h
+++ b/net/url_request/url_request_context_getter.h
@@ -7,7 +7,7 @@
#pragma once
#include "base/memory/ref_counted.h"
-#include "base/task.h"
+#include "base/message_loop_helpers.h"
#include "net/base/net_export.h"
namespace base {
@@ -40,7 +40,7 @@ class NET_EXPORT URLRequestContextGetter
protected:
friend class base::RefCountedThreadSafe<URLRequestContextGetter,
URLRequestContextGetterTraits>;
- friend class DeleteTask<const URLRequestContextGetter>;
+ friend class base::DeleteHelper<URLRequestContextGetter>;
friend struct URLRequestContextGetterTraits;
URLRequestContextGetter();
diff --git a/webkit/plugins/npapi/webplugin_delegate_impl.h b/webkit/plugins/npapi/webplugin_delegate_impl.h
index bd83fa72..0a89903 100644
--- a/webkit/plugins/npapi/webplugin_delegate_impl.h
+++ b/webkit/plugins/npapi/webplugin_delegate_impl.h
@@ -10,7 +10,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/task.h"
+#include "base/message_loop_helpers.h"
#include "base/time.h"
#include "base/timer.h"
#include "build/build_config.h"
@@ -231,7 +231,7 @@ class WEBKIT_PLUGINS_EXPORT WebPluginDelegateImpl : public WebPluginDelegate {
#endif
private:
- friend class DeleteTask<WebPluginDelegateImpl>;
+ friend class base::DeleteHelper<WebPluginDelegateImpl>;
friend class WebPluginDelegate;
WebPluginDelegateImpl(gfx::PluginWindowHandle containing_view,
diff --git a/webkit/plugins/ppapi/ppapi_webplugin_impl.h b/webkit/plugins/ppapi/ppapi_webplugin_impl.h
index 40e4178..21e693f 100644
--- a/webkit/plugins/ppapi/ppapi_webplugin_impl.h
+++ b/webkit/plugins/ppapi/ppapi_webplugin_impl.h
@@ -10,7 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "base/task.h"
+#include "base/message_loop_helpers.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
#include "ui/gfx/rect.h"
#include "webkit/plugins/webkit_plugins_export.h"
@@ -35,7 +35,7 @@ class WebPluginImpl : public WebKit::WebPlugin {
const base::WeakPtr<PluginDelegate>& plugin_delegate);
private:
- friend class DeleteTask<WebPluginImpl>;
+ friend class base::DeleteHelper<WebPluginImpl>;
WEBKIT_PLUGINS_EXPORT virtual ~WebPluginImpl();
diff --git a/webkit/plugins/webview_plugin.h b/webkit/plugins/webview_plugin.h
index 0a9b5d9..2915adda 100644
--- a/webkit/plugins/webview_plugin.h
+++ b/webkit/plugins/webview_plugin.h
@@ -8,7 +8,7 @@
#include <list>
#include "base/memory/scoped_ptr.h"
-#include "base/task.h"
+#include "base/message_loop_helpers.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
@@ -142,7 +142,7 @@ class WebViewPlugin: public WebKit::WebPlugin, public WebKit::WebViewClient,
const WebKit::WebURLResponse& response);
private:
- friend class DeleteTask<WebViewPlugin>;
+ friend class base::DeleteHelper<WebViewPlugin>;
virtual ~WebViewPlugin();
Delegate* delegate_;