Index: content/common/worker_task_runner.h |
diff --git a/content/common/worker_task_runner.h b/content/common/worker_task_runner.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..30cc25e6e024bfa0e9f9d4c564da206656106439 |
--- /dev/null |
+++ b/content/common/worker_task_runner.h |
@@ -0,0 +1,60 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_COMMON_WORKER_TASK_RUNNER_H_ |
+#define CONTENT_COMMON_WORKER_TASK_RUNNER_H_ |
+#pragma once |
+ |
+#include "base/callback_forward.h" |
+#include "base/synchronization/lock.h" |
+#include "base/threading/thread_local.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerRunLoop.h" |
+ |
+#include <map> |
darin (slow to review)
2011/12/08 22:41:21
nit: these are supposed to go above the other incl
dgrogan
2011/12/09 03:20:41
Done.
|
+#include <set> |
+ |
+class WorkerTaskRunner { |
+ public: |
+ WorkerTaskRunner(); |
+ |
+ void PostTask(int id, const base::Closure& task); |
+ int CurrentWorkerId(); |
+ static WorkerTaskRunner* Instance(); |
+ |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ virtual void OnWorkerRunLoopStarted(); |
+ virtual void OnWorkerRunLoopStopped(); |
michaeln
2011/12/09 00:43:32
pure virtual?
dgrogan
2011/12/09 03:20:41
I gave them a default empty implementation.
|
+ }; |
+ // Can be called on any thread. The notifications will be called on the |
+ // worker thread in question. |
+ void AddObserver(Observer* obs); |
+ // Unlike most Observerlists, observers can't remove themselves from this one |
+ // during a notification. Deadlock may result. |
+ // Returns number of observers removed. |
michaeln
2011/12/08 03:10:47
why the return value?
dgrogan
2011/12/09 03:20:41
Mostly because it's available and could feasibly b
|
+ int RemoveObserver(Observer* obs); |
+ |
+ private: |
+ friend class RendererWebKitPlatformSupportImpl; |
+ |
+ typedef std::map<int, WebKit::WebWorkerRunLoop> IDToLoopMap; |
+ |
+ ~WorkerTaskRunner(); |
+ void OnWorkerRunLoopStarted(const WebKit::WebWorkerRunLoop& loop); |
+ void OnWorkerRunLoopStopped(const WebKit::WebWorkerRunLoop& loop); |
+ |
+ base::ThreadLocalPointer<std::pair<int, WebKit::WebWorkerRunLoop> > |
+ current_tls_; |
+ |
+ base::Lock lock_; |
+ int id_sequence_; |
+ IDToLoopMap loop_map_; |
+ |
+ typedef std::set<Observer*> ObserverList; |
+ ObserverList observer_list_; |
+ base::Lock observer_lock_; |
+}; |
+ |
+#endif // CONTENT_COMMON_SOCKET_STREAM_H_ |