OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // An implementation of WebThread in terms of base::MessageLoop and |
| 6 // base::Thread |
| 7 |
| 8 #include "webkit/glue/webthread_impl.h" |
| 9 |
| 10 #include "base/scoped_ptr.h" |
| 11 #include "base/task.h" |
| 12 #include "base/message_loop.h" |
| 13 |
| 14 namespace webkit_glue { |
| 15 |
| 16 class TaskAdapter : public Task { |
| 17 public: |
| 18 TaskAdapter(WebKit::WebThread::Task* task) : task_(task) { } |
| 19 virtual void Run() { |
| 20 task_->run(); |
| 21 } |
| 22 private: |
| 23 scoped_ptr<WebKit::WebThread::Task> task_; |
| 24 }; |
| 25 |
| 26 WebThreadImpl::WebThreadImpl(const char* name) |
| 27 : thread_(new base::Thread(name)) { |
| 28 thread_->Start(); |
| 29 } |
| 30 |
| 31 void WebThreadImpl::postTask(Task* task) { |
| 32 thread_->message_loop()->PostTask(FROM_HERE, |
| 33 new TaskAdapter(task)); |
| 34 } |
| 35 void WebThreadImpl::postDelayedTask( |
| 36 Task* task, int64 delay_ms) { |
| 37 thread_->message_loop()->PostDelayedTask( |
| 38 FROM_HERE, new TaskAdapter(task), delay_ms); |
| 39 } |
| 40 |
| 41 WebThreadImpl::~WebThreadImpl() { |
| 42 thread_->Stop(); |
| 43 } |
| 44 |
| 45 } |
OLD | NEW |