Chromium Code Reviews| 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..f5d03cefb18ebdcdbf70741c9fc8b2ade855ff69 |
| --- /dev/null |
| +++ b/content/common/worker_task_runner.h |
| @@ -0,0 +1,59 @@ |
| +// 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/memory/ref_counted.h" |
| +#include "base/observer_list.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/threading/thread_local.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerRunLoop.h" |
| + |
| +#include <map> |
| + |
| +using WebKit::WebWorkerRunLoop; |
|
michaeln
2011/12/05 22:02:09
please avoid 'using' in .h files
dgrogan
2011/12/06 00:15:15
fixed
|
| + |
| +class WorkerTaskRunner : public base::RefCountedThreadSafe<WorkerTaskRunner> { |
| + public: |
| + WorkerTaskRunner(); |
| + ~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
|
| + // 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
|
| + // this class. |
| + void PostTask(int id, WebKit::WebWorkerRunLoop::Task* closure); |
| + int CurrentWorkerId(); |
| + |
| + class Observer { |
| + public: |
| + virtual ~Observer() { } |
| + 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.
|
| + virtual void onLoopUnregistered() { } |
| + }; |
| + // 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. |
| + void RemoveObserver(Observer* obs); |
| + |
| + private: |
| + friend class RendererWebKitPlatformSupportImpl; |
| + |
| + typedef std::map<int, WebWorkerRunLoop> IDToLoopMap; |
| + |
| + 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.
|
| + void UnRegisterCurrentWorkerLoop(const WebWorkerRunLoop& loop); |
| + |
| + base::ThreadLocalPointer<std::pair<int, WebWorkerRunLoop> > current_tls_; |
| + |
| + base::Lock lock_; |
| + int id_sequence_; |
| + IDToLoopMap loop_map_; |
| + |
| + ObserverList<Observer> observer_list_; |
| + base::Lock observer_lock_; |
| +}; |
| + |
| +#endif // CONTENT_COMMON_SOCKET_STREAM_H_ |