| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/child/indexed_db/indexed_db_callbacks_impl.h" | 5 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" |
| 6 | 6 |
| 7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 8 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 9 #include "content/child/indexed_db/indexed_db_key_builders.h" | 9 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 10 #include "content/child/indexed_db/webidbcursor_impl.h" | 10 #include "content/child/indexed_db/webidbcursor_impl.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 output->name = WebString::fromUTF16(metadata.name); | 58 output->name = WebString::fromUTF16(metadata.name); |
| 59 output->version = metadata.version; | 59 output->version = metadata.version; |
| 60 output->maxObjectStoreId = metadata.max_object_store_id; | 60 output->maxObjectStoreId = metadata.max_object_store_id; |
| 61 output->objectStores = | 61 output->objectStores = |
| 62 WebVector<WebIDBMetadata::ObjectStore>(metadata.object_stores.size()); | 62 WebVector<WebIDBMetadata::ObjectStore>(metadata.object_stores.size()); |
| 63 size_t i = 0; | 63 size_t i = 0; |
| 64 for (const auto& iter : metadata.object_stores) | 64 for (const auto& iter : metadata.object_stores) |
| 65 ConvertObjectStoreMetadata(iter.second, &output->objectStores[i++]); | 65 ConvertObjectStoreMetadata(iter.second, &output->objectStores[i++]); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ConvertValue(const indexed_db::mojom::ValuePtr& value, | 68 void ConvertReturnValue(const indexed_db::mojom::ReturnValuePtr& value, |
| 69 WebIDBValue* web_value) { | 69 WebIDBValue* web_value) { |
| 70 IndexedDBCallbacksImpl::ConvertValue(value->value, web_value); |
| 71 web_value->primaryKey = WebIDBKeyBuilder::Build(value->primary_key); |
| 72 web_value->keyPath = WebIDBKeyPathBuilder::Build(value->key_path); |
| 73 } |
| 74 |
| 75 } // namespace |
| 76 |
| 77 /* static */ void IndexedDBCallbacksImpl::ConvertValue( |
| 78 const indexed_db::mojom::ValuePtr& value, |
| 79 WebIDBValue* web_value) { |
| 70 if (value->bits.empty()) | 80 if (value->bits.empty()) |
| 71 return; | 81 return; |
| 72 | 82 |
| 73 blink::WebVector<WebBlobInfo> local_blob_info( | 83 blink::WebVector<WebBlobInfo> local_blob_info( |
| 74 value->blob_or_file_info.size()); | 84 value->blob_or_file_info.size()); |
| 75 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { | 85 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { |
| 76 const auto& info = value->blob_or_file_info[i]; | 86 const auto& info = value->blob_or_file_info[i]; |
| 77 if (info->file) { | 87 if (info->file) { |
| 78 local_blob_info[i] = | 88 local_blob_info[i] = |
| 79 WebBlobInfo(WebString::fromUTF8(info->uuid), | 89 WebBlobInfo(WebString::fromUTF8(info->uuid), |
| 80 blink::FilePathToWebString(info->file->path), | 90 blink::FilePathToWebString(info->file->path), |
| 81 WebString::fromUTF16(info->file->name), | 91 WebString::fromUTF16(info->file->name), |
| 82 WebString::fromUTF16(info->mime_type), | 92 WebString::fromUTF16(info->mime_type), |
| 83 info->file->last_modified.ToDoubleT(), info->size); | 93 info->file->last_modified.ToDoubleT(), info->size); |
| 84 } else { | 94 } else { |
| 85 local_blob_info[i] = | 95 local_blob_info[i] = |
| 86 WebBlobInfo(WebString::fromUTF8(info->uuid), | 96 WebBlobInfo(WebString::fromUTF8(info->uuid), |
| 87 WebString::fromUTF16(info->mime_type), info->size); | 97 WebString::fromUTF16(info->mime_type), info->size); |
| 88 } | 98 } |
| 89 } | 99 } |
| 90 | 100 |
| 91 web_value->data.assign(&*value->bits.begin(), value->bits.size()); | 101 web_value->data.assign(&*value->bits.begin(), value->bits.size()); |
| 92 web_value->webBlobInfo.swap(local_blob_info); | 102 web_value->webBlobInfo.swap(local_blob_info); |
| 93 } | 103 } |
| 94 | 104 |
| 95 void ConvertReturnValue(const indexed_db::mojom::ReturnValuePtr& value, | |
| 96 WebIDBValue* web_value) { | |
| 97 ConvertValue(value->value, web_value); | |
| 98 web_value->primaryKey = WebIDBKeyBuilder::Build(value->primary_key); | |
| 99 web_value->keyPath = WebIDBKeyPathBuilder::Build(value->key_path); | |
| 100 } | |
| 101 | |
| 102 } // namespace | |
| 103 | 105 |
| 104 IndexedDBCallbacksImpl::IndexedDBCallbacksImpl( | 106 IndexedDBCallbacksImpl::IndexedDBCallbacksImpl( |
| 105 std::unique_ptr<WebIDBCallbacks> callbacks, | 107 std::unique_ptr<WebIDBCallbacks> callbacks, |
| 106 int64_t transaction_id, | 108 int64_t transaction_id, |
| 107 const base::WeakPtr<WebIDBCursorImpl>& cursor, | 109 const base::WeakPtr<WebIDBCursorImpl>& cursor, |
| 108 scoped_refptr<base::SingleThreadTaskRunner> io_runner) | 110 scoped_refptr<base::SingleThreadTaskRunner> io_runner) |
| 109 : internal_state_(new InternalState(std::move(callbacks), | 111 : internal_state_(new InternalState(std::move(callbacks), |
| 110 transaction_id, | 112 transaction_id, |
| 111 cursor, | 113 cursor, |
| 112 std::move(io_runner))), | 114 std::move(io_runner))), |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 callbacks_.reset(); | 296 callbacks_.reset(); |
| 295 } | 297 } |
| 296 | 298 |
| 297 void IndexedDBCallbacksImpl::InternalState::SuccessCursor( | 299 void IndexedDBCallbacksImpl::InternalState::SuccessCursor( |
| 298 indexed_db::mojom::CursorAssociatedPtrInfo cursor_info, | 300 indexed_db::mojom::CursorAssociatedPtrInfo cursor_info, |
| 299 const IndexedDBKey& key, | 301 const IndexedDBKey& key, |
| 300 const IndexedDBKey& primary_key, | 302 const IndexedDBKey& primary_key, |
| 301 indexed_db::mojom::ValuePtr value) { | 303 indexed_db::mojom::ValuePtr value) { |
| 302 WebIDBValue web_value; | 304 WebIDBValue web_value; |
| 303 if (value) | 305 if (value) |
| 304 ConvertValue(value, &web_value); | 306 IndexedDBCallbacksImpl::ConvertValue(value, &web_value); |
| 305 | 307 |
| 306 WebIDBCursorImpl* cursor = | 308 WebIDBCursorImpl* cursor = |
| 307 new WebIDBCursorImpl(std::move(cursor_info), transaction_id_, io_runner_); | 309 new WebIDBCursorImpl(std::move(cursor_info), transaction_id_, io_runner_); |
| 308 callbacks_->onSuccess(cursor, WebIDBKeyBuilder::Build(key), | 310 callbacks_->onSuccess(cursor, WebIDBKeyBuilder::Build(key), |
| 309 WebIDBKeyBuilder::Build(primary_key), web_value); | 311 WebIDBKeyBuilder::Build(primary_key), web_value); |
| 310 callbacks_.reset(); | 312 callbacks_.reset(); |
| 311 } | 313 } |
| 312 | 314 |
| 313 void IndexedDBCallbacksImpl::InternalState::SuccessKey( | 315 void IndexedDBCallbacksImpl::InternalState::SuccessKey( |
| 314 const IndexedDBKey& key) { | 316 const IndexedDBKey& key) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 callbacks_->onSuccess(value); | 367 callbacks_->onSuccess(value); |
| 366 callbacks_.reset(); | 368 callbacks_.reset(); |
| 367 } | 369 } |
| 368 | 370 |
| 369 void IndexedDBCallbacksImpl::InternalState::Success() { | 371 void IndexedDBCallbacksImpl::InternalState::Success() { |
| 370 callbacks_->onSuccess(); | 372 callbacks_->onSuccess(); |
| 371 callbacks_.reset(); | 373 callbacks_.reset(); |
| 372 } | 374 } |
| 373 | 375 |
| 374 } // namespace content | 376 } // namespace content |
| OLD | NEW |