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 #include "content/renderer/indexed_db_dispatcher.h" | 5 #include "content/renderer/indexed_db_dispatcher.h" |
6 | 6 |
7 #include "content/common/indexed_db_messages.h" | 7 #include "content/common/indexed_db_messages.h" |
8 #include "content/renderer/render_thread_impl.h" | 8 #include "content/renderer/render_thread_impl.h" |
9 #include "content/renderer/render_view_impl.h" | 9 #include "content/renderer/render_view_impl.h" |
10 #include "content/renderer/renderer_webidbcursor_impl.h" | 10 #include "content/renderer/renderer_webidbcursor_impl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 using WebKit::WebExceptionCode; | 24 using WebKit::WebExceptionCode; |
25 using WebKit::WebFrame; | 25 using WebKit::WebFrame; |
26 using WebKit::WebIDBCallbacks; | 26 using WebKit::WebIDBCallbacks; |
27 using WebKit::WebIDBKeyRange; | 27 using WebKit::WebIDBKeyRange; |
28 using WebKit::WebIDBDatabase; | 28 using WebKit::WebIDBDatabase; |
29 using WebKit::WebIDBDatabaseCallbacks; | 29 using WebKit::WebIDBDatabaseCallbacks; |
30 using WebKit::WebIDBDatabaseError; | 30 using WebKit::WebIDBDatabaseError; |
31 using WebKit::WebIDBTransaction; | 31 using WebKit::WebIDBTransaction; |
32 using WebKit::WebIDBTransactionCallbacks; | 32 using WebKit::WebIDBTransactionCallbacks; |
33 | 33 |
34 IndexedDBDispatcher::IndexedDBDispatcher() { | 34 IndexedDBDispatcher::IndexedDBDispatcher(IndexedDBMessageFilter* filter) : |
| 35 pending_callbacks_(filter), |
| 36 pending_transaction_callbacks_(filter), |
| 37 pending_database_callbacks_(filter) { |
35 } | 38 } |
36 | 39 |
37 IndexedDBDispatcher::~IndexedDBDispatcher() { | 40 IndexedDBDispatcher::~IndexedDBDispatcher() { |
38 } | 41 } |
39 | 42 |
40 bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { | 43 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { |
41 bool handled = true; | 44 bool handled = true; |
42 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) | 45 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) |
43 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, | 46 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, |
44 OnSuccessOpenCursor) | 47 OnSuccessOpenCursor) |
45 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, | 48 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, |
46 OnSuccessCursorContinue) | 49 OnSuccessCursorContinue) |
47 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, | 50 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, |
48 OnSuccessIDBDatabase) | 51 OnSuccessIDBDatabase) |
49 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, | 52 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, |
50 OnSuccessIndexedDBKey) | 53 OnSuccessIndexedDBKey) |
51 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction, | 54 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction, |
52 OnSuccessIDBTransaction) | 55 OnSuccessIDBTransaction) |
53 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, | 56 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, |
54 OnSuccessStringList) | 57 OnSuccessStringList) |
55 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue, | 58 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue, |
56 OnSuccessSerializedScriptValue) | 59 OnSuccessSerializedScriptValue) |
57 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 60 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
58 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksBlocked, OnBlocked) | 61 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksBlocked, OnBlocked) |
59 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort) | 62 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort) |
60 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete) | 63 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete) |
61 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, | 64 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, |
62 OnVersionChange) | 65 OnVersionChange) |
63 IPC_MESSAGE_UNHANDLED(handled = false) | 66 IPC_MESSAGE_UNHANDLED(handled = false) |
64 IPC_END_MESSAGE_MAP() | 67 IPC_END_MESSAGE_MAP() |
65 return handled; | 68 // If a message gets here, IndexedDBMessageFilter already determined that it |
| 69 // is an IndexedDB message. |
| 70 DCHECK(handled); |
66 } | 71 } |
67 | 72 |
68 void IndexedDBDispatcher::Send(IPC::Message* msg) { | 73 void IndexedDBDispatcher::Send(IPC::Message* msg) { |
69 ChildThread::current()->Send(msg); | 74 ChildThread::current()->Send(msg); |
70 } | 75 } |
71 | 76 |
72 void IndexedDBDispatcher::RequestIDBCursorUpdate( | 77 void IndexedDBDispatcher::RequestIDBCursorUpdate( |
73 const content::SerializedScriptValue& value, | 78 const content::SerializedScriptValue& value, |
74 WebIDBCallbacks* callbacks_ptr, | 79 WebIDBCallbacks* callbacks_ptr, |
75 int32 idb_cursor_id, | 80 int32 idb_cursor_id, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 167 |
163 IndexedDBHostMsg_FactoryDeleteDatabase_Params params; | 168 IndexedDBHostMsg_FactoryDeleteDatabase_Params params; |
164 params.response_id = pending_callbacks_.Add(callbacks.release()); | 169 params.response_id = pending_callbacks_.Add(callbacks.release()); |
165 params.origin = origin; | 170 params.origin = origin; |
166 params.name = name; | 171 params.name = name; |
167 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); | 172 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); |
168 } | 173 } |
169 | 174 |
170 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32 idb_database_id) { | 175 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32 idb_database_id) { |
171 Send(new IndexedDBHostMsg_DatabaseClose(idb_database_id)); | 176 Send(new IndexedDBHostMsg_DatabaseClose(idb_database_id)); |
172 pending_database_callbacks_.Remove(idb_database_id); | 177 int callbacks_id = database_id_to_callbacks_id_[idb_database_id]; |
| 178 DCHECK(callbacks_id); |
| 179 pending_database_callbacks_.Remove(callbacks_id); |
| 180 database_id_to_callbacks_id_.erase(idb_database_id); |
173 } | 181 } |
174 | 182 |
175 void IndexedDBDispatcher::RequestIDBDatabaseOpen( | 183 void IndexedDBDispatcher::RequestIDBDatabaseOpen( |
176 WebIDBDatabaseCallbacks* callbacks_ptr, | 184 WebIDBDatabaseCallbacks* callbacks_ptr, |
177 int32 idb_database_id) { | 185 int32 idb_database_id) { |
178 scoped_ptr<WebIDBDatabaseCallbacks> callbacks(callbacks_ptr); | 186 scoped_ptr<WebIDBDatabaseCallbacks> callbacks(callbacks_ptr); |
179 | 187 |
180 int32 response_id = pending_database_callbacks_.Add(callbacks.release()); | 188 int response_id = pending_database_callbacks_.Add(callbacks.release()); |
181 Send(new IndexedDBHostMsg_DatabaseOpen(response_id, idb_database_id)); | 189 Send(new IndexedDBHostMsg_DatabaseOpen(idb_database_id, response_id)); |
| 190 DCHECK(!database_id_to_callbacks_id_[idb_database_id]); |
| 191 database_id_to_callbacks_id_[idb_database_id] = response_id; |
182 } | 192 } |
183 | 193 |
184 void IndexedDBDispatcher::RequestIDBDatabaseSetVersion( | 194 void IndexedDBDispatcher::RequestIDBDatabaseSetVersion( |
185 const string16& version, | 195 const string16& version, |
186 WebIDBCallbacks* callbacks_ptr, | 196 WebIDBCallbacks* callbacks_ptr, |
187 int32 idb_database_id, | 197 int32 idb_database_id, |
188 WebExceptionCode* ec) { | 198 WebExceptionCode* ec) { |
189 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 199 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
190 | 200 |
191 int32 response_id = pending_callbacks_.Add(callbacks.release()); | 201 int32 response_id = pending_callbacks_.Add(callbacks.release()); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 void IndexedDBDispatcher::OnVersionChange(int32 database_id, | 503 void IndexedDBDispatcher::OnVersionChange(int32 database_id, |
494 const string16& newVersion) { | 504 const string16& newVersion) { |
495 WebIDBDatabaseCallbacks* callbacks = | 505 WebIDBDatabaseCallbacks* callbacks = |
496 pending_database_callbacks_.Lookup(database_id); | 506 pending_database_callbacks_.Lookup(database_id); |
497 // callbacks would be NULL if a versionchange event is received after close | 507 // callbacks would be NULL if a versionchange event is received after close |
498 // has been called. | 508 // has been called. |
499 if (!callbacks) | 509 if (!callbacks) |
500 return; | 510 return; |
501 callbacks->onVersionChange(newVersion); | 511 callbacks->onVersionChange(newVersion); |
502 } | 512 } |
OLD | NEW |