OLD | NEW |
---|---|
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 Loading... | |
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 MessageLoop* message_loop, base::PlatformThreadId thread_id) |
83 : message_loop_(message_loop) { | 95 : message_loop_(message_loop) |
96 , thread_id_(thread_id) { | |
84 } | 97 } |
85 | 98 |
86 void WebThreadImplForMessageLoop::postTask(Task* task) { | 99 void WebThreadImplForMessageLoop::postTask(Task* task) { |
87 message_loop_->PostTask( | 100 message_loop_->PostTask( |
88 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task))); | 101 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task))); |
89 } | 102 } |
90 | 103 |
91 void WebThreadImplForMessageLoop::postDelayedTask( | 104 void WebThreadImplForMessageLoop::postDelayedTask( |
92 Task* task, long long delay_ms) { | 105 Task* task, long long delay_ms) { |
93 message_loop_->PostDelayedTask( | 106 message_loop_->PostDelayedTask( |
94 FROM_HERE, | 107 FROM_HERE, |
95 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), | 108 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), |
96 delay_ms); | 109 delay_ms); |
97 } | 110 } |
98 | 111 |
112 void WebThreadImplForMessageLoop::enterRunLoop() { | |
113 CHECK(IsCurrentThread()); | |
114 CHECK(!message_loop_->is_running()); // We don't support nesting. | |
115 message_loop_->Run(); | |
darin (slow to review)
2012/01/19 17:57:36
you could also just use MessageLoop::current()->Ru
| |
116 } | |
117 | |
118 void WebThreadImplForMessageLoop::exitRunLoop() { | |
119 CHECK(IsCurrentThread()); | |
120 CHECK(message_loop_->is_running()); | |
121 message_loop_->Quit(); | |
122 } | |
123 | |
99 bool WebThreadImplForMessageLoop::IsCurrentThread() const { | 124 bool WebThreadImplForMessageLoop::IsCurrentThread() const { |
100 return message_loop_->BelongsToCurrentThread(); | 125 return thread_id_ == base::PlatformThread::CurrentId(); |
101 } | 126 } |
102 | 127 |
103 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { | 128 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { |
104 } | 129 } |
105 | 130 |
106 } | 131 } |
OLD | NEW |