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 <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" | |
24 #include "content/browser/indexed_db/indexed_db_return_value.h" | 22 #include "content/browser/indexed_db/indexed_db_return_value.h" |
25 #include "content/browser/indexed_db/indexed_db_tracing.h" | 23 #include "content/browser/indexed_db/indexed_db_tracing.h" |
26 #include "content/browser/indexed_db/indexed_db_value.h" | 24 #include "content/browser/indexed_db/indexed_db_value.h" |
27 #include "content/common/indexed_db/indexed_db_constants.h" | 25 #include "content/common/indexed_db/indexed_db_constants.h" |
28 #include "content/common/indexed_db/indexed_db_messages.h" | 26 #include "content/common/indexed_db/indexed_db_messages.h" |
| 27 #include "content/common/indexed_db/indexed_db_metadata.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 const int32_t kNoCursor = -1; | 38 const int32_t kNoCursor = -1; |
39 const int32_t kNoDatabaseCallbacks = -1; | |
40 const int64_t kNoTransaction = -1; | 39 const int64_t kNoTransaction = -1; |
41 } | 40 } |
42 | 41 |
| 42 class IndexedDBCallbacks::IOThreadHelper { |
| 43 public: |
| 44 explicit IOThreadHelper(CallbacksAssociatedPtrInfo callbacks_info); |
| 45 ~IOThreadHelper(); |
| 46 |
| 47 void SendError(const IndexedDBDatabaseError& error); |
| 48 void SendSuccessStringList(const std::vector<base::string16>& value); |
| 49 void SendBlocked(int64_t existing_version); |
| 50 void SendUpgradeNeeded(int32_t database_id, |
| 51 int64_t old_version, |
| 52 blink::WebIDBDataLoss data_loss, |
| 53 const std::string& data_loss_message, |
| 54 const content::IndexedDBDatabaseMetadata& metadata); |
| 55 void SendSuccessDatabase(int32_t database_id, |
| 56 const content::IndexedDBDatabaseMetadata& metadata); |
| 57 void SendSuccessInteger(int64_t value); |
| 58 |
| 59 private: |
| 60 ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); |
| 63 }; |
| 64 |
43 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 65 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
44 int32_t ipc_thread_id, | 66 int32_t ipc_thread_id, |
45 int32_t ipc_callbacks_id) | 67 int32_t ipc_callbacks_id) |
46 : dispatcher_host_(dispatcher_host), | 68 : dispatcher_host_(dispatcher_host), |
47 ipc_callbacks_id_(ipc_callbacks_id), | 69 ipc_callbacks_id_(ipc_callbacks_id), |
48 ipc_thread_id_(ipc_thread_id), | 70 ipc_thread_id_(ipc_thread_id), |
49 ipc_cursor_id_(kNoCursor), | 71 ipc_cursor_id_(kNoCursor), |
50 host_transaction_id_(kNoTransaction), | 72 host_transaction_id_(kNoTransaction), |
51 ipc_database_id_(kNoDatabase), | 73 ipc_database_id_(kNoDatabase), |
52 ipc_database_callbacks_id_(kNoDatabaseCallbacks), | |
53 data_loss_(blink::WebIDBDataLossNone), | 74 data_loss_(blink::WebIDBDataLossNone), |
54 sent_blocked_(false) {} | 75 sent_blocked_(false), |
| 76 io_helper_(nullptr) {} |
55 | 77 |
56 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 78 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
57 int32_t ipc_thread_id, | 79 int32_t ipc_thread_id, |
58 int32_t ipc_callbacks_id, | 80 int32_t ipc_callbacks_id, |
59 int32_t ipc_cursor_id) | 81 int32_t ipc_cursor_id) |
60 : dispatcher_host_(dispatcher_host), | 82 : dispatcher_host_(dispatcher_host), |
61 ipc_callbacks_id_(ipc_callbacks_id), | 83 ipc_callbacks_id_(ipc_callbacks_id), |
62 ipc_thread_id_(ipc_thread_id), | 84 ipc_thread_id_(ipc_thread_id), |
63 ipc_cursor_id_(ipc_cursor_id), | 85 ipc_cursor_id_(ipc_cursor_id), |
64 host_transaction_id_(kNoTransaction), | 86 host_transaction_id_(kNoTransaction), |
65 ipc_database_id_(kNoDatabase), | 87 ipc_database_id_(kNoDatabase), |
66 ipc_database_callbacks_id_(kNoDatabaseCallbacks), | |
67 data_loss_(blink::WebIDBDataLossNone), | 88 data_loss_(blink::WebIDBDataLossNone), |
68 sent_blocked_(false) {} | 89 sent_blocked_(false), |
| 90 io_helper_(nullptr) {} |
69 | 91 |
70 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 92 IndexedDBCallbacks::IndexedDBCallbacks( |
71 int32_t ipc_thread_id, | 93 IndexedDBDispatcherHost* dispatcher_host, |
72 int32_t ipc_callbacks_id, | 94 const url::Origin& origin, |
73 int32_t ipc_database_callbacks_id, | 95 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) |
74 int64_t host_transaction_id, | |
75 const url::Origin& origin) | |
76 : dispatcher_host_(dispatcher_host), | 96 : dispatcher_host_(dispatcher_host), |
77 ipc_callbacks_id_(ipc_callbacks_id), | |
78 ipc_thread_id_(ipc_thread_id), | |
79 ipc_cursor_id_(kNoCursor), | 97 ipc_cursor_id_(kNoCursor), |
80 host_transaction_id_(host_transaction_id), | 98 host_transaction_id_(kNoTransaction), |
81 origin_(origin), | 99 origin_(origin), |
82 ipc_database_id_(kNoDatabase), | 100 ipc_database_id_(kNoDatabase), |
83 ipc_database_callbacks_id_(ipc_database_callbacks_id), | |
84 data_loss_(blink::WebIDBDataLossNone), | 101 data_loss_(blink::WebIDBDataLossNone), |
85 sent_blocked_(false) {} | 102 sent_blocked_(false), |
| 103 io_helper_(new IOThreadHelper(std::move(callbacks_info))) {} |
86 | 104 |
87 IndexedDBCallbacks::~IndexedDBCallbacks() {} | 105 IndexedDBCallbacks::~IndexedDBCallbacks() {} |
88 | 106 |
89 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { | 107 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { |
90 DCHECK(dispatcher_host_.get()); | 108 DCHECK(dispatcher_host_.get()); |
91 | 109 |
92 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( | 110 if (io_helper_) { |
93 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); | 111 BrowserThread::PostTask( |
94 dispatcher_host_ = NULL; | 112 BrowserThread::IO, FROM_HERE, |
| 113 base::Bind(&IOThreadHelper::SendError, |
| 114 base::Unretained(io_helper_.get()), error)); |
| 115 } else { |
| 116 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( |
| 117 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); |
| 118 } |
| 119 dispatcher_host_ = nullptr; |
95 | 120 |
96 if (!connection_open_start_time_.is_null()) { | 121 if (!connection_open_start_time_.is_null()) { |
97 UMA_HISTOGRAM_MEDIUM_TIMES( | 122 UMA_HISTOGRAM_MEDIUM_TIMES( |
98 "WebCore.IndexedDB.OpenTime.Error", | 123 "WebCore.IndexedDB.OpenTime.Error", |
99 base::TimeTicks::Now() - connection_open_start_time_); | 124 base::TimeTicks::Now() - connection_open_start_time_); |
100 connection_open_start_time_ = base::TimeTicks(); | 125 connection_open_start_time_ = base::TimeTicks(); |
101 } | 126 } |
102 } | 127 } |
103 | 128 |
104 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { | 129 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { |
105 DCHECK(dispatcher_host_.get()); | 130 DCHECK(dispatcher_host_.get()); |
106 | 131 DCHECK(io_helper_); |
107 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 132 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
108 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 133 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
109 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 134 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
110 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
111 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | |
112 | 135 |
113 std::vector<base::string16> list; | 136 BrowserThread::PostTask( |
114 for (unsigned i = 0; i < value.size(); ++i) | 137 BrowserThread::IO, FROM_HERE, |
115 list.push_back(value[i]); | 138 base::Bind(&IOThreadHelper::SendSuccessStringList, |
116 | 139 base::Unretained(io_helper_.get()), value)); |
117 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessStringList( | 140 dispatcher_host_ = nullptr; |
118 ipc_thread_id_, ipc_callbacks_id_, list)); | |
119 dispatcher_host_ = NULL; | |
120 } | 141 } |
121 | 142 |
122 void IndexedDBCallbacks::OnBlocked(int64_t existing_version) { | 143 void IndexedDBCallbacks::OnBlocked(int64_t existing_version) { |
123 DCHECK(dispatcher_host_.get()); | 144 DCHECK(dispatcher_host_.get()); |
124 | 145 DCHECK(io_helper_); |
125 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 146 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 | 147 |
131 if (sent_blocked_) | 148 if (sent_blocked_) |
132 return; | 149 return; |
133 | 150 |
134 sent_blocked_ = true; | 151 sent_blocked_ = true; |
135 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( | 152 |
136 ipc_thread_id_, ipc_callbacks_id_, existing_version)); | 153 BrowserThread::PostTask( |
| 154 BrowserThread::IO, FROM_HERE, |
| 155 base::Bind(&IOThreadHelper::SendBlocked, |
| 156 base::Unretained(io_helper_.get()), existing_version)); |
137 | 157 |
138 if (!connection_open_start_time_.is_null()) { | 158 if (!connection_open_start_time_.is_null()) { |
139 UMA_HISTOGRAM_MEDIUM_TIMES( | 159 UMA_HISTOGRAM_MEDIUM_TIMES( |
140 "WebCore.IndexedDB.OpenTime.Blocked", | 160 "WebCore.IndexedDB.OpenTime.Blocked", |
141 base::TimeTicks::Now() - connection_open_start_time_); | 161 base::TimeTicks::Now() - connection_open_start_time_); |
142 connection_open_start_time_ = base::TimeTicks(); | 162 connection_open_start_time_ = base::TimeTicks(); |
143 } | 163 } |
144 } | 164 } |
145 | 165 |
146 void IndexedDBCallbacks::OnUpgradeNeeded( | 166 void IndexedDBCallbacks::OnUpgradeNeeded( |
147 int64_t old_version, | 167 int64_t old_version, |
148 std::unique_ptr<IndexedDBConnection> connection, | 168 std::unique_ptr<IndexedDBConnection> connection, |
149 const IndexedDBDatabaseMetadata& metadata, | 169 const IndexedDBDatabaseMetadata& metadata, |
150 const IndexedDBDataLossInfo& data_loss_info) { | 170 const IndexedDBDataLossInfo& data_loss_info) { |
151 DCHECK(dispatcher_host_.get()); | 171 DCHECK(dispatcher_host_.get()); |
152 | 172 DCHECK(io_helper_); |
| 173 DCHECK_NE(kNoTransaction, host_transaction_id_); |
153 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 174 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
154 DCHECK_NE(kNoTransaction, host_transaction_id_); | |
155 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 175 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
156 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
157 | 176 |
158 data_loss_ = data_loss_info.status; | 177 data_loss_ = data_loss_info.status; |
159 dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_); | 178 dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_); |
160 int32_t ipc_database_id = | 179 int32_t ipc_database_id = |
161 dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_); | 180 dispatcher_host_->Add(connection.release(), origin_); |
162 if (ipc_database_id < 0) | 181 if (ipc_database_id < 0) |
163 return; | 182 return; |
| 183 |
164 ipc_database_id_ = ipc_database_id; | 184 ipc_database_id_ = ipc_database_id; |
165 IndexedDBMsg_CallbacksUpgradeNeeded_Params params; | 185 |
166 params.ipc_thread_id = ipc_thread_id_; | 186 BrowserThread::PostTask( |
167 params.ipc_callbacks_id = ipc_callbacks_id_; | 187 BrowserThread::IO, FROM_HERE, |
168 params.ipc_database_id = ipc_database_id; | 188 base::Bind(&IOThreadHelper::SendUpgradeNeeded, |
169 params.ipc_database_callbacks_id = ipc_database_callbacks_id_; | 189 base::Unretained(io_helper_.get()), ipc_database_id, |
170 params.old_version = old_version; | 190 old_version, data_loss_info.status, data_loss_info.message, |
171 params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata); | 191 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 | 192 |
176 if (!connection_open_start_time_.is_null()) { | 193 if (!connection_open_start_time_.is_null()) { |
177 UMA_HISTOGRAM_MEDIUM_TIMES( | 194 UMA_HISTOGRAM_MEDIUM_TIMES( |
178 "WebCore.IndexedDB.OpenTime.UpgradeNeeded", | 195 "WebCore.IndexedDB.OpenTime.UpgradeNeeded", |
179 base::TimeTicks::Now() - connection_open_start_time_); | 196 base::TimeTicks::Now() - connection_open_start_time_); |
180 connection_open_start_time_ = base::TimeTicks(); | 197 connection_open_start_time_ = base::TimeTicks(); |
181 } | 198 } |
182 } | 199 } |
183 | 200 |
184 void IndexedDBCallbacks::OnSuccess( | 201 void IndexedDBCallbacks::OnSuccess( |
185 std::unique_ptr<IndexedDBConnection> connection, | 202 std::unique_ptr<IndexedDBConnection> connection, |
186 const IndexedDBDatabaseMetadata& metadata) { | 203 const IndexedDBDatabaseMetadata& metadata) { |
187 DCHECK(dispatcher_host_.get()); | 204 DCHECK(dispatcher_host_.get()); |
188 | 205 DCHECK(io_helper_); |
189 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 206 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
190 DCHECK_NE(kNoTransaction, host_transaction_id_); | 207 DCHECK_NE(kNoTransaction, host_transaction_id_); |
191 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); | 208 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); |
192 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
193 | 209 |
194 scoped_refptr<IndexedDBCallbacks> self(this); | 210 scoped_refptr<IndexedDBCallbacks> self(this); |
195 | 211 |
196 int32_t ipc_object_id = kNoDatabase; | 212 int32_t ipc_object_id = kNoDatabase; |
197 // Only register if the connection was not previously sent in OnUpgradeNeeded. | 213 // Only register if the connection was not previously sent in OnUpgradeNeeded. |
198 if (ipc_database_id_ == kNoDatabase) { | 214 if (ipc_database_id_ == kNoDatabase) { |
199 ipc_object_id = | 215 ipc_object_id = dispatcher_host_->Add(connection.release(), origin_); |
200 dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_); | |
201 } | 216 } |
202 | 217 |
203 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( | 218 BrowserThread::PostTask( |
204 ipc_thread_id_, | 219 BrowserThread::IO, FROM_HERE, |
205 ipc_callbacks_id_, | 220 base::Bind(&IOThreadHelper::SendSuccessDatabase, |
206 ipc_database_callbacks_id_, | 221 base::Unretained(io_helper_.get()), ipc_object_id, metadata)); |
207 ipc_object_id, | 222 dispatcher_host_ = nullptr; |
208 IndexedDBDispatcherHost::ConvertMetadata(metadata))); | |
209 dispatcher_host_ = NULL; | |
210 | 223 |
211 if (!connection_open_start_time_.is_null()) { | 224 if (!connection_open_start_time_.is_null()) { |
212 UMA_HISTOGRAM_MEDIUM_TIMES( | 225 UMA_HISTOGRAM_MEDIUM_TIMES( |
213 "WebCore.IndexedDB.OpenTime.Success", | 226 "WebCore.IndexedDB.OpenTime.Success", |
214 base::TimeTicks::Now() - connection_open_start_time_); | 227 base::TimeTicks::Now() - connection_open_start_time_); |
215 connection_open_start_time_ = base::TimeTicks(); | 228 connection_open_start_time_ = base::TimeTicks(); |
216 } | 229 } |
217 } | 230 } |
218 | 231 |
219 static std::string CreateBlobData( | 232 static std::string CreateBlobData( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 iter.mark_used_callback().Run(); | 341 iter.mark_used_callback().Run(); |
329 } | 342 } |
330 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 343 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
331 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); | 344 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); |
332 } | 345 } |
333 | 346 |
334 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, | 347 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, |
335 const IndexedDBKey& key, | 348 const IndexedDBKey& key, |
336 const IndexedDBKey& primary_key, | 349 const IndexedDBKey& primary_key, |
337 IndexedDBValue* value) { | 350 IndexedDBValue* value) { |
| 351 DCHECK(!io_helper_); |
338 DCHECK(dispatcher_host_.get()); | 352 DCHECK(dispatcher_host_.get()); |
339 | 353 |
340 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 354 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
341 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 355 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
342 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 356 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
343 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
344 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 357 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
345 | 358 |
346 int32_t ipc_object_id = dispatcher_host_->Add(cursor.get()); | 359 int32_t ipc_object_id = dispatcher_host_->Add(cursor.get()); |
347 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params( | 360 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params( |
348 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params()); | 361 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params()); |
349 params->ipc_thread_id = ipc_thread_id_; | 362 params->ipc_thread_id = ipc_thread_id_; |
350 params->ipc_callbacks_id = ipc_callbacks_id_; | 363 params->ipc_callbacks_id = ipc_callbacks_id_; |
351 params->ipc_cursor_id = ipc_object_id; | 364 params->ipc_cursor_id = ipc_object_id; |
352 params->key = key; | 365 params->key = key; |
353 params->primary_key = primary_key; | 366 params->primary_key = primary_key; |
354 if (value && !value->empty()) | 367 if (value && !value->empty()) |
355 std::swap(params->value.bits, value->bits); | 368 std::swap(params->value.bits, value->bits); |
356 // TODO(alecflett): Avoid a copy here: the whole params object is | 369 // TODO(alecflett): Avoid a copy here: the whole params object is |
357 // being copied into the message. | 370 // being copied into the message. |
358 if (!value || value->blob_info.empty()) { | 371 if (!value || value->blob_info.empty()) { |
359 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(*params)); | 372 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(*params)); |
360 } else { | 373 } else { |
361 IndexedDBMsg_CallbacksSuccessIDBCursor_Params* p = params.get(); | 374 IndexedDBMsg_CallbacksSuccessIDBCursor_Params* p = params.get(); |
362 FillInBlobData(value->blob_info, &p->value.blob_or_file_info); | 375 FillInBlobData(value->blob_info, &p->value.blob_or_file_info); |
363 RegisterBlobsAndSend( | 376 RegisterBlobsAndSend( |
364 value->blob_info, | 377 value->blob_info, |
365 base::Bind( | 378 base::Bind( |
366 CreateBlobsAndSend<IndexedDBMsg_CallbacksSuccessIDBCursor_Params, | 379 CreateBlobsAndSend<IndexedDBMsg_CallbacksSuccessIDBCursor_Params, |
367 IndexedDBMsg_CallbacksSuccessIDBCursor>, | 380 IndexedDBMsg_CallbacksSuccessIDBCursor>, |
368 base::Owned(params.release()), dispatcher_host_, value->blob_info, | 381 base::Owned(params.release()), dispatcher_host_, value->blob_info, |
369 base::Unretained(&p->value.blob_or_file_info))); | 382 base::Unretained(&p->value.blob_or_file_info))); |
370 } | 383 } |
371 dispatcher_host_ = NULL; | 384 dispatcher_host_ = nullptr; |
372 } | 385 } |
373 | 386 |
374 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key, | 387 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key, |
375 const IndexedDBKey& primary_key, | 388 const IndexedDBKey& primary_key, |
376 IndexedDBValue* value) { | 389 IndexedDBValue* value) { |
| 390 DCHECK(!io_helper_); |
377 DCHECK(dispatcher_host_.get()); | 391 DCHECK(dispatcher_host_.get()); |
378 | 392 |
379 DCHECK_NE(kNoCursor, ipc_cursor_id_); | 393 DCHECK_NE(kNoCursor, ipc_cursor_id_); |
380 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 394 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
381 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 395 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
382 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
383 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 396 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
384 | 397 |
385 IndexedDBCursor* idb_cursor = | 398 IndexedDBCursor* idb_cursor = |
386 dispatcher_host_->GetCursorFromId(ipc_cursor_id_); | 399 dispatcher_host_->GetCursorFromId(ipc_cursor_id_); |
387 | 400 |
388 DCHECK(idb_cursor); | 401 DCHECK(idb_cursor); |
389 if (!idb_cursor) | 402 if (!idb_cursor) |
390 return; | 403 return; |
391 | 404 |
392 std::unique_ptr<IndexedDBMsg_CallbacksSuccessCursorContinue_Params> params( | 405 std::unique_ptr<IndexedDBMsg_CallbacksSuccessCursorContinue_Params> params( |
(...skipping 15 matching lines...) Expand all Loading... |
408 FillInBlobData(value->blob_info, &p->value.blob_or_file_info); | 421 FillInBlobData(value->blob_info, &p->value.blob_or_file_info); |
409 RegisterBlobsAndSend( | 422 RegisterBlobsAndSend( |
410 value->blob_info, | 423 value->blob_info, |
411 base::Bind(CreateBlobsAndSend< | 424 base::Bind(CreateBlobsAndSend< |
412 IndexedDBMsg_CallbacksSuccessCursorContinue_Params, | 425 IndexedDBMsg_CallbacksSuccessCursorContinue_Params, |
413 IndexedDBMsg_CallbacksSuccessCursorContinue>, | 426 IndexedDBMsg_CallbacksSuccessCursorContinue>, |
414 base::Owned(params.release()), dispatcher_host_, | 427 base::Owned(params.release()), dispatcher_host_, |
415 value->blob_info, | 428 value->blob_info, |
416 base::Unretained(&p->value.blob_or_file_info))); | 429 base::Unretained(&p->value.blob_or_file_info))); |
417 } | 430 } |
418 dispatcher_host_ = NULL; | 431 dispatcher_host_ = nullptr; |
419 } | 432 } |
420 | 433 |
421 void IndexedDBCallbacks::OnSuccessWithPrefetch( | 434 void IndexedDBCallbacks::OnSuccessWithPrefetch( |
422 const std::vector<IndexedDBKey>& keys, | 435 const std::vector<IndexedDBKey>& keys, |
423 const std::vector<IndexedDBKey>& primary_keys, | 436 const std::vector<IndexedDBKey>& primary_keys, |
424 std::vector<IndexedDBValue>* values) { | 437 std::vector<IndexedDBValue>* values) { |
| 438 DCHECK(!io_helper_); |
425 DCHECK_EQ(keys.size(), primary_keys.size()); | 439 DCHECK_EQ(keys.size(), primary_keys.size()); |
426 DCHECK_EQ(keys.size(), values->size()); | 440 DCHECK_EQ(keys.size(), values->size()); |
427 | 441 |
428 DCHECK(dispatcher_host_.get()); | 442 DCHECK(dispatcher_host_.get()); |
429 | 443 |
430 DCHECK_NE(kNoCursor, ipc_cursor_id_); | 444 DCHECK_NE(kNoCursor, ipc_cursor_id_); |
431 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 445 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
432 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 446 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
433 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
434 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 447 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
435 | 448 |
436 std::vector<IndexedDBKey> msg_keys; | 449 std::vector<IndexedDBKey> msg_keys; |
437 std::vector<IndexedDBKey> msg_primary_keys; | 450 std::vector<IndexedDBKey> msg_primary_keys; |
438 | 451 |
439 for (size_t i = 0; i < keys.size(); ++i) { | 452 for (size_t i = 0; i < keys.size(); ++i) { |
440 msg_keys.push_back(keys[i]); | 453 msg_keys.push_back(keys[i]); |
441 msg_primary_keys.push_back(primary_keys[i]); | 454 msg_primary_keys.push_back(primary_keys[i]); |
442 } | 455 } |
443 | 456 |
(...skipping 24 matching lines...) Expand all Loading... |
468 BrowserThread::PostTask(BrowserThread::IO, | 481 BrowserThread::PostTask(BrowserThread::IO, |
469 FROM_HERE, | 482 FROM_HERE, |
470 base::Bind(BlobLookupForCursorPrefetch, | 483 base::Bind(BlobLookupForCursorPrefetch, |
471 base::Owned(params.release()), | 484 base::Owned(params.release()), |
472 dispatcher_host_, | 485 dispatcher_host_, |
473 *values)); | 486 *values)); |
474 } else { | 487 } else { |
475 dispatcher_host_->Send( | 488 dispatcher_host_->Send( |
476 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params.get())); | 489 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params.get())); |
477 } | 490 } |
478 dispatcher_host_ = NULL; | 491 dispatcher_host_ = nullptr; |
479 } | 492 } |
480 | 493 |
481 void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { | 494 void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) { |
| 495 DCHECK(!io_helper_); |
482 DCHECK(dispatcher_host_.get()); | 496 DCHECK(dispatcher_host_.get()); |
483 | 497 |
484 if (value && value->primary_key.IsValid()) { | 498 if (value && value->primary_key.IsValid()) { |
485 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 499 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
486 } else { | 500 } else { |
487 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL); | 501 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL); |
488 } | 502 } |
489 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 503 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
490 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 504 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
491 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
492 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 505 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
493 | 506 |
494 std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params( | 507 std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params( |
495 new IndexedDBMsg_CallbacksSuccessValue_Params()); | 508 new IndexedDBMsg_CallbacksSuccessValue_Params()); |
496 params->ipc_thread_id = ipc_thread_id_; | 509 params->ipc_thread_id = ipc_thread_id_; |
497 params->ipc_callbacks_id = ipc_callbacks_id_; | 510 params->ipc_callbacks_id = ipc_callbacks_id_; |
498 if (value && value->primary_key.IsValid()) { | 511 if (value && value->primary_key.IsValid()) { |
499 params->value.primary_key = value->primary_key; | 512 params->value.primary_key = value->primary_key; |
500 params->value.key_path = value->key_path; | 513 params->value.key_path = value->key_path; |
501 } | 514 } |
502 if (value && !value->empty()) | 515 if (value && !value->empty()) |
503 std::swap(params->value.bits, value->bits); | 516 std::swap(params->value.bits, value->bits); |
504 if (!value || value->blob_info.empty()) { | 517 if (!value || value->blob_info.empty()) { |
505 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessValue(*params)); | 518 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessValue(*params)); |
506 } else { | 519 } else { |
507 IndexedDBMsg_CallbacksSuccessValue_Params* p = params.get(); | 520 IndexedDBMsg_CallbacksSuccessValue_Params* p = params.get(); |
508 FillInBlobData(value->blob_info, &p->value.blob_or_file_info); | 521 FillInBlobData(value->blob_info, &p->value.blob_or_file_info); |
509 RegisterBlobsAndSend( | 522 RegisterBlobsAndSend( |
510 value->blob_info, | 523 value->blob_info, |
511 base::Bind(CreateBlobsAndSend<IndexedDBMsg_CallbacksSuccessValue_Params, | 524 base::Bind(CreateBlobsAndSend<IndexedDBMsg_CallbacksSuccessValue_Params, |
512 IndexedDBMsg_CallbacksSuccessValue>, | 525 IndexedDBMsg_CallbacksSuccessValue>, |
513 base::Owned(params.release()), dispatcher_host_, | 526 base::Owned(params.release()), dispatcher_host_, |
514 value->blob_info, | 527 value->blob_info, |
515 base::Unretained(&p->value.blob_or_file_info))); | 528 base::Unretained(&p->value.blob_or_file_info))); |
516 } | 529 } |
517 dispatcher_host_ = NULL; | 530 dispatcher_host_ = nullptr; |
518 } | 531 } |
519 | 532 |
520 void IndexedDBCallbacks::OnSuccessArray( | 533 void IndexedDBCallbacks::OnSuccessArray( |
521 std::vector<IndexedDBReturnValue>* values, | 534 std::vector<IndexedDBReturnValue>* values, |
522 const IndexedDBKeyPath& key_path) { | 535 const IndexedDBKeyPath& key_path) { |
| 536 DCHECK(!io_helper_); |
523 DCHECK(dispatcher_host_.get()); | 537 DCHECK(dispatcher_host_.get()); |
524 | 538 |
525 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 539 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
526 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 540 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
527 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
528 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 541 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
529 | 542 |
530 std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params( | 543 std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params( |
531 new IndexedDBMsg_CallbacksSuccessArray_Params()); | 544 new IndexedDBMsg_CallbacksSuccessArray_Params()); |
532 params->ipc_thread_id = ipc_thread_id_; | 545 params->ipc_thread_id = ipc_thread_id_; |
533 params->ipc_callbacks_id = ipc_callbacks_id_; | 546 params->ipc_callbacks_id = ipc_callbacks_id_; |
534 params->values.resize(values->size()); | 547 params->values.resize(values->size()); |
535 | 548 |
536 bool found_blob_info = false; | 549 bool found_blob_info = false; |
537 for (size_t i = 0; i < values->size(); ++i) { | 550 for (size_t i = 0; i < values->size(); ++i) { |
(...skipping 14 matching lines...) Expand all Loading... |
552 | 565 |
553 if (found_blob_info) { | 566 if (found_blob_info) { |
554 BrowserThread::PostTask( | 567 BrowserThread::PostTask( |
555 BrowserThread::IO, FROM_HERE, | 568 BrowserThread::IO, FROM_HERE, |
556 base::Bind(BlobLookupForGetAll, base::Owned(params.release()), | 569 base::Bind(BlobLookupForGetAll, base::Owned(params.release()), |
557 dispatcher_host_, *values)); | 570 dispatcher_host_, *values)); |
558 } else { | 571 } else { |
559 dispatcher_host_->Send( | 572 dispatcher_host_->Send( |
560 new IndexedDBMsg_CallbacksSuccessArray(*params.get())); | 573 new IndexedDBMsg_CallbacksSuccessArray(*params.get())); |
561 } | 574 } |
562 dispatcher_host_ = NULL; | 575 dispatcher_host_ = nullptr; |
563 } | 576 } |
564 | 577 |
565 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { | 578 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { |
| 579 DCHECK(!io_helper_); |
566 DCHECK(dispatcher_host_.get()); | 580 DCHECK(dispatcher_host_.get()); |
567 | 581 |
568 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 582 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
569 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 583 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
570 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 584 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
571 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
572 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 585 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
573 | 586 |
574 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( | 587 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( |
575 ipc_thread_id_, ipc_callbacks_id_, value)); | 588 ipc_thread_id_, ipc_callbacks_id_, value)); |
576 dispatcher_host_ = NULL; | 589 dispatcher_host_ = nullptr; |
577 } | 590 } |
578 | 591 |
579 void IndexedDBCallbacks::OnSuccess(int64_t value) { | 592 void IndexedDBCallbacks::OnSuccess(int64_t value) { |
580 DCHECK(dispatcher_host_.get()); | 593 DCHECK(dispatcher_host_.get()); |
| 594 if (io_helper_) { |
| 595 BrowserThread::PostTask( |
| 596 BrowserThread::IO, FROM_HERE, |
| 597 base::Bind(&IOThreadHelper::SendSuccessInteger, |
| 598 base::Unretained(io_helper_.get()), value)); |
| 599 } else { |
| 600 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 601 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 602 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 603 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 604 |
| 605 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger( |
| 606 ipc_thread_id_, ipc_callbacks_id_, value)); |
| 607 } |
| 608 dispatcher_host_ = nullptr; |
| 609 } |
| 610 |
| 611 void IndexedDBCallbacks::OnSuccess() { |
| 612 DCHECK(!io_helper_); |
| 613 DCHECK(dispatcher_host_.get()); |
581 | 614 |
582 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 615 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
583 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 616 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
584 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 617 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_); | 618 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
601 | 619 |
602 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( | 620 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( |
603 ipc_thread_id_, ipc_callbacks_id_)); | 621 ipc_thread_id_, ipc_callbacks_id_)); |
604 dispatcher_host_ = NULL; | 622 dispatcher_host_ = nullptr; |
605 } | 623 } |
606 | 624 |
607 bool IndexedDBCallbacks::IsValid() const { | 625 bool IndexedDBCallbacks::IsValid() const { |
608 DCHECK(dispatcher_host_.get()); | 626 DCHECK(dispatcher_host_.get()); |
609 | 627 |
610 return dispatcher_host_->IsOpen(); | 628 return dispatcher_host_->IsOpen(); |
611 } | 629 } |
612 | 630 |
613 void IndexedDBCallbacks::SetConnectionOpenStartTime( | 631 void IndexedDBCallbacks::SetConnectionOpenStartTime( |
614 const base::TimeTicks& start_time) { | 632 const base::TimeTicks& start_time) { |
615 connection_open_start_time_ = start_time; | 633 connection_open_start_time_ = start_time; |
616 } | 634 } |
617 | 635 |
| 636 IndexedDBCallbacks::IOThreadHelper::IOThreadHelper( |
| 637 CallbacksAssociatedPtrInfo callbacks_info) { |
| 638 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 639 callbacks_.Bind(std::move(callbacks_info)); |
| 640 } |
| 641 |
| 642 IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {} |
| 643 |
| 644 void IndexedDBCallbacks::IOThreadHelper::SendError( |
| 645 const IndexedDBDatabaseError& error) { |
| 646 callbacks_->Error(error.code(), error.message()); |
| 647 } |
| 648 |
| 649 void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList( |
| 650 const std::vector<base::string16>& value) { |
| 651 callbacks_->SuccessStringList(value); |
| 652 } |
| 653 |
| 654 void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) { |
| 655 callbacks_->Blocked(existing_version); |
| 656 } |
| 657 |
| 658 void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded( |
| 659 int32_t database_id, |
| 660 int64_t old_version, |
| 661 blink::WebIDBDataLoss data_loss, |
| 662 const std::string& data_loss_message, |
| 663 const content::IndexedDBDatabaseMetadata& metadata) { |
| 664 callbacks_->UpgradeNeeded(database_id, old_version, data_loss, |
| 665 data_loss_message, metadata); |
| 666 } |
| 667 |
| 668 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( |
| 669 int32_t database_id, |
| 670 const content::IndexedDBDatabaseMetadata& metadata) { |
| 671 callbacks_->SuccessDatabase(database_id, metadata); |
| 672 } |
| 673 |
| 674 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { |
| 675 callbacks_->SuccessInteger(value); |
| 676 } |
| 677 |
618 } // namespace content | 678 } // namespace content |
OLD | NEW |