| 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 <math.h> | 8 #include <math.h> |
| 9 | 9 |
| 10 #include "content/child/webthread_impl.h" | 10 #include "content/child/webthread_impl.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 thread_->message_loop()->Quit(); | 86 thread_->message_loop()->Quit(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool WebThreadImpl::isCurrentThread() const { | 89 bool WebThreadImpl::isCurrentThread() const { |
| 90 return thread_->thread_id() == base::PlatformThread::CurrentId(); | 90 return thread_->thread_id() == base::PlatformThread::CurrentId(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void WebThreadImpl::setSharedTimerFiredFunction( | 93 void WebThreadImpl::setSharedTimerFiredFunction( |
| 94 SharedTimerFunction timerFunction) { | 94 SharedTimerFunction timerFunction) { |
| 95 shared_timer_function_ = timerFunction; | 95 shared_timer_function_ = timerFunction; |
| 96 if (shared_timer_function_ != NULL) |
| 97 shared_timer_.reset(new base::OneShotTimer<WebThreadImpl>()); |
| 98 else |
| 99 shared_timer_.reset(NULL); |
| 96 } | 100 } |
| 97 | 101 |
| 98 void WebThreadImpl::setSharedTimerFireInterval(double interval_seconds) { | 102 void WebThreadImpl::setSharedTimerFireInterval(double interval_seconds) { |
| 103 DCHECK(shared_timer_function_); |
| 104 |
| 99 // See BlinkPlatformImpl::setSharedTimerFireInterval for explanation of | 105 // See BlinkPlatformImpl::setSharedTimerFireInterval for explanation of |
| 100 // why ceil is used in the interval calculation. | 106 // why ceil is used in the interval calculation. |
| 101 int64 interval = static_cast<int64>( | 107 int64 interval = static_cast<int64>( |
| 102 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) | 108 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) |
| 103 * base::Time::kMicrosecondsPerMillisecond); | 109 * base::Time::kMicrosecondsPerMillisecond); |
| 104 | 110 |
| 105 if (interval < 0) | 111 if (interval < 0) |
| 106 interval = 0; | 112 interval = 0; |
| 107 | 113 |
| 108 shared_timer_.Stop(); | 114 shared_timer_->Stop(); |
| 109 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), | 115 shared_timer_->Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), |
| 110 this, &WebThreadImpl::OnTimeout); | 116 this, &WebThreadImpl::OnTimeout); |
| 111 } | 117 } |
| 112 | 118 |
| 113 void WebThreadImpl::stopSharedTimer() { | 119 void WebThreadImpl::stopSharedTimer() { |
| 114 shared_timer_.Stop(); | 120 DCHECK(shared_timer_function_); |
| 121 shared_timer_->Stop(); |
| 115 } | 122 } |
| 116 | 123 |
| 117 WebThreadImpl::~WebThreadImpl() { | 124 WebThreadImpl::~WebThreadImpl() { |
| 118 thread_->Stop(); | 125 thread_->Stop(); |
| 119 } | 126 } |
| 120 | 127 |
| 121 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( | 128 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( |
| 122 base::MessageLoopProxy* message_loop) | 129 base::MessageLoopProxy* message_loop) |
| 123 : message_loop_(message_loop) {} | 130 : message_loop_(message_loop) {} |
| 124 | 131 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 148 base::MessageLoop::current()->Quit(); | 155 base::MessageLoop::current()->Quit(); |
| 149 } | 156 } |
| 150 | 157 |
| 151 bool WebThreadImplForMessageLoop::isCurrentThread() const { | 158 bool WebThreadImplForMessageLoop::isCurrentThread() const { |
| 152 return message_loop_->BelongsToCurrentThread(); | 159 return message_loop_->BelongsToCurrentThread(); |
| 153 } | 160 } |
| 154 | 161 |
| 155 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} | 162 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} |
| 156 | 163 |
| 157 } // namespace content | 164 } // namespace content |
| OLD | NEW |