summaryrefslogtreecommitdiffstats
path: root/base/task.h
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-03 21:17:36 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-03 21:17:36 +0000
commitd3d6325dc3ae6f65cb8a5e8667b507938fcab332 (patch)
tree86ccde60258b15af95c01c9b488c8d03c06f0189 /base/task.h
parent92afac9f6a33689d471356eee7bef731c84d27c7 (diff)
downloadchromium_src-d3d6325dc3ae6f65cb8a5e8667b507938fcab332.zip
chromium_src-d3d6325dc3ae6f65cb8a5e8667b507938fcab332.tar.gz
chromium_src-d3d6325dc3ae6f65cb8a5e8667b507938fcab332.tar.bz2
base::Bind: Remove ScopedRunnableMethodFactory.
BUG=none TEST=none R=groby,awong,csilv Review URL: http://codereview.chromium.org/9071001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116198 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/task.h')
-rw-r--r--base/task.h144
1 files changed, 1 insertions, 143 deletions
diff --git a/base/task.h b/base/task.h
index 3d29d43..9666a65 100644
--- a/base/task.h
+++ b/base/task.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -65,148 +65,6 @@ class BASE_EXPORT CancelableTask : public Task {
virtual void Cancel() = 0;
};
-// Scoped Factories ------------------------------------------------------------
-//
-// These scoped factory objects can be used by non-refcounted objects to safely
-// place tasks in a message loop. Each factory guarantees that the tasks it
-// produces will not run after the factory is destroyed. Commonly, factories
-// are declared as class members, so the class' tasks will automatically cancel
-// when the class instance is destroyed.
-//
-// Exampe Usage:
-//
-// class MyClass {
-// private:
-// // This factory will be used to schedule invocations of SomeMethod.
-// ScopedRunnableMethodFactory<MyClass> some_method_factory_;
-//
-// public:
-// // It is safe to suppress warning 4355 here.
-// MyClass() : ALLOW_THIS_IN_INITIALIZER_LIST(some_method_factory_(this)) { }
-//
-// void SomeMethod() {
-// // If this function might be called directly, you might want to revoke
-// // any outstanding runnable methods scheduled to call it. If it's not
-// // referenced other than by the factory, this is unnecessary.
-// some_method_factory_.RevokeAll();
-// ...
-// }
-//
-// void ScheduleSomeMethod() {
-// // If you'd like to only only have one pending task at a time, test for
-// // |empty| before manufacturing another task.
-// if (!some_method_factory_.empty())
-// return;
-//
-// // The factories are not thread safe, so always invoke on
-// // |MessageLoop::current()|.
-// MessageLoop::current()->PostDelayedTask(
-// FROM_HERE,
-// some_method_factory_.NewRunnableMethod(&MyClass::SomeMethod),
-// kSomeMethodDelayMS);
-// }
-// };
-
-// A ScopedRunnableMethodFactory creates runnable methods for a specified
-// object. This is particularly useful for generating callbacks for
-// non-reference counted objects when the factory is a member of the object.
-template<class T>
-class ScopedRunnableMethodFactory {
- public:
- explicit ScopedRunnableMethodFactory(T* object) : weak_factory_(object) {
- }
-
- template <class Method>
- inline CancelableTask* NewRunnableMethod(Method method) {
- return new RunnableMethod<Method, Tuple0>(
- weak_factory_.GetWeakPtr(), method, MakeTuple());
- }
-
- template <class Method, class A>
- inline CancelableTask* NewRunnableMethod(Method method, const A& a) {
- return new RunnableMethod<Method, Tuple1<A> >(
- weak_factory_.GetWeakPtr(), method, MakeTuple(a));
- }
-
- template <class Method, class A, class B>
- inline CancelableTask* NewRunnableMethod(Method method, const A& a,
- const B& b) {
- return new RunnableMethod<Method, Tuple2<A, B> >(
- weak_factory_.GetWeakPtr(), method, MakeTuple(a, b));
- }
-
- template <class Method, class A, class B, class C>
- inline CancelableTask* NewRunnableMethod(Method method,
- const A& a,
- const B& b,
- const C& c) {
- return new RunnableMethod<Method, Tuple3<A, B, C> >(
- weak_factory_.GetWeakPtr(), method, MakeTuple(a, b, c));
- }
-
- template <class Method, class A, class B, class C, class D>
- inline CancelableTask* NewRunnableMethod(Method method,
- const A& a,
- const B& b,
- const C& c,
- const D& d) {
- return new RunnableMethod<Method, Tuple4<A, B, C, D> >(
- weak_factory_.GetWeakPtr(), method, MakeTuple(a, b, c, d));
- }
-
- template <class Method, class A, class B, class C, class D, class E>
- inline CancelableTask* NewRunnableMethod(Method method,
- const A& a,
- const B& b,
- const C& c,
- const D& d,
- const E& e) {
- return new RunnableMethod<Method, Tuple5<A, B, C, D, E> >(
- weak_factory_.GetWeakPtr(), method, MakeTuple(a, b, c, d, e));
- }
-
- void RevokeAll() { weak_factory_.InvalidateWeakPtrs(); }
-
- bool empty() const { return !weak_factory_.HasWeakPtrs(); }
-
- protected:
- template <class Method, class Params>
- class RunnableMethod : public CancelableTask {
- public:
- RunnableMethod(const base::WeakPtr<T>& obj,
- Method meth,
- const Params& params)
- : obj_(obj),
- meth_(meth),
- params_(params) {
- COMPILE_ASSERT(
- (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value),
- badscopedrunnablemethodparams);
- }
-
- virtual void Run() {
- if (obj_)
- DispatchToMethod(obj_.get(), meth_, params_);
- }
-
- virtual void Cancel() {
- obj_.reset();
- }
-
- private:
- base::WeakPtr<T> obj_;
- Method meth_;
- Params params_;
-
- DISALLOW_COPY_AND_ASSIGN(RunnableMethod);
- };
-
- private:
- base::WeakPtrFactory<T> weak_factory_;
-};
-
-// Delete helper for use with base::Bind(). If you're posting a task to delete
-// an object, prefer DeleteSoon().
template<typename T>
void DeletePointer(T* obj) {
delete obj;