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

Side by Side Diff: base/task.h

Issue 7210053: Implementation of PostTaskAndReply() in MessageLoopProxy and BrowserThread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unittests Created 9 years, 4 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
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 #ifndef BASE_TASK_H_ 5 #ifndef BASE_TASK_H_
6 #define BASE_TASK_H_ 6 #define BASE_TASK_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/base_export.h" 9 #include "base/base_export.h"
10 #include "base/callback.h"
10 #include "base/debug/alias.h" 11 #include "base/debug/alias.h"
11 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" 12 #include "base/memory/raw_scoped_refptr_mismatch_checker.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/tracked.h" 14 #include "base/tracked.h"
14 #include "base/tuple.h" 15 #include "base/tuple.h"
15 16
16 namespace base { 17 namespace base {
17 const size_t kDeadTask = 0xDEAD7A53; 18 const size_t kDeadTask = 0xDEAD7A53;
19 class MessageLoopProxy;
18 } 20 }
19 21
20 // Task ------------------------------------------------------------------------ 22 // Task ------------------------------------------------------------------------
21 // 23 //
22 // A task is a generic runnable thingy, usually used for running code on a 24 // A task is a generic runnable thingy, usually used for running code on a
23 // different thread or for scheduling future tasks off of the message loop. 25 // different thread or for scheduling future tasks off of the message loop.
24 26
25 class BASE_EXPORT Task : public tracked_objects::Tracked { 27 class BASE_EXPORT Task : public tracked_objects::Tracked {
26 public: 28 public:
27 Task(); 29 Task();
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 597
596 ~TaskClosureAdapter(); 598 ~TaskClosureAdapter();
597 599
598 Task* task_; 600 Task* task_;
599 bool* should_leak_task_; 601 bool* should_leak_task_;
600 static bool kTaskLeakingDefault; 602 static bool kTaskLeakingDefault;
601 }; 603 };
602 604
603 } // namespace subtle 605 } // namespace subtle
604 606
607 namespace internal {
608
609 // This relay class remembers the MessageLoop that it was created on, and
610 // ensures that both the |task| and |reply| Closures are deleted on this same
611 // thread. Also, |task| is guaranteed to be deleted before |reply| is run or
612 // deleted.
613 //
614 // If this is not possible because the originating MessageLoop is no longer
615 // available, the the |task| and |reply| Closures are leaked. Leaking is
616 // considered preferable to having a thread-safetey violations caused by
617 // invoking the Closure destructor on the wrong thread.
618 class PostTaskAndReplyRelay {
619 public:
620 PostTaskAndReplyRelay(const tracked_objects::Location& from_here,
621 const Closure& task, const Closure& reply);
622
623 ~PostTaskAndReplyRelay();
624
625 void Run();
626
627 private:
628 void RunReplyAndSelfDestruct();
629
630 tracked_objects::Location from_here_;
631 scoped_refptr<MessageLoopProxy> origin_loop_;
632 Closure reply_;
633 Closure task_;
634 };
635
636 } // namespace internal
637
605 } // namespace base 638 } // namespace base
606 639
607 #endif // BASE_TASK_H_ 640 #endif // BASE_TASK_H_
OLDNEW
« no previous file with comments | « base/message_loop_proxy.cc ('k') | base/task.cc » ('j') | base/task_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698