Chromium Code Reviews| 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 #ifndef CONTENT_COMMON_WORKER_TASK_RUNNER_H_ | |
| 6 #define CONTENT_COMMON_WORKER_TASK_RUNNER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/callback_forward.h" | |
| 10 #include "base/observer_list.h" | |
| 11 #include "base/synchronization/lock.h" | |
| 12 #include "base/threading/thread_local.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerRunLoop.h" | |
| 14 | |
| 15 #include <map> | |
| 16 | |
|
michaeln
2011/12/07 23:57:38
extra blank line
dgrogan
2011/12/08 02:02:14
Done.
| |
| 17 | |
| 18 class WorkerTaskRunner { | |
| 19 public: | |
| 20 WorkerTaskRunner(); | |
| 21 | |
| 22 void PostTask(int id, const base::Closure& task); | |
| 23 int CurrentWorkerId(); | |
| 24 | |
| 25 class Observer { | |
| 26 public: | |
| 27 virtual ~Observer() {} | |
| 28 virtual void OnWorkerRunLoopStarted(); | |
| 29 virtual void OnWorkerRunLoopStopped(); | |
| 30 }; | |
| 31 // Can be called on any thread. The notifications will be called on the | |
| 32 // worker thread in question. | |
| 33 void AddObserver(Observer* obs); | |
| 34 // Unlike most Observerlists, observers can't remove themselves from this one | |
| 35 // during a notification. Deadlock may result. | |
| 36 void RemoveObserver(Observer* obs); | |
| 37 | |
|
michaeln
2011/12/07 23:57:38
Might be nicer to have a static instance getter in
dgrogan
2011/12/08 02:02:14
Changed.
| |
| 38 private: | |
| 39 friend class RendererWebKitPlatformSupportImpl; | |
| 40 | |
| 41 typedef std::map<int, WebKit::WebWorkerRunLoop> IDToLoopMap; | |
| 42 | |
| 43 ~WorkerTaskRunner(); | |
| 44 void OnWorkerRunLoopStarted(const WebKit::WebWorkerRunLoop& loop); | |
| 45 void OnWorkerRunLoopStopped(const WebKit::WebWorkerRunLoop& loop); | |
| 46 | |
| 47 base::ThreadLocalPointer<std::pair<int, WebKit::WebWorkerRunLoop> > | |
| 48 current_tls_; | |
| 49 | |
| 50 base::Lock lock_; | |
| 51 int id_sequence_; | |
| 52 IDToLoopMap loop_map_; | |
| 53 | |
| 54 ObserverList<Observer> observer_list_; | |
| 55 base::Lock observer_lock_; | |
| 56 }; | |
| 57 | |
| 58 #endif // CONTENT_COMMON_SOCKET_STREAM_H_ | |
| OLD | NEW |