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

Unified Diff: webkit/glue/webthread_impl.cc

Issue 8586038: Implement WebThread::{add,remove}TaskObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move impl to WebThreadImpl 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/webthread_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/webthread_impl.cc
diff --git a/webkit/glue/webthread_impl.cc b/webkit/glue/webthread_impl.cc
index 236497e6891e07e6c64ddc005807b154ddca8631..1354bcb7f6f2903257816b504f940815ecf8d66d 100644
--- a/webkit/glue/webthread_impl.cc
+++ b/webkit/glue/webthread_impl.cc
@@ -10,9 +10,45 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop.h"
+#include "base/threading/platform_thread.h"
namespace webkit_glue {
+class WebThreadBase::TaskObserverAdapter : public MessageLoop::TaskObserver {
+public:
+ TaskObserverAdapter(WebThread::TaskObserver* observer)
+ : observer_(observer) { }
+
+ // WebThread::TaskObserver does not have a willProcessTask method.
+ virtual void WillProcessTask(base::TimeTicks) OVERRIDE { }
+
+ virtual void DidProcessTask(base::TimeTicks) OVERRIDE {
+ observer_->didProcessTask();
+ }
+
+private:
+ WebThread::TaskObserver* observer_;
+};
+
+void WebThreadBase::addTaskObserver(TaskObserver* observer) {
+ CHECK(IsCurrentThread());
+ std::pair<TaskObserverMap::iterator, bool> result = task_observer_map_.insert(
+ std::make_pair(observer, static_cast<TaskObserverAdapter*>(NULL)));
+ if (result.second)
+ result.first->second = new TaskObserverAdapter(observer);
+ MessageLoop::current()->AddTaskObserver(result.first->second);
+}
+
+void WebThreadBase::removeTaskObserver(TaskObserver* observer) {
+ CHECK(IsCurrentThread());
+ TaskObserverMap::iterator iter = task_observer_map_.find(observer);
+ if (iter == task_observer_map_.end())
+ return;
+ MessageLoop::current()->RemoveTaskObserver(iter->second);
+ delete iter->second;
+ task_observer_map_.erase(iter);
+}
+
WebThreadImpl::WebThreadImpl(const char* name)
: thread_(new base::Thread(name)) {
thread_->Start();
@@ -22,6 +58,7 @@ void WebThreadImpl::postTask(Task* task) {
thread_->message_loop()->PostTask(
FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)));
}
+
void WebThreadImpl::postDelayedTask(
Task* task, long long delay_ms) {
thread_->message_loop()->PostDelayedTask(
@@ -30,6 +67,10 @@ void WebThreadImpl::postDelayedTask(
delay_ms);
}
+bool WebThreadImpl::IsCurrentThread() const {
+ return thread_->thread_id() == base::PlatformThread::CurrentId();
darin (slow to review) 2011/11/30 06:45:39 it feels like this should be a method on the Threa
adamk 2011/11/30 21:58:25 Yeah...I think this doesn't come up too often beca
+}
+
WebThreadImpl::~WebThreadImpl() {
thread_->Stop();
}
@@ -52,6 +93,10 @@ void WebThreadImplForMessageLoop::postDelayedTask(
delay_ms);
}
+bool WebThreadImplForMessageLoop::IsCurrentThread() const {
+ return message_loop_->BelongsToCurrentThread();
+}
+
WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {
}
« no previous file with comments | « webkit/glue/webthread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698