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