Skip to content

Commit

Permalink
Add DISABLE_RUNNABLE_METHOD_REFCOUNT to make disabling refcounts in R…
Browse files Browse the repository at this point in the history
…unnableMethods easier.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/2830006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49887 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ajwong@chromium.org committed Jun 16, 2010
1 parent 6c23230 commit c56428f
Show file tree
Hide file tree
Showing 35 changed files with 67 additions and 182 deletions.
7 changes: 1 addition & 6 deletions base/message_pump_glib_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,7 @@ class MessagePumpGLibTest : public testing::Test {
} // namespace

// EventInjector is expected to always live longer than the runnable methods.
// This lets us call NewRunnableMethod on EventInjector instances.
template<>
struct RunnableMethodTraits<EventInjector> {
void RetainCallee(EventInjector* obj) { }
void ReleaseCallee(EventInjector* obj) { }
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(EventInjector);

TEST_F(MessagePumpGLibTest, TestQuit) {
// Checks that Quit works and that the basic infrastructure is working.
Expand Down
27 changes: 27 additions & 0 deletions base/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ class ReleaseTask : public CancelableTask {
// define other lifetime management. For example, if the callee is known to
// live longer than the RunnableMethod object, then a RunnableMethodTraits
// struct could be defined with empty RetainCallee and ReleaseCallee methods.
//
// The DISABLE_RUNNABLE_METHOD_REFCOUNT macro is provided as a convenient way
// for declaring a RunnableMethodTraits that disables refcounting.

template <class T>
struct RunnableMethodTraits {
Expand Down Expand Up @@ -251,6 +254,30 @@ struct RunnableMethodTraits {
#endif
};

// Convenience macro for declaring a RunnableMethodTraits that disables
// refcounting of a class. This is useful if you know that the callee
// will outlive the RunnableMethod object and thus do not need the ref counts.
//
// The invocation of DISABLE_RUNNABLE_METHOD_REFCOUNT should be done at the
// global namespace scope. Example:
//
// namespace foo {
// class Bar {
// ...
// };
// } // namespace foo
//
// DISABLE_RUNNABLE_METHOD_REFCOUNT(foo::Bar)
//
// This is different from DISALLOW_COPY_AND_ASSIGN which is declared inside the
// class.
#define DISABLE_RUNNABLE_METHOD_REFCOUNT(TypeName) \
template <> \
struct RunnableMethodTraits<TypeName> { \
void RetainCallee(TypeName* manager) {} \
void ReleaseCallee(TypeName* manager) {} \
}

// RunnableMethod and RunnableFunction -----------------------------------------
//
// Runnable methods are a type of task that call a function on an object when
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,7 @@ void BrowserProcessImpl::CreateStatusTrayManager() {

// The BrowserProcess object must outlive the file thread so we use traits
// which don't do any management.
template <>
struct RunnableMethodTraits<BrowserProcessImpl> {
void RetainCallee(BrowserProcessImpl* process) {}
void ReleaseCallee(BrowserProcessImpl* process) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);

void BrowserProcessImpl::CheckForInspectorFiles() {
file_thread()->message_loop()->PostTask
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/browsing_data_remover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@

// Done so that we can use PostTask on BrowsingDataRemovers and not have
// BrowsingDataRemover implement RefCounted.
template <>
struct RunnableMethodTraits<BrowsingDataRemover> {
void RetainCallee(BrowsingDataRemover* remover) {}
void ReleaseCallee(BrowsingDataRemover* remover) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowsingDataRemover);

bool BrowsingDataRemover::removing_ = false;

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/chrome_plugin_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,7 @@ class ModelessHtmlDialogDelegate : public HtmlDialogUIDelegate {

// Allows InvokeLater without adding refcounting. The object is only deleted
// when its last InvokeLater is run anyway.
template <>
struct RunnableMethodTraits<ModelessHtmlDialogDelegate> {
void RetainCallee(ModelessHtmlDialogDelegate* delegate) {}
void ReleaseCallee(ModelessHtmlDialogDelegate* delegate) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(ModelessHtmlDialogDelegate);

namespace {

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/chromeos/cros/language_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@

// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
struct RunnableMethodTraits<chromeos::LanguageLibraryImpl> {
void RetainCallee(chromeos::LanguageLibraryImpl* obj) {}
void ReleaseCallee(chromeos::LanguageLibraryImpl* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::LanguageLibraryImpl);

namespace {

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/chromeos/cros/mount_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
struct RunnableMethodTraits<chromeos::MountLibraryImpl> {
void RetainCallee(chromeos::MountLibraryImpl* obj) {}
void ReleaseCallee(chromeos::MountLibraryImpl* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);

namespace chromeos {

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/chromeos/cros/network_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@

// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
struct RunnableMethodTraits<chromeos::NetworkLibraryImpl> {
void RetainCallee(chromeos::NetworkLibraryImpl* obj) {}
void ReleaseCallee(chromeos::NetworkLibraryImpl* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl);

namespace chromeos {

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/chromeos/cros/power_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
struct RunnableMethodTraits<chromeos::PowerLibraryImpl> {
void RetainCallee(chromeos::PowerLibraryImpl* obj) {}
void ReleaseCallee(chromeos::PowerLibraryImpl* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::PowerLibraryImpl);

namespace chromeos {

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/chromeos/cros/screen_lock_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
struct RunnableMethodTraits<chromeos::ScreenLockLibraryImpl> {
void RetainCallee(chromeos::ScreenLockLibraryImpl* obj) {}
void ReleaseCallee(chromeos::ScreenLockLibraryImpl* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ScreenLockLibraryImpl);

namespace chromeos {

Expand Down
5 changes: 1 addition & 4 deletions chrome/browser/crash_handler_host_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
// Since classes derived from CrashHandlerHostLinux are singletons, it's only
// destroyed at the end of the processes lifetime, which is greater in span than
// the lifetime of the IO message loop.
template<> struct RunnableMethodTraits<CrashHandlerHostLinux> {
void RetainCallee(CrashHandlerHostLinux*) { }
void ReleaseCallee(CrashHandlerHostLinux*) { }
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(CrashHandlerHostLinux);

CrashHandlerHostLinux::CrashHandlerHostLinux()
: process_socket_(-1),
Expand Down
5 changes: 1 addition & 4 deletions chrome/browser/dom_ui/chrome_url_data_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ class ChromeURLDataManager {

// Since we have a single global ChromeURLDataManager, we don't need to
// grab a reference to it when creating Tasks involving it.
template <> struct RunnableMethodTraits<ChromeURLDataManager> {
void RetainCallee(ChromeURLDataManager* manager) {}
void ReleaseCallee(ChromeURLDataManager* manager) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeURLDataManager);

// Register our special URL handler under our special URL scheme.
// Must be done once at startup.
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/dom_ui/mediaplayer_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,7 @@ void MediaplayerHandler::HandleTogglePlaylist(const Value* value) {

// Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run.
template <>
struct RunnableMethodTraits<MediaPlayer> {
void RetainCallee(MediaPlayer* obj) {}
void ReleaseCallee(MediaPlayer* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(MediaPlayer);

void MediaPlayer::EnqueueMediaURL(const GURL& url, Browser* creator) {
if (handler_ == NULL) {
Expand Down
5 changes: 1 addition & 4 deletions chrome/browser/extensions/extension_error_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
// No AddRef required when using ExtensionErrorReporter with RunnableMethod.
// This is okay since the ExtensionErrorReporter is a singleton that lives until
// the end of the process.
template <> struct RunnableMethodTraits<ExtensionErrorReporter> {
void RetainCallee(ExtensionErrorReporter*) {}
void ReleaseCallee(ExtensionErrorReporter*) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(ExtensionErrorReporter);

ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL;

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/gears_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ class CreateShortcutCommand : public CPCommandInterface {

// Allows InvokeLater without adding refcounting. The object is only deleted
// when its last InvokeLater is run anyway.
template <>
struct RunnableMethodTraits<CreateShortcutCommand> {
void RetainCallee(CreateShortcutCommand* command) {}
void ReleaseCallee(CreateShortcutCommand* command) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(CreateShortcutCommand);

void GearsCreateShortcut(
const webkit_glue::WebApplicationInfo& app_info,
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/history/history_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ class HistoryTest;
// Specialize RunnableMethodTraits for HistoryTest so we can create callbacks.
// None of these callbacks can outlast the test, so there is not need to retain
// the HistoryTest object.
template <>
struct RunnableMethodTraits<history::HistoryTest> {
void RetainCallee(history::HistoryTest* obj) { }
void ReleaseCallee(history::HistoryTest* obj) { }
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(history::HistoryTest);

namespace history {

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ net::HostResolver* CreateGlobalHostResolver(

// The IOThread object must outlive any tasks posted to the IO thread before the
// Quit task.
template <>
struct RunnableMethodTraits<IOThread> {
void RetainCallee(IOThread* /* io_thread */) {}
void ReleaseCallee(IOThread* /* io_thread */) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread);

IOThread::IOThread()
: BrowserProcessSubThread(ChromeThread::IO),
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/sync/engine/syncapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ static const int kThreadExitTimeoutMsec = 60000;
static const int kSSLPort = 443;

// We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves.
template <>
struct RunnableMethodTraits<sync_api::SyncManager::SyncInternal> {
void RetainCallee(sync_api::SyncManager::SyncInternal*) {}
void ReleaseCallee(sync_api::SyncManager::SyncInternal*) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal);

namespace sync_api {

Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/web_applications/web_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,7 @@ void UpdateShortcutWorker::DeleteMeOnUIThread() {
#if defined(OS_WIN)
// Allows UpdateShortcutWorker without adding refcounting. UpdateShortcutWorker
// manages its own life time and will delete itself when it's done.
template <>
struct RunnableMethodTraits<UpdateShortcutWorker> {
void RetainCallee(UpdateShortcutWorker* worker) {}
void ReleaseCallee(UpdateShortcutWorker* worker) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(UpdateShortcutWorker);
#endif // defined(OS_WIN)

namespace web_app {
Expand Down
8 changes: 2 additions & 6 deletions chrome/common/net/fake_network_change_notifier_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@

// We manage the lifetime of
// chrome_common_net::FakeNetworkChangeNotifierThread ourselves.
template <>
struct RunnableMethodTraits<chrome_common_net::
FakeNetworkChangeNotifierThread> {
void RetainCallee(chrome_common_net::FakeNetworkChangeNotifierThread*) {}
void ReleaseCallee(chrome_common_net::FakeNetworkChangeNotifierThread*) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(
chrome_common_net::FakeNetworkChangeNotifierThread);

namespace chrome_common_net {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class FlagToggler;
} // namespace chrome_common_net

// We manage the lifetime of chrome_common_net::FlagToggler ourselves.
template <>
struct RunnableMethodTraits<chrome_common_net::FlagToggler> {
void RetainCallee(chrome_common_net::FlagToggler*) {}
void ReleaseCallee(chrome_common_net::FlagToggler*) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_common_net::FlagToggler);

namespace chrome_common_net {

Expand Down
6 changes: 1 addition & 5 deletions chrome/common/net/notifier/listener/mediator_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
#include "talk/xmpp/xmppclientsettings.h"

// We manage the lifetime of notifier::MediatorThreadImpl ourselves.
template <>
struct RunnableMethodTraits<notifier::MediatorThreadImpl> {
void RetainCallee(notifier::MediatorThreadImpl*) {}
void ReleaseCallee(notifier::MediatorThreadImpl*) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(notifier::MediatorThreadImpl);

namespace notifier {

Expand Down
6 changes: 1 addition & 5 deletions chrome/common/net/thread_blocker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@

// Since a ThreadBlocker is outlived by its target thread, we don't
// have to ref-count it.
template <>
struct RunnableMethodTraits<chrome_common_net::ThreadBlocker> {
void RetainCallee(chrome_common_net::ThreadBlocker*) {}
void ReleaseCallee(chrome_common_net::ThreadBlocker*) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_common_net::ThreadBlocker);

namespace chrome_common_net {

Expand Down
6 changes: 1 addition & 5 deletions chrome/common/net/thread_blocker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ class Flag;
}; // namespace chrome_common_net

// We manage the lifetime of chrome_common_net::Flag ourselves.
template <>
struct RunnableMethodTraits<chrome_common_net::Flag> {
void RetainCallee(chrome_common_net::Flag*) {}
void ReleaseCallee(chrome_common_net::Flag*) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_common_net::Flag);

namespace chrome_common_net {

Expand Down
5 changes: 1 addition & 4 deletions chrome_frame/chrome_frame_automation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,7 @@ ProxyFactory::ProxyCacheEntry::ProxyCacheEntry(const std::wstring& profile)
thread->Start();
}

template <> struct RunnableMethodTraits<ProxyFactory> {
void RetainCallee(ProxyFactory* obj) {}
void ReleaseCallee(ProxyFactory* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(ProxyFactory);

ProxyFactory::ProxyFactory()
: uma_send_interval_(0) {
Expand Down
7 changes: 2 additions & 5 deletions chrome_frame/chrome_frame_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ class ChromeFrameDelegate {
virtual ~ChromeFrameDelegate() {}
};

// Template specialization
template <> struct RunnableMethodTraits<ChromeFrameDelegate> {
void RetainCallee(ChromeFrameDelegate* obj) {}
void ReleaseCallee(ChromeFrameDelegate* obj) {}
};
// Disable refcounting of ChromeFrameDelegate.
DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeFrameDelegate);

extern UINT kAutomationServerReady;
extern UINT kMessageFromChromeFrame;
Expand Down
17 changes: 3 additions & 14 deletions chrome_frame/test/automation_client_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,9 @@ using testing::_;
using testing::CreateFunctor;
using testing::Return;

template <> struct RunnableMethodTraits<ProxyFactory::LaunchDelegate> {
void RetainCallee(ProxyFactory::LaunchDelegate* obj) {}
void ReleaseCallee(ProxyFactory::LaunchDelegate* obj) {}
};

template <> struct RunnableMethodTraits<ChromeFrameAutomationClient> {
void RetainCallee(ChromeFrameAutomationClient* obj) {}
void ReleaseCallee(ChromeFrameAutomationClient* obj) {}
};

template <> struct RunnableMethodTraits<chrome_frame_test::TimedMsgLoop> {
void RetainCallee(chrome_frame_test::TimedMsgLoop* obj) {}
void ReleaseCallee(chrome_frame_test::TimedMsgLoop* obj) {}
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(ProxyFactory::LaunchDelegate);
DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeFrameAutomationClient);
DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_frame_test::TimedMsgLoop);

void MockProxyFactory::GetServerImpl(ChromeFrameAutomationProxy* pxy,
void* proxy_id,
Expand Down
Loading

0 comments on commit c56428f

Please sign in to comment.