Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2262)

Unified Diff: base/task.h

Issue 9071001: base::Bind: Remove ScopedRunnableMethodFactory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/offline/offline_load_page.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task.h
diff --git a/base/task.h b/base/task.h
index 3d29d43cd6d6a3d85c84cc0865208b0048e266dd..9666a65c0b5c26df0e406e1a571bcad5c8ba3c3c 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;
« no previous file with comments | « no previous file | chrome/browser/chromeos/offline/offline_load_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698