Chromium Code Reviews| 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/indexed_db/indexed_db_dispatcher_host.h" | 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_vector.h" | |
| 10 #include "base/process/process.h" | 11 #include "base/process/process.h" |
| 12 #include "base/stl_util.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 14 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 13 #include "content/browser/indexed_db/indexed_db_connection.h" | 15 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 14 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 15 #include "content/browser/indexed_db/indexed_db_cursor.h" | 17 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 17 #include "content/browser/indexed_db/indexed_db_metadata.h" | 19 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 20 #include "content/browser/indexed_db/indexed_db_value.h" | |
| 18 #include "content/browser/renderer_host/render_message_filter.h" | 21 #include "content/browser/renderer_host/render_message_filter.h" |
| 19 #include "content/common/indexed_db/indexed_db_messages.h" | 22 #include "content/common/indexed_db/indexed_db_messages.h" |
| 20 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 22 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
| 24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 27 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 25 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 #include "webkit/browser/blob/blob_storage_context.h" | |
| 26 #include "webkit/browser/database/database_util.h" | 30 #include "webkit/browser/database/database_util.h" |
| 27 #include "webkit/common/database/database_identifier.h" | 31 #include "webkit/common/database/database_identifier.h" |
| 28 | 32 |
| 29 using webkit_database::DatabaseUtil; | 33 using webkit_database::DatabaseUtil; |
| 30 using blink::WebIDBKey; | 34 using blink::WebIDBKey; |
| 31 | 35 |
| 32 namespace content { | 36 namespace content { |
| 33 | 37 |
| 34 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 38 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 35 IndexedDBContextImpl* indexed_db_context) | 39 int ipc_process_id, |
| 36 : indexed_db_context_(indexed_db_context), | 40 net::URLRequestContextGetter* request_context_getter, |
| 41 IndexedDBContextImpl* indexed_db_context, | |
| 42 ChromeBlobStorageContext* blob_storage_context) | |
| 43 : request_context_getter_(request_context_getter), | |
| 44 request_context_(NULL), | |
| 45 indexed_db_context_(indexed_db_context), | |
| 46 blob_storage_context_(blob_storage_context), | |
| 37 database_dispatcher_host_(new DatabaseDispatcherHost(this)), | 47 database_dispatcher_host_(new DatabaseDispatcherHost(this)), |
| 38 cursor_dispatcher_host_(new CursorDispatcherHost(this)) { | 48 cursor_dispatcher_host_(new CursorDispatcherHost(this)), |
| 49 ipc_process_id_(ipc_process_id_) { | |
|
jsbell
2013/12/19 00:39:17
Note the trailing _ inside the ()
ericu
2013/12/19 05:19:11
*Man* I hate that class of typo. That should alwa
jsbell
2013/12/20 00:59:28
I was surprised that wasn't caught. I'll file a FR
| |
| 39 DCHECK(indexed_db_context_); | 50 DCHECK(indexed_db_context_); |
| 40 } | 51 } |
| 41 | 52 |
| 42 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} | 53 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 54 int ipc_process_id, | |
| 55 net::URLRequestContext* request_context, | |
| 56 IndexedDBContextImpl* indexed_db_context, | |
| 57 ChromeBlobStorageContext* blob_storage_context) | |
| 58 : request_context_(request_context), | |
| 59 indexed_db_context_(indexed_db_context), | |
| 60 blob_storage_context_(blob_storage_context), | |
| 61 database_dispatcher_host_(new DatabaseDispatcherHost(this)), | |
| 62 cursor_dispatcher_host_(new CursorDispatcherHost(this)), | |
| 63 ipc_process_id_(ipc_process_id) { | |
| 64 DCHECK(indexed_db_context_); | |
| 65 } | |
| 66 | |
| 67 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { | |
| 68 STLDeleteValues(&blob_data_handle_map_); | |
| 69 } | |
| 70 | |
| 71 void IndexedDBDispatcherHost::OnChannelConnected(int32 peer_pid) { | |
| 72 BrowserMessageFilter::OnChannelConnected(peer_pid); | |
| 73 | |
| 74 if (request_context_getter_.get()) { | |
| 75 DCHECK(!request_context_); | |
| 76 request_context_ = request_context_getter_->GetURLRequestContext(); | |
| 77 request_context_getter_ = NULL; | |
| 78 DCHECK(request_context_); | |
| 79 } | |
| 80 } | |
| 43 | 81 |
| 44 void IndexedDBDispatcherHost::OnChannelClosing() { | 82 void IndexedDBDispatcherHost::OnChannelClosing() { |
| 45 bool success = indexed_db_context_->TaskRunner()->PostTask( | 83 bool success = indexed_db_context_->TaskRunner()->PostTask( |
| 46 FROM_HERE, | 84 FROM_HERE, |
| 47 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); | 85 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); |
| 48 | 86 |
| 49 if (!success) | 87 if (!success) |
| 50 ResetDispatcherHosts(); | 88 ResetDispatcherHosts(); |
| 51 } | 89 } |
| 52 | 90 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 69 // Note that we explicitly separate CloseAll() from destruction of the | 107 // Note that we explicitly separate CloseAll() from destruction of the |
| 70 // DatabaseDispatcherHost, since CloseAll() can invoke callbacks which need to | 108 // DatabaseDispatcherHost, since CloseAll() can invoke callbacks which need to |
| 71 // be dispatched through database_dispatcher_host_. | 109 // be dispatched through database_dispatcher_host_. |
| 72 database_dispatcher_host_->CloseAll(); | 110 database_dispatcher_host_->CloseAll(); |
| 73 database_dispatcher_host_.reset(); | 111 database_dispatcher_host_.reset(); |
| 74 cursor_dispatcher_host_.reset(); | 112 cursor_dispatcher_host_.reset(); |
| 75 } | 113 } |
| 76 | 114 |
| 77 base::TaskRunner* IndexedDBDispatcherHost::OverrideTaskRunnerForMessage( | 115 base::TaskRunner* IndexedDBDispatcherHost::OverrideTaskRunnerForMessage( |
| 78 const IPC::Message& message) { | 116 const IPC::Message& message) { |
| 79 if (IPC_MESSAGE_CLASS(message) == IndexedDBMsgStart) | 117 if (IPC_MESSAGE_CLASS(message) == IndexedDBMsgStart) { |
| 80 return indexed_db_context_->TaskRunner(); | 118 if (message.type() != IndexedDBHostMsg_DatabasePut::ID) |
| 119 return indexed_db_context_->TaskRunner(); | |
| 120 } | |
| 81 return NULL; | 121 return NULL; |
| 82 } | 122 } |
| 83 | 123 |
| 84 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message, | 124 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| 85 bool* message_was_ok) { | 125 bool* message_was_ok) { |
| 86 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) | 126 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) |
| 87 return false; | 127 return false; |
| 88 | 128 |
| 89 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 129 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread() || |
| 130 message.type() == IndexedDBHostMsg_DatabasePut::ID); | |
| 90 | 131 |
| 91 bool handled = | 132 bool handled = |
| 92 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) || | 133 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) || |
| 93 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); | 134 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); |
| 94 | 135 |
| 95 if (!handled) { | 136 if (!handled) { |
| 96 handled = true; | 137 handled = true; |
| 97 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) | 138 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) |
| 98 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, | 139 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, |
| 99 OnIDBFactoryGetDatabaseNames) | 140 OnIDBFactoryGetDatabaseNames) |
| 100 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) | 141 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) |
| 101 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, | 142 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, |
| 102 OnIDBFactoryDeleteDatabase) | 143 OnIDBFactoryDeleteDatabase) |
| 144 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_AckReceivedBlobs, OnAckReceivedBlobs) | |
| 103 IPC_MESSAGE_UNHANDLED(handled = false) | 145 IPC_MESSAGE_UNHANDLED(handled = false) |
| 104 IPC_END_MESSAGE_MAP() | 146 IPC_END_MESSAGE_MAP() |
| 105 } | 147 } |
| 106 return handled; | 148 return handled; |
| 107 } | 149 } |
| 108 | 150 |
| 109 int32 IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { | 151 int32 IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { |
| 110 if (!cursor_dispatcher_host_) { | 152 if (!cursor_dispatcher_host_) { |
| 111 return 0; | 153 return 0; |
| 112 } | 154 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 int64 host_transaction_id) { | 201 int64 host_transaction_id) { |
| 160 return host_transaction_id & 0xffffffff; | 202 return host_transaction_id & 0xffffffff; |
| 161 } | 203 } |
| 162 | 204 |
| 163 // static | 205 // static |
| 164 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( | 206 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( |
| 165 int64 host_transaction_id) { | 207 int64 host_transaction_id) { |
| 166 return (host_transaction_id >> 32) & 0xffffffff; | 208 return (host_transaction_id >> 32) & 0xffffffff; |
| 167 } | 209 } |
| 168 | 210 |
| 211 void IndexedDBDispatcherHost::HoldBlobDataHandle( | |
| 212 const std::string& uuid, | |
| 213 scoped_ptr<webkit_blob::BlobDataHandle>& blob_data_handle) { | |
| 214 DCHECK(blob_data_handle_map_.find(uuid) == blob_data_handle_map_.end()); | |
| 215 blob_data_handle_map_[uuid] = blob_data_handle.release(); | |
| 216 } | |
| 217 | |
| 218 void IndexedDBDispatcherHost::DropBlobDataHandle( | |
| 219 const std::string& uuid) { | |
| 220 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); | |
| 221 if (iter != blob_data_handle_map_.end()) { | |
| 222 delete iter->second; | |
| 223 blob_data_handle_map_.erase(iter); | |
| 224 } else { | |
| 225 DLOG(FATAL) << "Failed to find blob UUID in map:" << uuid; | |
| 226 } | |
| 227 } | |
| 169 | 228 |
| 170 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { | 229 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { |
| 171 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 230 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 172 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); | 231 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); |
| 173 } | 232 } |
| 174 | 233 |
| 175 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( | 234 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( |
| 176 const content::IndexedDBDatabaseMetadata& web_metadata) { | 235 const content::IndexedDBDatabaseMetadata& web_metadata) { |
| 177 ::IndexedDBDatabaseMetadata metadata; | 236 ::IndexedDBDatabaseMetadata metadata; |
| 178 metadata.id = web_metadata.id; | 237 metadata.id = web_metadata.id; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 278 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 220 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 279 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 221 | 280 |
| 222 GURL origin_url = | 281 GURL origin_url = |
| 223 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 282 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
| 224 | 283 |
| 225 Context()->GetIDBFactory()->GetDatabaseNames( | 284 Context()->GetIDBFactory()->GetDatabaseNames( |
| 226 new IndexedDBCallbacks( | 285 new IndexedDBCallbacks( |
| 227 this, params.ipc_thread_id, params.ipc_callbacks_id), | 286 this, params.ipc_thread_id, params.ipc_callbacks_id), |
| 228 origin_url, | 287 origin_url, |
| 229 indexed_db_path); | 288 indexed_db_path, |
| 289 Context()->TaskRunner()); | |
| 230 } | 290 } |
| 231 | 291 |
| 232 void IndexedDBDispatcherHost::OnIDBFactoryOpen( | 292 void IndexedDBDispatcherHost::OnIDBFactoryOpen( |
| 233 const IndexedDBHostMsg_FactoryOpen_Params& params) { | 293 const IndexedDBHostMsg_FactoryOpen_Params& params) { |
| 234 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 294 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 235 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 295 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 236 | 296 |
| 237 GURL origin_url = | 297 GURL origin_url = |
| 238 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 298 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
| 239 | 299 |
| 240 int64 host_transaction_id = HostTransactionId(params.transaction_id); | 300 int64 host_transaction_id = HostTransactionId(params.transaction_id); |
| 241 | 301 |
| 242 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 302 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 243 // created) if this origin is already over quota. | 303 // created) if this origin is already over quota. |
| 244 scoped_refptr<IndexedDBCallbacks> callbacks = | 304 scoped_refptr<IndexedDBCallbacks> callbacks = |
| 245 new IndexedDBCallbacks(this, | 305 new IndexedDBCallbacks(this, |
| 246 params.ipc_thread_id, | 306 params.ipc_thread_id, |
| 247 params.ipc_callbacks_id, | 307 params.ipc_callbacks_id, |
| 248 params.ipc_database_callbacks_id, | 308 params.ipc_database_callbacks_id, |
| 249 host_transaction_id, | 309 host_transaction_id, |
| 250 origin_url); | 310 origin_url); |
| 251 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = | 311 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = |
| 252 new IndexedDBDatabaseCallbacks( | 312 new IndexedDBDatabaseCallbacks( |
| 253 this, params.ipc_thread_id, params.ipc_database_callbacks_id); | 313 this, params.ipc_thread_id, params.ipc_database_callbacks_id); |
| 254 Context()->GetIDBFactory()->Open(params.name, | 314 Context()->GetIDBFactory()->Open(params.name, |
| 255 params.version, | 315 params.version, |
| 316 request_context_, | |
| 256 host_transaction_id, | 317 host_transaction_id, |
| 257 callbacks, | 318 callbacks, |
| 258 database_callbacks, | 319 database_callbacks, |
| 259 origin_url, | 320 origin_url, |
| 260 indexed_db_path); | 321 indexed_db_path, |
| 322 ipc_process_id_, | |
| 323 Context()->TaskRunner()); | |
| 261 } | 324 } |
| 262 | 325 |
| 263 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( | 326 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( |
| 264 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { | 327 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { |
| 265 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 328 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 266 GURL origin_url = | 329 GURL origin_url = |
| 267 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 330 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
| 268 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 331 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 269 Context()->GetIDBFactory()->DeleteDatabase( | 332 Context()->GetIDBFactory()->DeleteDatabase( |
| 270 params.name, | 333 params.name, |
| 334 request_context_, | |
| 271 new IndexedDBCallbacks( | 335 new IndexedDBCallbacks( |
| 272 this, params.ipc_thread_id, params.ipc_callbacks_id), | 336 this, params.ipc_thread_id, params.ipc_callbacks_id), |
| 273 origin_url, | 337 origin_url, |
| 274 indexed_db_path); | 338 indexed_db_path, |
| 339 Context()->TaskRunner()); | |
| 340 } | |
| 341 | |
| 342 void IndexedDBDispatcherHost::OnAckReceivedBlobs( | |
| 343 const std::vector<std::string>& uuids) { | |
| 344 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | |
| 345 std::vector<std::string>::const_iterator iter; | |
| 346 for (iter = uuids.begin(); iter != uuids.end(); ++iter) { | |
| 347 DropBlobDataHandle(*iter); | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 void IndexedDBDispatcherHost::OnPutHelper( | |
| 352 const IndexedDBHostMsg_DatabasePut_Params& params, | |
| 353 std::vector<webkit_blob::BlobDataHandle*> handles) { | |
| 354 database_dispatcher_host_->OnPut(params, handles); | |
| 275 } | 355 } |
| 276 | 356 |
| 277 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, | 357 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, |
| 278 bool committed) { | 358 bool committed) { |
| 279 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 359 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 280 if (!database_dispatcher_host_) | 360 if (!database_dispatcher_host_) |
| 281 return; | 361 return; |
| 282 TransactionIDToURLMap& transaction_url_map = | 362 TransactionIDToURLMap& transaction_url_map = |
| 283 database_dispatcher_host_->transaction_url_map_; | 363 database_dispatcher_host_->transaction_url_map_; |
| 284 TransactionIDToSizeMap& transaction_size_map = | 364 TransactionIDToSizeMap& transaction_size_map = |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 if (connection && connection->IsConnected()) { | 456 if (connection && connection->IsConnected()) { |
| 377 connection->Close(); | 457 connection->Close(); |
| 378 parent_->Context()->ConnectionClosed(iter->second, connection); | 458 parent_->Context()->ConnectionClosed(iter->second, connection); |
| 379 } | 459 } |
| 380 } | 460 } |
| 381 } | 461 } |
| 382 | 462 |
| 383 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( | 463 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( |
| 384 const IPC::Message& message, | 464 const IPC::Message& message, |
| 385 bool* msg_is_ok) { | 465 bool* msg_is_ok) { |
| 386 DCHECK( | 466 |
| 467 DCHECK((message.type() == IndexedDBHostMsg_DatabasePut::ID) || | |
| 387 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 468 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 469 | |
| 388 bool handled = true; | 470 bool handled = true; |
| 389 IPC_BEGIN_MESSAGE_MAP_EX( | 471 IPC_BEGIN_MESSAGE_MAP_EX( |
| 390 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok) | 472 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok) |
| 391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, | 473 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, |
| 392 OnCreateObjectStore) | 474 OnCreateObjectStore) |
| 393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, | 475 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, |
| 394 OnDeleteObjectStore) | 476 OnDeleteObjectStore) |
| 395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, | 477 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, |
| 396 OnCreateTransaction) | 478 OnCreateTransaction) |
| 397 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) | 479 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) |
| 398 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) | 480 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) |
| 399 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) | 481 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) |
| 400 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut) | 482 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper) |
| 401 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) | 483 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) |
| 402 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, | 484 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, |
| 403 OnSetIndexesReady) | 485 OnSetIndexesReady) |
| 404 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) | 486 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) |
| 405 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) | 487 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) |
| 406 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) | 488 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) |
| 407 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) | 489 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) |
| 408 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex) | 490 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex) |
| 409 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex) | 491 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex) |
| 410 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort) | 492 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort) |
| 411 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit) | 493 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit) |
| 412 IPC_MESSAGE_UNHANDLED(handled = false) | 494 IPC_MESSAGE_UNHANDLED(handled = false) |
| 413 IPC_END_MESSAGE_MAP() | 495 IPC_END_MESSAGE_MAP() |
| 496 | |
| 414 return handled; | 497 return handled; |
| 415 } | 498 } |
| 416 | 499 |
| 417 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( | 500 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( |
| 418 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { | 501 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { |
| 419 DCHECK( | 502 DCHECK( |
| 420 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 503 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 421 IndexedDBConnection* connection = | 504 IndexedDBConnection* connection = |
| 422 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 505 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 423 if (!connection || !connection->IsConnected()) | 506 if (!connection || !connection->IsConnected()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 594 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 512 connection->database()->Get( | 595 connection->database()->Get( |
| 513 parent_->HostTransactionId(params.transaction_id), | 596 parent_->HostTransactionId(params.transaction_id), |
| 514 params.object_store_id, | 597 params.object_store_id, |
| 515 params.index_id, | 598 params.index_id, |
| 516 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), | 599 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), |
| 517 params.key_only, | 600 params.key_only, |
| 518 callbacks); | 601 callbacks); |
| 519 } | 602 } |
| 520 | 603 |
| 604 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( | |
|
jsbell
2013/12/19 00:55:49
This could definitely use a comment that OnPutWrap
ericu
2013/12/19 05:19:11
Done.
| |
| 605 const IndexedDBHostMsg_DatabasePut_Params& params) { | |
| 606 std::vector<webkit_blob::BlobDataHandle*> handles; | |
| 607 for (size_t i=0; i < params.blob_or_file_info.size(); ++i) { | |
| 608 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i]; | |
| 609 handles.push_back( | |
| 610 parent_->blob_storage_context_->context()->GetBlobDataFromUUID( | |
| 611 info.uuid).release()); | |
| 612 } | |
| 613 parent_->indexed_db_context_->TaskRunner()->PostTask( | |
| 614 FROM_HERE, | |
| 615 base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_, | |
| 616 params, handles)); | |
| 617 } | |
| 618 | |
| 521 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | 619 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( |
| 522 const IndexedDBHostMsg_DatabasePut_Params& params) { | 620 const IndexedDBHostMsg_DatabasePut_Params& params, |
| 621 std::vector<webkit_blob::BlobDataHandle*> handles) { | |
| 622 | |
| 523 DCHECK( | 623 DCHECK( |
| 524 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 624 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 525 | 625 |
| 626 ScopedVector<webkit_blob::BlobDataHandle> scoped_handles; | |
| 627 scoped_handles.swap(handles); | |
| 628 | |
| 526 IndexedDBConnection* connection = | 629 IndexedDBConnection* connection = |
| 527 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 630 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 528 if (!connection || !connection->IsConnected()) | 631 if (!connection || !connection->IsConnected()) |
| 529 return; | 632 return; |
| 530 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 633 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 531 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 634 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 532 | 635 |
| 533 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 636 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 637 | |
| 638 std::vector<IndexedDBBlobInfo> blob_info(params.blob_or_file_info.size()); | |
| 639 | |
| 640 for (size_t i=0; i < params.blob_or_file_info.size(); ++i) { | |
| 641 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i]; | |
| 642 if (info.is_file) | |
| 643 blob_info[i] = | |
| 644 IndexedDBBlobInfo(base::FilePath::FromUTF16Unsafe(info.file_path), | |
| 645 info.file_name, info.mime_type); | |
| 646 else | |
| 647 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); | |
| 648 } | |
| 534 // TODO(alecflett): Avoid a copy here. | 649 // TODO(alecflett): Avoid a copy here. |
| 535 std::string value_copy(params.value); | 650 IndexedDBValue value; |
| 651 value.bits = params.value; | |
| 652 value.blob_info.swap(blob_info); | |
| 536 connection->database()->Put( | 653 connection->database()->Put( |
| 537 host_transaction_id, | 654 host_transaction_id, |
| 538 params.object_store_id, | 655 params.object_store_id, |
| 539 &value_copy, | 656 &value, |
| 657 &scoped_handles, | |
| 540 make_scoped_ptr(new IndexedDBKey(params.key)), | 658 make_scoped_ptr(new IndexedDBKey(params.key)), |
| 541 static_cast<IndexedDBDatabase::PutMode>(params.put_mode), | 659 static_cast<IndexedDBDatabase::PutMode>(params.put_mode), |
| 542 callbacks, | 660 callbacks, |
| 543 params.index_ids, | 661 params.index_ids, |
| 544 params.index_keys); | 662 params.index_keys); |
| 545 TransactionIDToSizeMap* map = | 663 TransactionIDToSizeMap* map = |
| 546 &parent_->database_dispatcher_host_->transaction_size_map_; | 664 &parent_->database_dispatcher_host_->transaction_size_map_; |
| 547 // Size can't be big enough to overflow because it represents the | 665 // Size can't be big enough to overflow because it represents the |
| 548 // actual bytes passed through IPC. | 666 // actual bytes passed through IPC. |
| 549 (*map)[host_transaction_id] += params.value.size(); | 667 (*map)[host_transaction_id] += params.value.size(); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 IndexedDBDispatcherHost* parent) | 875 IndexedDBDispatcherHost* parent) |
| 758 : parent_(parent) { | 876 : parent_(parent) { |
| 759 map_.set_check_on_null_data(true); | 877 map_.set_check_on_null_data(true); |
| 760 } | 878 } |
| 761 | 879 |
| 762 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} | 880 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} |
| 763 | 881 |
| 764 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( | 882 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( |
| 765 const IPC::Message& message, | 883 const IPC::Message& message, |
| 766 bool* msg_is_ok) { | 884 bool* msg_is_ok) { |
| 767 DCHECK( | |
| 768 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | |
| 769 | |
| 770 bool handled = true; | 885 bool handled = true; |
| 771 IPC_BEGIN_MESSAGE_MAP_EX( | 886 IPC_BEGIN_MESSAGE_MAP_EX( |
| 772 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) | 887 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) |
| 773 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) | 888 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) |
| 774 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) | 889 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) |
| 775 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) | 890 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) |
| 776 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) | 891 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) |
| 777 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) | 892 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) |
| 778 IPC_MESSAGE_UNHANDLED(handled = false) | 893 IPC_MESSAGE_UNHANDLED(handled = false) |
| 779 IPC_END_MESSAGE_MAP() | 894 IPC_END_MESSAGE_MAP() |
| 895 | |
| 896 DCHECK(!handled || | |
| 897 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | |
| 898 | |
| 780 return handled; | 899 return handled; |
| 781 } | 900 } |
| 782 | 901 |
| 783 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( | 902 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( |
| 784 int32 ipc_cursor_id, | 903 int32 ipc_cursor_id, |
| 785 int32 ipc_thread_id, | 904 int32 ipc_thread_id, |
| 786 int32 ipc_callbacks_id, | 905 int32 ipc_callbacks_id, |
| 787 unsigned long count) { | 906 unsigned long count) { |
| 788 DCHECK( | 907 DCHECK( |
| 789 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 908 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 } | 972 } |
| 854 | 973 |
| 855 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 974 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 856 int32 ipc_object_id) { | 975 int32 ipc_object_id) { |
| 857 DCHECK( | 976 DCHECK( |
| 858 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 977 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 859 parent_->DestroyObject(&map_, ipc_object_id); | 978 parent_->DestroyObject(&map_, ipc_object_id); |
| 860 } | 979 } |
| 861 | 980 |
| 862 } // namespace content | 981 } // namespace content |
| OLD | NEW |