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

Side by Side Diff: cc/base/blocking_task_runner.cc

Issue 1533773002: Delete CC. (Closed) Base URL: git@github.com:domokit/mojo.git@cl-2e
Patch Set: rebase Created 5 years 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
« no previous file with comments | « cc/base/blocking_task_runner.h ('k') | cc/base/completion_event.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/base/blocking_task_runner.h"
6
7 #include <utility>
8
9 #include "base/callback.h"
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop_proxy.h"
12
13 namespace cc {
14
15 // static
16 scoped_ptr<BlockingTaskRunner> BlockingTaskRunner::Create(
17 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
18 return make_scoped_ptr(new BlockingTaskRunner(task_runner));
19 }
20
21 BlockingTaskRunner::BlockingTaskRunner(
22 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
23 : thread_id_(base::PlatformThread::CurrentId()),
24 task_runner_(task_runner),
25 capture_(0) {
26 }
27
28 BlockingTaskRunner::~BlockingTaskRunner() {
29 }
30
31 bool BlockingTaskRunner::BelongsToCurrentThread() {
32 return base::PlatformThread::CurrentId() == thread_id_;
33 }
34
35 bool BlockingTaskRunner::PostTask(const tracked_objects::Location& from_here,
36 const base::Closure& task) {
37 base::AutoLock lock(lock_);
38 DCHECK(task_runner_.get() || capture_);
39 if (!capture_)
40 return task_runner_->PostTask(from_here, task);
41 captured_tasks_.push_back(task);
42 return true;
43 }
44
45 void BlockingTaskRunner::SetCapture(bool capture) {
46 DCHECK(BelongsToCurrentThread());
47
48 std::vector<base::Closure> tasks;
49
50 {
51 base::AutoLock lock(lock_);
52 capture_ += capture ? 1 : -1;
53 DCHECK_GE(capture_, 0);
54
55 if (capture_)
56 return;
57
58 // We're done capturing, so grab all the captured tasks and run them.
59 tasks.swap(captured_tasks_);
60 }
61 for (size_t i = 0; i < tasks.size(); ++i)
62 tasks[i].Run();
63 }
64
65 BlockingTaskRunner::CapturePostTasks::CapturePostTasks(
66 BlockingTaskRunner* blocking_runner)
67 : blocking_runner_(blocking_runner) {
68 blocking_runner_->SetCapture(true);
69 }
70
71 BlockingTaskRunner::CapturePostTasks::~CapturePostTasks() {
72 blocking_runner_->SetCapture(false);
73 }
74
75 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/blocking_task_runner.h ('k') | cc/base/completion_event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698