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

Side by Side Diff: base/task.h

Issue 8960011: base::Bind: Remove NewRunnableFunction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Lame TODO. Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/message_pump_glib_unittest.cc ('k') | content/browser/browser_main_loop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // ============================================================================ 5 // ============================================================================
6 // **************************************************************************** 6 // ****************************************************************************
7 // * THIS HEADER IS DEPRECATED, SEE base/callback.h FOR NEW IMPLEMENTATION * 7 // * THIS HEADER IS DEPRECATED, SEE base/callback.h FOR NEW IMPLEMENTATION *
8 // **************************************************************************** 8 // ****************************************************************************
9 // ============================================================================ 9 // ============================================================================
10 // ============================================================================ 10 // ============================================================================
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // 297 //
298 // This is different from DISALLOW_COPY_AND_ASSIGN which is declared inside the 298 // This is different from DISALLOW_COPY_AND_ASSIGN which is declared inside the
299 // class. 299 // class.
300 #define DISABLE_RUNNABLE_METHOD_REFCOUNT(TypeName) \ 300 #define DISABLE_RUNNABLE_METHOD_REFCOUNT(TypeName) \
301 template <> \ 301 template <> \
302 struct RunnableMethodTraits<TypeName> { \ 302 struct RunnableMethodTraits<TypeName> { \
303 void RetainCallee(TypeName* manager) {} \ 303 void RetainCallee(TypeName* manager) {} \
304 void ReleaseCallee(TypeName* manager) {} \ 304 void ReleaseCallee(TypeName* manager) {} \
305 } 305 }
306 306
307 // RunnableMethod and RunnableFunction ----------------------------------------- 307 // RunnableMethod --------------------------------------------------------------
308 // 308 //
309 // Runnable methods are a type of task that call a function on an object when 309 // Runnable methods are a type of task that call a function on an object when
310 // they are run. We implement both an object and a set of NewRunnableMethod and 310 // they are run. We implement both an object and a set of NewRunnableMethod
311 // NewRunnableFunction functions for convenience. These functions are 311 // functions for convenience. These functions are overloaded and will infer the
312 // overloaded and will infer the template types, simplifying calling code. 312 // template types, simplifying calling code.
313 // 313 //
314 // The template definitions all use the following names: 314 // The template definitions all use the following names:
315 // T - the class type of the object you're supplying 315 // T - the class type of the object you're supplying
316 // this is not needed for the Static version of the call 316 // this is not needed for the Static version of the call
317 // Method/Function - the signature of a pointer to the method or function you 317 // Method/Function - the signature of a pointer to the method or function you
318 // want to call 318 // want to call
319 // Param - the parameter(s) to the method, possibly packed as a Tuple 319 // Param - the parameter(s) to the method, possibly packed as a Tuple
320 // A - the first parameter (if any) to the method 320 // A - the first parameter (if any) to the method
321 // B - the second parameter (if any) to the method 321 // B - the second parameter (if any) to the method
322 // 322 //
323 // Put these all together and you get an object that can call a method whose 323 // Put these all together and you get an object that can call a method whose
324 // signature is: 324 // signature is:
325 // R T::MyFunction([A[, B]]) 325 // R T::MyFunction([A[, B]])
326 // 326 //
327 // Usage: 327 // Usage:
328 // PostTask(FROM_HERE, NewRunnableMethod(object, &Object::method[, a[, b]]) 328 // PostTask(FROM_HERE, NewRunnableMethod(object, &Object::method[, a[, b]])
329 // PostTask(FROM_HERE, NewRunnableFunction(&function[, a[, b]])
330 329
331 // RunnableMethod and NewRunnableMethod implementation ------------------------- 330 // RunnableMethod and NewRunnableMethod implementation -------------------------
332 331
333 template <class T, class Method, class Params> 332 template <class T, class Method, class Params>
334 class RunnableMethod : public CancelableTask { 333 class RunnableMethod : public CancelableTask {
335 public: 334 public:
336 RunnableMethod(T* obj, Method meth, const Params& params) 335 RunnableMethod(T* obj, Method meth, const Params& params)
337 : obj_(obj), meth_(meth), params_(params) { 336 : obj_(obj), meth_(meth), params_(params) {
338 traits_.RetainCallee(obj_); 337 traits_.RetainCallee(obj_);
339 COMPILE_ASSERT( 338 COMPILE_ASSERT(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 const F& f, const G& g, const H& h) { 450 const F& f, const G& g, const H& h) {
452 return new RunnableMethod<T, 451 return new RunnableMethod<T,
453 Method, 452 Method,
454 Tuple8<A, B, C, D, E, F, G, H> >(object, 453 Tuple8<A, B, C, D, E, F, G, H> >(object,
455 method, 454 method,
456 MakeTuple(a, b, c, 455 MakeTuple(a, b, c,
457 d, e, f, 456 d, e, f,
458 g, h)); 457 g, h));
459 } 458 }
460 459
461 // RunnableFunction and NewRunnableFunction implementation ---------------------
462
463 template <class Function, class Params>
464 class RunnableFunction : public Task {
465 public:
466 RunnableFunction(Function function, const Params& params)
467 : function_(function), params_(params) {
468 COMPILE_ASSERT(
469 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value),
470 badrunnablefunctionparams);
471 }
472
473 ~RunnableFunction() {
474 function_ = reinterpret_cast<Function>(base::kDeadTask);
475 }
476
477 virtual void Run() {
478 if (function_)
479 DispatchToFunction(function_, params_);
480 }
481
482 private:
483 Function function_;
484 Params params_;
485 };
486
487 template <class Function>
488 inline Task* NewRunnableFunction(Function function) {
489 return new RunnableFunction<Function, Tuple0>(function, MakeTuple());
490 }
491
492 template <class Function, class A>
493 inline Task* NewRunnableFunction(Function function, const A& a) {
494 return new RunnableFunction<Function, Tuple1<A> >(function, MakeTuple(a));
495 }
496
497 template <class Function, class A, class B>
498 inline Task* NewRunnableFunction(Function function, const A& a, const B& b) {
499 return new RunnableFunction<Function, Tuple2<A, B> >(function,
500 MakeTuple(a, b));
501 }
502
503 template <class Function, class A, class B, class C>
504 inline Task* NewRunnableFunction(Function function, const A& a, const B& b,
505 const C& c) {
506 return new RunnableFunction<Function, Tuple3<A, B, C> >(function,
507 MakeTuple(a, b, c));
508 }
509
510 template <class Function, class A, class B, class C, class D>
511 inline Task* NewRunnableFunction(Function function, const A& a, const B& b,
512 const C& c, const D& d) {
513 return new RunnableFunction<Function, Tuple4<A, B, C, D> >(function,
514 MakeTuple(a, b,
515 c, d));
516 }
517
518 template <class Function, class A, class B, class C, class D, class E>
519 inline Task* NewRunnableFunction(Function function, const A& a, const B& b,
520 const C& c, const D& d, const E& e) {
521 return new RunnableFunction<Function, Tuple5<A, B, C, D, E> >(function,
522 MakeTuple(a, b,
523 c, d,
524 e));
525 }
526
527 template <class Function, class A, class B, class C, class D, class E,
528 class F>
529 inline Task* NewRunnableFunction(Function function, const A& a, const B& b,
530 const C& c, const D& d, const E& e,
531 const F& f) {
532 return new RunnableFunction<Function, Tuple6<A, B, C, D, E, F> >(function,
533 MakeTuple(a, b, c, d, e, f));
534 }
535
536 template <class Function, class A, class B, class C, class D, class E,
537 class F, class G>
538 inline Task* NewRunnableFunction(Function function, const A& a, const B& b,
539 const C& c, const D& d, const E& e, const F& f,
540 const G& g) {
541 return new RunnableFunction<Function, Tuple7<A, B, C, D, E, F, G> >(function,
542 MakeTuple(a, b, c, d, e, f, g));
543 }
544
545 template <class Function, class A, class B, class C, class D, class E,
546 class F, class G, class H>
547 inline Task* NewRunnableFunction(Function function, const A& a, const B& b,
548 const C& c, const D& d, const E& e, const F& f,
549 const G& g, const H& h) {
550 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >(
551 function, MakeTuple(a, b, c, d, e, f, g, h));
552 }
553
554 namespace base { 460 namespace base {
555 461
556 // ScopedTaskRunner is akin to scoped_ptr for Tasks. It ensures that the Task 462 // ScopedTaskRunner is akin to scoped_ptr for Tasks. It ensures that the Task
557 // is executed and deleted no matter how the current scope exits. 463 // is executed and deleted no matter how the current scope exits.
558 class BASE_EXPORT ScopedTaskRunner { 464 class BASE_EXPORT ScopedTaskRunner {
559 public: 465 public:
560 // Takes ownership of the task. 466 // Takes ownership of the task.
561 explicit ScopedTaskRunner(Task* task); 467 explicit ScopedTaskRunner(Task* task);
562 ~ScopedTaskRunner(); 468 ~ScopedTaskRunner();
563 469
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 Task* task_; 522 Task* task_;
617 bool* should_leak_task_; 523 bool* should_leak_task_;
618 static bool kTaskLeakingDefault; 524 static bool kTaskLeakingDefault;
619 }; 525 };
620 526
621 } // namespace subtle 527 } // namespace subtle
622 528
623 } // namespace base 529 } // namespace base
624 530
625 #endif // BASE_TASK_H_ 531 #endif // BASE_TASK_H_
OLDNEW
« no previous file with comments | « base/message_pump_glib_unittest.cc ('k') | content/browser/browser_main_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698