Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: content/child/indexed_db/indexed_db_callbacks_impl.cc

Issue 2601983002: [IndexedDB] Adding transaction and value support to observers (Closed)
Patch Set: added comments and bug link Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
78 void IndexedDBCallbacksImpl::ConvertValue(
79 const indexed_db::mojom::ValuePtr& value,
80 WebIDBValue* web_value) {
70 if (value->bits.empty()) 81 if (value->bits.empty())
71 return; 82 return;
72 83
73 blink::WebVector<WebBlobInfo> local_blob_info( 84 blink::WebVector<WebBlobInfo> local_blob_info(
74 value->blob_or_file_info.size()); 85 value->blob_or_file_info.size());
75 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { 86 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) {
76 const auto& info = value->blob_or_file_info[i]; 87 const auto& info = value->blob_or_file_info[i];
77 if (info->file) { 88 if (info->file) {
78 local_blob_info[i] = 89 local_blob_info[i] =
79 WebBlobInfo(WebString::fromUTF8(info->uuid), 90 WebBlobInfo(WebString::fromUTF8(info->uuid),
80 blink::FilePathToWebString(info->file->path), 91 blink::FilePathToWebString(info->file->path),
81 WebString::fromUTF16(info->file->name), 92 WebString::fromUTF16(info->file->name),
82 WebString::fromUTF16(info->mime_type), 93 WebString::fromUTF16(info->mime_type),
83 info->file->last_modified.ToDoubleT(), info->size); 94 info->file->last_modified.ToDoubleT(), info->size);
84 } else { 95 } else {
85 local_blob_info[i] = 96 local_blob_info[i] =
86 WebBlobInfo(WebString::fromUTF8(info->uuid), 97 WebBlobInfo(WebString::fromUTF8(info->uuid),
87 WebString::fromUTF16(info->mime_type), info->size); 98 WebString::fromUTF16(info->mime_type), info->size);
88 } 99 }
89 } 100 }
90 101
91 web_value->data.assign(&*value->bits.begin(), value->bits.size()); 102 web_value->data.assign(&*value->bits.begin(), value->bits.size());
92 web_value->webBlobInfo.swap(local_blob_info); 103 web_value->webBlobInfo.swap(local_blob_info);
93 } 104 }
94 105
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 106
104 IndexedDBCallbacksImpl::IndexedDBCallbacksImpl( 107 IndexedDBCallbacksImpl::IndexedDBCallbacksImpl(
105 std::unique_ptr<WebIDBCallbacks> callbacks, 108 std::unique_ptr<WebIDBCallbacks> callbacks,
106 int64_t transaction_id, 109 int64_t transaction_id,
107 const base::WeakPtr<WebIDBCursorImpl>& cursor, 110 const base::WeakPtr<WebIDBCursorImpl>& cursor,
108 scoped_refptr<base::SingleThreadTaskRunner> io_runner) 111 scoped_refptr<base::SingleThreadTaskRunner> io_runner)
109 : internal_state_(new InternalState(std::move(callbacks), 112 : internal_state_(new InternalState(std::move(callbacks),
110 transaction_id, 113 transaction_id,
111 cursor, 114 cursor,
112 std::move(io_runner))), 115 std::move(io_runner))),
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 callbacks_.reset(); 297 callbacks_.reset();
295 } 298 }
296 299
297 void IndexedDBCallbacksImpl::InternalState::SuccessCursor( 300 void IndexedDBCallbacksImpl::InternalState::SuccessCursor(
298 indexed_db::mojom::CursorAssociatedPtrInfo cursor_info, 301 indexed_db::mojom::CursorAssociatedPtrInfo cursor_info,
299 const IndexedDBKey& key, 302 const IndexedDBKey& key,
300 const IndexedDBKey& primary_key, 303 const IndexedDBKey& primary_key,
301 indexed_db::mojom::ValuePtr value) { 304 indexed_db::mojom::ValuePtr value) {
302 WebIDBValue web_value; 305 WebIDBValue web_value;
303 if (value) 306 if (value)
304 ConvertValue(value, &web_value); 307 IndexedDBCallbacksImpl::ConvertValue(value, &web_value);
305 308
306 WebIDBCursorImpl* cursor = 309 WebIDBCursorImpl* cursor =
307 new WebIDBCursorImpl(std::move(cursor_info), transaction_id_, io_runner_); 310 new WebIDBCursorImpl(std::move(cursor_info), transaction_id_, io_runner_);
308 callbacks_->onSuccess(cursor, WebIDBKeyBuilder::Build(key), 311 callbacks_->onSuccess(cursor, WebIDBKeyBuilder::Build(key),
309 WebIDBKeyBuilder::Build(primary_key), web_value); 312 WebIDBKeyBuilder::Build(primary_key), web_value);
310 callbacks_.reset(); 313 callbacks_.reset();
311 } 314 }
312 315
313 void IndexedDBCallbacksImpl::InternalState::SuccessKey( 316 void IndexedDBCallbacksImpl::InternalState::SuccessKey(
314 const IndexedDBKey& key) { 317 const IndexedDBKey& key) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 callbacks_->onSuccess(value); 368 callbacks_->onSuccess(value);
366 callbacks_.reset(); 369 callbacks_.reset();
367 } 370 }
368 371
369 void IndexedDBCallbacksImpl::InternalState::Success() { 372 void IndexedDBCallbacksImpl::InternalState::Success() {
370 callbacks_->onSuccess(); 373 callbacks_->onSuccess();
371 callbacks_.reset(); 374 callbacks_.reset();
372 } 375 }
373 376
374 } // namespace content 377 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/indexed_db_callbacks_impl.h ('k') | content/child/indexed_db/indexed_db_database_callbacks_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698