| 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/memory/scoped_vector.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 28 #include "content/public/common/result_codes.h" | 28 #include "content/public/common/result_codes.h" |
| 29 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 29 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 31 #include "webkit/browser/blob/blob_storage_context.h" | 31 #include "webkit/browser/blob/blob_storage_context.h" |
| 32 #include "webkit/browser/database/database_util.h" | 32 #include "webkit/browser/database/database_util.h" |
| 33 #include "webkit/common/database/database_identifier.h" | 33 #include "webkit/common/database/database_identifier.h" |
| 34 | 34 |
| 35 using webkit_database::DatabaseUtil; | 35 using storage::DatabaseUtil; |
| 36 using blink::WebIDBKey; | 36 using blink::WebIDBKey; |
| 37 | 37 |
| 38 namespace content { | 38 namespace content { |
| 39 | 39 |
| 40 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 40 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 41 int ipc_process_id, | 41 int ipc_process_id, |
| 42 net::URLRequestContextGetter* request_context_getter, | 42 net::URLRequestContextGetter* request_context_getter, |
| 43 IndexedDBContextImpl* indexed_db_context, | 43 IndexedDBContextImpl* indexed_db_context, |
| 44 ChromeBlobStorageContext* blob_storage_context) | 44 ChromeBlobStorageContext* blob_storage_context) |
| 45 : BrowserMessageFilter(IndexedDBMsgStart), | 45 : BrowserMessageFilter(IndexedDBMsgStart), |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 // static | 206 // static |
| 207 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( | 207 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( |
| 208 int64 host_transaction_id) { | 208 int64 host_transaction_id) { |
| 209 return (host_transaction_id >> 32) & 0xffffffff; | 209 return (host_transaction_id >> 32) & 0xffffffff; |
| 210 } | 210 } |
| 211 | 211 |
| 212 void IndexedDBDispatcherHost::HoldBlobDataHandle( | 212 void IndexedDBDispatcherHost::HoldBlobDataHandle( |
| 213 const std::string& uuid, | 213 const std::string& uuid, |
| 214 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle) { | 214 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 215 DCHECK(!ContainsKey(blob_data_handle_map_, uuid)); | 215 DCHECK(!ContainsKey(blob_data_handle_map_, uuid)); |
| 216 blob_data_handle_map_[uuid] = blob_data_handle.release(); | 216 blob_data_handle_map_[uuid] = blob_data_handle.release(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void IndexedDBDispatcherHost::DropBlobDataHandle(const std::string& uuid) { | 219 void IndexedDBDispatcherHost::DropBlobDataHandle(const std::string& uuid) { |
| 220 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); | 220 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); |
| 221 if (iter != blob_data_handle_map_.end()) { | 221 if (iter != blob_data_handle_map_.end()) { |
| 222 delete iter->second; | 222 delete iter->second; |
| 223 blob_data_handle_map_.erase(iter); | 223 blob_data_handle_map_.erase(iter); |
| 224 } else { | 224 } else { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 271 } |
| 272 return metadata; | 272 return metadata; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( | 275 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( |
| 276 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { | 276 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { |
| 277 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 277 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 278 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 278 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 279 | 279 |
| 280 GURL origin_url = | 280 GURL origin_url = |
| 281 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 281 storage::GetOriginFromIdentifier(params.database_identifier); |
| 282 | 282 |
| 283 Context()->GetIDBFactory()->GetDatabaseNames( | 283 Context()->GetIDBFactory()->GetDatabaseNames( |
| 284 new IndexedDBCallbacks( | 284 new IndexedDBCallbacks( |
| 285 this, params.ipc_thread_id, params.ipc_callbacks_id), | 285 this, params.ipc_thread_id, params.ipc_callbacks_id), |
| 286 origin_url, | 286 origin_url, |
| 287 indexed_db_path, | 287 indexed_db_path, |
| 288 request_context_); | 288 request_context_); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void IndexedDBDispatcherHost::OnIDBFactoryOpen( | 291 void IndexedDBDispatcherHost::OnIDBFactoryOpen( |
| 292 const IndexedDBHostMsg_FactoryOpen_Params& params) { | 292 const IndexedDBHostMsg_FactoryOpen_Params& params) { |
| 293 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 293 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 294 base::TimeTicks begin_time = base::TimeTicks::Now(); | 294 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 295 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 295 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 296 | 296 |
| 297 GURL origin_url = | 297 GURL origin_url = |
| 298 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 298 storage::GetOriginFromIdentifier(params.database_identifier); |
| 299 | 299 |
| 300 int64 host_transaction_id = HostTransactionId(params.transaction_id); | 300 int64 host_transaction_id = HostTransactionId(params.transaction_id); |
| 301 | 301 |
| 302 // 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 |
| 303 // created) if this origin is already over quota. | 303 // created) if this origin is already over quota. |
| 304 scoped_refptr<IndexedDBCallbacks> callbacks = | 304 scoped_refptr<IndexedDBCallbacks> callbacks = |
| 305 new IndexedDBCallbacks(this, | 305 new IndexedDBCallbacks(this, |
| 306 params.ipc_thread_id, | 306 params.ipc_thread_id, |
| 307 params.ipc_callbacks_id, | 307 params.ipc_callbacks_id, |
| 308 params.ipc_database_callbacks_id, | 308 params.ipc_database_callbacks_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 319 params.version); | 319 params.version); |
| 320 DCHECK(request_context_); | 320 DCHECK(request_context_); |
| 321 Context()->GetIDBFactory()->Open( | 321 Context()->GetIDBFactory()->Open( |
| 322 params.name, connection, request_context_, origin_url, indexed_db_path); | 322 params.name, connection, request_context_, origin_url, indexed_db_path); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( | 325 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( |
| 326 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { | 326 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { |
| 327 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 327 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 328 GURL origin_url = | 328 GURL origin_url = |
| 329 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 329 storage::GetOriginFromIdentifier(params.database_identifier); |
| 330 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 330 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 331 DCHECK(request_context_); | 331 DCHECK(request_context_); |
| 332 Context()->GetIDBFactory()->DeleteDatabase( | 332 Context()->GetIDBFactory()->DeleteDatabase( |
| 333 params.name, | 333 params.name, |
| 334 request_context_, | 334 request_context_, |
| 335 new IndexedDBCallbacks( | 335 new IndexedDBCallbacks( |
| 336 this, params.ipc_thread_id, params.ipc_callbacks_id), | 336 this, params.ipc_thread_id, params.ipc_callbacks_id), |
| 337 origin_url, | 337 origin_url, |
| 338 indexed_db_path); | 338 indexed_db_path); |
| 339 } | 339 } |
| 340 | 340 |
| 341 // OnPutHelper exists only to allow us to hop threads while holding a reference | 341 // OnPutHelper exists only to allow us to hop threads while holding a reference |
| 342 // to the IndexedDBDispatcherHost. | 342 // to the IndexedDBDispatcherHost. |
| 343 void IndexedDBDispatcherHost::OnPutHelper( | 343 void IndexedDBDispatcherHost::OnPutHelper( |
| 344 const IndexedDBHostMsg_DatabasePut_Params& params, | 344 const IndexedDBHostMsg_DatabasePut_Params& params, |
| 345 std::vector<webkit_blob::BlobDataHandle*> handles) { | 345 std::vector<storage::BlobDataHandle*> handles) { |
| 346 database_dispatcher_host_->OnPut(params, handles); | 346 database_dispatcher_host_->OnPut(params, handles); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void IndexedDBDispatcherHost::OnAckReceivedBlobs( | 349 void IndexedDBDispatcherHost::OnAckReceivedBlobs( |
| 350 const std::vector<std::string>& uuids) { | 350 const std::vector<std::string>& uuids) { |
| 351 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 351 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 352 std::vector<std::string>::const_iterator iter; | 352 std::vector<std::string>::const_iterator iter; |
| 353 for (iter = uuids.begin(); iter != uuids.end(); ++iter) | 353 for (iter = uuids.begin(); iter != uuids.end(); ++iter) |
| 354 DropBlobDataHandle(*iter); | 354 DropBlobDataHandle(*iter); |
| 355 } | 355 } |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 parent_->HostTransactionId(params.transaction_id), | 611 parent_->HostTransactionId(params.transaction_id), |
| 612 params.object_store_id, | 612 params.object_store_id, |
| 613 params.index_id, | 613 params.index_id, |
| 614 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), | 614 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), |
| 615 params.key_only, | 615 params.key_only, |
| 616 callbacks); | 616 callbacks); |
| 617 } | 617 } |
| 618 | 618 |
| 619 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( | 619 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( |
| 620 const IndexedDBHostMsg_DatabasePut_Params& params) { | 620 const IndexedDBHostMsg_DatabasePut_Params& params) { |
| 621 std::vector<webkit_blob::BlobDataHandle*> handles; | 621 std::vector<storage::BlobDataHandle*> handles; |
| 622 for (size_t i = 0; i < params.blob_or_file_info.size(); ++i) { | 622 for (size_t i = 0; i < params.blob_or_file_info.size(); ++i) { |
| 623 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i]; | 623 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i]; |
| 624 handles.push_back(parent_->blob_storage_context_->context() | 624 handles.push_back(parent_->blob_storage_context_->context() |
| 625 ->GetBlobDataFromUUID(info.uuid) | 625 ->GetBlobDataFromUUID(info.uuid) |
| 626 .release()); | 626 .release()); |
| 627 } | 627 } |
| 628 parent_->indexed_db_context_->TaskRunner()->PostTask( | 628 parent_->indexed_db_context_->TaskRunner()->PostTask( |
| 629 FROM_HERE, | 629 FROM_HERE, |
| 630 base::Bind( | 630 base::Bind( |
| 631 &IndexedDBDispatcherHost::OnPutHelper, parent_, params, handles)); | 631 &IndexedDBDispatcherHost::OnPutHelper, parent_, params, handles)); |
| 632 } | 632 } |
| 633 | 633 |
| 634 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | 634 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( |
| 635 const IndexedDBHostMsg_DatabasePut_Params& params, | 635 const IndexedDBHostMsg_DatabasePut_Params& params, |
| 636 std::vector<webkit_blob::BlobDataHandle*> handles) { | 636 std::vector<storage::BlobDataHandle*> handles) { |
| 637 | |
| 638 DCHECK( | 637 DCHECK( |
| 639 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 638 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 640 | 639 |
| 641 ScopedVector<webkit_blob::BlobDataHandle> scoped_handles; | 640 ScopedVector<storage::BlobDataHandle> scoped_handles; |
| 642 scoped_handles.swap(handles); | 641 scoped_handles.swap(handles); |
| 643 | 642 |
| 644 IndexedDBConnection* connection = | 643 IndexedDBConnection* connection = |
| 645 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 644 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 646 if (!connection || !connection->IsConnected()) | 645 if (!connection || !connection->IsConnected()) |
| 647 return; | 646 return; |
| 648 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 647 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 649 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 648 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 650 | 649 |
| 651 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 650 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 } | 992 } |
| 994 | 993 |
| 995 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 994 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 996 int32 ipc_object_id) { | 995 int32 ipc_object_id) { |
| 997 DCHECK( | 996 DCHECK( |
| 998 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 997 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 999 parent_->DestroyObject(&map_, ipc_object_id); | 998 parent_->DestroyObject(&map_, ipc_object_id); |
| 1000 } | 999 } |
| 1001 | 1000 |
| 1002 } // namespace content | 1001 } // namespace content |
| OLD | NEW |