OLD | NEW |
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 // 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/child/webthread_impl.h" | 8 #include "webkit/child/webthread_impl.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void WebThreadImpl::postTask(Task* task) { | 63 void WebThreadImpl::postTask(Task* task) { |
64 thread_->message_loop()->PostTask( | 64 thread_->message_loop()->PostTask( |
65 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task))); | 65 FROM_HERE, base::Bind(&blink::WebThread::Task::run, base::Owned(task))); |
66 } | 66 } |
67 | 67 |
68 void WebThreadImpl::postDelayedTask( | 68 void WebThreadImpl::postDelayedTask( |
69 Task* task, long long delay_ms) { | 69 Task* task, long long delay_ms) { |
70 thread_->message_loop()->PostDelayedTask( | 70 thread_->message_loop()->PostDelayedTask( |
71 FROM_HERE, | 71 FROM_HERE, |
72 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), | 72 base::Bind(&blink::WebThread::Task::run, base::Owned(task)), |
73 base::TimeDelta::FromMilliseconds(delay_ms)); | 73 base::TimeDelta::FromMilliseconds(delay_ms)); |
74 } | 74 } |
75 | 75 |
76 void WebThreadImpl::enterRunLoop() { | 76 void WebThreadImpl::enterRunLoop() { |
77 CHECK(isCurrentThread()); | 77 CHECK(isCurrentThread()); |
78 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting. | 78 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting. |
79 thread_->message_loop()->Run(); | 79 thread_->message_loop()->Run(); |
80 } | 80 } |
81 | 81 |
82 void WebThreadImpl::exitRunLoop() { | 82 void WebThreadImpl::exitRunLoop() { |
(...skipping 10 matching lines...) Expand all Loading... |
93 thread_->Stop(); | 93 thread_->Stop(); |
94 } | 94 } |
95 | 95 |
96 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( | 96 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( |
97 base::MessageLoopProxy* message_loop) | 97 base::MessageLoopProxy* message_loop) |
98 : message_loop_(message_loop) { | 98 : message_loop_(message_loop) { |
99 } | 99 } |
100 | 100 |
101 void WebThreadImplForMessageLoop::postTask(Task* task) { | 101 void WebThreadImplForMessageLoop::postTask(Task* task) { |
102 message_loop_->PostTask( | 102 message_loop_->PostTask( |
103 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task))); | 103 FROM_HERE, base::Bind(&blink::WebThread::Task::run, base::Owned(task))); |
104 } | 104 } |
105 | 105 |
106 void WebThreadImplForMessageLoop::postDelayedTask( | 106 void WebThreadImplForMessageLoop::postDelayedTask( |
107 Task* task, long long delay_ms) { | 107 Task* task, long long delay_ms) { |
108 message_loop_->PostDelayedTask( | 108 message_loop_->PostDelayedTask( |
109 FROM_HERE, | 109 FROM_HERE, |
110 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), | 110 base::Bind(&blink::WebThread::Task::run, base::Owned(task)), |
111 base::TimeDelta::FromMilliseconds(delay_ms)); | 111 base::TimeDelta::FromMilliseconds(delay_ms)); |
112 } | 112 } |
113 | 113 |
114 void WebThreadImplForMessageLoop::enterRunLoop() { | 114 void WebThreadImplForMessageLoop::enterRunLoop() { |
115 CHECK(isCurrentThread()); | 115 CHECK(isCurrentThread()); |
116 CHECK(!base::MessageLoop::current() | 116 CHECK(!base::MessageLoop::current() |
117 ->is_running()); // We don't support nesting. | 117 ->is_running()); // We don't support nesting. |
118 base::MessageLoop::current()->Run(); | 118 base::MessageLoop::current()->Run(); |
119 } | 119 } |
120 | 120 |
121 void WebThreadImplForMessageLoop::exitRunLoop() { | 121 void WebThreadImplForMessageLoop::exitRunLoop() { |
122 CHECK(isCurrentThread()); | 122 CHECK(isCurrentThread()); |
123 CHECK(base::MessageLoop::current()->is_running()); | 123 CHECK(base::MessageLoop::current()->is_running()); |
124 base::MessageLoop::current()->Quit(); | 124 base::MessageLoop::current()->Quit(); |
125 } | 125 } |
126 | 126 |
127 bool WebThreadImplForMessageLoop::isCurrentThread() const { | 127 bool WebThreadImplForMessageLoop::isCurrentThread() const { |
128 return message_loop_->BelongsToCurrentThread(); | 128 return message_loop_->BelongsToCurrentThread(); |
129 } | 129 } |
130 | 130 |
131 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { | 131 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { |
132 } | 132 } |
133 | 133 |
134 } | 134 } |
OLD | NEW |