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

Side by Side Diff: mojo/services/html_viewer/webthread_impl.cc

Issue 1094833002: Mojo changes for moving WebScheduler to WebThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix it Created 5 years, 8 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
« no previous file with comments | « mojo/services/html_viewer/webthread_impl.h ('k') | 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 "mojo/services/html_viewer/webthread_impl.h" 8 #include "mojo/services/html_viewer/webthread_impl.h"
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 CHECK(isCurrentThread()); 50 CHECK(isCurrentThread());
51 TaskObserverMap::iterator iter = task_observer_map_.find(observer); 51 TaskObserverMap::iterator iter = task_observer_map_.find(observer);
52 if (iter == task_observer_map_.end()) 52 if (iter == task_observer_map_.end())
53 return; 53 return;
54 base::MessageLoop::current()->RemoveTaskObserver(iter->second); 54 base::MessageLoop::current()->RemoveTaskObserver(iter->second);
55 delete iter->second; 55 delete iter->second;
56 task_observer_map_.erase(iter); 56 task_observer_map_.erase(iter);
57 } 57 }
58 58
59 WebThreadImpl::WebThreadImpl(const char* name) 59 WebThreadImpl::WebThreadImpl(const char* name)
60 : thread_(new base::Thread(name)) { 60 : thread_(new base::Thread(name)),
61 web_scheduler_(new WebSchedulerImpl(thread_->task_runner())) {
61 thread_->Start(); 62 thread_->Start();
62 } 63 }
63 64
64 // RunWebThreadTask takes the ownership of |task| from base::Closure and 65 // RunWebThreadTask takes the ownership of |task| from base::Closure and
65 // deletes it on the first invocation of the closure for thread-safety. 66 // deletes it on the first invocation of the closure for thread-safety.
66 // base::Closure made from RunWebThreadTask is copyable but Closure::Run 67 // base::Closure made from RunWebThreadTask is copyable but Closure::Run
67 // should be called at most only once. 68 // should be called at most only once.
68 // This is because WebThread::Task can contain RefPtr to a 69 // This is because WebThread::Task can contain RefPtr to a
69 // thread-unsafe-reference-counted object (e.g. WorkerThreadTask can contain 70 // thread-unsafe-reference-counted object (e.g. WorkerThreadTask can contain
70 // RefPtr to WebKit's StringImpl), and if we don't delete |task| here, 71 // RefPtr to WebKit's StringImpl), and if we don't delete |task| here,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting. 110 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting.
110 thread_->message_loop()->Run(); 111 thread_->message_loop()->Run();
111 } 112 }
112 113
113 void WebThreadImpl::exitRunLoop() { 114 void WebThreadImpl::exitRunLoop() {
114 CHECK(isCurrentThread()); 115 CHECK(isCurrentThread());
115 CHECK(thread_->message_loop()->is_running()); 116 CHECK(thread_->message_loop()->is_running());
116 thread_->message_loop()->Quit(); 117 thread_->message_loop()->Quit();
117 } 118 }
118 119
120 blink::WebScheduler* WebThreadImpl::scheduler() const {
121 return web_scheduler_.get();
122 }
123
119 bool WebThreadImpl::isCurrentThread() const { 124 bool WebThreadImpl::isCurrentThread() const {
120 return thread_->thread_id() == base::PlatformThread::CurrentId(); 125 return thread_->thread_id() == base::PlatformThread::CurrentId();
121 } 126 }
122 127
123 blink::PlatformThreadId WebThreadImpl::threadId() const { 128 blink::PlatformThreadId WebThreadImpl::threadId() const {
124 return thread_->thread_id(); 129 return thread_->thread_id();
125 } 130 }
126 131
127 WebThreadImpl::~WebThreadImpl() { 132 WebThreadImpl::~WebThreadImpl() {
128 thread_->Stop(); 133 thread_->Stop();
129 } 134 }
130 135
131 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( 136 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop(
132 base::MessageLoopProxy* message_loop) 137 base::MessageLoopProxy* message_loop)
133 : message_loop_(message_loop) {} 138 : message_loop_(message_loop),
139 web_scheduler_(new WebSchedulerImpl(message_loop_)) {
140 }
134 141
135 void WebThreadImplForMessageLoop::postTask( 142 void WebThreadImplForMessageLoop::postTask(
136 const blink::WebTraceLocation& location, 143 const blink::WebTraceLocation& location,
137 Task* task) { 144 Task* task) {
138 postDelayedTask(location, task, 0); 145 postDelayedTask(location, task, 0);
139 } 146 }
140 147
141 void WebThreadImplForMessageLoop::postDelayedTask( 148 void WebThreadImplForMessageLoop::postDelayedTask(
142 const blink::WebTraceLocation& web_location, 149 const blink::WebTraceLocation& web_location,
143 Task* task, 150 Task* task,
(...skipping 12 matching lines...) Expand all
156 CHECK(!base::MessageLoop::current()->is_running()); 163 CHECK(!base::MessageLoop::current()->is_running());
157 base::MessageLoop::current()->Run(); 164 base::MessageLoop::current()->Run();
158 } 165 }
159 166
160 void WebThreadImplForMessageLoop::exitRunLoop() { 167 void WebThreadImplForMessageLoop::exitRunLoop() {
161 CHECK(isCurrentThread()); 168 CHECK(isCurrentThread());
162 CHECK(base::MessageLoop::current()->is_running()); 169 CHECK(base::MessageLoop::current()->is_running());
163 base::MessageLoop::current()->Quit(); 170 base::MessageLoop::current()->Quit();
164 } 171 }
165 172
173 blink::WebScheduler* WebThreadImplForMessageLoop::scheduler() const {
174 return web_scheduler_.get();
175 }
176
166 bool WebThreadImplForMessageLoop::isCurrentThread() const { 177 bool WebThreadImplForMessageLoop::isCurrentThread() const {
167 return message_loop_->BelongsToCurrentThread(); 178 return message_loop_->BelongsToCurrentThread();
168 } 179 }
169 180
170 blink::PlatformThreadId WebThreadImplForMessageLoop::threadId() const { 181 blink::PlatformThreadId WebThreadImplForMessageLoop::threadId() const {
171 return thread_id_; 182 return thread_id_;
172 } 183 }
173 184
174 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} 185 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {}
175 186
176 } // namespace html_viewer 187 } // namespace html_viewer
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/webthread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698