OLD | NEW |
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 void WebThreadImpl::exitRunLoop() { | 81 void WebThreadImpl::exitRunLoop() { |
82 CHECK(isCurrentThread()); | 82 CHECK(isCurrentThread()); |
83 CHECK(thread_->message_loop()->is_running()); | 83 CHECK(thread_->message_loop()->is_running()); |
84 thread_->message_loop()->Quit(); | 84 thread_->message_loop()->Quit(); |
85 } | 85 } |
86 | 86 |
87 bool WebThreadImpl::isCurrentThread() const { | 87 bool WebThreadImpl::isCurrentThread() const { |
88 return thread_->thread_id() == base::PlatformThread::CurrentId(); | 88 return thread_->thread_id() == base::PlatformThread::CurrentId(); |
89 } | 89 } |
90 | 90 |
| 91 void WebThreadImpl::setSharedTimerFiredFunction( |
| 92 SharedTimerFunction timerFunction) { |
| 93 shared_timer_function_ = timerFunction; |
| 94 } |
| 95 |
| 96 void WebThreadImpl::setSharedTimerFireInterval(double interval_seconds) { |
| 97 // See BlinkPlatformImpl::setSharedTimerFireInterval for explanation of |
| 98 // why ceil is used in the interval calculation. |
| 99 int64 interval = static_cast<int64>( |
| 100 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) |
| 101 * base::Time::kMicrosecondsPerMillisecond); |
| 102 |
| 103 if (interval < 0) |
| 104 interval = 0; |
| 105 |
| 106 shared_timer_.Stop(); |
| 107 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), |
| 108 this, &WebThreadImpl::OnTimeout); |
| 109 } |
| 110 |
| 111 void WebThreadImpl::stopSharedTimer() { |
| 112 shared_timer_.Stop(); |
| 113 } |
| 114 |
91 WebThreadImpl::~WebThreadImpl() { | 115 WebThreadImpl::~WebThreadImpl() { |
92 thread_->Stop(); | 116 thread_->Stop(); |
93 } | 117 } |
94 | 118 |
95 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( | 119 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( |
96 base::MessageLoopProxy* message_loop) | 120 base::MessageLoopProxy* message_loop) |
97 : message_loop_(message_loop) {} | 121 : message_loop_(message_loop) {} |
98 | 122 |
99 void WebThreadImplForMessageLoop::postTask(Task* task) { | 123 void WebThreadImplForMessageLoop::postTask(Task* task) { |
100 message_loop_->PostTask( | 124 message_loop_->PostTask( |
(...skipping 21 matching lines...) Expand all Loading... |
122 base::MessageLoop::current()->Quit(); | 146 base::MessageLoop::current()->Quit(); |
123 } | 147 } |
124 | 148 |
125 bool WebThreadImplForMessageLoop::isCurrentThread() const { | 149 bool WebThreadImplForMessageLoop::isCurrentThread() const { |
126 return message_loop_->BelongsToCurrentThread(); | 150 return message_loop_->BelongsToCurrentThread(); |
127 } | 151 } |
128 | 152 |
129 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} | 153 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} |
130 | 154 |
131 } // namespace content | 155 } // namespace content |
OLD | NEW |