 Chromium Code Reviews
 Chromium Code Reviews Issue 810403004:
  [Storage] Blob Storage Refactoring pt 1  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 810403004:
  [Storage] Blob Storage Refactoring pt 1  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/guid.h" | 10 #include "base/guid.h" | 
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( | 216 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( | 
| 217 int64 host_transaction_id) { | 217 int64 host_transaction_id) { | 
| 218 return (host_transaction_id >> 32) & 0xffffffff; | 218 return (host_transaction_id >> 32) & 0xffffffff; | 
| 219 } | 219 } | 
| 220 | 220 | 
| 221 std::string IndexedDBDispatcherHost::HoldBlobData( | 221 std::string IndexedDBDispatcherHost::HoldBlobData( | 
| 222 const IndexedDBBlobInfo& blob_info) { | 222 const IndexedDBBlobInfo& blob_info) { | 
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 224 std::string uuid = blob_info.uuid(); | 224 std::string uuid = blob_info.uuid(); | 
| 225 storage::BlobStorageContext* context = blob_storage_context_->context(); | 225 storage::BlobStorageContext* context = blob_storage_context_->context(); | 
| 226 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 226 scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle; | 
| 227 if (uuid.empty()) { | 227 if (uuid.empty()) { | 
| 228 uuid = base::GenerateGUID(); | 228 uuid = base::GenerateGUID(); | 
| 229 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); | 229 scoped_ptr<storage::BlobDataBuilder> blob_data( | 
| 230 new storage::BlobDataBuilder(uuid)); | |
| 230 blob_data->set_content_type(base::UTF16ToUTF8(blob_info.type())); | 231 blob_data->set_content_type(base::UTF16ToUTF8(blob_info.type())); | 
| 231 blob_data->AppendFile(blob_info.file_path(), 0, blob_info.size(), | 232 blob_data->AppendFile(blob_info.file_path(), 0, blob_info.size(), | 
| 232 blob_info.last_modified()); | 233 blob_info.last_modified()); | 
| 233 blob_data_handle = context->AddFinishedBlob(blob_data.get()); | 234 blob_data_handle = context->AddFinishedBlob(*blob_data.get()); | 
| 234 } else { | 235 } else { | 
| 235 auto iter = blob_data_handle_map_.find(uuid); | 236 auto iter = blob_data_handle_map_.find(uuid); | 
| 236 if (iter != blob_data_handle_map_.end()) { | 237 if (iter != blob_data_handle_map_.end()) { | 
| 237 iter->second.second += 1; | 238 iter->second.second += 1; | 
| 238 return uuid; | 239 return uuid; | 
| 239 } | 240 } | 
| 240 blob_data_handle = context->GetBlobDataFromUUID(uuid); | 241 blob_data_handle = context->GetBlobDataFromUUID(uuid); | 
| 241 } | 242 } | 
| 242 | 243 | 
| 243 DCHECK(!ContainsKey(blob_data_handle_map_, uuid)); | 244 DCHECK(!ContainsKey(blob_data_handle_map_, uuid)); | 
| 244 blob_data_handle_map_[uuid] = std::make_pair(blob_data_handle.release(), 1); | 245 blob_data_handle_map_[uuid] = std::make_pair(blob_data_handle.release(), 1); | 
| 
michaeln
2015/01/16 00:09:09
also for this use case, we really only want to ret
 
dmurph
2015/01/16 23:45:56
I think this is fixed from the decoupling of the s
 | |
| 245 return uuid; | 246 return uuid; | 
| 246 } | 247 } | 
| 247 | 248 | 
| 248 void IndexedDBDispatcherHost::DropBlobData(const std::string& uuid) { | 249 void IndexedDBDispatcherHost::DropBlobData(const std::string& uuid) { | 
| 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 250 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); | 251 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); | 
| 251 if (iter != blob_data_handle_map_.end()) { | 252 if (iter != blob_data_handle_map_.end()) { | 
| 252 DCHECK_GE(iter->second.second, 1); | 253 DCHECK_GE(iter->second.second, 1); | 
| 253 if (iter->second.second == 1) { | 254 if (iter->second.second == 1) { | 
| 254 delete iter->second.first; | 255 delete iter->second.first; | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 new IndexedDBCallbacks( | 365 new IndexedDBCallbacks( | 
| 365 this, params.ipc_thread_id, params.ipc_callbacks_id), | 366 this, params.ipc_thread_id, params.ipc_callbacks_id), | 
| 366 origin_url, | 367 origin_url, | 
| 367 indexed_db_path); | 368 indexed_db_path); | 
| 368 } | 369 } | 
| 369 | 370 | 
| 370 // OnPutHelper exists only to allow us to hop threads while holding a reference | 371 // OnPutHelper exists only to allow us to hop threads while holding a reference | 
| 371 // to the IndexedDBDispatcherHost. | 372 // to the IndexedDBDispatcherHost. | 
| 372 void IndexedDBDispatcherHost::OnPutHelper( | 373 void IndexedDBDispatcherHost::OnPutHelper( | 
| 373 const IndexedDBHostMsg_DatabasePut_Params& params, | 374 const IndexedDBHostMsg_DatabasePut_Params& params, | 
| 374 std::vector<storage::BlobDataHandle*> handles) { | 375 std::vector<storage::BlobDataSnapshotHandle*> handles) { | 
| 375 database_dispatcher_host_->OnPut(params, handles); | 376 database_dispatcher_host_->OnPut(params, handles); | 
| 376 } | 377 } | 
| 377 | 378 | 
| 378 void IndexedDBDispatcherHost::OnAckReceivedBlobs( | 379 void IndexedDBDispatcherHost::OnAckReceivedBlobs( | 
| 379 const std::vector<std::string>& uuids) { | 380 const std::vector<std::string>& uuids) { | 
| 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 381 for (const auto& uuid : uuids) | 382 for (const auto& uuid : uuids) | 
| 382 DropBlobData(uuid); | 383 DropBlobData(uuid); | 
| 383 } | 384 } | 
| 384 | 385 | 
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 parent_->HostTransactionId(params.transaction_id), | 638 parent_->HostTransactionId(params.transaction_id), | 
| 638 params.object_store_id, | 639 params.object_store_id, | 
| 639 params.index_id, | 640 params.index_id, | 
| 640 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), | 641 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), | 
| 641 params.key_only, | 642 params.key_only, | 
| 642 callbacks); | 643 callbacks); | 
| 643 } | 644 } | 
| 644 | 645 | 
| 645 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( | 646 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( | 
| 646 const IndexedDBHostMsg_DatabasePut_Params& params) { | 647 const IndexedDBHostMsg_DatabasePut_Params& params) { | 
| 647 std::vector<storage::BlobDataHandle*> handles; | 648 std::vector<storage::BlobDataSnapshotHandle*> handles; | 
| 648 for (size_t i = 0; i < params.blob_or_file_info.size(); ++i) { | 649 for (size_t i = 0; i < params.blob_or_file_info.size(); ++i) { | 
| 649 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i]; | 650 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i]; | 
| 650 handles.push_back(parent_->blob_storage_context_->context() | 651 handles.push_back(parent_->blob_storage_context_->context() | 
| 651 ->GetBlobDataFromUUID(info.uuid) | 652 ->GetBlobDataFromUUID(info.uuid) | 
| 652 .release()); | 653 .release()); | 
| 653 } | 654 } | 
| 654 parent_->indexed_db_context_->TaskRunner()->PostTask( | 655 parent_->indexed_db_context_->TaskRunner()->PostTask( | 
| 655 FROM_HERE, | 656 FROM_HERE, | 
| 656 base::Bind( | 657 base::Bind( | 
| 657 &IndexedDBDispatcherHost::OnPutHelper, parent_, params, handles)); | 658 &IndexedDBDispatcherHost::OnPutHelper, parent_, params, handles)); | 
| 658 } | 659 } | 
| 659 | 660 | 
| 660 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | 661 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | 
| 661 const IndexedDBHostMsg_DatabasePut_Params& params, | 662 const IndexedDBHostMsg_DatabasePut_Params& params, | 
| 662 std::vector<storage::BlobDataHandle*> handles) { | 663 std::vector<storage::BlobDataSnapshotHandle*> handles) { | 
| 663 DCHECK( | 664 DCHECK( | 
| 664 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 665 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 
| 665 | 666 | 
| 666 ScopedVector<storage::BlobDataHandle> scoped_handles; | 667 ScopedVector<storage::BlobDataSnapshotHandle> scoped_handles; | 
| 667 scoped_handles.swap(handles); | 668 scoped_handles.swap(handles); | 
| 668 | 669 | 
| 669 IndexedDBConnection* connection = | 670 IndexedDBConnection* connection = | 
| 670 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 671 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 
| 671 if (!connection || !connection->IsConnected()) | 672 if (!connection || !connection->IsConnected()) | 
| 672 return; | 673 return; | 
| 673 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 674 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 
| 674 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 675 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 
| 675 | 676 | 
| 676 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 677 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 } | 1022 } | 
| 1022 | 1023 | 
| 1023 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 1024 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 
| 1024 int32 ipc_object_id) { | 1025 int32 ipc_object_id) { | 
| 1025 DCHECK( | 1026 DCHECK( | 
| 1026 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 1027 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 
| 1027 parent_->DestroyObject(&map_, ipc_object_id); | 1028 parent_->DestroyObject(&map_, ipc_object_id); | 
| 1028 } | 1029 } | 
| 1029 | 1030 | 
| 1030 } // namespace content | 1031 } // namespace content | 
| OLD | NEW |