| 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_callbacks.h" | 5 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 ipc_object_id, | 179 ipc_object_id, |
| 180 IndexedDBDispatcherHost::ConvertMetadata(metadata))); | 180 IndexedDBDispatcherHost::ConvertMetadata(metadata))); |
| 181 dispatcher_host_ = NULL; | 181 dispatcher_host_ = NULL; |
| 182 } | 182 } |
| 183 | 183 |
| 184 static std::string CreateBlobData( | 184 static std::string CreateBlobData( |
| 185 const IndexedDBBlobInfo& blob_info, | 185 const IndexedDBBlobInfo& blob_info, |
| 186 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 186 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, |
| 187 webkit_blob::BlobStorageContext* blob_storage_context, | 187 webkit_blob::BlobStorageContext* blob_storage_context, |
| 188 base::TaskRunner* task_runner) { | 188 base::TaskRunner* task_runner) { |
| 189 std::string uuid = blob_info.uuid(); |
| 190 if (!uuid.empty()) { |
| 191 // We're sending back a live blob, not a reference into our backing store. |
| 192 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle( |
| 193 blob_storage_context->GetBlobDataFromUUID(uuid)); |
| 194 dispatcher_host->HoldBlobDataHandle(uuid, blob_data_handle); |
| 195 return uuid; |
| 196 } |
| 189 scoped_refptr<ShareableFileReference> shareable_file = | 197 scoped_refptr<ShareableFileReference> shareable_file = |
| 190 ShareableFileReference::Get(blob_info.file_path()); | 198 ShareableFileReference::Get(blob_info.file_path()); |
| 191 if (!shareable_file.get()) { | 199 if (!shareable_file.get()) { |
| 192 shareable_file = ShareableFileReference::GetOrCreate( | 200 shareable_file = ShareableFileReference::GetOrCreate( |
| 193 blob_info.file_path(), | 201 blob_info.file_path(), |
| 194 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, | 202 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, |
| 195 task_runner); | 203 task_runner); |
| 196 shareable_file->AddFinalReleaseCallback(blob_info.release_callback()); | 204 if (!blob_info.release_callback().is_null()) |
| 205 shareable_file->AddFinalReleaseCallback(blob_info.release_callback()); |
| 197 } | 206 } |
| 198 | 207 |
| 199 std::string uuid(base::GenerateGUID()); | 208 uuid = base::GenerateGUID(); |
| 200 scoped_refptr<webkit_blob::BlobData> blob_data = | 209 scoped_refptr<webkit_blob::BlobData> blob_data = |
| 201 new webkit_blob::BlobData(uuid); | 210 new webkit_blob::BlobData(uuid); |
| 202 blob_data->AppendFile( | 211 blob_data->AppendFile( |
| 203 blob_info.file_path(), 0, blob_info.size(), blob_info.last_modified()); | 212 blob_info.file_path(), 0, blob_info.size(), blob_info.last_modified()); |
| 204 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle( | 213 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle( |
| 205 blob_storage_context->AddFinishedBlob(blob_data.get())); | 214 blob_storage_context->AddFinishedBlob(blob_data.get())); |
| 206 dispatcher_host->HoldBlobDataHandle(uuid, blob_data_handle); | 215 dispatcher_host->HoldBlobDataHandle(uuid, blob_data_handle); |
| 207 | 216 |
| 208 return uuid; | 217 return uuid; |
| 209 } | 218 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 std::vector<IndexedDBMsg_BlobOrFileInfo>* blob_or_file_info) { | 272 std::vector<IndexedDBMsg_BlobOrFileInfo>* blob_or_file_info) { |
| 264 for (std::vector<IndexedDBBlobInfo>::const_iterator iter = blob_info.begin(); | 273 for (std::vector<IndexedDBBlobInfo>::const_iterator iter = blob_info.begin(); |
| 265 iter != blob_info.end(); | 274 iter != blob_info.end(); |
| 266 ++iter) { | 275 ++iter) { |
| 267 if (iter->is_file()) { | 276 if (iter->is_file()) { |
| 268 IndexedDBMsg_BlobOrFileInfo info; | 277 IndexedDBMsg_BlobOrFileInfo info; |
| 269 info.is_file = true; | 278 info.is_file = true; |
| 270 info.mime_type = iter->type(); | 279 info.mime_type = iter->type(); |
| 271 info.file_name = iter->file_name(); | 280 info.file_name = iter->file_name(); |
| 272 info.file_path = iter->file_path().AsUTF16Unsafe(); | 281 info.file_path = iter->file_path().AsUTF16Unsafe(); |
| 273 DCHECK_NE(-1, iter->size()); | |
| 274 info.size = iter->size(); | 282 info.size = iter->size(); |
| 275 info.last_modified = iter->last_modified().ToDoubleT(); | 283 info.last_modified = iter->last_modified().ToDoubleT(); |
| 276 blob_or_file_info->push_back(info); | 284 blob_or_file_info->push_back(info); |
| 277 } else { | 285 } else { |
| 278 IndexedDBMsg_BlobOrFileInfo info; | 286 IndexedDBMsg_BlobOrFileInfo info; |
| 279 info.mime_type = iter->type(); | 287 info.mime_type = iter->type(); |
| 280 info.size = iter->size(); | 288 info.size = iter->size(); |
| 281 blob_or_file_info->push_back(info); | 289 blob_or_file_info->push_back(info); |
| 282 } | 290 } |
| 283 } | 291 } |
| 284 } | 292 } |
| 285 | 293 |
| 286 void IndexedDBCallbacks::RegisterBlobsAndSend( | 294 void IndexedDBCallbacks::RegisterBlobsAndSend( |
| 287 const std::vector<IndexedDBBlobInfo>& blob_info, | 295 const std::vector<IndexedDBBlobInfo>& blob_info, |
| 288 const base::Closure& callback) { | 296 const base::Closure& callback) { |
| 289 std::vector<IndexedDBBlobInfo>::const_iterator iter; | 297 std::vector<IndexedDBBlobInfo>::const_iterator iter; |
| 290 for (iter = blob_info.begin(); iter != blob_info.end(); ++iter) { | 298 for (iter = blob_info.begin(); iter != blob_info.end(); ++iter) { |
| 291 iter->mark_used_callback().Run(); | 299 if (!iter->mark_used_callback().is_null()) |
| 300 iter->mark_used_callback().Run(); |
| 292 } | 301 } |
| 293 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 302 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 294 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); | 303 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); |
| 295 } | 304 } |
| 296 | 305 |
| 297 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, | 306 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, |
| 298 const IndexedDBKey& key, | 307 const IndexedDBKey& key, |
| 299 const IndexedDBKey& primary_key, | 308 const IndexedDBKey& primary_key, |
| 300 IndexedDBValue* value) { | 309 IndexedDBValue* value) { |
| 301 DCHECK(dispatcher_host_.get()); | 310 DCHECK(dispatcher_host_.get()); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 std::vector<IndexedDBValue>::iterator iter = values.begin(); | 433 std::vector<IndexedDBValue>::iterator iter = values.begin(); |
| 425 for (size_t i = 0; iter != values.end(); ++iter, ++i) { | 434 for (size_t i = 0; iter != values.end(); ++iter, ++i) { |
| 426 values_bits[i].swap(iter->bits); | 435 values_bits[i].swap(iter->bits); |
| 427 if (iter->blob_info.size()) { | 436 if (iter->blob_info.size()) { |
| 428 found_blob_info = true; | 437 found_blob_info = true; |
| 429 FillInBlobData(iter->blob_info, &values_blob_infos[i]); | 438 FillInBlobData(iter->blob_info, &values_blob_infos[i]); |
| 430 std::vector<IndexedDBBlobInfo>::const_iterator blob_iter; | 439 std::vector<IndexedDBBlobInfo>::const_iterator blob_iter; |
| 431 for (blob_iter = iter->blob_info.begin(); | 440 for (blob_iter = iter->blob_info.begin(); |
| 432 blob_iter != iter->blob_info.end(); | 441 blob_iter != iter->blob_info.end(); |
| 433 ++blob_iter) { | 442 ++blob_iter) { |
| 434 blob_iter->mark_used_callback().Run(); | 443 if (!blob_iter->mark_used_callback().is_null()) |
| 444 blob_iter->mark_used_callback().Run(); |
| 435 } | 445 } |
| 436 } | 446 } |
| 437 } | 447 } |
| 438 | 448 |
| 439 if (found_blob_info) { | 449 if (found_blob_info) { |
| 440 BrowserThread::PostTask( | 450 BrowserThread::PostTask( |
| 441 BrowserThread::IO, | 451 BrowserThread::IO, |
| 442 FROM_HERE, | 452 FROM_HERE, |
| 443 base::Bind(BlobLookupForCursorPrefetch, | 453 base::Bind(BlobLookupForCursorPrefetch, |
| 444 base::Owned(params.release()), | 454 base::Owned(params.release()), |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 567 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 558 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 568 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
| 559 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 569 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 560 | 570 |
| 561 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( | 571 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( |
| 562 ipc_thread_id_, ipc_callbacks_id_)); | 572 ipc_thread_id_, ipc_callbacks_id_)); |
| 563 dispatcher_host_ = NULL; | 573 dispatcher_host_ = NULL; |
| 564 } | 574 } |
| 565 | 575 |
| 566 } // namespace content | 576 } // namespace content |
| OLD | NEW |