Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: webkit/glue/webthread_impl.cc

Issue 8550010: base::Bind() conversion for webkit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/task.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 13
13 namespace webkit_glue { 14 namespace webkit_glue {
14 15
15 class TaskAdapter : public Task {
16 public:
17 TaskAdapter(WebKit::WebThread::Task* task) : task_(task) { }
18 virtual void Run() {
19 task_->run();
20 }
21 private:
22 scoped_ptr<WebKit::WebThread::Task> task_;
23 };
24
25 WebThreadImpl::WebThreadImpl(const char* name) 16 WebThreadImpl::WebThreadImpl(const char* name)
26 : thread_(new base::Thread(name)) { 17 : thread_(new base::Thread(name)) {
27 thread_->Start(); 18 thread_->Start();
28 } 19 }
29 20
30 void WebThreadImpl::postTask(Task* task) { 21 void WebThreadImpl::postTask(Task* task) {
31 thread_->message_loop()->PostTask(FROM_HERE, 22 thread_->message_loop()->PostTask(
32 new TaskAdapter(task)); 23 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)));
33 } 24 }
34 void WebThreadImpl::postDelayedTask( 25 void WebThreadImpl::postDelayedTask(
35 Task* task, long long delay_ms) { 26 Task* task, long long delay_ms) {
36 thread_->message_loop()->PostDelayedTask( 27 thread_->message_loop()->PostDelayedTask(
37 FROM_HERE, new TaskAdapter(task), delay_ms); 28 FROM_HERE,
29 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)),
30 delay_ms);
38 } 31 }
39 32
40 WebThreadImpl::~WebThreadImpl() { 33 WebThreadImpl::~WebThreadImpl() {
41 thread_->Stop(); 34 thread_->Stop();
42 } 35 }
43 36
44 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( 37 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop(
45 base::MessageLoopProxy* message_loop) 38 base::MessageLoopProxy* message_loop)
46 : message_loop_(message_loop) { 39 : message_loop_(message_loop) {
47 } 40 }
48 41
49 void WebThreadImplForMessageLoop::postTask(Task* task) { 42 void WebThreadImplForMessageLoop::postTask(Task* task) {
50 message_loop_->PostTask(FROM_HERE, new TaskAdapter(task)); 43 message_loop_->PostTask(
44 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)));
51 } 45 }
52 46
53 void WebThreadImplForMessageLoop::postDelayedTask( 47 void WebThreadImplForMessageLoop::postDelayedTask(
54 Task* task, long long delay_ms) { 48 Task* task, long long delay_ms) {
55 message_loop_->PostDelayedTask(FROM_HERE, new TaskAdapter(task), delay_ms); 49 message_loop_->PostDelayedTask(
50 FROM_HERE,
51 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)),
52 delay_ms);
56 } 53 }
57 54
58 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { 55 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {
59 } 56 }
60 57
61 } 58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698