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

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

Issue 2449953008: Port messages sent by WebIDBDatabaseImpl to Mojo. (Closed)
Patch Set: Created 4 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/webidbdatabase_impl.h" 5 #include "content/child/indexed_db/webidbdatabase_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "content/child/indexed_db/indexed_db_callbacks_impl.h"
13 #include "content/child/indexed_db/indexed_db_dispatcher.h" 14 #include "content/child/indexed_db/indexed_db_dispatcher.h"
14 #include "content/child/indexed_db/indexed_db_key_builders.h" 15 #include "content/child/indexed_db/indexed_db_key_builders.h"
15 #include "content/child/thread_safe_sender.h" 16 #include "content/child/thread_safe_sender.h"
16 #include "content/child/worker_thread_registry.h" 17 #include "content/child/worker_thread_registry.h"
17 #include "content/common/indexed_db/indexed_db_messages.h" 18 #include "content/common/indexed_db/indexed_db_messages.h"
19 #include "mojo/public/cpp/bindings/strong_associated_binding.h"
18 #include "third_party/WebKit/public/platform/WebBlobInfo.h" 20 #include "third_party/WebKit/public/platform/WebBlobInfo.h"
19 #include "third_party/WebKit/public/platform/WebString.h" 21 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/WebVector.h" 22 #include "third_party/WebKit/public/platform/WebVector.h"
23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr or.h"
24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBKeyPath.h" 25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBKeyPath.h"
22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h" 26 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h"
23 27
24 using blink::WebBlobInfo; 28 using blink::WebBlobInfo;
25 using blink::WebIDBCallbacks; 29 using blink::WebIDBCallbacks;
26 using blink::WebIDBCursor; 30 using blink::WebIDBCursor;
27 using blink::WebIDBDatabase; 31 using blink::WebIDBDatabase;
28 using blink::WebIDBDatabaseCallbacks; 32 using blink::WebIDBDatabaseCallbacks;
29 using blink::WebIDBMetadata; 33 using blink::WebIDBMetadata;
30 using blink::WebIDBKey; 34 using blink::WebIDBKey;
31 using blink::WebIDBKeyPath; 35 using blink::WebIDBKeyPath;
32 using blink::WebIDBKeyRange; 36 using blink::WebIDBKeyRange;
33 using blink::WebIDBObserver; 37 using blink::WebIDBObserver;
34 using blink::WebString; 38 using blink::WebString;
35 using blink::WebVector; 39 using blink::WebVector;
40 using indexed_db::mojom::CallbacksAssociatedPtrInfo;
41 using indexed_db::mojom::DatabaseAssociatedPtrInfo;
36 42
37 namespace content { 43 namespace content {
38 44
39 WebIDBDatabaseImpl::WebIDBDatabaseImpl(int32_t ipc_database_id, 45 namespace {
40 ThreadSafeSender* thread_safe_sender) 46
41 : ipc_database_id_(ipc_database_id), 47 std::vector<content::IndexedDBIndexKeys> ConvertWebIndexKeys(
42 thread_safe_sender_(thread_safe_sender) {} 48 const WebVector<long long>& index_ids,
49 const WebVector<WebIDBDatabase::WebIndexKeys>& index_keys) {
50 DCHECK_EQ(index_ids.size(), index_keys.size());
51 std::vector<content::IndexedDBIndexKeys> result;
52 result.resize(index_ids.size());
53 for (size_t i = 0, len = index_ids.size(); i < len; ++i) {
54 result[i].first = index_ids[i];
55 result[i].second.resize(index_keys[i].size());
56 for (size_t j = 0; j < index_keys[i].size(); ++j)
57 result[i].second[j] = IndexedDBKeyBuilder::Build(index_keys[i][j]);
58 }
59 return result;
60 }
61
62 } // namespace
63
64 class WebIDBDatabaseImpl::IOThreadHelper {
65 public:
66 IOThreadHelper();
67 ~IOThreadHelper();
68
69 void Bind(DatabaseAssociatedPtrInfo database_info);
70 void CreateObjectStore(int64_t transaction_id,
71 int64_t object_store_id,
72 const base::string16& name,
73 const IndexedDBKeyPath& key_path,
74 bool auto_increment);
75 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id);
76 void RenameObjectStore(int64_t transaction_id,
77 int64_t object_store_id,
78 const base::string16& new_name);
79 void CreateTransaction(int64_t transaction_id,
80 const std::vector<int64_t>& object_store_ids,
81 blink::WebIDBTransactionMode mode);
82 void Close();
83 void VersionChangeIgnored();
84 void AddObserver(int64_t transaction_id,
85 int32_t observer_id,
86 bool include_transaction,
87 bool no_records,
88 bool values,
89 uint16_t operation_types);
90 void RemoveObservers(const std::vector<int32_t>& observers);
91 void Get(int64_t transaction_id,
92 int64_t object_store_id,
93 int64_t index_id,
94 const IndexedDBKeyRange& key_range,
95 bool key_only,
96 std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
97 void GetAll(int64_t transaction_id,
98 int64_t object_store_id,
99 int64_t index_id,
100 const IndexedDBKeyRange& key_range,
101 int64_t max_count,
102 bool key_only,
103 std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
104 void Put(int64_t transaction_id,
105 int64_t object_store_id,
106 indexed_db::mojom::ValuePtr value,
107 const IndexedDBKey& key,
108 blink::WebIDBPutMode mode,
109 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
110 const std::vector<content::IndexedDBIndexKeys>& index_keys);
111 void SetIndexKeys(int64_t transaction_id,
112 int64_t object_store_id,
113 const IndexedDBKey& primary_key,
114 const std::vector<content::IndexedDBIndexKeys>& index_keys);
115 void SetIndexesReady(int64_t transaction_id,
116 int64_t object_store_id,
117 const std::vector<int64_t>& index_ids);
118 void OpenCursor(int64_t transaction_id,
119 int64_t object_store_id,
120 int64_t index_id,
121 const IndexedDBKeyRange& key_range,
122 blink::WebIDBCursorDirection direction,
123 bool key_only,
124 blink::WebIDBTaskType task_type,
125 std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
126 void Count(int64_t transaction_id,
127 int64_t object_store_id,
128 int64_t index_id,
129 const IndexedDBKeyRange& key_range,
130 std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
131 void DeleteRange(int64_t transaction_id,
132 int64_t object_store_id,
133 const IndexedDBKeyRange& key_range,
134 std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
135 void Clear(int64_t transaction_id,
136 int64_t object_store_id,
137 std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
138 void CreateIndex(int64_t transaction_id,
139 int64_t object_store_id,
140 int64_t index_id,
141 const base::string16& name,
142 const IndexedDBKeyPath& key_path,
143 bool unique,
144 bool multi_entry);
145 void DeleteIndex(int64_t transaction_id,
146 int64_t object_store_id,
147 int64_t index_id);
148 void RenameIndex(int64_t transaction_id,
149 int64_t object_store_id,
150 int64_t index_id,
151 const base::string16& new_name);
152 void Abort(int64_t transaction_id);
153 void Commit(int64_t transaction_id);
154 void AckReceivedBlobs(const std::vector<std::string>& uuids);
155
156 private:
157 CallbacksAssociatedPtrInfo GetCallbacksProxy(
158 std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
159
160 indexed_db::mojom::DatabaseAssociatedPtr database_;
161
162 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
163 };
164
165 WebIDBDatabaseImpl::WebIDBDatabaseImpl(
166 DatabaseAssociatedPtrInfo database_info,
167 scoped_refptr<base::SingleThreadTaskRunner> io_runner,
168 scoped_refptr<ThreadSafeSender> thread_safe_sender)
169 : helper_(new IOThreadHelper()),
170 io_runner_(std::move(io_runner)),
171 thread_safe_sender_(std::move(thread_safe_sender)) {
172 io_runner_->PostTask(
173 FROM_HERE, base::Bind(&IOThreadHelper::Bind, base::Unretained(helper_),
174 base::Passed(&database_info)));
175 }
43 176
44 WebIDBDatabaseImpl::~WebIDBDatabaseImpl() { 177 WebIDBDatabaseImpl::~WebIDBDatabaseImpl() {
45 // It's not possible for there to be pending callbacks that address this 178 io_runner_->DeleteSoon(FROM_HERE, helper_);
46 // object since inside WebKit, they hold a reference to the object which owns
47 // this object. But, if that ever changed, then we'd need to invalidate
48 // any such pointers.
49 thread_safe_sender_->Send(
50 new IndexedDBHostMsg_DatabaseDestroyed(ipc_database_id_));
51 IndexedDBDispatcher* dispatcher =
52 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
53 dispatcher->DatabaseDestroyed(ipc_database_id_);
54 } 179 }
55 180
56 void WebIDBDatabaseImpl::createObjectStore(long long transaction_id, 181 void WebIDBDatabaseImpl::createObjectStore(long long transaction_id,
57 long long object_store_id, 182 long long object_store_id,
58 const WebString& name, 183 const WebString& name,
59 const WebIDBKeyPath& key_path, 184 const WebIDBKeyPath& key_path,
60 bool auto_increment) { 185 bool auto_increment) {
61 IndexedDBHostMsg_DatabaseCreateObjectStore_Params params; 186 io_runner_->PostTask(
62 params.ipc_database_id = ipc_database_id_; 187 FROM_HERE,
63 params.transaction_id = transaction_id; 188 base::Bind(&IOThreadHelper::CreateObjectStore, base::Unretained(helper_),
64 params.object_store_id = object_store_id; 189 transaction_id, object_store_id, base::string16(name),
65 params.name = name; 190 IndexedDBKeyPathBuilder::Build(key_path), auto_increment));
66 params.key_path = IndexedDBKeyPathBuilder::Build(key_path);
67 params.auto_increment = auto_increment;
68
69 thread_safe_sender_->Send(
70 new IndexedDBHostMsg_DatabaseCreateObjectStore(params));
71 } 191 }
72 192
73 void WebIDBDatabaseImpl::deleteObjectStore(long long transaction_id, 193 void WebIDBDatabaseImpl::deleteObjectStore(long long transaction_id,
74 long long object_store_id) { 194 long long object_store_id) {
75 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseDeleteObjectStore( 195 io_runner_->PostTask(FROM_HERE, base::Bind(&IOThreadHelper::DeleteObjectStore,
76 ipc_database_id_, transaction_id, object_store_id)); 196 base::Unretained(helper_),
197 transaction_id, object_store_id));
77 } 198 }
78 199
79 void WebIDBDatabaseImpl::renameObjectStore(long long transaction_id, 200 void WebIDBDatabaseImpl::renameObjectStore(long long transaction_id,
80 long long object_store_id, 201 long long object_store_id,
81 const blink::WebString& new_name) { 202 const blink::WebString& new_name) {
82 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseRenameObjectStore( 203 io_runner_->PostTask(
83 ipc_database_id_, transaction_id, object_store_id, new_name)); 204 FROM_HERE,
205 base::Bind(&IOThreadHelper::RenameObjectStore, base::Unretained(helper_),
206 transaction_id, object_store_id, base::string16(new_name)));
84 } 207 }
85 208
86 void WebIDBDatabaseImpl::createTransaction( 209 void WebIDBDatabaseImpl::createTransaction(
87 long long transaction_id, 210 long long transaction_id,
88 const WebVector<long long>& object_store_ids, 211 const WebVector<long long>& object_store_ids,
89 blink::WebIDBTransactionMode mode) { 212 blink::WebIDBTransactionMode mode) {
90 IndexedDBDispatcher* dispatcher = 213 io_runner_->PostTask(
91 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 214 FROM_HERE,
92 dispatcher->RequestIDBDatabaseCreateTransaction( 215 base::Bind(&IOThreadHelper::CreateTransaction, base::Unretained(helper_),
93 ipc_database_id_, transaction_id, object_store_ids, mode); 216 transaction_id, std::vector<int64_t>(object_store_ids.begin(),
217 object_store_ids.end()),
218 mode));
94 } 219 }
95 220
96 void WebIDBDatabaseImpl::close() { 221 void WebIDBDatabaseImpl::close() {
97 IndexedDBDispatcher* dispatcher = 222 IndexedDBDispatcher* dispatcher =
98 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 223 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
99 dispatcher->RemoveIDBObservers(observer_ids_); 224 std::vector<int32_t> remove_observer_ids(observer_ids_.begin(),
100 dispatcher->RequestIDBDatabaseClose(ipc_database_id_); 225 observer_ids_.end());
226 dispatcher->RemoveObservers(remove_observer_ids);
227 io_runner_->PostTask(
228 FROM_HERE, base::Bind(&IOThreadHelper::Close, base::Unretained(helper_)));
101 } 229 }
102 230
103 void WebIDBDatabaseImpl::versionChangeIgnored() { 231 void WebIDBDatabaseImpl::versionChangeIgnored() {
104 IndexedDBDispatcher* dispatcher = 232 io_runner_->PostTask(FROM_HERE,
105 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 233 base::Bind(&IOThreadHelper::VersionChangeIgnored,
106 dispatcher->NotifyIDBDatabaseVersionChangeIgnored(ipc_database_id_); 234 base::Unretained(helper_)));
107 } 235 }
108 236
109 int32_t WebIDBDatabaseImpl::addObserver( 237 int32_t WebIDBDatabaseImpl::addObserver(
110 std::unique_ptr<WebIDBObserver> observer, 238 std::unique_ptr<WebIDBObserver> observer,
111 long long transaction_id) { 239 long long transaction_id) {
112 IndexedDBDispatcher* dispatcher = 240 IndexedDBDispatcher* dispatcher =
113 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 241 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
114 242 WebIDBObserver* observer_ptr = observer.get();
115 int32_t observer_id = dispatcher->AddIDBObserver( 243 int32_t observer_id = dispatcher->RegisterObserver(std::move(observer));
116 ipc_database_id_, transaction_id, std::move(observer));
117 observer_ids_.insert(observer_id); 244 observer_ids_.insert(observer_id);
245 static_assert(blink::WebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT,
246 "WebIDBOperationType Count exceeds size of uint16_t");
247 io_runner_->PostTask(
248 FROM_HERE,
249 base::Bind(&IOThreadHelper::AddObserver, base::Unretained(helper_),
250 transaction_id, observer_id, observer_ptr->transaction(),
251 observer_ptr->noRecords(), observer_ptr->values(),
252 observer_ptr->operationTypes().to_ulong()));
118 return observer_id; 253 return observer_id;
119 } 254 }
120 255
121 void WebIDBDatabaseImpl::removeObservers( 256 void WebIDBDatabaseImpl::removeObservers(
122 const WebVector<int32_t>& observer_ids_to_remove) { 257 const WebVector<int32_t>& observer_ids_to_remove) {
123 std::vector<int32_t> remove_observer_ids( 258 std::vector<int32_t> remove_observer_ids(
124 observer_ids_to_remove.data(), 259 observer_ids_to_remove.data(),
125 observer_ids_to_remove.data() + observer_ids_to_remove.size()); 260 observer_ids_to_remove.data() + observer_ids_to_remove.size());
126 for (int32_t id : observer_ids_to_remove) 261 for (int32_t id : observer_ids_to_remove)
127 observer_ids_.erase(id); 262 observer_ids_.erase(id);
128 263
129 IndexedDBDispatcher* dispatcher = 264 IndexedDBDispatcher* dispatcher =
130 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 265 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
131 dispatcher->RemoveIDBObserversFromDatabase(ipc_database_id_, 266 dispatcher->RemoveObservers(remove_observer_ids);
132 remove_observer_ids); 267 io_runner_->PostTask(
268 FROM_HERE, base::Bind(&IOThreadHelper::RemoveObservers,
269 base::Unretained(helper_), remove_observer_ids));
133 } 270 }
134 271
135 void WebIDBDatabaseImpl::get(long long transaction_id, 272 void WebIDBDatabaseImpl::get(long long transaction_id,
136 long long object_store_id, 273 long long object_store_id,
137 long long index_id, 274 long long index_id,
138 const WebIDBKeyRange& key_range, 275 const WebIDBKeyRange& key_range,
139 bool key_only, 276 bool key_only,
140 WebIDBCallbacks* callbacks) { 277 WebIDBCallbacks* callbacks) {
141 IndexedDBDispatcher* dispatcher = 278 IndexedDBDispatcher* dispatcher =
142 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 279 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
143 dispatcher->RequestIDBDatabaseGet(ipc_database_id_, 280 dispatcher->ResetCursorPrefetchCaches(transaction_id,
144 transaction_id, 281 IndexedDBDispatcher::kAllCursors);
145 object_store_id, 282
146 index_id, 283 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
147 IndexedDBKeyRangeBuilder::Build(key_range), 284 base::WrapUnique(callbacks), transaction_id, io_runner_,
148 key_only, 285 thread_safe_sender_);
149 callbacks); 286 io_runner_->PostTask(
287 FROM_HERE, base::Bind(&IOThreadHelper::Get, base::Unretained(helper_),
288 transaction_id, object_store_id, index_id,
289 IndexedDBKeyRangeBuilder::Build(key_range),
290 key_only, base::Passed(&callbacks_impl)));
150 } 291 }
151 292
152 void WebIDBDatabaseImpl::getAll(long long transaction_id, 293 void WebIDBDatabaseImpl::getAll(long long transaction_id,
153 long long object_store_id, 294 long long object_store_id,
154 long long index_id, 295 long long index_id,
155 const WebIDBKeyRange& key_range, 296 const WebIDBKeyRange& key_range,
156 long long max_count, 297 long long max_count,
157 bool key_only, 298 bool key_only,
158 WebIDBCallbacks* callbacks) { 299 WebIDBCallbacks* callbacks) {
159 IndexedDBDispatcher* dispatcher = 300 IndexedDBDispatcher* dispatcher =
160 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 301 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
161 dispatcher->RequestIDBDatabaseGetAll( 302 dispatcher->ResetCursorPrefetchCaches(transaction_id,
162 ipc_database_id_, transaction_id, object_store_id, index_id, 303 IndexedDBDispatcher::kAllCursors);
163 IndexedDBKeyRangeBuilder::Build(key_range), key_only, max_count, 304
164 callbacks); 305 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
306 base::WrapUnique(callbacks), transaction_id, io_runner_,
307 thread_safe_sender_);
308 io_runner_->PostTask(
309 FROM_HERE,
310 base::Bind(&IOThreadHelper::GetAll, base::Unretained(helper_),
311 transaction_id, object_store_id, index_id,
312 IndexedDBKeyRangeBuilder::Build(key_range), max_count,
313 key_only, base::Passed(&callbacks_impl)));
165 } 314 }
166 315
167 void WebIDBDatabaseImpl::put(long long transaction_id, 316 void WebIDBDatabaseImpl::put(long long transaction_id,
168 long long object_store_id, 317 long long object_store_id,
169 const blink::WebData& value, 318 const blink::WebData& value,
170 const blink::WebVector<WebBlobInfo>& web_blob_info, 319 const blink::WebVector<WebBlobInfo>& web_blob_info,
171 const WebIDBKey& key, 320 const WebIDBKey& web_key,
172 blink::WebIDBPutMode put_mode, 321 blink::WebIDBPutMode put_mode,
173 WebIDBCallbacks* callbacks, 322 WebIDBCallbacks* callbacks,
174 const WebVector<long long>& web_index_ids, 323 const WebVector<long long>& index_ids,
175 const WebVector<WebIndexKeys>& web_index_keys) { 324 const WebVector<WebIndexKeys>& index_keys) {
325 IndexedDBKey key = IndexedDBKeyBuilder::Build(web_key);
326
327 if (value.size() + key.size_estimate() > max_put_value_size_) {
328 callbacks->onError(blink::WebIDBDatabaseError(
329 blink::WebIDBDatabaseExceptionUnknownError,
330 WebString::fromUTF8(
331 base::StringPrintf("The serialized value is too large"
332 " (size=%" PRIuS " bytes, max=%" PRIuS
333 " bytes).",
334 value.size(), max_put_value_size_)
335 .c_str())));
336 return;
337 }
338
176 IndexedDBDispatcher* dispatcher = 339 IndexedDBDispatcher* dispatcher =
177 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 340 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
178 dispatcher->RequestIDBDatabasePut(ipc_database_id_, 341 dispatcher->ResetCursorPrefetchCaches(transaction_id,
179 transaction_id, 342 IndexedDBDispatcher::kAllCursors);
180 object_store_id, 343
181 value, 344 auto mojo_value = indexed_db::mojom::Value::New();
182 web_blob_info, 345 mojo_value->bits.assign(value.data(), value.data() + value.size());
183 IndexedDBKeyBuilder::Build(key), 346 mojo_value->blob_or_file_info.reserve(web_blob_info.size());
184 put_mode, 347 for (const WebBlobInfo& info : web_blob_info) {
185 callbacks, 348 auto blob_or_file_info = indexed_db::mojom::BlobOrFileInfo::New();
186 web_index_ids, 349 blob_or_file_info->is_file = info.isFile();
187 web_index_keys); 350 if (info.isFile()) {
351 blob_or_file_info->file_path = info.filePath();
352 blob_or_file_info->file_name = info.fileName();
353 blob_or_file_info->last_modified = info.lastModified();
354 }
355 blob_or_file_info->size = info.size();
356 blob_or_file_info->uuid = info.uuid().latin1();
357 DCHECK(blob_or_file_info->uuid.size());
358 blob_or_file_info->mime_type = info.type();
359 mojo_value->blob_or_file_info.push_back(std::move(blob_or_file_info));
360 }
361
362 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
363 base::WrapUnique(callbacks), transaction_id, io_runner_,
364 thread_safe_sender_);
365 io_runner_->PostTask(
366 FROM_HERE,
367 base::Bind(&IOThreadHelper::Put, base::Unretained(helper_),
368 transaction_id, object_store_id, base::Passed(&mojo_value),
369 key, put_mode, base::Passed(&callbacks_impl),
370 ConvertWebIndexKeys(index_ids, index_keys)));
188 } 371 }
189 372
190 void WebIDBDatabaseImpl::setIndexKeys( 373 void WebIDBDatabaseImpl::setIndexKeys(
191 long long transaction_id, 374 long long transaction_id,
192 long long object_store_id, 375 long long object_store_id,
193 const WebIDBKey& primary_key, 376 const WebIDBKey& primary_key,
194 const WebVector<long long>& index_ids, 377 const WebVector<long long>& index_ids,
195 const WebVector<WebIndexKeys>& index_keys) { 378 const WebVector<WebIndexKeys>& index_keys) {
196 IndexedDBHostMsg_DatabaseSetIndexKeys_Params params; 379 io_runner_->PostTask(
197 params.ipc_database_id = ipc_database_id_; 380 FROM_HERE,
198 params.transaction_id = transaction_id; 381 base::Bind(&IOThreadHelper::SetIndexKeys, base::Unretained(helper_),
199 params.object_store_id = object_store_id; 382 transaction_id, object_store_id,
200 params.primary_key = IndexedDBKeyBuilder::Build(primary_key); 383 IndexedDBKeyBuilder::Build(primary_key),
201 384 ConvertWebIndexKeys(index_ids, index_keys)));
202 DCHECK_EQ(index_ids.size(), index_keys.size());
203 params.index_keys.resize(index_ids.size());
204 for (size_t i = 0, len = index_ids.size(); i < len; ++i) {
205 params.index_keys[i].first = index_ids[i];
206 params.index_keys[i].second.resize(index_keys[i].size());
207 for (size_t j = 0; j < index_keys[i].size(); ++j) {
208 params.index_keys[i].second[j] =
209 IndexedDBKey(IndexedDBKeyBuilder::Build(index_keys[i][j]));
210 }
211 }
212
213 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexKeys(params));
214 } 385 }
215 386
216 void WebIDBDatabaseImpl::setIndexesReady( 387 void WebIDBDatabaseImpl::setIndexesReady(
217 long long transaction_id, 388 long long transaction_id,
218 long long object_store_id, 389 long long object_store_id,
219 const WebVector<long long>& web_index_ids) { 390 const WebVector<long long>& web_index_ids) {
220 std::vector<int64_t> index_ids(web_index_ids.data(), 391 std::vector<int64_t> index_ids(web_index_ids.data(),
221 web_index_ids.data() + web_index_ids.size()); 392 web_index_ids.data() + web_index_ids.size());
222 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexesReady( 393 io_runner_->PostTask(
223 ipc_database_id_, transaction_id, object_store_id, index_ids)); 394 FROM_HERE,
395 base::Bind(&IOThreadHelper::SetIndexesReady, base::Unretained(helper_),
396 transaction_id, object_store_id, base::Passed(&index_ids)));
224 } 397 }
225 398
226 void WebIDBDatabaseImpl::openCursor(long long transaction_id, 399 void WebIDBDatabaseImpl::openCursor(long long transaction_id,
227 long long object_store_id, 400 long long object_store_id,
228 long long index_id, 401 long long index_id,
229 const WebIDBKeyRange& key_range, 402 const WebIDBKeyRange& key_range,
230 blink::WebIDBCursorDirection direction, 403 blink::WebIDBCursorDirection direction,
231 bool key_only, 404 bool key_only,
232 blink::WebIDBTaskType task_type, 405 blink::WebIDBTaskType task_type,
233 WebIDBCallbacks* callbacks) { 406 WebIDBCallbacks* callbacks) {
234 IndexedDBDispatcher* dispatcher = 407 IndexedDBDispatcher* dispatcher =
235 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 408 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
236 dispatcher->RequestIDBDatabaseOpenCursor( 409 dispatcher->ResetCursorPrefetchCaches(transaction_id,
237 ipc_database_id_, 410 IndexedDBDispatcher::kAllCursors);
238 transaction_id, 411
239 object_store_id, 412 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
240 index_id, 413 base::WrapUnique(callbacks), transaction_id, io_runner_,
241 IndexedDBKeyRangeBuilder::Build(key_range), 414 thread_safe_sender_);
242 direction, 415 io_runner_->PostTask(
243 key_only, 416 FROM_HERE,
244 task_type, 417 base::Bind(&IOThreadHelper::OpenCursor, base::Unretained(helper_),
245 callbacks); 418 transaction_id, object_store_id, index_id,
419 IndexedDBKeyRangeBuilder::Build(key_range), direction,
420 key_only, task_type, base::Passed(&callbacks_impl)));
246 } 421 }
247 422
248 void WebIDBDatabaseImpl::count(long long transaction_id, 423 void WebIDBDatabaseImpl::count(long long transaction_id,
249 long long object_store_id, 424 long long object_store_id,
250 long long index_id, 425 long long index_id,
251 const WebIDBKeyRange& key_range, 426 const WebIDBKeyRange& key_range,
252 WebIDBCallbacks* callbacks) { 427 WebIDBCallbacks* callbacks) {
253 IndexedDBDispatcher* dispatcher = 428 IndexedDBDispatcher* dispatcher =
254 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 429 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
255 dispatcher->RequestIDBDatabaseCount( 430 dispatcher->ResetCursorPrefetchCaches(transaction_id,
256 ipc_database_id_, 431 IndexedDBDispatcher::kAllCursors);
257 transaction_id, 432
258 object_store_id, 433 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
259 index_id, 434 base::WrapUnique(callbacks), transaction_id, io_runner_,
260 IndexedDBKeyRangeBuilder::Build(key_range), 435 thread_safe_sender_);
261 callbacks); 436 io_runner_->PostTask(
437 FROM_HERE, base::Bind(&IOThreadHelper::Count, base::Unretained(helper_),
438 transaction_id, object_store_id, index_id,
439 IndexedDBKeyRangeBuilder::Build(key_range),
440 base::Passed(&callbacks_impl)));
262 } 441 }
263 442
264 void WebIDBDatabaseImpl::deleteRange(long long transaction_id, 443 void WebIDBDatabaseImpl::deleteRange(long long transaction_id,
265 long long object_store_id, 444 long long object_store_id,
266 const WebIDBKeyRange& key_range, 445 const WebIDBKeyRange& key_range,
267 WebIDBCallbacks* callbacks) { 446 WebIDBCallbacks* callbacks) {
268 IndexedDBDispatcher* dispatcher = 447 IndexedDBDispatcher* dispatcher =
269 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 448 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
270 dispatcher->RequestIDBDatabaseDeleteRange( 449 dispatcher->ResetCursorPrefetchCaches(transaction_id,
271 ipc_database_id_, 450 IndexedDBDispatcher::kAllCursors);
272 transaction_id, 451
273 object_store_id, 452 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
274 IndexedDBKeyRangeBuilder::Build(key_range), 453 base::WrapUnique(callbacks), transaction_id, io_runner_,
275 callbacks); 454 thread_safe_sender_);
455 io_runner_->PostTask(
456 FROM_HERE,
457 base::Bind(&IOThreadHelper::DeleteRange, base::Unretained(helper_),
458 transaction_id, object_store_id,
459 IndexedDBKeyRangeBuilder::Build(key_range),
460 base::Passed(&callbacks_impl)));
276 } 461 }
277 462
278 void WebIDBDatabaseImpl::clear(long long transaction_id, 463 void WebIDBDatabaseImpl::clear(long long transaction_id,
279 long long object_store_id, 464 long long object_store_id,
280 WebIDBCallbacks* callbacks) { 465 WebIDBCallbacks* callbacks) {
281 IndexedDBDispatcher* dispatcher = 466 IndexedDBDispatcher* dispatcher =
282 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 467 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
283 dispatcher->RequestIDBDatabaseClear( 468 dispatcher->ResetCursorPrefetchCaches(transaction_id,
284 ipc_database_id_, transaction_id, object_store_id, callbacks); 469 IndexedDBDispatcher::kAllCursors);
470
471 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
472 base::WrapUnique(callbacks), transaction_id, io_runner_,
473 thread_safe_sender_);
474 io_runner_->PostTask(
475 FROM_HERE, base::Bind(&IOThreadHelper::Clear, base::Unretained(helper_),
476 transaction_id, object_store_id,
477 base::Passed(&callbacks_impl)));
285 } 478 }
286 479
287 void WebIDBDatabaseImpl::createIndex(long long transaction_id, 480 void WebIDBDatabaseImpl::createIndex(long long transaction_id,
288 long long object_store_id, 481 long long object_store_id,
289 long long index_id, 482 long long index_id,
290 const WebString& name, 483 const WebString& name,
291 const WebIDBKeyPath& key_path, 484 const WebIDBKeyPath& key_path,
292 bool unique, 485 bool unique,
293 bool multi_entry) { 486 bool multi_entry) {
294 IndexedDBHostMsg_DatabaseCreateIndex_Params params; 487 io_runner_->PostTask(
295 params.ipc_database_id = ipc_database_id_; 488 FROM_HERE,
296 params.transaction_id = transaction_id; 489 base::Bind(&IOThreadHelper::CreateIndex, base::Unretained(helper_),
297 params.object_store_id = object_store_id; 490 transaction_id, object_store_id, index_id,
298 params.index_id = index_id; 491 base::string16(name), IndexedDBKeyPathBuilder::Build(key_path),
299 params.name = name; 492 unique, multi_entry));
300 params.key_path = IndexedDBKeyPathBuilder::Build(key_path);
301 params.unique = unique;
302 params.multi_entry = multi_entry;
303
304 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseCreateIndex(params));
305 } 493 }
306 494
307 void WebIDBDatabaseImpl::deleteIndex(long long transaction_id, 495 void WebIDBDatabaseImpl::deleteIndex(long long transaction_id,
308 long long object_store_id, 496 long long object_store_id,
309 long long index_id) { 497 long long index_id) {
310 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseDeleteIndex( 498 io_runner_->PostTask(
311 ipc_database_id_, transaction_id, object_store_id, index_id)); 499 FROM_HERE,
500 base::Bind(&IOThreadHelper::DeleteIndex, base::Unretained(helper_),
501 transaction_id, object_store_id, index_id));
312 } 502 }
313 503
314 void WebIDBDatabaseImpl::renameIndex(long long transaction_id, 504 void WebIDBDatabaseImpl::renameIndex(long long transaction_id,
315 long long object_store_id, 505 long long object_store_id,
316 long long index_id, 506 long long index_id,
317 const WebString& new_name) { 507 const WebString& new_name) {
318 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseRenameIndex( 508 io_runner_->PostTask(
319 ipc_database_id_, transaction_id, object_store_id, index_id, new_name)); 509 FROM_HERE,
510 base::Bind(&IOThreadHelper::RenameIndex, base::Unretained(helper_),
511 transaction_id, object_store_id, index_id, new_name));
320 } 512 }
321 513
322 void WebIDBDatabaseImpl::abort(long long transaction_id) { 514 void WebIDBDatabaseImpl::abort(long long transaction_id) {
323 thread_safe_sender_->Send( 515 io_runner_->PostTask(
324 new IndexedDBHostMsg_DatabaseAbort(ipc_database_id_, transaction_id)); 516 FROM_HERE, base::Bind(&IOThreadHelper::Abort, base::Unretained(helper_),
517 transaction_id));
325 } 518 }
326 519
327 void WebIDBDatabaseImpl::commit(long long transaction_id) { 520 void WebIDBDatabaseImpl::commit(long long transaction_id) {
328 thread_safe_sender_->Send( 521 io_runner_->PostTask(
329 new IndexedDBHostMsg_DatabaseCommit(ipc_database_id_, transaction_id)); 522 FROM_HERE, base::Bind(&IOThreadHelper::Commit, base::Unretained(helper_),
523 transaction_id));
330 } 524 }
331 525
332 void WebIDBDatabaseImpl::ackReceivedBlobs(const WebVector<WebString>& uuids) { 526 void WebIDBDatabaseImpl::ackReceivedBlobs(const WebVector<WebString>& uuids) {
333 DCHECK(uuids.size()); 527 DCHECK(uuids.size());
334 std::vector<std::string> param(uuids.size()); 528 std::vector<std::string> param(uuids.size());
335 for (size_t i = 0; i < uuids.size(); ++i) 529 for (size_t i = 0; i < uuids.size(); ++i)
336 param[i] = uuids[i].latin1().data(); 530 param[i] = uuids[i].latin1().data();
337 thread_safe_sender_->Send(new IndexedDBHostMsg_AckReceivedBlobs(param)); 531 io_runner_->PostTask(FROM_HERE,
532 base::Bind(&IOThreadHelper::AckReceivedBlobs,
533 base::Unretained(helper_), std::move(param)));
534 }
535
536 WebIDBDatabaseImpl::IOThreadHelper::IOThreadHelper() {}
537
538 WebIDBDatabaseImpl::IOThreadHelper::~IOThreadHelper() {}
539
540 void WebIDBDatabaseImpl::IOThreadHelper::Bind(
541 DatabaseAssociatedPtrInfo database_info) {
542 database_.Bind(std::move(database_info));
543 }
544
545 void WebIDBDatabaseImpl::IOThreadHelper::CreateObjectStore(
546 int64_t transaction_id,
547 int64_t object_store_id,
548 const base::string16& name,
549 const IndexedDBKeyPath& key_path,
550 bool auto_increment) {
551 database_->CreateObjectStore(transaction_id, object_store_id, name, key_path,
552 auto_increment);
553 }
554
555 void WebIDBDatabaseImpl::IOThreadHelper::DeleteObjectStore(
556 int64_t transaction_id,
557 int64_t object_store_id) {
558 database_->DeleteObjectStore(transaction_id, object_store_id);
559 }
560
561 void WebIDBDatabaseImpl::IOThreadHelper::RenameObjectStore(
562 int64_t transaction_id,
563 int64_t object_store_id,
564 const base::string16& new_name) {
565 database_->RenameObjectStore(transaction_id, object_store_id, new_name);
566 }
567
568 void WebIDBDatabaseImpl::IOThreadHelper::CreateTransaction(
569 int64_t transaction_id,
570 const std::vector<int64_t>& object_store_ids,
571 blink::WebIDBTransactionMode mode) {
572 database_->CreateTransaction(transaction_id, object_store_ids, mode);
573 }
574
575 void WebIDBDatabaseImpl::IOThreadHelper::Close() {
576 database_->Close();
577 }
578
579 void WebIDBDatabaseImpl::IOThreadHelper::VersionChangeIgnored() {
580 database_->VersionChangeIgnored();
581 }
582
583 void WebIDBDatabaseImpl::IOThreadHelper::AddObserver(int64_t transaction_id,
584 int32_t observer_id,
585 bool include_transaction,
586 bool no_records,
587 bool values,
588 uint16_t operation_types) {
589 database_->AddObserver(transaction_id, observer_id, include_transaction,
590 no_records, values, operation_types);
591 }
592
593 void WebIDBDatabaseImpl::IOThreadHelper::RemoveObservers(
594 const std::vector<int32_t>& observers) {
595 database_->RemoveObservers(observers);
596 }
597
598 void WebIDBDatabaseImpl::IOThreadHelper::Get(
599 int64_t transaction_id,
600 int64_t object_store_id,
601 int64_t index_id,
602 const IndexedDBKeyRange& key_range,
603 bool key_only,
604 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
605 database_->Get(transaction_id, object_store_id, index_id, key_range, key_only,
606 GetCallbacksProxy(std::move(callbacks)));
607 }
608
609 void WebIDBDatabaseImpl::IOThreadHelper::GetAll(
610 int64_t transaction_id,
611 int64_t object_store_id,
612 int64_t index_id,
613 const IndexedDBKeyRange& key_range,
614 int64_t max_count,
615 bool key_only,
616 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
617 database_->GetAll(transaction_id, object_store_id, index_id, key_range,
618 key_only, max_count,
619 GetCallbacksProxy(std::move(callbacks)));
620 }
621
622 void WebIDBDatabaseImpl::IOThreadHelper::Put(
623 int64_t transaction_id,
624 int64_t object_store_id,
625 indexed_db::mojom::ValuePtr value,
626 const IndexedDBKey& key,
627 blink::WebIDBPutMode mode,
628 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
629 const std::vector<content::IndexedDBIndexKeys>& index_keys) {
630 database_->Put(transaction_id, object_store_id, std::move(value), key, mode,
631 index_keys, GetCallbacksProxy(std::move(callbacks)));
632 }
633
634 void WebIDBDatabaseImpl::IOThreadHelper::SetIndexKeys(
635 int64_t transaction_id,
636 int64_t object_store_id,
637 const IndexedDBKey& primary_key,
638 const std::vector<content::IndexedDBIndexKeys>& index_keys) {
639 database_->SetIndexKeys(transaction_id, object_store_id, primary_key,
640 index_keys);
641 }
642
643 void WebIDBDatabaseImpl::IOThreadHelper::SetIndexesReady(
644 int64_t transaction_id,
645 int64_t object_store_id,
646 const std::vector<int64_t>& index_ids) {
647 database_->SetIndexesReady(transaction_id, object_store_id, index_ids);
648 }
649
650 void WebIDBDatabaseImpl::IOThreadHelper::OpenCursor(
651 int64_t transaction_id,
652 int64_t object_store_id,
653 int64_t index_id,
654 const IndexedDBKeyRange& key_range,
655 blink::WebIDBCursorDirection direction,
656 bool key_only,
657 blink::WebIDBTaskType task_type,
658 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
659 database_->OpenCursor(transaction_id, object_store_id, index_id, key_range,
660 direction, key_only, task_type,
661 GetCallbacksProxy(std::move(callbacks)));
662 }
663
664 void WebIDBDatabaseImpl::IOThreadHelper::Count(
665 int64_t transaction_id,
666 int64_t object_store_id,
667 int64_t index_id,
668 const IndexedDBKeyRange& key_range,
669 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
670 database_->Count(transaction_id, object_store_id, index_id, key_range,
671 GetCallbacksProxy(std::move(callbacks)));
672 }
673
674 void WebIDBDatabaseImpl::IOThreadHelper::DeleteRange(
675 int64_t transaction_id,
676 int64_t object_store_id,
677 const IndexedDBKeyRange& key_range,
678 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
679 database_->DeleteRange(transaction_id, object_store_id, key_range,
680 GetCallbacksProxy(std::move(callbacks)));
681 }
682
683 void WebIDBDatabaseImpl::IOThreadHelper::Clear(
684 int64_t transaction_id,
685 int64_t object_store_id,
686 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
687 database_->Clear(transaction_id, object_store_id,
688 GetCallbacksProxy(std::move(callbacks)));
689 }
690
691 void WebIDBDatabaseImpl::IOThreadHelper::CreateIndex(
692 int64_t transaction_id,
693 int64_t object_store_id,
694 int64_t index_id,
695 const base::string16& name,
696 const IndexedDBKeyPath& key_path,
697 bool unique,
698 bool multi_entry) {
699 database_->CreateIndex(transaction_id, object_store_id, index_id, name,
700 key_path, unique, multi_entry);
701 }
702
703 void WebIDBDatabaseImpl::IOThreadHelper::DeleteIndex(int64_t transaction_id,
704 int64_t object_store_id,
705 int64_t index_id) {
706 database_->DeleteIndex(transaction_id, object_store_id, index_id);
707 }
708
709 void WebIDBDatabaseImpl::IOThreadHelper::RenameIndex(
710 int64_t transaction_id,
711 int64_t object_store_id,
712 int64_t index_id,
713 const base::string16& new_name) {
714 database_->RenameIndex(transaction_id, object_store_id, index_id, new_name);
715 }
716
717 void WebIDBDatabaseImpl::IOThreadHelper::Abort(int64_t transaction_id) {
718 database_->Abort(transaction_id);
719 }
720
721 void WebIDBDatabaseImpl::IOThreadHelper::Commit(int64_t transaction_id) {
722 database_->Commit(transaction_id);
723 }
724
725 void WebIDBDatabaseImpl::IOThreadHelper::AckReceivedBlobs(
726 const std::vector<std::string>& uuids) {
727 database_->AckReceivedBlobs(uuids);
728 }
729
730 CallbacksAssociatedPtrInfo
731 WebIDBDatabaseImpl::IOThreadHelper::GetCallbacksProxy(
732 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
733 CallbacksAssociatedPtrInfo ptr_info;
734 indexed_db::mojom::CallbacksAssociatedRequest request;
735 database_.associated_group()->CreateAssociatedInterface(
736 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
737 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
738 return ptr_info;
338 } 739 }
339 740
340 } // namespace content 741 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698