Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / child / worker_task_runner.h
blob6230551989b5d457677df988acb9d954c6fb8bf7
1 // Copyright 2014 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.
5 #ifndef CONTENT_CHILD_WORKER_TASK_RUNNER_H_
6 #define CONTENT_CHILD_WORKER_TASK_RUNNER_H_
8 #include <map>
10 #include "base/atomic_sequence_num.h"
11 #include "base/callback_forward.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_local.h"
14 #include "content/common/content_export.h"
15 #include "third_party/WebKit/public/platform/WebWorkerRunLoop.h"
17 namespace content {
19 class CONTENT_EXPORT WorkerTaskRunner {
20 public:
21 WorkerTaskRunner();
23 bool PostTask(int id, const base::Closure& task);
24 int PostTaskToAllThreads(const base::Closure& task);
25 int CurrentWorkerId();
26 static WorkerTaskRunner* Instance();
28 class CONTENT_EXPORT Observer {
29 public:
30 virtual ~Observer() {}
31 virtual void OnWorkerRunLoopStopped() = 0;
33 // Add/Remove an observer that will get notified when the current worker run
34 // loop is stopping. This observer will not get notified when other threads
35 // are stopping. It's only valid to call these on a worker thread.
36 void AddStopObserver(Observer* observer);
37 void RemoveStopObserver(Observer* observer);
39 void OnWorkerRunLoopStarted(const blink::WebWorkerRunLoop& loop);
40 void OnWorkerRunLoopStopped(const blink::WebWorkerRunLoop& loop);
42 private:
43 friend class WorkerTaskRunnerTest;
45 typedef std::map<int, blink::WebWorkerRunLoop> IDToLoopMap;
47 ~WorkerTaskRunner();
49 struct ThreadLocalState;
50 base::ThreadLocalPointer<ThreadLocalState> current_tls_;
52 base::AtomicSequenceNumber id_sequence_;
53 IDToLoopMap loop_map_;
54 base::Lock loop_map_lock_;
57 } // namespace content
59 #endif // CONTENT_CHILD_WORKER_TASK_RUNNER_H_