OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_RENDERER_INDEXED_DB_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ |
6 #define CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
13 #include "base/nullable_string16.h" | 13 #include "base/nullable_string16.h" |
| 14 #include "content/common/child_thread.h" |
| 15 #include "content/renderer/indexed_db_message_filter.h" |
14 #include "ipc/ipc_channel.h" | 16 #include "ipc/ipc_channel.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCall
backs.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCall
backs.h" |
20 | 22 |
21 class IndexedDBKey; | 23 class IndexedDBKey; |
22 class RendererWebIDBCursorImpl; | 24 class RendererWebIDBCursorImpl; |
23 | 25 |
24 namespace WebKit { | 26 namespace WebKit { |
25 class WebFrame; | 27 class WebFrame; |
26 class WebIDBKeyRange; | 28 class WebIDBKeyRange; |
27 class WebIDBTransaction; | 29 class WebIDBTransaction; |
28 } | 30 } |
29 | 31 |
30 namespace content { | 32 namespace content { |
31 class SerializedScriptValue; | 33 class SerializedScriptValue; |
32 } | 34 } |
33 | 35 |
34 // Handle the indexed db related communication for this entire renderer. | 36 // Handle the indexed db related communication for this entire renderer. |
35 class IndexedDBDispatcher : public IPC::Channel::Listener { | 37 class IndexedDBDispatcher { |
36 public: | 38 public: |
37 IndexedDBDispatcher(); | 39 IndexedDBDispatcher(IndexedDBMessageFilter*); |
38 virtual ~IndexedDBDispatcher(); | 40 virtual ~IndexedDBDispatcher(); |
39 | 41 |
40 // IPC::Channel::Listener implementation. | 42 void OnMessageReceived(const IPC::Message& msg); |
41 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | |
42 void Send(IPC::Message* msg); | 43 void Send(IPC::Message* msg); |
43 | 44 |
44 void RequestIDBFactoryGetDatabaseNames( | 45 void RequestIDBFactoryGetDatabaseNames( |
45 WebKit::WebIDBCallbacks* callbacks, | 46 WebKit::WebIDBCallbacks* callbacks, |
46 const string16& origin, | 47 const string16& origin, |
47 WebKit::WebFrame* web_frame); | 48 WebKit::WebFrame* web_frame); |
48 | 49 |
49 void RequestIDBFactoryOpen( | 50 void RequestIDBFactoryOpen( |
50 const string16& name, | 51 const string16& name, |
51 WebKit::WebIDBCallbacks* callbacks, | 52 WebKit::WebIDBCallbacks* callbacks, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 const std::vector<string16>& value); | 179 const std::vector<string16>& value); |
179 void OnSuccessSerializedScriptValue( | 180 void OnSuccessSerializedScriptValue( |
180 int32 response_id, | 181 int32 response_id, |
181 const content::SerializedScriptValue& value); | 182 const content::SerializedScriptValue& value); |
182 void OnError(int32 response_id, int code, const string16& message); | 183 void OnError(int32 response_id, int code, const string16& message); |
183 void OnBlocked(int32 response_id); | 184 void OnBlocked(int32 response_id); |
184 void OnAbort(int32 transaction_id); | 185 void OnAbort(int32 transaction_id); |
185 void OnComplete(int32 transaction_id); | 186 void OnComplete(int32 transaction_id); |
186 void OnVersionChange(int32 database_id, const string16& newVersion); | 187 void OnVersionChange(int32 database_id, const string16& newVersion); |
187 | 188 |
| 189 // This class facilitates mapping callback ids specified in incoming IPC |
| 190 // messages to threads. It: |
| 191 // * Retrieves process-unique ids for each stored WebIDBCallbacks object. The |
| 192 // browser process includes these ids in messages sent back to us. |
| 193 // * Registers incoming transaction and database callback ids that are created |
| 194 // in the browser process. We'll need to revisit this scheme if the browser |
| 195 // stops generating unique ids. |
| 196 // * Ensures, through IDMap, that it is only called on a single thread. |
| 197 template<class CallbackType> |
| 198 class CallbackIDMap { |
| 199 public: |
| 200 CallbackIDMap(IndexedDBMessageFilter* filter) : filter_(filter) { |
| 201 } |
| 202 void AddWithID(CallbackType* callbacks, int32 id) { |
| 203 filter_->NotifyAddWithIDForType(id, callbacks); |
| 204 map_.AddWithID(callbacks, id); |
| 205 } |
| 206 int32 Add(CallbackType* callbacks) { |
| 207 int id = filter_->GetUniqueID(); |
| 208 map_.AddWithID(callbacks, id); |
| 209 return id; |
| 210 } |
| 211 void Remove(int32 id) { |
| 212 filter_->RemoveForType(id, (CallbackType*)NULL); |
| 213 map_.Remove(id); |
| 214 } |
| 215 CallbackType* Lookup(int32 id) { |
| 216 return map_.Lookup(id); |
| 217 } |
| 218 private: |
| 219 // The filter is alive for the life of the process, nothing deletes it. |
| 220 IndexedDBMessageFilter* filter_; |
| 221 IDMap<CallbackType, IDMapOwnPointer> map_; |
| 222 }; |
| 223 |
188 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | 224 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be |
189 // destroyed and used on the same thread it was created on. | 225 // destroyed and used on the same thread it was created on. |
190 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | 226 CallbackIDMap<WebKit::WebIDBCallbacks> pending_callbacks_; |
191 IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer> | 227 CallbackIDMap<WebKit::WebIDBTransactionCallbacks> |
192 pending_transaction_callbacks_; | 228 pending_transaction_callbacks_; |
193 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> | 229 CallbackIDMap<WebKit::WebIDBDatabaseCallbacks> pending_database_callbacks_; |
194 pending_database_callbacks_; | |
195 | 230 |
196 // Map from cursor id to RendererWebIDBCursorImpl. | 231 // Map from cursor id to RendererWebIDBCursorImpl. |
197 std::map<int32, RendererWebIDBCursorImpl*> cursors_; | 232 std::map<int32, RendererWebIDBCursorImpl*> cursors_; |
198 | 233 |
199 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 234 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); |
200 }; | 235 }; |
201 | 236 |
202 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ | 237 #endif // CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ |
OLD | NEW |