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

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

Issue 485043003: cc: Use correct message loop proxy in BlockingTaskRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits. Created 6 years, 3 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 | « cc/trees/blocking_task_runner.h ('k') | cc/trees/blocking_task_runner_unittest.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 2013 The Chromium Authors. All rights reserved. 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 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 #include "cc/trees/blocking_task_runner.h" 5 #include "cc/trees/blocking_task_runner.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/memory/singleton.h"
11 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 12
13 namespace cc { 13 namespace cc {
14 14
15 struct TaskRunnerPairs {
16 static TaskRunnerPairs* GetInstance() {
17 return Singleton<TaskRunnerPairs>::get();
18 }
19
20 base::Lock lock;
21 std::vector<scoped_refptr<BlockingTaskRunner> > runners;
22
23 private:
24 friend struct DefaultSingletonTraits<TaskRunnerPairs>;
25 };
26
27 // static 15 // static
28 scoped_refptr<BlockingTaskRunner> BlockingTaskRunner::current() { 16 scoped_ptr<BlockingTaskRunner> BlockingTaskRunner::Create(
29 TaskRunnerPairs* task_runners = TaskRunnerPairs::GetInstance(); 17 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
30 base::PlatformThreadId thread_id = base::PlatformThread::CurrentId(); 18 return make_scoped_ptr(new BlockingTaskRunner(task_runner));
31
32 base::AutoLock lock(task_runners->lock);
33
34 scoped_refptr<BlockingTaskRunner> current_task_runner;
35
36 for (size_t i = 0; i < task_runners->runners.size(); ++i) {
37 if (task_runners->runners[i]->thread_id_ == thread_id) {
38 current_task_runner = task_runners->runners[i];
39 } else if (task_runners->runners[i]->HasOneRef()) {
40 task_runners->runners.erase(task_runners->runners.begin() + i);
41 i--;
42 }
43 }
44
45 if (current_task_runner.get())
46 return current_task_runner;
47
48 scoped_refptr<BlockingTaskRunner> runner =
49 new BlockingTaskRunner(base::MessageLoopProxy::current());
50 task_runners->runners.push_back(runner);
51 return runner;
52 } 19 }
53 20
54 BlockingTaskRunner::BlockingTaskRunner( 21 BlockingTaskRunner::BlockingTaskRunner(
55 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 22 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
56 : thread_id_(base::PlatformThread::CurrentId()), 23 : thread_id_(base::PlatformThread::CurrentId()),
57 task_runner_(task_runner), 24 task_runner_(task_runner),
58 capture_(0) { 25 capture_(0) {
59 } 26 }
60 27
61 BlockingTaskRunner::~BlockingTaskRunner() {} 28 BlockingTaskRunner::~BlockingTaskRunner() {}
(...skipping 25 matching lines...) Expand all
87 if (capture_) 54 if (capture_)
88 return; 55 return;
89 56
90 // We're done capturing, so grab all the captured tasks and run them. 57 // We're done capturing, so grab all the captured tasks and run them.
91 tasks.swap(captured_tasks_); 58 tasks.swap(captured_tasks_);
92 } 59 }
93 for (size_t i = 0; i < tasks.size(); ++i) 60 for (size_t i = 0; i < tasks.size(); ++i)
94 tasks[i].Run(); 61 tasks[i].Run();
95 } 62 }
96 63
97 BlockingTaskRunner::CapturePostTasks::CapturePostTasks() 64 BlockingTaskRunner::CapturePostTasks::CapturePostTasks(
98 : blocking_runner_(BlockingTaskRunner::current()) { 65 BlockingTaskRunner* blocking_runner)
66 : blocking_runner_(blocking_runner) {
99 blocking_runner_->SetCapture(true); 67 blocking_runner_->SetCapture(true);
100 } 68 }
101 69
102 BlockingTaskRunner::CapturePostTasks::~CapturePostTasks() { 70 BlockingTaskRunner::CapturePostTasks::~CapturePostTasks() {
103 blocking_runner_->SetCapture(false); 71 blocking_runner_->SetCapture(false);
104 } 72 }
105 73
106 } // namespace cc 74 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/blocking_task_runner.h ('k') | cc/trees/blocking_task_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698