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/memory/ref_counted.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 | |
| 17 using WebKit::WebWorkerRunLoop; | |
|
michaeln
2011/12/05 22:02:09
please avoid 'using' in .h files
dgrogan
2011/12/06 00:15:15
fixed
| |
| 18 | |
| 19 class WorkerTaskRunner : public base::RefCountedThreadSafe<WorkerTaskRunner> { | |
| 20 public: | |
| 21 WorkerTaskRunner(); | |
| 22 ~WorkerTaskRunner(); | |
|
michaeln
2011/12/05 22:02:09
refcounted classes don't need public dtors
dgrogan
2011/12/06 00:15:15
A clang plugin told me to add one:
[chromium-style
| |
| 23 // This could be changed to take a chromium closure that is then wrapped by | |
|
michaeln
2011/12/05 22:02:09
i think it'd be good to use a base::Bind closure h
dgrogan
2011/12/06 00:15:15
Agreed. I skipped that because I wanted cut anyth
| |
| 24 // this class. | |
| 25 void PostTask(int id, WebKit::WebWorkerRunLoop::Task* closure); | |
| 26 int CurrentWorkerId(); | |
| 27 | |
| 28 class Observer { | |
| 29 public: | |
| 30 virtual ~Observer() { } | |
| 31 virtual void onLoopRegistered() { } | |
|
michaeln
2011/12/05 22:02:09
nits: upper case method names and no space needed
dgrogan
2011/12/06 00:15:15
Done.
| |
| 32 virtual void onLoopUnregistered() { } | |
| 33 }; | |
| 34 // Can be called on any thread. The notifications will be called on the | |
| 35 // worker thread in question. | |
| 36 void AddObserver(Observer* obs); | |
| 37 // Unlike most Observerlists, observers can't remove themselves from this one | |
| 38 // during a notification. Deadlock may result. | |
| 39 void RemoveObserver(Observer* obs); | |
| 40 | |
| 41 private: | |
| 42 friend class RendererWebKitPlatformSupportImpl; | |
| 43 | |
| 44 typedef std::map<int, WebWorkerRunLoop> IDToLoopMap; | |
| 45 | |
| 46 void RegisterCurrentWorkerLoop(const WebWorkerRunLoop& loop); | |
|
michaeln
2011/12/05 22:02:09
consider making the method names for start/stop no
dgrogan
2011/12/06 00:15:15
Done.
| |
| 47 void UnRegisterCurrentWorkerLoop(const WebWorkerRunLoop& loop); | |
| 48 | |
| 49 base::ThreadLocalPointer<std::pair<int, WebWorkerRunLoop> > current_tls_; | |
| 50 | |
| 51 base::Lock lock_; | |
| 52 int id_sequence_; | |
| 53 IDToLoopMap loop_map_; | |
| 54 | |
| 55 ObserverList<Observer> observer_list_; | |
| 56 base::Lock observer_lock_; | |
| 57 }; | |
| 58 | |
| 59 #endif // CONTENT_COMMON_SOCKET_STREAM_H_ | |
| OLD | NEW |