summaryrefslogtreecommitdiffstats
path: root/base/message_loop_proxy.h
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 03:31:34 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 03:31:34 +0000
commit2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd (patch)
tree9bae18a794cacca3aa2164deca4e6460815f20b9 /base/message_loop_proxy.h
parentad3d7273dff93e5107a947c05c6a47c35ea7eea7 (diff)
downloadchromium_src-2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd.zip
chromium_src-2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd.tar.gz
chromium_src-2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd.tar.bz2
Created a MessageLoopProxy interface. This provides a thread-safe refcounted interface to the Post* methods
of a message loop. This class can outlive the target message loop. Changed ChromeThread to vend an implementation of this proxy. BUG=None TEST=ChromeThread unit-tests modified. Review URL: http://codereview.chromium.org/1800008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop_proxy.h')
-rw-r--r--base/message_loop_proxy.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/base/message_loop_proxy.h b/base/message_loop_proxy.h
new file mode 100644
index 0000000..0cfe7ee
--- /dev/null
+++ b/base/message_loop_proxy.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2010 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_PROXY_H_
+#define BASE_MESSAGE_LOOP_PROXY_H_
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/task.h"
+
+// This class provides a thread-safe refcounted interface to the Post* methods
+// of a message loop. This class can outlive the target message loop.
+class MessageLoopProxy : public base::RefCountedThreadSafe<MessageLoopProxy> {
+ public:
+ // These are the same methods in message_loop.h, but are guaranteed to either
+ // get posted to the MessageLoop if it's still alive, or be deleted otherwise.
+ // They return true iff the thread existed and the task was posted. Note that
+ // even if the task is posted, there's no guarantee that it will run, since
+ // the target thread may already have a Quit message in its queue.
+ virtual bool PostTask(const tracked_objects::Location& from_here,
+ Task* task) = 0;
+ virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
+ Task* task, int64 delay_ms) = 0;
+ virtual bool PostNonNestableTask(const tracked_objects::Location& from_here,
+ Task* task) = 0;
+ virtual bool PostNonNestableDelayedTask(
+ const tracked_objects::Location& from_here,
+ Task* task,
+ int64 delay_ms) = 0;
+
+ template <class T>
+ bool DeleteSoon(const tracked_objects::Location& from_here,
+ T* object) {
+ return PostNonNestableTask(from_here, new DeleteTask<T>(object));
+ }
+ template <class T>
+ bool ReleaseSoon(const tracked_objects::Location& from_here,
+ T* object) {
+ return PostNonNestableTask(from_here, new ReleaseTask<T>(object));
+ }
+};
+
+#endif // BASE_MESSAGE_LOOP_PROXY_H_
+