Chromium Code Reviews

Side by Side Diff: content/common/worker_task_runner.h

Issue 8747002: Dispatch IndexedDB IPC messages to worker threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: repurpose obsolete indexed-db switch to control idb on workers Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
(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;
18
19 class WorkerTaskRunner : public base::RefCountedThreadSafe<WorkerTaskRunner> {
20 public:
21 WorkerTaskRunner();
22 ~WorkerTaskRunner();
23 // This could be changed to take a chromium closure that is then wrapped by
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() { }
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);
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_
OLDNEW

Powered by Google App Engine