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

Side by Side Diff: content/browser/indexed_db/indexed_db_callbacks.cc

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Allow cpp_only to be set by the invoker. Created 4 years, 2 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 (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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/browser/child_process_security_policy_impl.h" 15 #include "content/browser/child_process_security_policy_impl.h"
16 #include "content/browser/fileapi/fileapi_message_filter.h" 16 #include "content/browser/fileapi/fileapi_message_filter.h"
17 #include "content/browser/indexed_db/indexed_db_blob_info.h" 17 #include "content/browser/indexed_db/indexed_db_blob_info.h"
18 #include "content/browser/indexed_db/indexed_db_connection.h" 18 #include "content/browser/indexed_db/indexed_db_connection.h"
19 #include "content/browser/indexed_db/indexed_db_context_impl.h" 19 #include "content/browser/indexed_db/indexed_db_context_impl.h"
20 #include "content/browser/indexed_db/indexed_db_cursor.h" 20 #include "content/browser/indexed_db/indexed_db_cursor.h"
21 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
22 #include "content/browser/indexed_db/indexed_db_database_error.h" 21 #include "content/browser/indexed_db/indexed_db_database_error.h"
23 #include "content/browser/indexed_db/indexed_db_metadata.h" 22 #include "content/browser/indexed_db/indexed_db_metadata.h"
24 #include "content/browser/indexed_db/indexed_db_return_value.h" 23 #include "content/browser/indexed_db/indexed_db_return_value.h"
25 #include "content/browser/indexed_db/indexed_db_tracing.h" 24 #include "content/browser/indexed_db/indexed_db_tracing.h"
26 #include "content/browser/indexed_db/indexed_db_value.h" 25 #include "content/browser/indexed_db/indexed_db_value.h"
27 #include "content/common/indexed_db/indexed_db_constants.h" 26 #include "content/common/indexed_db/indexed_db_constants.h"
28 #include "content/common/indexed_db/indexed_db_messages.h" 27 #include "content/common/indexed_db/indexed_db_messages.h"
29 #include "storage/browser/blob/blob_storage_context.h" 28 #include "storage/browser/blob/blob_storage_context.h"
30 #include "storage/browser/blob/shareable_file_reference.h" 29 #include "storage/browser/blob/shareable_file_reference.h"
31 #include "storage/browser/quota/quota_manager.h" 30 #include "storage/browser/quota/quota_manager.h"
32 31
32 using indexed_db::mojom::CallbacksAssociatedPtrInfo;
33 using storage::ShareableFileReference; 33 using storage::ShareableFileReference;
34 34
35 namespace content { 35 namespace content {
36 36
37 namespace { 37 namespace {
38
38 const int32_t kNoCursor = -1; 39 const int32_t kNoCursor = -1;
39 const int32_t kNoDatabaseCallbacks = -1;
40 const int64_t kNoTransaction = -1; 40 const int64_t kNoTransaction = -1;
41
42 ::indexed_db::mojom::DatabaseMetadataPtr ConvertMetadata(
43 const content::IndexedDBDatabaseMetadata& web_metadata) {
44 auto metadata = ::indexed_db::mojom::DatabaseMetadata::New();
45 metadata->id = web_metadata.id;
46 metadata->name = web_metadata.name;
47 metadata->version = web_metadata.version;
48 metadata->max_object_store_id = web_metadata.max_object_store_id;
49
50 for (const auto& iter : web_metadata.object_stores) {
51 const content::IndexedDBObjectStoreMetadata& web_store_metadata =
52 iter.second;
53 auto store_metadata = ::indexed_db::mojom::ObjectStoreMetadata::New();
54 store_metadata->id = web_store_metadata.id;
55 store_metadata->name = web_store_metadata.name;
56 store_metadata->key_path = web_store_metadata.key_path;
57 store_metadata->auto_increment = web_store_metadata.auto_increment;
58 store_metadata->max_index_id = web_store_metadata.max_index_id;
59
60 for (const auto& index_iter : web_store_metadata.indexes) {
61 const content::IndexedDBIndexMetadata& web_index_metadata =
62 index_iter.second;
63 auto index_metadata = ::indexed_db::mojom::IndexMetadata::New();
64 index_metadata->id = web_index_metadata.id;
65 index_metadata->name = web_index_metadata.name;
66 index_metadata->key_path = web_index_metadata.key_path;
67 index_metadata->unique = web_index_metadata.unique;
68 index_metadata->multi_entry = web_index_metadata.multi_entry;
69 store_metadata->indexes.push_back(std::move(index_metadata));
70 }
71 metadata->object_stores.push_back(std::move(store_metadata));
72 }
73 return metadata;
41 } 74 }
75 }
76
77 class IndexedDBCallbacks::IOThreadHelper {
78 public:
79 IOThreadHelper(CallbacksAssociatedPtrInfo callbacks_info);
80 ~IOThreadHelper();
81
82 void SendBlocked(int64_t existing_version);
83 void SendError(const IndexedDBDatabaseError& error);
84 void SendSuccessDatabase(int32_t database_id,
85 ::indexed_db::mojom::DatabaseMetadataPtr metadata);
86 void SendSuccessInteger(int64_t value);
87 void SendSuccessStringList(const std::vector<base::string16>& value);
88 void SendUpgradeNeeded(int32_t database_id,
89 int64_t old_version,
90 blink::WebIDBDataLoss data_loss,
91 const std::string& data_loss_message,
92 ::indexed_db::mojom::DatabaseMetadataPtr metadata);
93
94 private:
95 ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_;
96 };
42 97
43 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, 98 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
44 int32_t ipc_thread_id, 99 int32_t ipc_thread_id,
45 int32_t ipc_callbacks_id) 100 int32_t ipc_callbacks_id)
46 : dispatcher_host_(dispatcher_host), 101 : dispatcher_host_(dispatcher_host),
47 ipc_callbacks_id_(ipc_callbacks_id), 102 ipc_callbacks_id_(ipc_callbacks_id),
48 ipc_thread_id_(ipc_thread_id), 103 ipc_thread_id_(ipc_thread_id),
49 ipc_cursor_id_(kNoCursor), 104 ipc_cursor_id_(kNoCursor),
50 host_transaction_id_(kNoTransaction), 105 host_transaction_id_(kNoTransaction),
51 ipc_database_id_(kNoDatabase), 106 ipc_database_id_(kNoDatabase),
52 ipc_database_callbacks_id_(kNoDatabaseCallbacks),
53 data_loss_(blink::WebIDBDataLossNone), 107 data_loss_(blink::WebIDBDataLossNone),
54 sent_blocked_(false) {} 108 sent_blocked_(false),
109 helper_(nullptr) {}
55 110
56 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, 111 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
57 int32_t ipc_thread_id, 112 int32_t ipc_thread_id,
58 int32_t ipc_callbacks_id, 113 int32_t ipc_callbacks_id,
59 int32_t ipc_cursor_id) 114 int32_t ipc_cursor_id)
60 : dispatcher_host_(dispatcher_host), 115 : dispatcher_host_(dispatcher_host),
61 ipc_callbacks_id_(ipc_callbacks_id), 116 ipc_callbacks_id_(ipc_callbacks_id),
62 ipc_thread_id_(ipc_thread_id), 117 ipc_thread_id_(ipc_thread_id),
63 ipc_cursor_id_(ipc_cursor_id), 118 ipc_cursor_id_(ipc_cursor_id),
64 host_transaction_id_(kNoTransaction), 119 host_transaction_id_(kNoTransaction),
65 ipc_database_id_(kNoDatabase), 120 ipc_database_id_(kNoDatabase),
66 ipc_database_callbacks_id_(kNoDatabaseCallbacks),
67 data_loss_(blink::WebIDBDataLossNone), 121 data_loss_(blink::WebIDBDataLossNone),
68 sent_blocked_(false) {} 122 sent_blocked_(false),
123 helper_(nullptr) {}
69 124
70 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, 125 IndexedDBCallbacks::IndexedDBCallbacks(
71 int32_t ipc_thread_id, 126 IndexedDBDispatcherHost* dispatcher_host,
72 int32_t ipc_callbacks_id, 127 const url::Origin& origin,
73 int32_t ipc_database_callbacks_id, 128 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info)
74 int64_t host_transaction_id,
75 const url::Origin& origin)
76 : dispatcher_host_(dispatcher_host), 129 : dispatcher_host_(dispatcher_host),
77 ipc_callbacks_id_(ipc_callbacks_id),
78 ipc_thread_id_(ipc_thread_id),
79 ipc_cursor_id_(kNoCursor), 130 ipc_cursor_id_(kNoCursor),
80 host_transaction_id_(host_transaction_id), 131 host_transaction_id_(kNoTransaction),
81 origin_(origin), 132 origin_(origin),
82 ipc_database_id_(kNoDatabase), 133 ipc_database_id_(kNoDatabase),
83 ipc_database_callbacks_id_(ipc_database_callbacks_id),
84 data_loss_(blink::WebIDBDataLossNone), 134 data_loss_(blink::WebIDBDataLossNone),
85 sent_blocked_(false) {} 135 sent_blocked_(false),
136 helper_(nullptr) {
137 if (callbacks_info.is_valid())
138 helper_ = new IOThreadHelper(std::move(callbacks_info));
139 }
86 140
87 IndexedDBCallbacks::~IndexedDBCallbacks() {} 141 IndexedDBCallbacks::~IndexedDBCallbacks() {
142 if (helper_)
143 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, helper_);
144 }
88 145
89 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { 146 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) {
90 DCHECK(dispatcher_host_.get()); 147 DCHECK(dispatcher_host_.get());
91 148
92 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( 149 if (helper_) {
93 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); 150 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
151 base::Bind(&IOThreadHelper::SendError,
152 base::Unretained(helper_), error));
153 } else {
154 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError(
155 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message()));
156 }
94 dispatcher_host_ = NULL; 157 dispatcher_host_ = NULL;
95 158
96 if (!connection_open_start_time_.is_null()) { 159 if (!connection_open_start_time_.is_null()) {
97 UMA_HISTOGRAM_MEDIUM_TIMES( 160 UMA_HISTOGRAM_MEDIUM_TIMES(
98 "WebCore.IndexedDB.OpenTime.Error", 161 "WebCore.IndexedDB.OpenTime.Error",
99 base::TimeTicks::Now() - connection_open_start_time_); 162 base::TimeTicks::Now() - connection_open_start_time_);
100 connection_open_start_time_ = base::TimeTicks(); 163 connection_open_start_time_ = base::TimeTicks();
101 } 164 }
102 } 165 }
103 166
104 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { 167 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) {
105 DCHECK(dispatcher_host_.get()); 168 DCHECK(dispatcher_host_.get());
106 169 DCHECK(helper_);
107 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 170 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
108 DCHECK_EQ(kNoTransaction, host_transaction_id_); 171 DCHECK_EQ(kNoTransaction, host_transaction_id_);
109 DCHECK_EQ(kNoDatabase, ipc_database_id_); 172 DCHECK_EQ(kNoDatabase, ipc_database_id_);
110 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
111 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
112 173
113 std::vector<base::string16> list; 174 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
114 for (unsigned i = 0; i < value.size(); ++i) 175 base::Bind(&IOThreadHelper::SendSuccessStringList,
115 list.push_back(value[i]); 176 base::Unretained(helper_), value));
116
117 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessStringList(
118 ipc_thread_id_, ipc_callbacks_id_, list));
119 dispatcher_host_ = NULL; 177 dispatcher_host_ = NULL;
120 } 178 }
121 179
122 void IndexedDBCallbacks::OnBlocked(int64_t existing_version) { 180 void IndexedDBCallbacks::OnBlocked(int64_t existing_version) {
123 DCHECK(dispatcher_host_.get()); 181 DCHECK(dispatcher_host_.get());
124 182 DCHECK(helper_);
125 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 183 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
126 // No transaction/db callbacks for DeleteDatabase.
127 DCHECK_EQ(kNoTransaction == host_transaction_id_,
128 kNoDatabaseCallbacks == ipc_database_callbacks_id_);
129 DCHECK_EQ(kNoDatabase, ipc_database_id_);
130 184
131 if (sent_blocked_) 185 if (sent_blocked_)
132 return; 186 return;
133 187
134 sent_blocked_ = true; 188 sent_blocked_ = true;
135 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( 189
136 ipc_thread_id_, ipc_callbacks_id_, existing_version)); 190 BrowserThread::PostTask(
191 BrowserThread::IO, FROM_HERE,
192 base::Bind(&IOThreadHelper::SendBlocked, base::Unretained(helper_),
193 existing_version));
137 194
138 if (!connection_open_start_time_.is_null()) { 195 if (!connection_open_start_time_.is_null()) {
139 UMA_HISTOGRAM_MEDIUM_TIMES( 196 UMA_HISTOGRAM_MEDIUM_TIMES(
140 "WebCore.IndexedDB.OpenTime.Blocked", 197 "WebCore.IndexedDB.OpenTime.Blocked",
141 base::TimeTicks::Now() - connection_open_start_time_); 198 base::TimeTicks::Now() - connection_open_start_time_);
142 connection_open_start_time_ = base::TimeTicks(); 199 connection_open_start_time_ = base::TimeTicks();
143 } 200 }
144 } 201 }
145 202
146 void IndexedDBCallbacks::OnUpgradeNeeded( 203 void IndexedDBCallbacks::OnUpgradeNeeded(
147 int64_t old_version, 204 int64_t old_version,
148 std::unique_ptr<IndexedDBConnection> connection, 205 std::unique_ptr<IndexedDBConnection> connection,
149 const IndexedDBDatabaseMetadata& metadata, 206 const IndexedDBDatabaseMetadata& metadata,
150 const IndexedDBDataLossInfo& data_loss_info) { 207 const IndexedDBDataLossInfo& data_loss_info) {
151 DCHECK(dispatcher_host_.get()); 208 DCHECK(dispatcher_host_.get());
152 209 DCHECK(helper_);
210 DCHECK_NE(kNoTransaction, host_transaction_id_);
153 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 211 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
154 DCHECK_NE(kNoTransaction, host_transaction_id_);
155 DCHECK_EQ(kNoDatabase, ipc_database_id_); 212 DCHECK_EQ(kNoDatabase, ipc_database_id_);
156 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
157 213
158 data_loss_ = data_loss_info.status; 214 data_loss_ = data_loss_info.status;
159 dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_); 215 dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_);
160 int32_t ipc_database_id = 216 int32_t ipc_database_id =
161 dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_); 217 dispatcher_host_->Add(connection.release(), origin_);
162 if (ipc_database_id < 0) 218 if (ipc_database_id < 0)
163 return; 219 return;
220
164 ipc_database_id_ = ipc_database_id; 221 ipc_database_id_ = ipc_database_id;
165 IndexedDBMsg_CallbacksUpgradeNeeded_Params params; 222
166 params.ipc_thread_id = ipc_thread_id_; 223 BrowserThread::PostTask(
167 params.ipc_callbacks_id = ipc_callbacks_id_; 224 BrowserThread::IO, FROM_HERE,
168 params.ipc_database_id = ipc_database_id; 225 base::Bind(&IOThreadHelper::SendUpgradeNeeded, base::Unretained(helper_),
169 params.ipc_database_callbacks_id = ipc_database_callbacks_id_; 226 ipc_database_id, old_version, data_loss_info.status,
170 params.old_version = old_version; 227 data_loss_info.message,
171 params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata); 228 base::Passed(ConvertMetadata(metadata))));
172 params.data_loss = data_loss_info.status;
173 params.data_loss_message = data_loss_info.message;
174 dispatcher_host_->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params));
175 229
176 if (!connection_open_start_time_.is_null()) { 230 if (!connection_open_start_time_.is_null()) {
177 UMA_HISTOGRAM_MEDIUM_TIMES( 231 UMA_HISTOGRAM_MEDIUM_TIMES(
178 "WebCore.IndexedDB.OpenTime.UpgradeNeeded", 232 "WebCore.IndexedDB.OpenTime.UpgradeNeeded",
179 base::TimeTicks::Now() - connection_open_start_time_); 233 base::TimeTicks::Now() - connection_open_start_time_);
180 connection_open_start_time_ = base::TimeTicks(); 234 connection_open_start_time_ = base::TimeTicks();
181 } 235 }
182 } 236 }
183 237
184 void IndexedDBCallbacks::OnSuccess( 238 void IndexedDBCallbacks::OnSuccess(
185 std::unique_ptr<IndexedDBConnection> connection, 239 std::unique_ptr<IndexedDBConnection> connection,
186 const IndexedDBDatabaseMetadata& metadata) { 240 const IndexedDBDatabaseMetadata& metadata) {
187 DCHECK(dispatcher_host_.get()); 241 DCHECK(dispatcher_host_.get());
188 242 DCHECK(helper_);
189 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 243 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
190 DCHECK_NE(kNoTransaction, host_transaction_id_); 244 DCHECK_NE(kNoTransaction, host_transaction_id_);
191 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); 245 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection);
192 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
193 246
194 scoped_refptr<IndexedDBCallbacks> self(this); 247 scoped_refptr<IndexedDBCallbacks> self(this);
195 248
196 int32_t ipc_object_id = kNoDatabase; 249 int32_t ipc_object_id = kNoDatabase;
197 // Only register if the connection was not previously sent in OnUpgradeNeeded. 250 // Only register if the connection was not previously sent in OnUpgradeNeeded.
198 if (ipc_database_id_ == kNoDatabase) { 251 if (ipc_database_id_ == kNoDatabase) {
199 ipc_object_id = 252 ipc_object_id = dispatcher_host_->Add(connection.release(), origin_);
200 dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_);
201 } 253 }
202 254
203 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( 255 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
204 ipc_thread_id_, 256 base::Bind(&IOThreadHelper::SendSuccessDatabase,
205 ipc_callbacks_id_, 257 base::Unretained(helper_), ipc_object_id,
206 ipc_database_callbacks_id_, 258 base::Passed(ConvertMetadata(metadata))));
207 ipc_object_id,
208 IndexedDBDispatcherHost::ConvertMetadata(metadata)));
209 dispatcher_host_ = NULL; 259 dispatcher_host_ = NULL;
210 260
211 if (!connection_open_start_time_.is_null()) { 261 if (!connection_open_start_time_.is_null()) {
212 UMA_HISTOGRAM_MEDIUM_TIMES( 262 UMA_HISTOGRAM_MEDIUM_TIMES(
213 "WebCore.IndexedDB.OpenTime.Success", 263 "WebCore.IndexedDB.OpenTime.Success",
214 base::TimeTicks::Now() - connection_open_start_time_); 264 base::TimeTicks::Now() - connection_open_start_time_);
215 connection_open_start_time_ = base::TimeTicks(); 265 connection_open_start_time_ = base::TimeTicks();
216 } 266 }
217 } 267 }
218 268
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 iter.mark_used_callback().Run(); 378 iter.mark_used_callback().Run();
329 } 379 }
330 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); 380 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
331 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); 381 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback);
332 } 382 }
333 383
334 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, 384 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
335 const IndexedDBKey& key, 385 const IndexedDBKey& key,
336 const IndexedDBKey& primary_key, 386 const IndexedDBKey& primary_key,
337 IndexedDBValue* value) { 387 IndexedDBValue* value) {
388 DCHECK(!helper_);
338 DCHECK(dispatcher_host_.get()); 389 DCHECK(dispatcher_host_.get());
339 390
340 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 391 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
341 DCHECK_EQ(kNoTransaction, host_transaction_id_); 392 DCHECK_EQ(kNoTransaction, host_transaction_id_);
342 DCHECK_EQ(kNoDatabase, ipc_database_id_); 393 DCHECK_EQ(kNoDatabase, ipc_database_id_);
343 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
344 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 394 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
345 395
346 int32_t ipc_object_id = dispatcher_host_->Add(cursor.get()); 396 int32_t ipc_object_id = dispatcher_host_->Add(cursor.get());
347 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params( 397 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params(
348 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params()); 398 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params());
349 params->ipc_thread_id = ipc_thread_id_; 399 params->ipc_thread_id = ipc_thread_id_;
350 params->ipc_callbacks_id = ipc_callbacks_id_; 400 params->ipc_callbacks_id = ipc_callbacks_id_;
351 params->ipc_cursor_id = ipc_object_id; 401 params->ipc_cursor_id = ipc_object_id;
352 params->key = key; 402 params->key = key;
353 params->primary_key = primary_key; 403 params->primary_key = primary_key;
(...skipping 13 matching lines...) Expand all
367 IndexedDBMsg_CallbacksSuccessIDBCursor>, 417 IndexedDBMsg_CallbacksSuccessIDBCursor>,
368 base::Owned(params.release()), dispatcher_host_, value->blob_info, 418 base::Owned(params.release()), dispatcher_host_, value->blob_info,
369 base::Unretained(&p->value.blob_or_file_info))); 419 base::Unretained(&p->value.blob_or_file_info)));
370 } 420 }
371 dispatcher_host_ = NULL; 421 dispatcher_host_ = NULL;
372 } 422 }
373 423
374 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key, 424 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key,
375 const IndexedDBKey& primary_key, 425 const IndexedDBKey& primary_key,
376 IndexedDBValue* value) { 426 IndexedDBValue* value) {
427 DCHECK(!helper_);
377 DCHECK(dispatcher_host_.get()); 428 DCHECK(dispatcher_host_.get());
378 429
379 DCHECK_NE(kNoCursor, ipc_cursor_id_); 430 DCHECK_NE(kNoCursor, ipc_cursor_id_);
380 DCHECK_EQ(kNoTransaction, host_transaction_id_); 431 DCHECK_EQ(kNoTransaction, host_transaction_id_);
381 DCHECK_EQ(kNoDatabase, ipc_database_id_); 432 DCHECK_EQ(kNoDatabase, ipc_database_id_);
382 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
383 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 433 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
384 434
385 IndexedDBCursor* idb_cursor = 435 IndexedDBCursor* idb_cursor =
386 dispatcher_host_->GetCursorFromId(ipc_cursor_id_); 436 dispatcher_host_->GetCursorFromId(ipc_cursor_id_);
387 437
388 DCHECK(idb_cursor); 438 DCHECK(idb_cursor);
389 if (!idb_cursor) 439 if (!idb_cursor)
390 return; 440 return;
391 441
392 std::unique_ptr<IndexedDBMsg_CallbacksSuccessCursorContinue_Params> params( 442 std::unique_ptr<IndexedDBMsg_CallbacksSuccessCursorContinue_Params> params(
(...skipping 22 matching lines...) Expand all
415 value->blob_info, 465 value->blob_info,
416 base::Unretained(&p->value.blob_or_file_info))); 466 base::Unretained(&p->value.blob_or_file_info)));
417 } 467 }
418 dispatcher_host_ = NULL; 468 dispatcher_host_ = NULL;
419 } 469 }
420 470
421 void IndexedDBCallbacks::OnSuccessWithPrefetch( 471 void IndexedDBCallbacks::OnSuccessWithPrefetch(
422 const std::vector<IndexedDBKey>& keys, 472 const std::vector<IndexedDBKey>& keys,
423 const std::vector<IndexedDBKey>& primary_keys, 473 const std::vector<IndexedDBKey>& primary_keys,
424 std::vector<IndexedDBValue>* values) { 474 std::vector<IndexedDBValue>* values) {
475 DCHECK(!helper_);
425 DCHECK_EQ(keys.size(), primary_keys.size()); 476 DCHECK_EQ(keys.size(), primary_keys.size());
426 DCHECK_EQ(keys.size(), values->size()); 477 DCHECK_EQ(keys.size(), values->size());
427 478
428 DCHECK(dispatcher_host_.get()); 479 DCHECK(dispatcher_host_.get());
429 480
430 DCHECK_NE(kNoCursor, ipc_cursor_id_); 481 DCHECK_NE(kNoCursor, ipc_cursor_id_);
431 DCHECK_EQ(kNoTransaction, host_transaction_id_); 482 DCHECK_EQ(kNoTransaction, host_transaction_id_);
432 DCHECK_EQ(kNoDatabase, ipc_database_id_); 483 DCHECK_EQ(kNoDatabase, ipc_database_id_);
433 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
434 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 484 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
435 485
436 std::vector<IndexedDBKey> msg_keys; 486 std::vector<IndexedDBKey> msg_keys;
437 std::vector<IndexedDBKey> msg_primary_keys; 487 std::vector<IndexedDBKey> msg_primary_keys;
438 488
439 for (size_t i = 0; i < keys.size(); ++i) { 489 for (size_t i = 0; i < keys.size(); ++i) {
440 msg_keys.push_back(keys[i]); 490 msg_keys.push_back(keys[i]);
441 msg_primary_keys.push_back(primary_keys[i]); 491 msg_primary_keys.push_back(primary_keys[i]);
442 } 492 }
443 493
(...skipping 28 matching lines...) Expand all
472 dispatcher_host_, 522 dispatcher_host_,
473 *values)); 523 *values));
474 } else { 524 } else {
475 dispatcher_host_->Send( 525 dispatcher_host_->Send(
476 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params.get())); 526 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params.get()));
477 } 527 }
478 dispatcher_host_ = NULL; 528 dispatcher_host_ = NULL;
479 } 529 }
480 530
481 void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { 531 void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) {
532 DCHECK(!helper_);
482 DCHECK(dispatcher_host_.get()); 533 DCHECK(dispatcher_host_.get());
483 534
484 if (value && value->primary_key.IsValid()) { 535 if (value && value->primary_key.IsValid()) {
485 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 536 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
486 } else { 537 } else {
487 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL); 538 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL);
488 } 539 }
489 DCHECK_EQ(kNoTransaction, host_transaction_id_); 540 DCHECK_EQ(kNoTransaction, host_transaction_id_);
490 DCHECK_EQ(kNoDatabase, ipc_database_id_); 541 DCHECK_EQ(kNoDatabase, ipc_database_id_);
491 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
492 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 542 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
493 543
494 std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params( 544 std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params(
495 new IndexedDBMsg_CallbacksSuccessValue_Params()); 545 new IndexedDBMsg_CallbacksSuccessValue_Params());
496 params->ipc_thread_id = ipc_thread_id_; 546 params->ipc_thread_id = ipc_thread_id_;
497 params->ipc_callbacks_id = ipc_callbacks_id_; 547 params->ipc_callbacks_id = ipc_callbacks_id_;
498 if (value && value->primary_key.IsValid()) { 548 if (value && value->primary_key.IsValid()) {
499 params->value.primary_key = value->primary_key; 549 params->value.primary_key = value->primary_key;
500 params->value.key_path = value->key_path; 550 params->value.key_path = value->key_path;
501 } 551 }
(...skipping 11 matching lines...) Expand all
513 base::Owned(params.release()), dispatcher_host_, 563 base::Owned(params.release()), dispatcher_host_,
514 value->blob_info, 564 value->blob_info,
515 base::Unretained(&p->value.blob_or_file_info))); 565 base::Unretained(&p->value.blob_or_file_info)));
516 } 566 }
517 dispatcher_host_ = NULL; 567 dispatcher_host_ = NULL;
518 } 568 }
519 569
520 void IndexedDBCallbacks::OnSuccessArray( 570 void IndexedDBCallbacks::OnSuccessArray(
521 std::vector<IndexedDBReturnValue>* values, 571 std::vector<IndexedDBReturnValue>* values,
522 const IndexedDBKeyPath& key_path) { 572 const IndexedDBKeyPath& key_path) {
573 DCHECK(!helper_);
523 DCHECK(dispatcher_host_.get()); 574 DCHECK(dispatcher_host_.get());
524 575
525 DCHECK_EQ(kNoTransaction, host_transaction_id_); 576 DCHECK_EQ(kNoTransaction, host_transaction_id_);
526 DCHECK_EQ(kNoDatabase, ipc_database_id_); 577 DCHECK_EQ(kNoDatabase, ipc_database_id_);
527 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
528 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 578 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
529 579
530 std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params( 580 std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params(
531 new IndexedDBMsg_CallbacksSuccessArray_Params()); 581 new IndexedDBMsg_CallbacksSuccessArray_Params());
532 params->ipc_thread_id = ipc_thread_id_; 582 params->ipc_thread_id = ipc_thread_id_;
533 params->ipc_callbacks_id = ipc_callbacks_id_; 583 params->ipc_callbacks_id = ipc_callbacks_id_;
534 params->values.resize(values->size()); 584 params->values.resize(values->size());
535 585
536 bool found_blob_info = false; 586 bool found_blob_info = false;
537 for (size_t i = 0; i < values->size(); ++i) { 587 for (size_t i = 0; i < values->size(); ++i) {
(...skipping 18 matching lines...) Expand all
556 base::Bind(BlobLookupForGetAll, base::Owned(params.release()), 606 base::Bind(BlobLookupForGetAll, base::Owned(params.release()),
557 dispatcher_host_, *values)); 607 dispatcher_host_, *values));
558 } else { 608 } else {
559 dispatcher_host_->Send( 609 dispatcher_host_->Send(
560 new IndexedDBMsg_CallbacksSuccessArray(*params.get())); 610 new IndexedDBMsg_CallbacksSuccessArray(*params.get()));
561 } 611 }
562 dispatcher_host_ = NULL; 612 dispatcher_host_ = NULL;
563 } 613 }
564 614
565 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { 615 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) {
616 DCHECK(!helper_);
566 DCHECK(dispatcher_host_.get()); 617 DCHECK(dispatcher_host_.get());
567 618
568 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 619 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
569 DCHECK_EQ(kNoTransaction, host_transaction_id_); 620 DCHECK_EQ(kNoTransaction, host_transaction_id_);
570 DCHECK_EQ(kNoDatabase, ipc_database_id_); 621 DCHECK_EQ(kNoDatabase, ipc_database_id_);
571 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
572 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 622 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
573 623
574 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( 624 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey(
575 ipc_thread_id_, ipc_callbacks_id_, value)); 625 ipc_thread_id_, ipc_callbacks_id_, value));
576 dispatcher_host_ = NULL; 626 dispatcher_host_ = NULL;
577 } 627 }
578 628
579 void IndexedDBCallbacks::OnSuccess(int64_t value) { 629 void IndexedDBCallbacks::OnSuccess(int64_t value) {
580 DCHECK(dispatcher_host_.get()); 630 DCHECK(dispatcher_host_.get());
631 if (helper_) {
632 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
633 base::Bind(&IOThreadHelper::SendSuccessInteger,
634 base::Unretained(helper_), value));
635 } else {
636 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
637 DCHECK_EQ(kNoTransaction, host_transaction_id_);
638 DCHECK_EQ(kNoDatabase, ipc_database_id_);
639 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
640
641 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger(
642 ipc_thread_id_, ipc_callbacks_id_, value));
643 }
644 dispatcher_host_ = NULL;
645 }
646
647 void IndexedDBCallbacks::OnSuccess() {
648 DCHECK(!helper_);
649 DCHECK(dispatcher_host_.get());
581 650
582 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 651 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
583 DCHECK_EQ(kNoTransaction, host_transaction_id_); 652 DCHECK_EQ(kNoTransaction, host_transaction_id_);
584 DCHECK_EQ(kNoDatabase, ipc_database_id_); 653 DCHECK_EQ(kNoDatabase, ipc_database_id_);
585 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
586 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
587
588 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger(
589 ipc_thread_id_, ipc_callbacks_id_, value));
590 dispatcher_host_ = NULL;
591 }
592
593 void IndexedDBCallbacks::OnSuccess() {
594 DCHECK(dispatcher_host_.get());
595
596 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
597 DCHECK_EQ(kNoTransaction, host_transaction_id_);
598 DCHECK_EQ(kNoDatabase, ipc_database_id_);
599 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
600 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); 654 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
601 655
602 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( 656 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined(
603 ipc_thread_id_, ipc_callbacks_id_)); 657 ipc_thread_id_, ipc_callbacks_id_));
604 dispatcher_host_ = NULL; 658 dispatcher_host_ = NULL;
605 } 659 }
606 660
607 void IndexedDBCallbacks::SetConnectionOpenStartTime( 661 void IndexedDBCallbacks::SetConnectionOpenStartTime(
608 const base::TimeTicks& start_time) { 662 const base::TimeTicks& start_time) {
609 connection_open_start_time_ = start_time; 663 connection_open_start_time_ = start_time;
610 } 664 }
611 665
666 IndexedDBCallbacks::IOThreadHelper::IOThreadHelper(
667 CallbacksAssociatedPtrInfo callbacks_info) {
668 callbacks_.Bind(std::move(callbacks_info));
669 }
670
671 IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {}
672
673 void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) {
674 callbacks_->Blocked(existing_version);
675 }
676
677 void IndexedDBCallbacks::IOThreadHelper::SendError(
678 const IndexedDBDatabaseError& error) {
679 callbacks_->Error(error.code(), error.message());
680 }
681
682 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase(
683 int32_t database_id,
684 ::indexed_db::mojom::DatabaseMetadataPtr metadata) {
685 callbacks_->SuccessDatabase(database_id, std::move(metadata));
686 }
687
688 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) {
689 callbacks_->SuccessInteger(value);
690 }
691
692 void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList(
693 const std::vector<base::string16>& value) {
694 callbacks_->SuccessStringList(value);
695 }
696
697 void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded(
698 int32_t database_id,
699 int64_t old_version,
700 blink::WebIDBDataLoss data_loss,
701 const std::string& data_loss_message,
702 ::indexed_db::mojom::DatabaseMetadataPtr metadata) {
703 callbacks_->UpgradeNeeded(
704 database_id, old_version,
705 static_cast<::indexed_db::mojom::DataLoss>(data_loss), data_loss_message,
706 std::move(metadata));
707 }
708
612 } // namespace content 709 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698