| 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) { |
| 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(const std::string& uuid) { |
| 219 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); |
| 220 if (iter != blob_data_handle_map_.end()) { |
| 221 delete iter->second; |
| 222 blob_data_handle_map_.erase(iter); |
| 223 } else { |
| 224 DLOG(FATAL) << "Failed to find blob UUID in map:" << uuid; |
| 225 } |
| 226 } |
| 169 | 227 |
| 170 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { | 228 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { |
| 171 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 229 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 172 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); | 230 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); |
| 173 } | 231 } |
| 174 | 232 |
| 175 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( | 233 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( |
| 176 const content::IndexedDBDatabaseMetadata& web_metadata) { | 234 const content::IndexedDBDatabaseMetadata& web_metadata) { |
| 177 ::IndexedDBDatabaseMetadata metadata; | 235 ::IndexedDBDatabaseMetadata metadata; |
| 178 metadata.id = web_metadata.id; | 236 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()); | 277 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 220 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 278 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 221 | 279 |
| 222 GURL origin_url = | 280 GURL origin_url = |
| 223 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 281 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
| 224 | 282 |
| 225 Context()->GetIDBFactory()->GetDatabaseNames( | 283 Context()->GetIDBFactory()->GetDatabaseNames( |
| 226 new IndexedDBCallbacks( | 284 new IndexedDBCallbacks( |
| 227 this, params.ipc_thread_id, params.ipc_callbacks_id), | 285 this, params.ipc_thread_id, params.ipc_callbacks_id), |
| 228 origin_url, | 286 origin_url, |
| 229 indexed_db_path); | 287 indexed_db_path, |
| 288 Context()->TaskRunner()); |
| 230 } | 289 } |
| 231 | 290 |
| 232 void IndexedDBDispatcherHost::OnIDBFactoryOpen( | 291 void IndexedDBDispatcherHost::OnIDBFactoryOpen( |
| 233 const IndexedDBHostMsg_FactoryOpen_Params& params) { | 292 const IndexedDBHostMsg_FactoryOpen_Params& params) { |
| 234 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 293 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 235 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 294 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 236 | 295 |
| 237 GURL origin_url = | 296 GURL origin_url = |
| 238 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 297 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
| 239 | 298 |
| 240 int64 host_transaction_id = HostTransactionId(params.transaction_id); | 299 int64 host_transaction_id = HostTransactionId(params.transaction_id); |
| 241 | 300 |
| 242 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 301 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 243 // created) if this origin is already over quota. | 302 // created) if this origin is already over quota. |
| 244 scoped_refptr<IndexedDBCallbacks> callbacks = | 303 scoped_refptr<IndexedDBCallbacks> callbacks = |
| 245 new IndexedDBCallbacks(this, | 304 new IndexedDBCallbacks(this, |
| 246 params.ipc_thread_id, | 305 params.ipc_thread_id, |
| 247 params.ipc_callbacks_id, | 306 params.ipc_callbacks_id, |
| 248 params.ipc_database_callbacks_id, | 307 params.ipc_database_callbacks_id, |
| 249 host_transaction_id, | 308 host_transaction_id, |
| 250 origin_url); | 309 origin_url); |
| 251 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = | 310 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = |
| 252 new IndexedDBDatabaseCallbacks( | 311 new IndexedDBDatabaseCallbacks( |
| 253 this, params.ipc_thread_id, params.ipc_database_callbacks_id); | 312 this, params.ipc_thread_id, params.ipc_database_callbacks_id); |
| 254 Context()->GetIDBFactory()->Open(params.name, | 313 Context()->GetIDBFactory()->Open(params.name, |
| 255 params.version, | 314 params.version, |
| 315 request_context_, |
| 256 host_transaction_id, | 316 host_transaction_id, |
| 257 callbacks, | 317 callbacks, |
| 258 database_callbacks, | 318 database_callbacks, |
| 259 origin_url, | 319 origin_url, |
| 260 indexed_db_path); | 320 indexed_db_path, |
| 321 ipc_process_id_, |
| 322 Context()->TaskRunner()); |
| 261 } | 323 } |
| 262 | 324 |
| 263 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( | 325 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( |
| 264 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { | 326 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { |
| 265 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 327 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 266 GURL origin_url = | 328 GURL origin_url = |
| 267 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 329 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
| 268 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 330 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 269 Context()->GetIDBFactory()->DeleteDatabase( | 331 Context()->GetIDBFactory()->DeleteDatabase( |
| 270 params.name, | 332 params.name, |
| 333 request_context_, |
| 271 new IndexedDBCallbacks( | 334 new IndexedDBCallbacks( |
| 272 this, params.ipc_thread_id, params.ipc_callbacks_id), | 335 this, params.ipc_thread_id, params.ipc_callbacks_id), |
| 273 origin_url, | 336 origin_url, |
| 274 indexed_db_path); | 337 indexed_db_path, |
| 338 Context()->TaskRunner()); |
| 339 } |
| 340 |
| 341 void IndexedDBDispatcherHost::OnAckReceivedBlobs( |
| 342 const std::vector<std::string>& uuids) { |
| 343 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 344 std::vector<std::string>::const_iterator iter; |
| 345 for (iter = uuids.begin(); iter != uuids.end(); ++iter) { |
| 346 DropBlobDataHandle(*iter); |
| 347 } |
| 348 } |
| 349 |
| 350 // OnPutHelper exists only to allow us to hop threads while holding a reference |
| 351 // to the IndexedDBDispatcherHost. |
| 352 void IndexedDBDispatcherHost::OnPutHelper( |
| 353 const IndexedDBHostMsg_DatabasePut_Params& params, |
| 354 std::vector<webkit_blob::BlobDataHandle*> handles) { |
| 355 database_dispatcher_host_->OnPut(params, handles); |
| 275 } | 356 } |
| 276 | 357 |
| 277 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, | 358 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, |
| 278 bool committed) { | 359 bool committed) { |
| 279 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 360 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 280 if (!database_dispatcher_host_) | 361 if (!database_dispatcher_host_) |
| 281 return; | 362 return; |
| 282 TransactionIDToURLMap& transaction_url_map = | 363 TransactionIDToURLMap& transaction_url_map = |
| 283 database_dispatcher_host_->transaction_url_map_; | 364 database_dispatcher_host_->transaction_url_map_; |
| 284 TransactionIDToSizeMap& transaction_size_map = | 365 TransactionIDToSizeMap& transaction_size_map = |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 if (connection && connection->IsConnected()) { | 457 if (connection && connection->IsConnected()) { |
| 377 connection->Close(); | 458 connection->Close(); |
| 378 parent_->Context()->ConnectionClosed(iter->second, connection); | 459 parent_->Context()->ConnectionClosed(iter->second, connection); |
| 379 } | 460 } |
| 380 } | 461 } |
| 381 } | 462 } |
| 382 | 463 |
| 383 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( | 464 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( |
| 384 const IPC::Message& message, | 465 const IPC::Message& message, |
| 385 bool* msg_is_ok) { | 466 bool* msg_is_ok) { |
| 467 |
| 386 DCHECK( | 468 DCHECK( |
| 469 (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(parent_->blob_storage_context_->context() |
| 612 ->GetBlobDataFromUUID(info.uuid) |
| 613 .release()); |
| 614 } |
| 615 parent_->indexed_db_context_->TaskRunner()->PostTask( |
| 616 FROM_HERE, |
| 617 base::Bind( |
| 618 &IndexedDBDispatcherHost::OnPutHelper, parent_, 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 |
| 628 ScopedVector<webkit_blob::BlobDataHandle> scoped_handles; |
| 629 scoped_handles.swap(handles); |
| 630 |
| 526 IndexedDBConnection* connection = | 631 IndexedDBConnection* connection = |
| 527 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 632 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 528 if (!connection || !connection->IsConnected()) | 633 if (!connection || !connection->IsConnected()) |
| 529 return; | 634 return; |
| 530 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 635 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 531 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 636 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 532 | 637 |
| 533 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 638 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 639 |
| 640 std::vector<IndexedDBBlobInfo> blob_info(params.blob_or_file_info.size()); |
| 641 |
| 642 for (size_t i = 0; i < params.blob_or_file_info.size(); ++i) { |
| 643 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i]; |
| 644 if (info.is_file) |
| 645 blob_info[i] = |
| 646 IndexedDBBlobInfo(base::FilePath::FromUTF16Unsafe(info.file_path), |
| 647 info.file_name, |
| 648 info.mime_type); |
| 649 else |
| 650 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); |
| 651 } |
| 534 // TODO(alecflett): Avoid a copy here. | 652 // TODO(alecflett): Avoid a copy here. |
| 535 std::string value_copy(params.value); | 653 IndexedDBValue value; |
| 654 value.bits = params.value; |
| 655 value.blob_info.swap(blob_info); |
| 536 connection->database()->Put( | 656 connection->database()->Put( |
| 537 host_transaction_id, | 657 host_transaction_id, |
| 538 params.object_store_id, | 658 params.object_store_id, |
| 539 &value_copy, | 659 &value, |
| 660 &scoped_handles, |
| 540 make_scoped_ptr(new IndexedDBKey(params.key)), | 661 make_scoped_ptr(new IndexedDBKey(params.key)), |
| 541 static_cast<IndexedDBDatabase::PutMode>(params.put_mode), | 662 static_cast<IndexedDBDatabase::PutMode>(params.put_mode), |
| 542 callbacks, | 663 callbacks, |
| 543 params.index_ids, | 664 params.index_ids, |
| 544 params.index_keys); | 665 params.index_keys); |
| 545 TransactionIDToSizeMap* map = | 666 TransactionIDToSizeMap* map = |
| 546 &parent_->database_dispatcher_host_->transaction_size_map_; | 667 &parent_->database_dispatcher_host_->transaction_size_map_; |
| 547 // Size can't be big enough to overflow because it represents the | 668 // Size can't be big enough to overflow because it represents the |
| 548 // actual bytes passed through IPC. | 669 // actual bytes passed through IPC. |
| 549 (*map)[host_transaction_id] += params.value.size(); | 670 (*map)[host_transaction_id] += params.value.size(); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 IndexedDBDispatcherHost* parent) | 878 IndexedDBDispatcherHost* parent) |
| 758 : parent_(parent) { | 879 : parent_(parent) { |
| 759 map_.set_check_on_null_data(true); | 880 map_.set_check_on_null_data(true); |
| 760 } | 881 } |
| 761 | 882 |
| 762 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} | 883 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} |
| 763 | 884 |
| 764 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( | 885 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( |
| 765 const IPC::Message& message, | 886 const IPC::Message& message, |
| 766 bool* msg_is_ok) { | 887 bool* msg_is_ok) { |
| 767 DCHECK( | |
| 768 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | |
| 769 | |
| 770 bool handled = true; | 888 bool handled = true; |
| 771 IPC_BEGIN_MESSAGE_MAP_EX( | 889 IPC_BEGIN_MESSAGE_MAP_EX( |
| 772 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) | 890 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) |
| 773 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) | 891 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) |
| 774 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) | 892 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) |
| 775 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) | 893 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) |
| 776 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) | 894 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) |
| 777 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) | 895 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) |
| 778 IPC_MESSAGE_UNHANDLED(handled = false) | 896 IPC_MESSAGE_UNHANDLED(handled = false) |
| 779 IPC_END_MESSAGE_MAP() | 897 IPC_END_MESSAGE_MAP() |
| 898 |
| 899 DCHECK( |
| 900 !handled || |
| 901 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 902 |
| 780 return handled; | 903 return handled; |
| 781 } | 904 } |
| 782 | 905 |
| 783 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( | 906 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( |
| 784 int32 ipc_cursor_id, | 907 int32 ipc_cursor_id, |
| 785 int32 ipc_thread_id, | 908 int32 ipc_thread_id, |
| 786 int32 ipc_callbacks_id, | 909 int32 ipc_callbacks_id, |
| 787 unsigned long count) { | 910 unsigned long count) { |
| 788 DCHECK( | 911 DCHECK( |
| 789 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 912 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 } | 976 } |
| 854 | 977 |
| 855 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 978 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 856 int32 ipc_object_id) { | 979 int32 ipc_object_id) { |
| 857 DCHECK( | 980 DCHECK( |
| 858 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 981 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 859 parent_->DestroyObject(&map_, ipc_object_id); | 982 parent_->DestroyObject(&map_, ipc_object_id); |
| 860 } | 983 } |
| 861 | 984 |
| 862 } // namespace content | 985 } // namespace content |
| OLD | NEW |