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

Side by Side Diff: content/child/webthread_impl.cc

Issue 807423002: [Thread-safe] Apply base::Passed to WebThread::Task (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // An implementation of WebThread in terms of base::MessageLoop and 5 // An implementation of WebThread in terms of base::MessageLoop and
6 // base::Thread 6 // base::Thread
7 7
8 #include "content/child/webthread_impl.h" 8 #include "content/child/webthread_impl.h"
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 base::MessageLoop::current()->RemoveTaskObserver(iter->second); 53 base::MessageLoop::current()->RemoveTaskObserver(iter->second);
54 delete iter->second; 54 delete iter->second;
55 task_observer_map_.erase(iter); 55 task_observer_map_.erase(iter);
56 } 56 }
57 57
58 WebThreadImpl::WebThreadImpl(const char* name) 58 WebThreadImpl::WebThreadImpl(const char* name)
59 : thread_(new base::Thread(name)) { 59 : thread_(new base::Thread(name)) {
60 thread_->Start(); 60 thread_->Start();
61 } 61 }
62 62
63 static void RunWebThreadTask(scoped_ptr<blink::WebThread::Task> task)
dcheng 2014/12/18 19:31:38 This code is really subtle. Can we expand this com
hiroshige 2014/12/19 09:16:11 Added comments.
64 // Take ownership of blink::WebThread::Task and delete it on first |run|
nasko 2014/12/18 17:53:25 nit: Comment should be before the method starts.
hiroshige 2014/12/19 09:16:11 Done.
65 // for thread-safety. http://crbug.com/390851, Comment #19
66 {
nasko 2014/12/18 17:53:25 Brace goes on the same line as the method params e
hiroshige 2014/12/19 09:16:11 Done.
67 task->run();
68 }
69
63 void WebThreadImpl::postTask(Task* task) { 70 void WebThreadImpl::postTask(Task* task) {
64 thread_->message_loop()->PostTask( 71 thread_->message_loop()->PostTask(
65 FROM_HERE, base::Bind(&blink::WebThread::Task::run, base::Owned(task))); 72 FROM_HERE,
73 base::Bind(RunWebThreadTask, base::Passed(scoped_ptr<Task>(task))));
dcheng 2014/12/18 19:31:38 It's slightly shorter to use make_scoped_ptr.
hiroshige 2014/12/19 09:16:11 Done.
66 } 74 }
67 75
68 void WebThreadImpl::postDelayedTask(Task* task, long long delay_ms) { 76 void WebThreadImpl::postDelayedTask(Task* task, long long delay_ms) {
69 thread_->message_loop()->PostDelayedTask( 77 thread_->message_loop()->PostDelayedTask(
70 FROM_HERE, 78 FROM_HERE,
71 base::Bind(&blink::WebThread::Task::run, base::Owned(task)), 79 base::Bind(RunWebThreadTask, base::Passed(scoped_ptr<Task>(task))),
72 base::TimeDelta::FromMilliseconds(delay_ms)); 80 base::TimeDelta::FromMilliseconds(delay_ms));
73 } 81 }
74 82
75 void WebThreadImpl::enterRunLoop() { 83 void WebThreadImpl::enterRunLoop() {
76 CHECK(isCurrentThread()); 84 CHECK(isCurrentThread());
77 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting. 85 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting.
78 thread_->message_loop()->Run(); 86 thread_->message_loop()->Run();
79 } 87 }
80 88
81 void WebThreadImpl::exitRunLoop() { 89 void WebThreadImpl::exitRunLoop() {
(...skipping 14 matching lines...) Expand all
96 thread_->Stop(); 104 thread_->Stop();
97 } 105 }
98 106
99 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( 107 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop(
100 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) 108 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
101 : main_thread_task_runner_(main_thread_task_runner), 109 : main_thread_task_runner_(main_thread_task_runner),
102 thread_id_(base::PlatformThread::CurrentId()) {} 110 thread_id_(base::PlatformThread::CurrentId()) {}
103 111
104 void WebThreadImplForMessageLoop::postTask(Task* task) { 112 void WebThreadImplForMessageLoop::postTask(Task* task) {
105 main_thread_task_runner_->PostTask( 113 main_thread_task_runner_->PostTask(
106 FROM_HERE, base::Bind(&blink::WebThread::Task::run, base::Owned(task))); 114 FROM_HERE,
115 base::Bind(RunWebThreadTask, base::Passed(scoped_ptr<Task>(task))));
107 } 116 }
108 117
109 void WebThreadImplForMessageLoop::postDelayedTask(Task* task, 118 void WebThreadImplForMessageLoop::postDelayedTask(Task* task,
110 long long delay_ms) { 119 long long delay_ms) {
111 main_thread_task_runner_->PostDelayedTask( 120 main_thread_task_runner_->PostDelayedTask(
112 FROM_HERE, 121 FROM_HERE,
113 base::Bind(&blink::WebThread::Task::run, base::Owned(task)), 122 base::Bind(RunWebThreadTask, base::Passed(scoped_ptr<Task>(task))),
114 base::TimeDelta::FromMilliseconds(delay_ms)); 123 base::TimeDelta::FromMilliseconds(delay_ms));
115 } 124 }
116 125
117 void WebThreadImplForMessageLoop::enterRunLoop() { 126 void WebThreadImplForMessageLoop::enterRunLoop() {
118 CHECK(isCurrentThread()); 127 CHECK(isCurrentThread());
119 // We don't support nesting. 128 // We don't support nesting.
120 CHECK(!base::MessageLoop::current()->is_running()); 129 CHECK(!base::MessageLoop::current()->is_running());
121 base::MessageLoop::current()->Run(); 130 base::MessageLoop::current()->Run();
122 } 131 }
123 132
124 void WebThreadImplForMessageLoop::exitRunLoop() { 133 void WebThreadImplForMessageLoop::exitRunLoop() {
125 CHECK(isCurrentThread()); 134 CHECK(isCurrentThread());
126 CHECK(base::MessageLoop::current()->is_running()); 135 CHECK(base::MessageLoop::current()->is_running());
127 base::MessageLoop::current()->Quit(); 136 base::MessageLoop::current()->Quit();
128 } 137 }
129 138
130 bool WebThreadImplForMessageLoop::isCurrentThread() const { 139 bool WebThreadImplForMessageLoop::isCurrentThread() const {
131 return main_thread_task_runner_->BelongsToCurrentThread(); 140 return main_thread_task_runner_->BelongsToCurrentThread();
132 } 141 }
133 142
134 blink::PlatformThreadId WebThreadImplForMessageLoop::threadId() const { 143 blink::PlatformThreadId WebThreadImplForMessageLoop::threadId() const {
135 return thread_id_; 144 return thread_id_;
136 } 145 }
137 146
138 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} 147 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {}
139 148
140 } // namespace content 149 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698