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

Side by Side Diff: webkit/glue/webthread_impl.cc

Issue 9167034: Add support for Run + Quit to WebKit::WebThread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: uses MessageLoop::current and restores MessageLoopProxy, removes OVERRIDE Created 8 years, 11 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 | « webkit/glue/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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/glue/webthread_impl.h" 8 #include "webkit/glue/webthread_impl.h"
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 void WebThreadImpl::postDelayedTask( 65 void WebThreadImpl::postDelayedTask(
66 Task* task, long long delay_ms) { 66 Task* task, long long delay_ms) {
67 thread_->message_loop()->PostDelayedTask( 67 thread_->message_loop()->PostDelayedTask(
68 FROM_HERE, 68 FROM_HERE,
69 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), 69 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)),
70 base::TimeDelta::FromMilliseconds(delay_ms)); 70 base::TimeDelta::FromMilliseconds(delay_ms));
71 } 71 }
72 72
73 void WebThreadImpl::enterRunLoop() {
74 CHECK(IsCurrentThread());
75 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting.
76 thread_->message_loop()->Run();
77 }
78
79 void WebThreadImpl::exitRunLoop() {
80 CHECK(IsCurrentThread());
81 CHECK(thread_->message_loop()->is_running());
82 thread_->message_loop()->Quit();
83 }
84
73 bool WebThreadImpl::IsCurrentThread() const { 85 bool WebThreadImpl::IsCurrentThread() const {
74 return thread_->thread_id() == base::PlatformThread::CurrentId(); 86 return thread_->thread_id() == base::PlatformThread::CurrentId();
75 } 87 }
76 88
77 WebThreadImpl::~WebThreadImpl() { 89 WebThreadImpl::~WebThreadImpl() {
78 thread_->Stop(); 90 thread_->Stop();
79 } 91 }
80 92
81 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( 93 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop(
82 base::MessageLoopProxy* message_loop) 94 base::MessageLoopProxy* message_loop)
83 : message_loop_(message_loop) { 95 : message_loop_(message_loop) {
84 } 96 }
85 97
86 void WebThreadImplForMessageLoop::postTask(Task* task) { 98 void WebThreadImplForMessageLoop::postTask(Task* task) {
87 message_loop_->PostTask( 99 message_loop_->PostTask(
88 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task))); 100 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)));
89 } 101 }
90 102
91 void WebThreadImplForMessageLoop::postDelayedTask( 103 void WebThreadImplForMessageLoop::postDelayedTask(
92 Task* task, long long delay_ms) { 104 Task* task, long long delay_ms) {
93 message_loop_->PostDelayedTask( 105 message_loop_->PostDelayedTask(
94 FROM_HERE, 106 FROM_HERE,
95 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), 107 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)),
96 delay_ms); 108 delay_ms);
97 } 109 }
98 110
111 void WebThreadImplForMessageLoop::enterRunLoop() {
112 CHECK(IsCurrentThread());
113 CHECK(!MessageLoop::current()->is_running()); // We don't support nesting.
114 MessageLoop::current()->Run();
115 }
116
117 void WebThreadImplForMessageLoop::exitRunLoop() {
118 CHECK(IsCurrentThread());
119 CHECK(MessageLoop::current()->is_running());
120 MessageLoop::current()->Quit();
121 }
122
99 bool WebThreadImplForMessageLoop::IsCurrentThread() const { 123 bool WebThreadImplForMessageLoop::IsCurrentThread() const {
100 return message_loop_->BelongsToCurrentThread(); 124 return message_loop_->BelongsToCurrentThread();
101 } 125 }
102 126
103 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { 127 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {
104 } 128 }
105 129
106 } 130 }
OLDNEW
« no previous file with comments | « webkit/glue/webthread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698