OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/strings/nullable_string16.h" | 14 #include "base/strings/nullable_string16.h" |
| 15 #include "content/child/worker_task_runner.h" |
15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
16 #include "ipc/ipc_sync_message_filter.h" | 17 #include "ipc/ipc_sync_message_filter.h" |
17 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | 18 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" |
18 #include "third_party/WebKit/public/platform/WebIDBCursor.h" | 19 #include "third_party/WebKit/public/platform/WebIDBCursor.h" |
19 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | 20 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" |
20 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" | 21 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" |
21 #include "webkit/child/worker_task_runner.h" | |
22 | 22 |
23 struct IndexedDBDatabaseMetadata; | 23 struct IndexedDBDatabaseMetadata; |
24 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; | 24 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; |
25 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; | 25 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; |
26 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; | 26 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; |
27 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; | 27 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; |
28 | 28 |
29 namespace blink { | 29 namespace blink { |
30 class WebData; | 30 class WebData; |
31 } | 31 } |
32 | 32 |
33 namespace content { | 33 namespace content { |
34 class IndexedDBKey; | 34 class IndexedDBKey; |
35 class IndexedDBKeyPath; | 35 class IndexedDBKeyPath; |
36 class IndexedDBKeyRange; | 36 class IndexedDBKeyRange; |
37 class WebIDBCursorImpl; | 37 class WebIDBCursorImpl; |
38 class WebIDBDatabaseImpl; | 38 class WebIDBDatabaseImpl; |
39 class ThreadSafeSender; | 39 class ThreadSafeSender; |
40 | 40 |
41 CONTENT_EXPORT extern const size_t kMaxIDBValueSizeInBytes; | 41 CONTENT_EXPORT extern const size_t kMaxIDBValueSizeInBytes; |
42 | 42 |
43 // Handle the indexed db related communication for this context thread - the | 43 // Handle the indexed db related communication for this context thread - the |
44 // main thread and each worker thread have their own copies. | 44 // main thread and each worker thread have their own copies. |
45 class CONTENT_EXPORT IndexedDBDispatcher | 45 class CONTENT_EXPORT IndexedDBDispatcher : public WorkerTaskRunner::Observer { |
46 : public webkit_glue::WorkerTaskRunner::Observer { | |
47 public: | 46 public: |
48 // Constructor made public to allow RenderThreadImpl to own a copy without | 47 // Constructor made public to allow RenderThreadImpl to own a copy without |
49 // failing a NOTREACHED in ThreadSpecificInstance in tests that instantiate | 48 // failing a NOTREACHED in ThreadSpecificInstance in tests that instantiate |
50 // two copies of RenderThreadImpl on the same thread. Everyone else probably | 49 // two copies of RenderThreadImpl on the same thread. Everyone else probably |
51 // wants to use ThreadSpecificInstance(). | 50 // wants to use ThreadSpecificInstance(). |
52 explicit IndexedDBDispatcher(ThreadSafeSender* thread_safe_sender); | 51 explicit IndexedDBDispatcher(ThreadSafeSender* thread_safe_sender); |
53 virtual ~IndexedDBDispatcher(); | 52 virtual ~IndexedDBDispatcher(); |
54 | 53 |
55 // |thread_safe_sender| needs to be passed in because if the call leads to | 54 // |thread_safe_sender| needs to be passed in because if the call leads to |
56 // construction it will be needed. | 55 // construction it will be needed. |
57 static IndexedDBDispatcher* ThreadSpecificInstance( | 56 static IndexedDBDispatcher* ThreadSpecificInstance( |
58 ThreadSafeSender* thread_safe_sender); | 57 ThreadSafeSender* thread_safe_sender); |
59 | 58 |
60 // webkit_glue::WorkerTaskRunner::Observer implementation. | 59 // WorkerTaskRunner::Observer implementation. |
61 virtual void OnWorkerRunLoopStopped() OVERRIDE; | 60 virtual void OnWorkerRunLoopStopped() OVERRIDE; |
62 | 61 |
63 static blink::WebIDBMetadata ConvertMetadata( | 62 static blink::WebIDBMetadata ConvertMetadata( |
64 const IndexedDBDatabaseMetadata& idb_metadata); | 63 const IndexedDBDatabaseMetadata& idb_metadata); |
65 | 64 |
66 void OnMessageReceived(const IPC::Message& msg); | 65 void OnMessageReceived(const IPC::Message& msg); |
67 | 66 |
68 // This method is virtual so it can be overridden in unit tests. | 67 // This method is virtual so it can be overridden in unit tests. |
69 virtual bool Send(IPC::Message* msg); | 68 virtual bool Send(IPC::Message* msg); |
70 | 69 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 void DatabaseDestroyed(int32 ipc_database_id); | 168 void DatabaseDestroyed(int32 ipc_database_id); |
170 | 169 |
171 private: | 170 private: |
172 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); | 171 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); |
173 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); | 172 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); |
174 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest); | 173 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest); |
175 | 174 |
176 enum { kAllCursors = -1 }; | 175 enum { kAllCursors = -1 }; |
177 | 176 |
178 static int32 CurrentWorkerId() { | 177 static int32 CurrentWorkerId() { |
179 return webkit_glue::WorkerTaskRunner::Instance()->CurrentWorkerId(); | 178 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
180 } | 179 } |
181 | 180 |
182 template <typename T> | 181 template <typename T> |
183 void init_params(T& params, blink::WebIDBCallbacks* callbacks_ptr) { | 182 void init_params(T& params, blink::WebIDBCallbacks* callbacks_ptr) { |
184 scoped_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); | 183 scoped_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); |
185 params.ipc_thread_id = CurrentWorkerId(); | 184 params.ipc_thread_id = CurrentWorkerId(); |
186 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | 185 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); |
187 } | 186 } |
188 | 187 |
189 // IDBCallback message handlers. | 188 // IDBCallback message handlers. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 std::map<int32, WebIDBCursorImpl*> cursors_; | 259 std::map<int32, WebIDBCursorImpl*> cursors_; |
261 | 260 |
262 std::map<int32, WebIDBDatabaseImpl*> databases_; | 261 std::map<int32, WebIDBDatabaseImpl*> databases_; |
263 | 262 |
264 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 263 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); |
265 }; | 264 }; |
266 | 265 |
267 } // namespace content | 266 } // namespace content |
268 | 267 |
269 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 268 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
OLD | NEW |