OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/in_process_webkit/indexed_db_dispatcher_host.h" | 5 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 30 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
31 #include "webkit/base/file_path_string_conversions.h" | 31 #include "webkit/base/file_path_string_conversions.h" |
32 #include "webkit/browser/database/database_util.h" | 32 #include "webkit/browser/database/database_util.h" |
33 #include "webkit/common/database/database_identifier.h" | 33 #include "webkit/common/database/database_identifier.h" |
34 | 34 |
35 using webkit_database::DatabaseUtil; | 35 using webkit_database::DatabaseUtil; |
36 using WebKit::WebIDBDatabaseError; | 36 using WebKit::WebIDBDatabaseError; |
37 using WebKit::WebIDBKey; | 37 using WebKit::WebIDBKey; |
38 | 38 |
39 namespace content { | 39 namespace content { |
40 namespace { | |
41 | |
42 template <class T> | |
43 void DeleteOnWebKitThread(T* obj) { | |
44 if (!BrowserThread::DeleteSoon( | |
45 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, obj)) | |
46 delete obj; | |
47 } | |
48 } | |
49 | 40 |
50 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 41 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
51 int ipc_process_id, | 42 int ipc_process_id, |
52 IndexedDBContextImpl* indexed_db_context) | 43 IndexedDBContextImpl* indexed_db_context) |
53 : indexed_db_context_(indexed_db_context), | 44 : indexed_db_context_(indexed_db_context), |
54 database_dispatcher_host_(new DatabaseDispatcherHost(this)), | 45 database_dispatcher_host_(new DatabaseDispatcherHost(this)), |
55 cursor_dispatcher_host_(new CursorDispatcherHost(this)), | 46 cursor_dispatcher_host_(new CursorDispatcherHost(this)), |
56 ipc_process_id_(ipc_process_id) { | 47 ipc_process_id_(ipc_process_id) { |
57 DCHECK(indexed_db_context_.get()); | 48 DCHECK(indexed_db_context_.get()); |
58 } | 49 } |
59 | 50 |
60 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} | 51 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} |
61 | 52 |
62 void IndexedDBDispatcherHost::OnChannelClosing() { | 53 void IndexedDBDispatcherHost::OnChannelClosing() { |
63 BrowserMessageFilter::OnChannelClosing(); | 54 BrowserMessageFilter::OnChannelClosing(); |
64 | 55 |
65 bool success = BrowserThread::PostTask( | 56 bool success = indexed_db_context_->TaskRunner()->PostTask( |
66 BrowserThread::WEBKIT_DEPRECATED, | |
67 FROM_HERE, | 57 FROM_HERE, |
68 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); | 58 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); |
69 | 59 |
70 if (!success) | 60 if (!success) |
71 ResetDispatcherHosts(); | 61 ResetDispatcherHosts(); |
72 } | 62 } |
73 | 63 |
| 64 void IndexedDBDispatcherHost::OnDestruct() const { |
| 65 // The last reference to the dispatcher may be a posted task, which would |
| 66 // be destructed on the IndexedDB thread. Without this override, that would |
| 67 // take the dispatcher with it. Since the dispatcher may be keeping the |
| 68 // IndexedDBContext alive, it might be destructed to on its own thread, |
| 69 // which is not supported. Ensure destruction runs on the IO thread instead. |
| 70 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 71 } |
| 72 |
74 void IndexedDBDispatcherHost::ResetDispatcherHosts() { | 73 void IndexedDBDispatcherHost::ResetDispatcherHosts() { |
75 // It is important that the various *_dispatcher_host_ members are reset | 74 // It is important that the various *_dispatcher_host_ members are reset |
76 // on the WebKit thread, since there might be incoming messages on that | 75 // on the IndexedDB thread, since there might be incoming messages on that |
77 // thread, and we must not reset the dispatcher hosts until after those | 76 // thread, and we must not reset the dispatcher hosts until after those |
78 // messages are processed. | 77 // messages are processed. |
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED) || | 78 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
80 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)); | |
81 | 79 |
82 // Note that we explicitly separate CloseAll() from destruction of the | 80 // Note that we explicitly separate CloseAll() from destruction of the |
83 // DatabaseDispatcherHost, since CloseAll() can invoke callbacks which need to | 81 // DatabaseDispatcherHost, since CloseAll() can invoke callbacks which need to |
84 // be dispatched through database_dispatcher_host_. | 82 // be dispatched through database_dispatcher_host_. |
85 database_dispatcher_host_->CloseAll(); | 83 database_dispatcher_host_->CloseAll(); |
86 database_dispatcher_host_.reset(); | 84 database_dispatcher_host_.reset(); |
87 cursor_dispatcher_host_.reset(); | 85 cursor_dispatcher_host_.reset(); |
88 } | 86 } |
89 | 87 |
90 void IndexedDBDispatcherHost::OverrideThreadForMessage( | 88 base::TaskRunner* IndexedDBDispatcherHost::OverrideTaskRunnerForMessage( |
91 const IPC::Message& message, | 89 const IPC::Message& message) { |
92 BrowserThread::ID* thread) { | |
93 if (IPC_MESSAGE_CLASS(message) == IndexedDBMsgStart) | 90 if (IPC_MESSAGE_CLASS(message) == IndexedDBMsgStart) |
94 *thread = BrowserThread::WEBKIT_DEPRECATED; | 91 return indexed_db_context_->TaskRunner(); |
| 92 return NULL; |
95 } | 93 } |
96 | 94 |
97 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message, | 95 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message, |
98 bool* message_was_ok) { | 96 bool* message_was_ok) { |
99 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) | 97 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) |
100 return false; | 98 return false; |
101 | 99 |
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 100 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
103 | 101 |
104 bool handled = | 102 bool handled = |
105 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) || | 103 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) || |
106 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); | 104 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); |
107 | 105 |
108 if (!handled) { | 106 if (!handled) { |
109 handled = true; | 107 handled = true; |
110 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) | 108 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) |
111 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, | 109 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, |
112 OnIDBFactoryGetDatabaseNames) | 110 OnIDBFactoryGetDatabaseNames) |
113 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) | 111 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) |
114 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, | 112 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, |
115 OnIDBFactoryDeleteDatabase) | 113 OnIDBFactoryDeleteDatabase) |
116 IPC_MESSAGE_UNHANDLED(handled = false) | 114 IPC_MESSAGE_UNHANDLED(handled = false) |
117 IPC_END_MESSAGE_MAP() | 115 IPC_END_MESSAGE_MAP() |
118 } | 116 } |
119 return handled; | 117 return handled; |
120 } | 118 } |
121 | 119 |
122 int32 IndexedDBDispatcherHost::Add(WebIDBCursorImpl* idb_cursor) { | 120 int32 IndexedDBDispatcherHost::Add(WebIDBCursorImpl* idb_cursor) { |
123 if (!cursor_dispatcher_host_) { | 121 if (!cursor_dispatcher_host_) { |
124 delete idb_cursor; | 122 delete idb_cursor; |
125 return 0; | 123 return 0; |
126 } | 124 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 160 |
163 int64 IndexedDBDispatcherHost::RendererTransactionId( | 161 int64 IndexedDBDispatcherHost::RendererTransactionId( |
164 int64 host_transaction_id) { | 162 int64 host_transaction_id) { |
165 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle())) | 163 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle())) |
166 << "Invalid renderer target for transaction id"; | 164 << "Invalid renderer target for transaction id"; |
167 return host_transaction_id & 0xffffffff; | 165 return host_transaction_id & 0xffffffff; |
168 } | 166 } |
169 | 167 |
170 WebIDBCursorImpl* IndexedDBDispatcherHost::GetCursorFromId( | 168 WebIDBCursorImpl* IndexedDBDispatcherHost::GetCursorFromId( |
171 int32 ipc_cursor_id) { | 169 int32 ipc_cursor_id) { |
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 170 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
173 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); | 171 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); |
174 } | 172 } |
175 | 173 |
176 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( | 174 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( |
177 const content::IndexedDBDatabaseMetadata& web_metadata) { | 175 const content::IndexedDBDatabaseMetadata& web_metadata) { |
178 ::IndexedDBDatabaseMetadata metadata; | 176 ::IndexedDBDatabaseMetadata metadata; |
179 metadata.id = web_metadata.id; | 177 metadata.id = web_metadata.id; |
180 metadata.name = web_metadata.name; | 178 metadata.name = web_metadata.name; |
181 metadata.version = web_metadata.version; | 179 metadata.version = web_metadata.version; |
182 metadata.int_version = web_metadata.int_version; | 180 metadata.int_version = web_metadata.int_version; |
(...skipping 27 matching lines...) Expand all Loading... |
210 idb_index_metadata.multiEntry = web_index_metadata.multi_entry; | 208 idb_index_metadata.multiEntry = web_index_metadata.multi_entry; |
211 idb_store_metadata.indexes.push_back(idb_index_metadata); | 209 idb_store_metadata.indexes.push_back(idb_index_metadata); |
212 } | 210 } |
213 metadata.object_stores.push_back(idb_store_metadata); | 211 metadata.object_stores.push_back(idb_store_metadata); |
214 } | 212 } |
215 return metadata; | 213 return metadata; |
216 } | 214 } |
217 | 215 |
218 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( | 216 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( |
219 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { | 217 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 218 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
221 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 219 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
222 | 220 |
223 Context()->GetIDBFactory()->getDatabaseNames( | 221 Context()->GetIDBFactory()->getDatabaseNames( |
224 new IndexedDBCallbacks<std::vector<string16> >( | 222 new IndexedDBCallbacks<std::vector<string16> >( |
225 this, params.ipc_thread_id, params.ipc_callbacks_id), | 223 this, params.ipc_thread_id, params.ipc_callbacks_id), |
226 WebKit::WebString::fromUTF8(params.database_identifier), | 224 WebKit::WebString::fromUTF8(params.database_identifier), |
227 webkit_base::FilePathToWebString(indexed_db_path)); | 225 webkit_base::FilePathToWebString(indexed_db_path)); |
228 } | 226 } |
229 | 227 |
230 void IndexedDBDispatcherHost::OnIDBFactoryOpen( | 228 void IndexedDBDispatcherHost::OnIDBFactoryOpen( |
231 const IndexedDBHostMsg_FactoryOpen_Params& params) { | 229 const IndexedDBHostMsg_FactoryOpen_Params& params) { |
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 230 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
233 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 231 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
234 | 232 |
235 GURL origin_url = | 233 GURL origin_url = |
236 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 234 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
237 | 235 |
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | |
239 | |
240 int64 host_transaction_id = HostTransactionId(params.transaction_id); | 236 int64 host_transaction_id = HostTransactionId(params.transaction_id); |
241 | 237 |
242 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 238 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
243 // created) if this origin is already over quota. | 239 // created) if this origin is already over quota. |
244 Context()->GetIDBFactory() | 240 Context()->GetIDBFactory() |
245 ->open(params.name, | 241 ->open(params.name, |
246 params.version, | 242 params.version, |
247 host_transaction_id, | 243 host_transaction_id, |
248 new IndexedDBCallbacksDatabase(this, | 244 new IndexedDBCallbacksDatabase(this, |
249 params.ipc_thread_id, | 245 params.ipc_thread_id, |
250 params.ipc_callbacks_id, | 246 params.ipc_callbacks_id, |
251 params.ipc_database_callbacks_id, | 247 params.ipc_database_callbacks_id, |
252 host_transaction_id, | 248 host_transaction_id, |
253 origin_url), | 249 origin_url), |
254 new IndexedDBDatabaseCallbacks( | 250 new IndexedDBDatabaseCallbacks( |
255 this, params.ipc_thread_id, params.ipc_database_callbacks_id), | 251 this, params.ipc_thread_id, params.ipc_database_callbacks_id), |
256 WebKit::WebString::fromUTF8(params.database_identifier), | 252 WebKit::WebString::fromUTF8(params.database_identifier), |
257 webkit_base::FilePathToWebString(indexed_db_path)); | 253 webkit_base::FilePathToWebString(indexed_db_path)); |
258 } | 254 } |
259 | 255 |
260 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( | 256 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( |
261 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { | 257 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { |
| 258 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
262 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 259 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
263 | 260 |
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | |
265 Context()->GetIDBFactory() | 261 Context()->GetIDBFactory() |
266 ->deleteDatabase(params.name, | 262 ->deleteDatabase(params.name, |
267 new IndexedDBCallbacks<std::vector<char> >( | 263 new IndexedDBCallbacks<std::vector<char> >( |
268 this, params.ipc_thread_id, params.ipc_callbacks_id), | 264 this, params.ipc_thread_id, params.ipc_callbacks_id), |
269 WebKit::WebString::fromUTF8(params.database_identifier), | 265 WebKit::WebString::fromUTF8(params.database_identifier), |
270 webkit_base::FilePathToWebString(indexed_db_path)); | 266 webkit_base::FilePathToWebString(indexed_db_path)); |
271 } | 267 } |
272 | 268 |
273 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, | 269 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, |
274 bool committed) { | 270 bool committed) { |
| 271 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
275 TransactionIDToURLMap& transaction_url_map = | 272 TransactionIDToURLMap& transaction_url_map = |
276 database_dispatcher_host_->transaction_url_map_; | 273 database_dispatcher_host_->transaction_url_map_; |
277 TransactionIDToSizeMap& transaction_size_map = | 274 TransactionIDToSizeMap& transaction_size_map = |
278 database_dispatcher_host_->transaction_size_map_; | 275 database_dispatcher_host_->transaction_size_map_; |
279 TransactionIDToDatabaseIDMap& transaction_database_map = | 276 TransactionIDToDatabaseIDMap& transaction_database_map = |
280 database_dispatcher_host_->transaction_database_map_; | 277 database_dispatcher_host_->transaction_database_map_; |
281 if (committed) | 278 if (committed) |
282 Context()->TransactionComplete(transaction_url_map[host_transaction_id]); | 279 Context()->TransactionComplete(transaction_url_map[host_transaction_id]); |
283 // It's unclear if std::map::erase(key) has defined behavior if the | 280 // It's unclear if std::map::erase(key) has defined behavior if the |
284 // key is not found. | 281 // key is not found. |
(...skipping 10 matching lines...) Expand all Loading... |
295 } | 292 } |
296 | 293 |
297 ////////////////////////////////////////////////////////////////////// | 294 ////////////////////////////////////////////////////////////////////// |
298 // Helper templates. | 295 // Helper templates. |
299 // | 296 // |
300 | 297 |
301 template <typename ObjectType> | 298 template <typename ObjectType> |
302 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( | 299 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( |
303 IDMap<ObjectType, IDMapOwnPointer>* map, | 300 IDMap<ObjectType, IDMapOwnPointer>* map, |
304 int32 ipc_return_object_id) { | 301 int32 ipc_return_object_id) { |
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 302 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
306 ObjectType* return_object = map->Lookup(ipc_return_object_id); | 303 ObjectType* return_object = map->Lookup(ipc_return_object_id); |
307 if (!return_object) { | 304 if (!return_object) { |
308 NOTREACHED() << "Uh oh, couldn't find object with id " | 305 NOTREACHED() << "Uh oh, couldn't find object with id " |
309 << ipc_return_object_id; | 306 << ipc_return_object_id; |
310 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF")); | 307 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF")); |
311 BadMessageReceived(); | 308 BadMessageReceived(); |
312 } | 309 } |
313 return return_object; | 310 return return_object; |
314 } | 311 } |
315 | 312 |
(...skipping 15 matching lines...) Expand all Loading... |
331 map_.set_check_on_null_data(true); | 328 map_.set_check_on_null_data(true); |
332 } | 329 } |
333 | 330 |
334 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { | 331 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { |
335 // TODO(alecflett): uncomment these when we find the source of these leaks. | 332 // TODO(alecflett): uncomment these when we find the source of these leaks. |
336 // DCHECK(transaction_size_map_.empty()); | 333 // DCHECK(transaction_size_map_.empty()); |
337 // DCHECK(transaction_url_map_.empty()); | 334 // DCHECK(transaction_url_map_.empty()); |
338 } | 335 } |
339 | 336 |
340 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { | 337 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { |
| 338 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
341 // Abort outstanding transactions started by connections in the associated | 339 // Abort outstanding transactions started by connections in the associated |
342 // front-end to unblock later transactions. This should only occur on unclean | 340 // front-end to unblock later transactions. This should only occur on unclean |
343 // (crash) or abrupt (process-kill) shutdowns. | 341 // (crash) or abrupt (process-kill) shutdowns. |
344 for (TransactionIDToDatabaseIDMap::iterator iter = | 342 for (TransactionIDToDatabaseIDMap::iterator iter = |
345 transaction_database_map_.begin(); | 343 transaction_database_map_.begin(); |
346 iter != transaction_database_map_.end();) { | 344 iter != transaction_database_map_.end();) { |
347 int64 transaction_id = iter->first; | 345 int64 transaction_id = iter->first; |
348 int32 ipc_database_id = iter->second; | 346 int32 ipc_database_id = iter->second; |
349 ++iter; | 347 ++iter; |
350 WebIDBDatabaseImpl* database = map_.Lookup(ipc_database_id); | 348 WebIDBDatabaseImpl* database = map_.Lookup(ipc_database_id); |
(...skipping 12 matching lines...) Expand all Loading... |
363 if (database) { | 361 if (database) { |
364 database->close(); | 362 database->close(); |
365 parent_->Context()->ConnectionClosed(iter->second, database); | 363 parent_->Context()->ConnectionClosed(iter->second, database); |
366 } | 364 } |
367 } | 365 } |
368 } | 366 } |
369 | 367 |
370 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( | 368 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( |
371 const IPC::Message& message, | 369 const IPC::Message& message, |
372 bool* msg_is_ok) { | 370 bool* msg_is_ok) { |
| 371 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
373 bool handled = true; | 372 bool handled = true; |
374 IPC_BEGIN_MESSAGE_MAP_EX( | 373 IPC_BEGIN_MESSAGE_MAP_EX( |
375 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok) | 374 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok) |
376 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, | 375 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, |
377 OnCreateObjectStore) | 376 OnCreateObjectStore) |
378 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, | 377 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, |
379 OnDeleteObjectStore) | 378 OnDeleteObjectStore) |
380 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, | 379 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, |
381 OnCreateTransaction) | 380 OnCreateTransaction) |
382 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) | 381 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) |
383 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) | 382 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) |
384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) | 383 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) |
385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut) | 384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut) |
386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) | 385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) |
387 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, | 386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, |
388 OnSetIndexesReady) | 387 OnSetIndexesReady) |
389 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) | 388 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) |
390 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) | 389 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) |
391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) | 390 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) |
392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) | 391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) |
393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex) | 392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex) |
394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex) | 393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex) |
395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort) | 394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort) |
396 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit) | 395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit) |
397 IPC_MESSAGE_UNHANDLED(handled = false) | 396 IPC_MESSAGE_UNHANDLED(handled = false) |
398 IPC_END_MESSAGE_MAP() | 397 IPC_END_MESSAGE_MAP() |
399 return handled; | 398 return handled; |
400 } | 399 } |
401 | 400 |
402 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( | 401 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( |
403 IPC::Message* message) { | 402 IPC::Message* message) { |
404 parent_->Send(message); | 403 parent_->Send(message); |
405 } | 404 } |
406 | 405 |
407 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( | 406 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( |
408 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { | 407 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { |
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 408 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
410 WebIDBDatabaseImpl* database = | 409 WebIDBDatabaseImpl* database = |
411 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 410 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
412 if (!database) | 411 if (!database) |
413 return; | 412 return; |
414 | 413 |
415 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 414 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
416 database->createObjectStore(host_transaction_id, | 415 database->createObjectStore(host_transaction_id, |
417 params.object_store_id, | 416 params.object_store_id, |
418 params.name, | 417 params.name, |
419 params.key_path, | 418 params.key_path, |
420 params.auto_increment); | 419 params.auto_increment); |
421 if (parent_->Context()->IsOverQuota( | 420 if (parent_->Context()->IsOverQuota( |
422 database_url_map_[params.ipc_database_id])) { | 421 database_url_map_[params.ipc_database_id])) { |
423 database->abort( | 422 database->abort( |
424 host_transaction_id, | 423 host_transaction_id, |
425 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 424 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); |
426 } | 425 } |
427 } | 426 } |
428 | 427 |
429 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( | 428 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( |
430 int32 ipc_database_id, | 429 int32 ipc_database_id, |
431 int64 transaction_id, | 430 int64 transaction_id, |
432 int64 object_store_id) { | 431 int64 object_store_id) { |
433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 432 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
434 WebIDBDatabaseImpl* database = | 433 WebIDBDatabaseImpl* database = |
435 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 434 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
436 if (!database) | 435 if (!database) |
437 return; | 436 return; |
438 | 437 |
439 database->deleteObjectStore(parent_->HostTransactionId(transaction_id), | 438 database->deleteObjectStore(parent_->HostTransactionId(transaction_id), |
440 object_store_id); | 439 object_store_id); |
441 } | 440 } |
442 | 441 |
443 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( | 442 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( |
444 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { | 443 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { |
| 444 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
445 WebIDBDatabaseImpl* database = | 445 WebIDBDatabaseImpl* database = |
446 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 446 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
447 if (!database) | 447 if (!database) |
448 return; | 448 return; |
449 | 449 |
450 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 450 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
451 | 451 |
452 database->createTransaction( | 452 database->createTransaction( |
453 host_transaction_id, | 453 host_transaction_id, |
454 new IndexedDBDatabaseCallbacks( | 454 new IndexedDBDatabaseCallbacks( |
455 parent_, params.ipc_thread_id, params.ipc_database_callbacks_id), | 455 parent_, params.ipc_thread_id, params.ipc_database_callbacks_id), |
456 params.object_store_ids, | 456 params.object_store_ids, |
457 params.mode); | 457 params.mode); |
458 transaction_database_map_[host_transaction_id] = params.ipc_database_id; | 458 transaction_database_map_[host_transaction_id] = params.ipc_database_id; |
459 parent_->RegisterTransactionId(host_transaction_id, | 459 parent_->RegisterTransactionId(host_transaction_id, |
460 database_url_map_[params.ipc_database_id]); | 460 database_url_map_[params.ipc_database_id]); |
461 } | 461 } |
462 | 462 |
463 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( | 463 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( |
464 int32 ipc_database_id) { | 464 int32 ipc_database_id) { |
| 465 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
465 WebIDBDatabaseImpl* database = | 466 WebIDBDatabaseImpl* database = |
466 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 467 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
467 if (!database) | 468 if (!database) |
468 return; | 469 return; |
469 database->close(); | 470 database->close(); |
470 } | 471 } |
471 | 472 |
472 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( | 473 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( |
473 int32 ipc_object_id) { | 474 int32 ipc_object_id) { |
| 475 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
474 WebIDBDatabaseImpl* database = map_.Lookup(ipc_object_id); | 476 WebIDBDatabaseImpl* database = map_.Lookup(ipc_object_id); |
475 parent_->Context() | 477 parent_->Context() |
476 ->ConnectionClosed(database_url_map_[ipc_object_id], database); | 478 ->ConnectionClosed(database_url_map_[ipc_object_id], database); |
477 database_url_map_.erase(ipc_object_id); | 479 database_url_map_.erase(ipc_object_id); |
478 parent_->DestroyObject(&map_, ipc_object_id); | 480 parent_->DestroyObject(&map_, ipc_object_id); |
479 } | 481 } |
480 | 482 |
481 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( | 483 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( |
482 const IndexedDBHostMsg_DatabaseGet_Params& params) { | 484 const IndexedDBHostMsg_DatabaseGet_Params& params) { |
483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 485 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
484 WebIDBDatabaseImpl* database = | 486 WebIDBDatabaseImpl* database = |
485 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 487 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
486 if (!database) | 488 if (!database) |
487 return; | 489 return; |
488 | 490 |
489 scoped_ptr<IndexedDBCallbacksBase> callbacks( | 491 scoped_ptr<IndexedDBCallbacksBase> callbacks( |
490 new IndexedDBCallbacks<std::vector<char> >( | 492 new IndexedDBCallbacks<std::vector<char> >( |
491 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 493 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
492 database->get(parent_->HostTransactionId(params.transaction_id), | 494 database->get(parent_->HostTransactionId(params.transaction_id), |
493 params.object_store_id, | 495 params.object_store_id, |
494 params.index_id, | 496 params.index_id, |
495 params.key_range, | 497 params.key_range, |
496 params.key_only, | 498 params.key_only, |
497 callbacks.release()); | 499 callbacks.release()); |
498 } | 500 } |
499 | 501 |
500 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | 502 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( |
501 const IndexedDBHostMsg_DatabasePut_Params& params) { | 503 const IndexedDBHostMsg_DatabasePut_Params& params) { |
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 504 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
503 | 505 |
504 WebIDBDatabaseImpl* database = | 506 WebIDBDatabaseImpl* database = |
505 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 507 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
506 if (!database) | 508 if (!database) |
507 return; | 509 return; |
508 scoped_ptr<IndexedDBCallbacksBase> callbacks( | 510 scoped_ptr<IndexedDBCallbacksBase> callbacks( |
509 new IndexedDBCallbacks<IndexedDBKey>( | 511 new IndexedDBCallbacks<IndexedDBKey>( |
510 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 512 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
511 | 513 |
512 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 514 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
513 // TODO(alecflett): Avoid a copy here. | 515 // TODO(alecflett): Avoid a copy here. |
514 std::vector<char> value_copy = params.value; | 516 std::vector<char> value_copy = params.value; |
515 database->put(host_transaction_id, | 517 database->put(host_transaction_id, |
516 params.object_store_id, | 518 params.object_store_id, |
517 &value_copy, | 519 &value_copy, |
518 params.key, | 520 params.key, |
519 params.put_mode, | 521 params.put_mode, |
520 callbacks.release(), | 522 callbacks.release(), |
521 params.index_ids, | 523 params.index_ids, |
522 params.index_keys); | 524 params.index_keys); |
523 TransactionIDToSizeMap* map = | 525 TransactionIDToSizeMap* map = |
524 &parent_->database_dispatcher_host_->transaction_size_map_; | 526 &parent_->database_dispatcher_host_->transaction_size_map_; |
525 // Size can't be big enough to overflow because it represents the | 527 // Size can't be big enough to overflow because it represents the |
526 // actual bytes passed through IPC. | 528 // actual bytes passed through IPC. |
527 (*map)[host_transaction_id] += params.value.size(); | 529 (*map)[host_transaction_id] += params.value.size(); |
528 } | 530 } |
529 | 531 |
530 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( | 532 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( |
531 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { | 533 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { |
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 534 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
533 WebIDBDatabaseImpl* database = | 535 WebIDBDatabaseImpl* database = |
534 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 536 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
535 if (!database) | 537 if (!database) |
536 return; | 538 return; |
537 | 539 |
538 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 540 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
539 if (params.index_ids.size() != params.index_keys.size()) { | 541 if (params.index_ids.size() != params.index_keys.size()) { |
540 database->abort( | 542 database->abort( |
541 host_transaction_id, | 543 host_transaction_id, |
542 WebIDBDatabaseError( | 544 WebIDBDatabaseError( |
543 WebKit::WebIDBDatabaseExceptionUnknownError, | 545 WebKit::WebIDBDatabaseExceptionUnknownError, |
544 "Malformed IPC message: index_ids.size() != index_keys.size()")); | 546 "Malformed IPC message: index_ids.size() != index_keys.size()")); |
545 return; | 547 return; |
546 } | 548 } |
547 | 549 |
548 database->setIndexKeys(host_transaction_id, | 550 database->setIndexKeys(host_transaction_id, |
549 params.object_store_id, | 551 params.object_store_id, |
550 params.primary_key, | 552 params.primary_key, |
551 params.index_ids, | 553 params.index_ids, |
552 params.index_keys); | 554 params.index_keys); |
553 } | 555 } |
554 | 556 |
555 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( | 557 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( |
556 int32 ipc_database_id, | 558 int32 ipc_database_id, |
557 int64 transaction_id, | 559 int64 transaction_id, |
558 int64 object_store_id, | 560 int64 object_store_id, |
559 const std::vector<int64>& index_ids) { | 561 const std::vector<int64>& index_ids) { |
560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 562 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
561 WebIDBDatabaseImpl* database = | 563 WebIDBDatabaseImpl* database = |
562 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 564 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
563 if (!database) | 565 if (!database) |
564 return; | 566 return; |
565 | 567 |
566 database->setIndexesReady( | 568 database->setIndexesReady( |
567 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); | 569 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); |
568 } | 570 } |
569 | 571 |
570 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( | 572 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( |
571 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { | 573 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { |
572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 574 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
573 WebIDBDatabaseImpl* database = | 575 WebIDBDatabaseImpl* database = |
574 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 576 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
575 if (!database) | 577 if (!database) |
576 return; | 578 return; |
577 | 579 |
578 scoped_ptr<IndexedDBCallbacksBase> callbacks( | 580 scoped_ptr<IndexedDBCallbacksBase> callbacks( |
579 new IndexedDBCallbacks<WebIDBCursorImpl>( | 581 new IndexedDBCallbacks<WebIDBCursorImpl>( |
580 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); | 582 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); |
581 database->openCursor(parent_->HostTransactionId(params.transaction_id), | 583 database->openCursor(parent_->HostTransactionId(params.transaction_id), |
582 params.object_store_id, | 584 params.object_store_id, |
583 params.index_id, | 585 params.index_id, |
584 params.key_range, | 586 params.key_range, |
585 params.direction, | 587 params.direction, |
586 params.key_only, | 588 params.key_only, |
587 params.task_type, | 589 params.task_type, |
588 callbacks.release()); | 590 callbacks.release()); |
589 } | 591 } |
590 | 592 |
591 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( | 593 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( |
592 const IndexedDBHostMsg_DatabaseCount_Params& params) { | 594 const IndexedDBHostMsg_DatabaseCount_Params& params) { |
593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 595 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
594 WebIDBDatabaseImpl* database = | 596 WebIDBDatabaseImpl* database = |
595 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 597 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
596 if (!database) | 598 if (!database) |
597 return; | 599 return; |
598 | 600 |
599 scoped_ptr<IndexedDBCallbacksBase> callbacks( | 601 scoped_ptr<IndexedDBCallbacksBase> callbacks( |
600 new IndexedDBCallbacks<std::vector<char> >( | 602 new IndexedDBCallbacks<std::vector<char> >( |
601 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 603 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
602 database->count(parent_->HostTransactionId(params.transaction_id), | 604 database->count(parent_->HostTransactionId(params.transaction_id), |
603 params.object_store_id, | 605 params.object_store_id, |
604 params.index_id, | 606 params.index_id, |
605 params.key_range, | 607 params.key_range, |
606 callbacks.release()); | 608 callbacks.release()); |
607 } | 609 } |
608 | 610 |
609 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( | 611 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( |
610 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { | 612 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { |
611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 613 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
612 WebIDBDatabaseImpl* database = | 614 WebIDBDatabaseImpl* database = |
613 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 615 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
614 if (!database) | 616 if (!database) |
615 return; | 617 return; |
616 | 618 |
617 scoped_ptr<IndexedDBCallbacksBase> callbacks( | 619 scoped_ptr<IndexedDBCallbacksBase> callbacks( |
618 new IndexedDBCallbacks<std::vector<char> >( | 620 new IndexedDBCallbacks<std::vector<char> >( |
619 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 621 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
620 database->deleteRange(parent_->HostTransactionId(params.transaction_id), | 622 database->deleteRange(parent_->HostTransactionId(params.transaction_id), |
621 params.object_store_id, | 623 params.object_store_id, |
622 params.key_range, | 624 params.key_range, |
623 callbacks.release()); | 625 callbacks.release()); |
624 } | 626 } |
625 | 627 |
626 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( | 628 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( |
627 int32 ipc_thread_id, | 629 int32 ipc_thread_id, |
628 int32 ipc_callbacks_id, | 630 int32 ipc_callbacks_id, |
629 int32 ipc_database_id, | 631 int32 ipc_database_id, |
630 int64 transaction_id, | 632 int64 transaction_id, |
631 int64 object_store_id) { | 633 int64 object_store_id) { |
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 634 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
633 WebIDBDatabaseImpl* database = | 635 WebIDBDatabaseImpl* database = |
634 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 636 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
635 if (!database) | 637 if (!database) |
636 return; | 638 return; |
637 | 639 |
638 scoped_ptr<IndexedDBCallbacksBase> callbacks( | 640 scoped_ptr<IndexedDBCallbacksBase> callbacks( |
639 new IndexedDBCallbacks<std::vector<char> >( | 641 new IndexedDBCallbacks<std::vector<char> >( |
640 parent_, ipc_thread_id, ipc_callbacks_id)); | 642 parent_, ipc_thread_id, ipc_callbacks_id)); |
641 | 643 |
642 database->clear(parent_->HostTransactionId(transaction_id), | 644 database->clear(parent_->HostTransactionId(transaction_id), |
643 object_store_id, | 645 object_store_id, |
644 callbacks.release()); | 646 callbacks.release()); |
645 } | 647 } |
646 | 648 |
647 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( | 649 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( |
648 int32 ipc_database_id, | 650 int32 ipc_database_id, |
649 int64 transaction_id) { | 651 int64 transaction_id) { |
650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 652 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
651 WebIDBDatabaseImpl* database = | 653 WebIDBDatabaseImpl* database = |
652 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 654 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
653 if (!database) | 655 if (!database) |
654 return; | 656 return; |
655 | 657 |
656 database->abort(parent_->HostTransactionId(transaction_id)); | 658 database->abort(parent_->HostTransactionId(transaction_id)); |
657 } | 659 } |
658 | 660 |
659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( | 661 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( |
660 int32 ipc_database_id, | 662 int32 ipc_database_id, |
661 int64 transaction_id) { | 663 int64 transaction_id) { |
662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 664 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
663 WebIDBDatabaseImpl* database = | 665 WebIDBDatabaseImpl* database = |
664 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 666 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
665 if (!database) | 667 if (!database) |
666 return; | 668 return; |
667 | 669 |
668 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); | 670 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); |
669 int64 transaction_size = transaction_size_map_[host_transaction_id]; | 671 int64 transaction_size = transaction_size_map_[host_transaction_id]; |
670 if (transaction_size && | 672 if (transaction_size && |
671 parent_->Context()->WouldBeOverQuota( | 673 parent_->Context()->WouldBeOverQuota( |
672 transaction_url_map_[host_transaction_id], transaction_size)) { | 674 transaction_url_map_[host_transaction_id], transaction_size)) { |
673 database->abort( | 675 database->abort( |
674 host_transaction_id, | 676 host_transaction_id, |
675 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 677 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); |
676 return; | 678 return; |
677 } | 679 } |
678 | 680 |
679 database->commit(host_transaction_id); | 681 database->commit(host_transaction_id); |
680 } | 682 } |
681 | 683 |
682 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( | 684 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( |
683 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { | 685 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { |
684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 686 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
685 WebIDBDatabaseImpl* database = | 687 WebIDBDatabaseImpl* database = |
686 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 688 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
687 if (!database) | 689 if (!database) |
688 return; | 690 return; |
689 | 691 |
690 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 692 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
691 database->createIndex(host_transaction_id, | 693 database->createIndex(host_transaction_id, |
692 params.object_store_id, | 694 params.object_store_id, |
693 params.index_id, | 695 params.index_id, |
694 params.name, | 696 params.name, |
695 params.key_path, | 697 params.key_path, |
696 params.unique, | 698 params.unique, |
697 params.multi_entry); | 699 params.multi_entry); |
698 if (parent_->Context()->IsOverQuota( | 700 if (parent_->Context()->IsOverQuota( |
699 database_url_map_[params.ipc_database_id])) { | 701 database_url_map_[params.ipc_database_id])) { |
700 database->abort( | 702 database->abort( |
701 host_transaction_id, | 703 host_transaction_id, |
702 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 704 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); |
703 } | 705 } |
704 } | 706 } |
705 | 707 |
706 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( | 708 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( |
707 int32 ipc_database_id, | 709 int32 ipc_database_id, |
708 int64 transaction_id, | 710 int64 transaction_id, |
709 int64 object_store_id, | 711 int64 object_store_id, |
710 int64 index_id) { | 712 int64 index_id) { |
711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 713 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
712 WebIDBDatabaseImpl* database = | 714 WebIDBDatabaseImpl* database = |
713 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 715 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
714 if (!database) | 716 if (!database) |
715 return; | 717 return; |
716 | 718 |
717 database->deleteIndex( | 719 database->deleteIndex( |
718 parent_->HostTransactionId(transaction_id), object_store_id, index_id); | 720 parent_->HostTransactionId(transaction_id), object_store_id, index_id); |
719 } | 721 } |
720 | 722 |
721 ////////////////////////////////////////////////////////////////////// | 723 ////////////////////////////////////////////////////////////////////// |
722 // IndexedDBDispatcherHost::CursorDispatcherHost | 724 // IndexedDBDispatcherHost::CursorDispatcherHost |
723 // | 725 // |
724 | 726 |
725 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( | 727 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( |
726 IndexedDBDispatcherHost* parent) | 728 IndexedDBDispatcherHost* parent) |
727 : parent_(parent) { | 729 : parent_(parent) { |
728 map_.set_check_on_null_data(true); | 730 map_.set_check_on_null_data(true); |
729 } | 731 } |
730 | 732 |
731 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} | 733 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} |
732 | 734 |
733 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( | 735 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( |
734 const IPC::Message& message, | 736 const IPC::Message& message, |
735 bool* msg_is_ok) { | 737 bool* msg_is_ok) { |
| 738 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
| 739 |
736 bool handled = true; | 740 bool handled = true; |
737 IPC_BEGIN_MESSAGE_MAP_EX( | 741 IPC_BEGIN_MESSAGE_MAP_EX( |
738 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) | 742 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) |
739 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) | 743 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) |
740 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) | 744 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) |
741 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) | 745 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) |
742 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) | 746 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) |
743 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) | 747 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) |
744 IPC_MESSAGE_UNHANDLED(handled = false) | 748 IPC_MESSAGE_UNHANDLED(handled = false) |
745 IPC_END_MESSAGE_MAP() | 749 IPC_END_MESSAGE_MAP() |
746 return handled; | 750 return handled; |
747 } | 751 } |
748 | 752 |
749 void IndexedDBDispatcherHost::CursorDispatcherHost::Send( | 753 void IndexedDBDispatcherHost::CursorDispatcherHost::Send( |
750 IPC::Message* message) { | 754 IPC::Message* message) { |
751 parent_->Send(message); | 755 parent_->Send(message); |
752 } | 756 } |
753 | 757 |
754 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( | 758 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( |
755 int32 ipc_cursor_id, | 759 int32 ipc_cursor_id, |
756 int32 ipc_thread_id, | 760 int32 ipc_thread_id, |
757 int32 ipc_callbacks_id, | 761 int32 ipc_callbacks_id, |
758 unsigned long count) { | 762 unsigned long count) { |
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 763 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
760 WebIDBCursorImpl* idb_cursor = | 764 WebIDBCursorImpl* idb_cursor = |
761 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 765 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
762 if (!idb_cursor) | 766 if (!idb_cursor) |
763 return; | 767 return; |
764 | 768 |
765 idb_cursor->advance( | 769 idb_cursor->advance( |
766 count, | 770 count, |
767 new IndexedDBCallbacks<WebIDBCursorImpl>( | 771 new IndexedDBCallbacks<WebIDBCursorImpl>( |
768 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); | 772 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); |
769 } | 773 } |
770 | 774 |
771 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( | 775 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( |
772 int32 ipc_cursor_id, | 776 int32 ipc_cursor_id, |
773 int32 ipc_thread_id, | 777 int32 ipc_thread_id, |
774 int32 ipc_callbacks_id, | 778 int32 ipc_callbacks_id, |
775 const IndexedDBKey& key) { | 779 const IndexedDBKey& key) { |
776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 780 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
777 WebIDBCursorImpl* idb_cursor = | 781 WebIDBCursorImpl* idb_cursor = |
778 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 782 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
779 if (!idb_cursor) | 783 if (!idb_cursor) |
780 return; | 784 return; |
781 | 785 |
782 idb_cursor->continueFunction( | 786 idb_cursor->continueFunction( |
783 key, | 787 key, |
784 new IndexedDBCallbacks<WebIDBCursorImpl>( | 788 new IndexedDBCallbacks<WebIDBCursorImpl>( |
785 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); | 789 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); |
786 } | 790 } |
787 | 791 |
788 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch( | 792 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch( |
789 int32 ipc_cursor_id, | 793 int32 ipc_cursor_id, |
790 int32 ipc_thread_id, | 794 int32 ipc_thread_id, |
791 int32 ipc_callbacks_id, | 795 int32 ipc_callbacks_id, |
792 int n) { | 796 int n) { |
793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 797 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
794 WebIDBCursorImpl* idb_cursor = | 798 WebIDBCursorImpl* idb_cursor = |
795 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 799 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
796 if (!idb_cursor) | 800 if (!idb_cursor) |
797 return; | 801 return; |
798 | 802 |
799 idb_cursor->prefetchContinue( | 803 idb_cursor->prefetchContinue( |
800 n, | 804 n, |
801 new IndexedDBCallbacks<WebIDBCursorImpl>( | 805 new IndexedDBCallbacks<WebIDBCursorImpl>( |
802 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); | 806 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); |
803 } | 807 } |
804 | 808 |
805 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset( | 809 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset( |
806 int32 ipc_cursor_id, | 810 int32 ipc_cursor_id, |
807 int used_prefetches, | 811 int used_prefetches, |
808 int unused_prefetches) { | 812 int unused_prefetches) { |
809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 813 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
810 WebIDBCursorImpl* idb_cursor = | 814 WebIDBCursorImpl* idb_cursor = |
811 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 815 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
812 if (!idb_cursor) | 816 if (!idb_cursor) |
813 return; | 817 return; |
814 | 818 |
815 idb_cursor->prefetchReset(used_prefetches, unused_prefetches); | 819 idb_cursor->prefetchReset(used_prefetches, unused_prefetches); |
816 } | 820 } |
817 | 821 |
818 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 822 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
819 int32 ipc_object_id) { | 823 int32 ipc_object_id) { |
| 824 DCHECK(parent_->indexed_db_context_->OnIndexedDBThread()); |
820 parent_->DestroyObject(&map_, ipc_object_id); | 825 parent_->DestroyObject(&map_, ipc_object_id); |
821 } | 826 } |
822 | 827 |
823 } // namespace content | 828 } // namespace content |
OLD | NEW |