Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: content/browser/in_process_webkit/indexed_db_dispatcher_host.cc

Issue 17518004: Move IndexedDB from WEBKIT_DEPRECATED to dedicated thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: IOS build fix Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_->TaskRunner()->RunsTasksOnCurrentThread());
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_->TaskRunner()->RunsTasksOnCurrentThread());
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
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_->TaskRunner()->RunsTasksOnCurrentThread());
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
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_->TaskRunner()->RunsTasksOnCurrentThread());
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_->TaskRunner()->RunsTasksOnCurrentThread());
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_->TaskRunner()->RunsTasksOnCurrentThread());
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_->TaskRunner()->RunsTasksOnCurrentThread());
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
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_->TaskRunner()->RunsTasksOnCurrentThread());
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
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(
339 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
341 // Abort outstanding transactions started by connections in the associated 340 // Abort outstanding transactions started by connections in the associated
342 // front-end to unblock later transactions. This should only occur on unclean 341 // front-end to unblock later transactions. This should only occur on unclean
343 // (crash) or abrupt (process-kill) shutdowns. 342 // (crash) or abrupt (process-kill) shutdowns.
344 for (TransactionIDToDatabaseIDMap::iterator iter = 343 for (TransactionIDToDatabaseIDMap::iterator iter =
345 transaction_database_map_.begin(); 344 transaction_database_map_.begin();
346 iter != transaction_database_map_.end();) { 345 iter != transaction_database_map_.end();) {
347 int64 transaction_id = iter->first; 346 int64 transaction_id = iter->first;
348 int32 ipc_database_id = iter->second; 347 int32 ipc_database_id = iter->second;
349 ++iter; 348 ++iter;
350 WebIDBDatabaseImpl* database = map_.Lookup(ipc_database_id); 349 WebIDBDatabaseImpl* database = map_.Lookup(ipc_database_id);
(...skipping 12 matching lines...) Expand all
363 if (database) { 362 if (database) {
364 database->close(); 363 database->close();
365 parent_->Context()->ConnectionClosed(iter->second, database); 364 parent_->Context()->ConnectionClosed(iter->second, database);
366 } 365 }
367 } 366 }
368 } 367 }
369 368
370 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( 369 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
371 const IPC::Message& message, 370 const IPC::Message& message,
372 bool* msg_is_ok) { 371 bool* msg_is_ok) {
372 DCHECK(
373 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
373 bool handled = true; 374 bool handled = true;
374 IPC_BEGIN_MESSAGE_MAP_EX( 375 IPC_BEGIN_MESSAGE_MAP_EX(
375 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok) 376 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok)
376 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, 377 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore,
377 OnCreateObjectStore) 378 OnCreateObjectStore)
378 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, 379 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore,
379 OnDeleteObjectStore) 380 OnDeleteObjectStore)
380 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, 381 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction,
381 OnCreateTransaction) 382 OnCreateTransaction)
382 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) 383 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose)
383 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) 384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed)
384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) 385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet)
385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut) 386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut)
386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) 387 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys)
387 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, 388 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady,
388 OnSetIndexesReady) 389 OnSetIndexesReady)
389 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) 390 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor)
390 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) 391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount)
391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) 392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange)
392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) 393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear)
393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex) 394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex)
394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex) 395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex)
395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort) 396 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort)
396 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit) 397 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit)
397 IPC_MESSAGE_UNHANDLED(handled = false) 398 IPC_MESSAGE_UNHANDLED(handled = false)
398 IPC_END_MESSAGE_MAP() 399 IPC_END_MESSAGE_MAP()
399 return handled; 400 return handled;
400 } 401 }
401 402
402 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( 403 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send(
403 IPC::Message* message) { 404 IPC::Message* message) {
404 parent_->Send(message); 405 parent_->Send(message);
405 } 406 }
406 407
407 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( 408 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
408 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { 409 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) {
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 410 DCHECK(
411 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
410 WebIDBDatabaseImpl* database = 412 WebIDBDatabaseImpl* database =
411 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 413 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
412 if (!database) 414 if (!database)
413 return; 415 return;
414 416
415 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 417 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
416 database->createObjectStore(host_transaction_id, 418 database->createObjectStore(host_transaction_id,
417 params.object_store_id, 419 params.object_store_id,
418 params.name, 420 params.name,
419 params.key_path, 421 params.key_path,
420 params.auto_increment); 422 params.auto_increment);
421 if (parent_->Context()->IsOverQuota( 423 if (parent_->Context()->IsOverQuota(
422 database_url_map_[params.ipc_database_id])) { 424 database_url_map_[params.ipc_database_id])) {
423 database->abort( 425 database->abort(
424 host_transaction_id, 426 host_transaction_id,
425 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); 427 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
426 } 428 }
427 } 429 }
428 430
429 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( 431 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore(
430 int32 ipc_database_id, 432 int32 ipc_database_id,
431 int64 transaction_id, 433 int64 transaction_id,
432 int64 object_store_id) { 434 int64 object_store_id) {
433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 435 DCHECK(
436 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
434 WebIDBDatabaseImpl* database = 437 WebIDBDatabaseImpl* database =
435 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 438 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
436 if (!database) 439 if (!database)
437 return; 440 return;
438 441
439 database->deleteObjectStore(parent_->HostTransactionId(transaction_id), 442 database->deleteObjectStore(parent_->HostTransactionId(transaction_id),
440 object_store_id); 443 object_store_id);
441 } 444 }
442 445
443 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( 446 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction(
444 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { 447 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) {
448 DCHECK(
449 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
445 WebIDBDatabaseImpl* database = 450 WebIDBDatabaseImpl* database =
446 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 451 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
447 if (!database) 452 if (!database)
448 return; 453 return;
449 454
450 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 455 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
451 456
452 database->createTransaction( 457 database->createTransaction(
453 host_transaction_id, 458 host_transaction_id,
454 new IndexedDBDatabaseCallbacks( 459 new IndexedDBDatabaseCallbacks(
455 parent_, params.ipc_thread_id, params.ipc_database_callbacks_id), 460 parent_, params.ipc_thread_id, params.ipc_database_callbacks_id),
456 params.object_store_ids, 461 params.object_store_ids,
457 params.mode); 462 params.mode);
458 transaction_database_map_[host_transaction_id] = params.ipc_database_id; 463 transaction_database_map_[host_transaction_id] = params.ipc_database_id;
459 parent_->RegisterTransactionId(host_transaction_id, 464 parent_->RegisterTransactionId(host_transaction_id,
460 database_url_map_[params.ipc_database_id]); 465 database_url_map_[params.ipc_database_id]);
461 } 466 }
462 467
463 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( 468 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose(
464 int32 ipc_database_id) { 469 int32 ipc_database_id) {
470 DCHECK(
471 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
465 WebIDBDatabaseImpl* database = 472 WebIDBDatabaseImpl* database =
466 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 473 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
467 if (!database) 474 if (!database)
468 return; 475 return;
469 database->close(); 476 database->close();
470 } 477 }
471 478
472 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( 479 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
473 int32 ipc_object_id) { 480 int32 ipc_object_id) {
481 DCHECK(
482 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
474 WebIDBDatabaseImpl* database = map_.Lookup(ipc_object_id); 483 WebIDBDatabaseImpl* database = map_.Lookup(ipc_object_id);
475 parent_->Context() 484 parent_->Context()
476 ->ConnectionClosed(database_url_map_[ipc_object_id], database); 485 ->ConnectionClosed(database_url_map_[ipc_object_id], database);
477 database_url_map_.erase(ipc_object_id); 486 database_url_map_.erase(ipc_object_id);
478 parent_->DestroyObject(&map_, ipc_object_id); 487 parent_->DestroyObject(&map_, ipc_object_id);
479 } 488 }
480 489
481 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( 490 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(
482 const IndexedDBHostMsg_DatabaseGet_Params& params) { 491 const IndexedDBHostMsg_DatabaseGet_Params& params) {
483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 492 DCHECK(
493 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
484 WebIDBDatabaseImpl* database = 494 WebIDBDatabaseImpl* database =
485 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 495 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
486 if (!database) 496 if (!database)
487 return; 497 return;
488 498
489 scoped_ptr<IndexedDBCallbacksBase> callbacks( 499 scoped_ptr<IndexedDBCallbacksBase> callbacks(
490 new IndexedDBCallbacks<std::vector<char> >( 500 new IndexedDBCallbacks<std::vector<char> >(
491 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 501 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
492 database->get(parent_->HostTransactionId(params.transaction_id), 502 database->get(parent_->HostTransactionId(params.transaction_id),
493 params.object_store_id, 503 params.object_store_id,
494 params.index_id, 504 params.index_id,
495 params.key_range, 505 params.key_range,
496 params.key_only, 506 params.key_only,
497 callbacks.release()); 507 callbacks.release());
498 } 508 }
499 509
500 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( 510 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut(
501 const IndexedDBHostMsg_DatabasePut_Params& params) { 511 const IndexedDBHostMsg_DatabasePut_Params& params) {
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 512 DCHECK(
513 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
503 514
504 WebIDBDatabaseImpl* database = 515 WebIDBDatabaseImpl* database =
505 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 516 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
506 if (!database) 517 if (!database)
507 return; 518 return;
508 scoped_ptr<IndexedDBCallbacksBase> callbacks( 519 scoped_ptr<IndexedDBCallbacksBase> callbacks(
509 new IndexedDBCallbacks<IndexedDBKey>( 520 new IndexedDBCallbacks<IndexedDBKey>(
510 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 521 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
511 522
512 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 523 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
513 // TODO(alecflett): Avoid a copy here. 524 // TODO(alecflett): Avoid a copy here.
514 std::vector<char> value_copy = params.value; 525 std::vector<char> value_copy = params.value;
515 database->put(host_transaction_id, 526 database->put(host_transaction_id,
516 params.object_store_id, 527 params.object_store_id,
517 &value_copy, 528 &value_copy,
518 params.key, 529 params.key,
519 params.put_mode, 530 params.put_mode,
520 callbacks.release(), 531 callbacks.release(),
521 params.index_ids, 532 params.index_ids,
522 params.index_keys); 533 params.index_keys);
523 TransactionIDToSizeMap* map = 534 TransactionIDToSizeMap* map =
524 &parent_->database_dispatcher_host_->transaction_size_map_; 535 &parent_->database_dispatcher_host_->transaction_size_map_;
525 // Size can't be big enough to overflow because it represents the 536 // Size can't be big enough to overflow because it represents the
526 // actual bytes passed through IPC. 537 // actual bytes passed through IPC.
527 (*map)[host_transaction_id] += params.value.size(); 538 (*map)[host_transaction_id] += params.value.size();
528 } 539 }
529 540
530 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( 541 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys(
531 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { 542 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 543 DCHECK(
544 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
533 WebIDBDatabaseImpl* database = 545 WebIDBDatabaseImpl* database =
534 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 546 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
535 if (!database) 547 if (!database)
536 return; 548 return;
537 549
538 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 550 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
539 if (params.index_ids.size() != params.index_keys.size()) { 551 if (params.index_ids.size() != params.index_keys.size()) {
540 database->abort( 552 database->abort(
541 host_transaction_id, 553 host_transaction_id,
542 WebIDBDatabaseError( 554 WebIDBDatabaseError(
543 WebKit::WebIDBDatabaseExceptionUnknownError, 555 WebKit::WebIDBDatabaseExceptionUnknownError,
544 "Malformed IPC message: index_ids.size() != index_keys.size()")); 556 "Malformed IPC message: index_ids.size() != index_keys.size()"));
545 return; 557 return;
546 } 558 }
547 559
548 database->setIndexKeys(host_transaction_id, 560 database->setIndexKeys(host_transaction_id,
549 params.object_store_id, 561 params.object_store_id,
550 params.primary_key, 562 params.primary_key,
551 params.index_ids, 563 params.index_ids,
552 params.index_keys); 564 params.index_keys);
553 } 565 }
554 566
555 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( 567 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady(
556 int32 ipc_database_id, 568 int32 ipc_database_id,
557 int64 transaction_id, 569 int64 transaction_id,
558 int64 object_store_id, 570 int64 object_store_id,
559 const std::vector<int64>& index_ids) { 571 const std::vector<int64>& index_ids) {
560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 572 DCHECK(
573 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
561 WebIDBDatabaseImpl* database = 574 WebIDBDatabaseImpl* database =
562 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 575 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
563 if (!database) 576 if (!database)
564 return; 577 return;
565 578
566 database->setIndexesReady( 579 database->setIndexesReady(
567 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); 580 parent_->HostTransactionId(transaction_id), object_store_id, index_ids);
568 } 581 }
569 582
570 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( 583 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor(
571 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { 584 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) {
572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 585 DCHECK(
586 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
573 WebIDBDatabaseImpl* database = 587 WebIDBDatabaseImpl* database =
574 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 588 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
575 if (!database) 589 if (!database)
576 return; 590 return;
577 591
578 scoped_ptr<IndexedDBCallbacksBase> callbacks( 592 scoped_ptr<IndexedDBCallbacksBase> callbacks(
579 new IndexedDBCallbacks<WebIDBCursorImpl>( 593 new IndexedDBCallbacks<WebIDBCursorImpl>(
580 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); 594 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1));
581 database->openCursor(parent_->HostTransactionId(params.transaction_id), 595 database->openCursor(parent_->HostTransactionId(params.transaction_id),
582 params.object_store_id, 596 params.object_store_id,
583 params.index_id, 597 params.index_id,
584 params.key_range, 598 params.key_range,
585 params.direction, 599 params.direction,
586 params.key_only, 600 params.key_only,
587 params.task_type, 601 params.task_type,
588 callbacks.release()); 602 callbacks.release());
589 } 603 }
590 604
591 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( 605 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount(
592 const IndexedDBHostMsg_DatabaseCount_Params& params) { 606 const IndexedDBHostMsg_DatabaseCount_Params& params) {
593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 607 DCHECK(
608 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
594 WebIDBDatabaseImpl* database = 609 WebIDBDatabaseImpl* database =
595 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 610 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
596 if (!database) 611 if (!database)
597 return; 612 return;
598 613
599 scoped_ptr<IndexedDBCallbacksBase> callbacks( 614 scoped_ptr<IndexedDBCallbacksBase> callbacks(
600 new IndexedDBCallbacks<std::vector<char> >( 615 new IndexedDBCallbacks<std::vector<char> >(
601 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 616 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
602 database->count(parent_->HostTransactionId(params.transaction_id), 617 database->count(parent_->HostTransactionId(params.transaction_id),
603 params.object_store_id, 618 params.object_store_id,
604 params.index_id, 619 params.index_id,
605 params.key_range, 620 params.key_range,
606 callbacks.release()); 621 callbacks.release());
607 } 622 }
608 623
609 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( 624 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange(
610 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { 625 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) {
611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 626 DCHECK(
627 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
612 WebIDBDatabaseImpl* database = 628 WebIDBDatabaseImpl* database =
613 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 629 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
614 if (!database) 630 if (!database)
615 return; 631 return;
616 632
617 scoped_ptr<IndexedDBCallbacksBase> callbacks( 633 scoped_ptr<IndexedDBCallbacksBase> callbacks(
618 new IndexedDBCallbacks<std::vector<char> >( 634 new IndexedDBCallbacks<std::vector<char> >(
619 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 635 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
620 database->deleteRange(parent_->HostTransactionId(params.transaction_id), 636 database->deleteRange(parent_->HostTransactionId(params.transaction_id),
621 params.object_store_id, 637 params.object_store_id,
622 params.key_range, 638 params.key_range,
623 callbacks.release()); 639 callbacks.release());
624 } 640 }
625 641
626 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( 642 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear(
627 int32 ipc_thread_id, 643 int32 ipc_thread_id,
628 int32 ipc_callbacks_id, 644 int32 ipc_callbacks_id,
629 int32 ipc_database_id, 645 int32 ipc_database_id,
630 int64 transaction_id, 646 int64 transaction_id,
631 int64 object_store_id) { 647 int64 object_store_id) {
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 648 DCHECK(
649 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
633 WebIDBDatabaseImpl* database = 650 WebIDBDatabaseImpl* database =
634 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 651 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
635 if (!database) 652 if (!database)
636 return; 653 return;
637 654
638 scoped_ptr<IndexedDBCallbacksBase> callbacks( 655 scoped_ptr<IndexedDBCallbacksBase> callbacks(
639 new IndexedDBCallbacks<std::vector<char> >( 656 new IndexedDBCallbacks<std::vector<char> >(
640 parent_, ipc_thread_id, ipc_callbacks_id)); 657 parent_, ipc_thread_id, ipc_callbacks_id));
641 658
642 database->clear(parent_->HostTransactionId(transaction_id), 659 database->clear(parent_->HostTransactionId(transaction_id),
643 object_store_id, 660 object_store_id,
644 callbacks.release()); 661 callbacks.release());
645 } 662 }
646 663
647 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( 664 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort(
648 int32 ipc_database_id, 665 int32 ipc_database_id,
649 int64 transaction_id) { 666 int64 transaction_id) {
650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 667 DCHECK(
668 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
651 WebIDBDatabaseImpl* database = 669 WebIDBDatabaseImpl* database =
652 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 670 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
653 if (!database) 671 if (!database)
654 return; 672 return;
655 673
656 database->abort(parent_->HostTransactionId(transaction_id)); 674 database->abort(parent_->HostTransactionId(transaction_id));
657 } 675 }
658 676
659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( 677 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit(
660 int32 ipc_database_id, 678 int32 ipc_database_id,
661 int64 transaction_id) { 679 int64 transaction_id) {
662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 680 DCHECK(
681 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
663 WebIDBDatabaseImpl* database = 682 WebIDBDatabaseImpl* database =
664 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 683 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
665 if (!database) 684 if (!database)
666 return; 685 return;
667 686
668 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); 687 int64 host_transaction_id = parent_->HostTransactionId(transaction_id);
669 int64 transaction_size = transaction_size_map_[host_transaction_id]; 688 int64 transaction_size = transaction_size_map_[host_transaction_id];
670 if (transaction_size && 689 if (transaction_size &&
671 parent_->Context()->WouldBeOverQuota( 690 parent_->Context()->WouldBeOverQuota(
672 transaction_url_map_[host_transaction_id], transaction_size)) { 691 transaction_url_map_[host_transaction_id], transaction_size)) {
673 database->abort( 692 database->abort(
674 host_transaction_id, 693 host_transaction_id,
675 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); 694 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
676 return; 695 return;
677 } 696 }
678 697
679 database->commit(host_transaction_id); 698 database->commit(host_transaction_id);
680 } 699 }
681 700
682 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( 701 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex(
683 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { 702 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) {
684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 703 DCHECK(
704 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
685 WebIDBDatabaseImpl* database = 705 WebIDBDatabaseImpl* database =
686 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 706 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
687 if (!database) 707 if (!database)
688 return; 708 return;
689 709
690 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 710 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
691 database->createIndex(host_transaction_id, 711 database->createIndex(host_transaction_id,
692 params.object_store_id, 712 params.object_store_id,
693 params.index_id, 713 params.index_id,
694 params.name, 714 params.name,
695 params.key_path, 715 params.key_path,
696 params.unique, 716 params.unique,
697 params.multi_entry); 717 params.multi_entry);
698 if (parent_->Context()->IsOverQuota( 718 if (parent_->Context()->IsOverQuota(
699 database_url_map_[params.ipc_database_id])) { 719 database_url_map_[params.ipc_database_id])) {
700 database->abort( 720 database->abort(
701 host_transaction_id, 721 host_transaction_id,
702 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); 722 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
703 } 723 }
704 } 724 }
705 725
706 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( 726 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex(
707 int32 ipc_database_id, 727 int32 ipc_database_id,
708 int64 transaction_id, 728 int64 transaction_id,
709 int64 object_store_id, 729 int64 object_store_id,
710 int64 index_id) { 730 int64 index_id) {
711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 731 DCHECK(
732 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
712 WebIDBDatabaseImpl* database = 733 WebIDBDatabaseImpl* database =
713 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 734 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
714 if (!database) 735 if (!database)
715 return; 736 return;
716 737
717 database->deleteIndex( 738 database->deleteIndex(
718 parent_->HostTransactionId(transaction_id), object_store_id, index_id); 739 parent_->HostTransactionId(transaction_id), object_store_id, index_id);
719 } 740 }
720 741
721 ////////////////////////////////////////////////////////////////////// 742 //////////////////////////////////////////////////////////////////////
722 // IndexedDBDispatcherHost::CursorDispatcherHost 743 // IndexedDBDispatcherHost::CursorDispatcherHost
723 // 744 //
724 745
725 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( 746 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost(
726 IndexedDBDispatcherHost* parent) 747 IndexedDBDispatcherHost* parent)
727 : parent_(parent) { 748 : parent_(parent) {
728 map_.set_check_on_null_data(true); 749 map_.set_check_on_null_data(true);
729 } 750 }
730 751
731 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} 752 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {}
732 753
733 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( 754 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived(
734 const IPC::Message& message, 755 const IPC::Message& message,
735 bool* msg_is_ok) { 756 bool* msg_is_ok) {
757 DCHECK(
758 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
759
736 bool handled = true; 760 bool handled = true;
737 IPC_BEGIN_MESSAGE_MAP_EX( 761 IPC_BEGIN_MESSAGE_MAP_EX(
738 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) 762 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok)
739 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) 763 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance)
740 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) 764 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue)
741 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) 765 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch)
742 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) 766 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset)
743 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) 767 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed)
744 IPC_MESSAGE_UNHANDLED(handled = false) 768 IPC_MESSAGE_UNHANDLED(handled = false)
745 IPC_END_MESSAGE_MAP() 769 IPC_END_MESSAGE_MAP()
746 return handled; 770 return handled;
747 } 771 }
748 772
749 void IndexedDBDispatcherHost::CursorDispatcherHost::Send( 773 void IndexedDBDispatcherHost::CursorDispatcherHost::Send(
750 IPC::Message* message) { 774 IPC::Message* message) {
751 parent_->Send(message); 775 parent_->Send(message);
752 } 776 }
753 777
754 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( 778 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance(
755 int32 ipc_cursor_id, 779 int32 ipc_cursor_id,
756 int32 ipc_thread_id, 780 int32 ipc_thread_id,
757 int32 ipc_callbacks_id, 781 int32 ipc_callbacks_id,
758 unsigned long count) { 782 unsigned long count) {
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 783 DCHECK(
784 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
760 WebIDBCursorImpl* idb_cursor = 785 WebIDBCursorImpl* idb_cursor =
761 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 786 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
762 if (!idb_cursor) 787 if (!idb_cursor)
763 return; 788 return;
764 789
765 idb_cursor->advance( 790 idb_cursor->advance(
766 count, 791 count,
767 new IndexedDBCallbacks<WebIDBCursorImpl>( 792 new IndexedDBCallbacks<WebIDBCursorImpl>(
768 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); 793 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
769 } 794 }
770 795
771 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( 796 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue(
772 int32 ipc_cursor_id, 797 int32 ipc_cursor_id,
773 int32 ipc_thread_id, 798 int32 ipc_thread_id,
774 int32 ipc_callbacks_id, 799 int32 ipc_callbacks_id,
775 const IndexedDBKey& key) { 800 const IndexedDBKey& key) {
776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 801 DCHECK(
802 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
777 WebIDBCursorImpl* idb_cursor = 803 WebIDBCursorImpl* idb_cursor =
778 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 804 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
779 if (!idb_cursor) 805 if (!idb_cursor)
780 return; 806 return;
781 807
782 idb_cursor->continueFunction( 808 idb_cursor->continueFunction(
783 key, 809 key,
784 new IndexedDBCallbacks<WebIDBCursorImpl>( 810 new IndexedDBCallbacks<WebIDBCursorImpl>(
785 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); 811 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
786 } 812 }
787 813
788 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch( 814 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch(
789 int32 ipc_cursor_id, 815 int32 ipc_cursor_id,
790 int32 ipc_thread_id, 816 int32 ipc_thread_id,
791 int32 ipc_callbacks_id, 817 int32 ipc_callbacks_id,
792 int n) { 818 int n) {
793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 819 DCHECK(
820 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
794 WebIDBCursorImpl* idb_cursor = 821 WebIDBCursorImpl* idb_cursor =
795 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 822 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
796 if (!idb_cursor) 823 if (!idb_cursor)
797 return; 824 return;
798 825
799 idb_cursor->prefetchContinue( 826 idb_cursor->prefetchContinue(
800 n, 827 n,
801 new IndexedDBCallbacks<WebIDBCursorImpl>( 828 new IndexedDBCallbacks<WebIDBCursorImpl>(
802 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); 829 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
803 } 830 }
804 831
805 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset( 832 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset(
806 int32 ipc_cursor_id, 833 int32 ipc_cursor_id,
807 int used_prefetches, 834 int used_prefetches,
808 int unused_prefetches) { 835 int unused_prefetches) {
809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 836 DCHECK(
837 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
810 WebIDBCursorImpl* idb_cursor = 838 WebIDBCursorImpl* idb_cursor =
811 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 839 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
812 if (!idb_cursor) 840 if (!idb_cursor)
813 return; 841 return;
814 842
815 idb_cursor->prefetchReset(used_prefetches, unused_prefetches); 843 idb_cursor->prefetchReset(used_prefetches, unused_prefetches);
816 } 844 }
817 845
818 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 846 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
819 int32 ipc_object_id) { 847 int32 ipc_object_id) {
848 DCHECK(
849 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
820 parent_->DestroyObject(&map_, ipc_object_id); 850 parent_->DestroyObject(&map_, ipc_object_id);
821 } 851 }
822 852
823 } // namespace content 853 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_dispatcher_host.h ('k') | content/browser/indexed_db/indexed_db_context_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698