OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser/indexed_db/indexed_db_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 20 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
20 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 21 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
21 #include "content/browser/indexed_db/indexed_db_connection.h" | 22 #include "content/browser/indexed_db/indexed_db_connection.h" |
22 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 23 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 69 } |
69 | 70 |
70 } // namespace | 71 } // namespace |
71 | 72 |
72 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the | 73 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the |
73 // in-progress connection. | 74 // in-progress connection. |
74 class IndexedDBDatabase::PendingUpgradeCall { | 75 class IndexedDBDatabase::PendingUpgradeCall { |
75 public: | 76 public: |
76 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, | 77 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, |
77 scoped_ptr<IndexedDBConnection> connection, | 78 scoped_ptr<IndexedDBConnection> connection, |
78 int64 transaction_id, | 79 int64_t transaction_id, |
79 int64 version) | 80 int64_t version) |
80 : callbacks_(callbacks), | 81 : callbacks_(callbacks), |
81 connection_(connection.Pass()), | 82 connection_(connection.Pass()), |
82 version_(version), | 83 version_(version), |
83 transaction_id_(transaction_id) {} | 84 transaction_id_(transaction_id) {} |
84 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } | 85 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } |
85 // Takes ownership of the connection object. | 86 // Takes ownership of the connection object. |
86 scoped_ptr<IndexedDBConnection> ReleaseConnection() WARN_UNUSED_RESULT { | 87 scoped_ptr<IndexedDBConnection> ReleaseConnection() WARN_UNUSED_RESULT { |
87 return connection_.Pass(); | 88 return connection_.Pass(); |
88 } | 89 } |
89 int64 version() const { return version_; } | 90 int64_t version() const { return version_; } |
90 int64 transaction_id() const { return transaction_id_; } | 91 int64_t transaction_id() const { return transaction_id_; } |
91 | 92 |
92 private: | 93 private: |
93 scoped_refptr<IndexedDBCallbacks> callbacks_; | 94 scoped_refptr<IndexedDBCallbacks> callbacks_; |
94 scoped_ptr<IndexedDBConnection> connection_; | 95 scoped_ptr<IndexedDBConnection> connection_; |
95 int64 version_; | 96 int64_t version_; |
96 const int64 transaction_id_; | 97 const int64_t transaction_id_; |
97 }; | 98 }; |
98 | 99 |
99 // PendingSuccessCall has a IndexedDBConnection* because the connection is now | 100 // PendingSuccessCall has a IndexedDBConnection* because the connection is now |
100 // owned elsewhere, but we need to cancel the success call if that connection | 101 // owned elsewhere, but we need to cancel the success call if that connection |
101 // closes before it is sent. | 102 // closes before it is sent. |
102 class IndexedDBDatabase::PendingSuccessCall { | 103 class IndexedDBDatabase::PendingSuccessCall { |
103 public: | 104 public: |
104 PendingSuccessCall(scoped_refptr<IndexedDBCallbacks> callbacks, | 105 PendingSuccessCall(scoped_refptr<IndexedDBCallbacks> callbacks, |
105 IndexedDBConnection* connection, | 106 IndexedDBConnection* connection, |
106 int64 version) | 107 int64_t version) |
107 : callbacks_(callbacks), connection_(connection), version_(version) {} | 108 : callbacks_(callbacks), connection_(connection), version_(version) {} |
108 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } | 109 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } |
109 IndexedDBConnection* connection() const { return connection_; } | 110 IndexedDBConnection* connection() const { return connection_; } |
110 int64 version() const { return version_; } | 111 int64_t version() const { return version_; } |
111 | 112 |
112 private: | 113 private: |
113 scoped_refptr<IndexedDBCallbacks> callbacks_; | 114 scoped_refptr<IndexedDBCallbacks> callbacks_; |
114 IndexedDBConnection* connection_; | 115 IndexedDBConnection* connection_; |
115 int64 version_; | 116 int64_t version_; |
116 }; | 117 }; |
117 | 118 |
118 class IndexedDBDatabase::PendingDeleteCall { | 119 class IndexedDBDatabase::PendingDeleteCall { |
119 public: | 120 public: |
120 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) | 121 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) |
121 : callbacks_(callbacks) {} | 122 : callbacks_(callbacks) {} |
122 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } | 123 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } |
123 | 124 |
124 private: | 125 private: |
125 scoped_refptr<IndexedDBCallbacks> callbacks_; | 126 scoped_refptr<IndexedDBCallbacks> callbacks_; |
(...skipping 29 matching lines...) Expand all Loading... |
155 kNoStringVersion, | 156 kNoStringVersion, |
156 IndexedDBDatabaseMetadata::NO_INT_VERSION, | 157 IndexedDBDatabaseMetadata::NO_INT_VERSION, |
157 kInvalidId), | 158 kInvalidId), |
158 identifier_(unique_identifier), | 159 identifier_(unique_identifier), |
159 factory_(factory) { | 160 factory_(factory) { |
160 DCHECK(factory != NULL); | 161 DCHECK(factory != NULL); |
161 } | 162 } |
162 | 163 |
163 void IndexedDBDatabase::AddObjectStore( | 164 void IndexedDBDatabase::AddObjectStore( |
164 const IndexedDBObjectStoreMetadata& object_store, | 165 const IndexedDBObjectStoreMetadata& object_store, |
165 int64 new_max_object_store_id) { | 166 int64_t new_max_object_store_id) { |
166 DCHECK(metadata_.object_stores.find(object_store.id) == | 167 DCHECK(metadata_.object_stores.find(object_store.id) == |
167 metadata_.object_stores.end()); | 168 metadata_.object_stores.end()); |
168 if (new_max_object_store_id != IndexedDBObjectStoreMetadata::kInvalidId) { | 169 if (new_max_object_store_id != IndexedDBObjectStoreMetadata::kInvalidId) { |
169 DCHECK_LT(metadata_.max_object_store_id, new_max_object_store_id); | 170 DCHECK_LT(metadata_.max_object_store_id, new_max_object_store_id); |
170 metadata_.max_object_store_id = new_max_object_store_id; | 171 metadata_.max_object_store_id = new_max_object_store_id; |
171 } | 172 } |
172 metadata_.object_stores[object_store.id] = object_store; | 173 metadata_.object_stores[object_store.id] = object_store; |
173 } | 174 } |
174 | 175 |
175 void IndexedDBDatabase::RemoveObjectStore(int64 object_store_id) { | 176 void IndexedDBDatabase::RemoveObjectStore(int64_t object_store_id) { |
176 DCHECK(metadata_.object_stores.find(object_store_id) != | 177 DCHECK(metadata_.object_stores.find(object_store_id) != |
177 metadata_.object_stores.end()); | 178 metadata_.object_stores.end()); |
178 metadata_.object_stores.erase(object_store_id); | 179 metadata_.object_stores.erase(object_store_id); |
179 } | 180 } |
180 | 181 |
181 void IndexedDBDatabase::AddIndex(int64 object_store_id, | 182 void IndexedDBDatabase::AddIndex(int64_t object_store_id, |
182 const IndexedDBIndexMetadata& index, | 183 const IndexedDBIndexMetadata& index, |
183 int64 new_max_index_id) { | 184 int64_t new_max_index_id) { |
184 DCHECK(metadata_.object_stores.find(object_store_id) != | 185 DCHECK(metadata_.object_stores.find(object_store_id) != |
185 metadata_.object_stores.end()); | 186 metadata_.object_stores.end()); |
186 IndexedDBObjectStoreMetadata object_store = | 187 IndexedDBObjectStoreMetadata object_store = |
187 metadata_.object_stores[object_store_id]; | 188 metadata_.object_stores[object_store_id]; |
188 | 189 |
189 DCHECK(object_store.indexes.find(index.id) == object_store.indexes.end()); | 190 DCHECK(object_store.indexes.find(index.id) == object_store.indexes.end()); |
190 object_store.indexes[index.id] = index; | 191 object_store.indexes[index.id] = index; |
191 if (new_max_index_id != IndexedDBIndexMetadata::kInvalidId) { | 192 if (new_max_index_id != IndexedDBIndexMetadata::kInvalidId) { |
192 DCHECK_LT(object_store.max_index_id, new_max_index_id); | 193 DCHECK_LT(object_store.max_index_id, new_max_index_id); |
193 object_store.max_index_id = new_max_index_id; | 194 object_store.max_index_id = new_max_index_id; |
194 } | 195 } |
195 metadata_.object_stores[object_store_id] = object_store; | 196 metadata_.object_stores[object_store_id] = object_store; |
196 } | 197 } |
197 | 198 |
198 void IndexedDBDatabase::RemoveIndex(int64 object_store_id, int64 index_id) { | 199 void IndexedDBDatabase::RemoveIndex(int64_t object_store_id, int64_t index_id) { |
199 DCHECK(metadata_.object_stores.find(object_store_id) != | 200 DCHECK(metadata_.object_stores.find(object_store_id) != |
200 metadata_.object_stores.end()); | 201 metadata_.object_stores.end()); |
201 IndexedDBObjectStoreMetadata object_store = | 202 IndexedDBObjectStoreMetadata object_store = |
202 metadata_.object_stores[object_store_id]; | 203 metadata_.object_stores[object_store_id]; |
203 | 204 |
204 DCHECK(object_store.indexes.find(index_id) != object_store.indexes.end()); | 205 DCHECK(object_store.indexes.find(index_id) != object_store.indexes.end()); |
205 object_store.indexes.erase(index_id); | 206 object_store.indexes.erase(index_id); |
206 metadata_.object_stores[object_store_id] = object_store; | 207 metadata_.object_stores[object_store_id] = object_store; |
207 } | 208 } |
208 | 209 |
(...skipping 27 matching lines...) Expand all Loading... |
236 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 237 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
237 int child_process_id) { | 238 int child_process_id) { |
238 scoped_ptr<IndexedDBConnection> connection( | 239 scoped_ptr<IndexedDBConnection> connection( |
239 new IndexedDBConnection(this, database_callbacks)); | 240 new IndexedDBConnection(this, database_callbacks)); |
240 connections_.insert(connection.get()); | 241 connections_.insert(connection.get()); |
241 backing_store_->GrantChildProcessPermissions(child_process_id); | 242 backing_store_->GrantChildProcessPermissions(child_process_id); |
242 return connection.Pass(); | 243 return connection.Pass(); |
243 } | 244 } |
244 | 245 |
245 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( | 246 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( |
246 int64 transaction_id) const { | 247 int64_t transaction_id) const { |
247 TransactionMap::const_iterator trans_iterator = | 248 TransactionMap::const_iterator trans_iterator = |
248 transactions_.find(transaction_id); | 249 transactions_.find(transaction_id); |
249 if (trans_iterator == transactions_.end()) | 250 if (trans_iterator == transactions_.end()) |
250 return NULL; | 251 return NULL; |
251 return trans_iterator->second; | 252 return trans_iterator->second; |
252 } | 253 } |
253 | 254 |
254 bool IndexedDBDatabase::ValidateObjectStoreId(int64 object_store_id) const { | 255 bool IndexedDBDatabase::ValidateObjectStoreId(int64_t object_store_id) const { |
255 if (!ContainsKey(metadata_.object_stores, object_store_id)) { | 256 if (!ContainsKey(metadata_.object_stores, object_store_id)) { |
256 DLOG(ERROR) << "Invalid object_store_id"; | 257 DLOG(ERROR) << "Invalid object_store_id"; |
257 return false; | 258 return false; |
258 } | 259 } |
259 return true; | 260 return true; |
260 } | 261 } |
261 | 262 |
262 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId(int64 object_store_id, | 263 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId( |
263 int64 index_id) const { | 264 int64_t object_store_id, |
| 265 int64_t index_id) const { |
264 if (!ValidateObjectStoreId(object_store_id)) | 266 if (!ValidateObjectStoreId(object_store_id)) |
265 return false; | 267 return false; |
266 const IndexedDBObjectStoreMetadata& object_store_metadata = | 268 const IndexedDBObjectStoreMetadata& object_store_metadata = |
267 metadata_.object_stores.find(object_store_id)->second; | 269 metadata_.object_stores.find(object_store_id)->second; |
268 if (!ContainsKey(object_store_metadata.indexes, index_id)) { | 270 if (!ContainsKey(object_store_metadata.indexes, index_id)) { |
269 DLOG(ERROR) << "Invalid index_id"; | 271 DLOG(ERROR) << "Invalid index_id"; |
270 return false; | 272 return false; |
271 } | 273 } |
272 return true; | 274 return true; |
273 } | 275 } |
274 | 276 |
275 bool IndexedDBDatabase::ValidateObjectStoreIdAndOptionalIndexId( | 277 bool IndexedDBDatabase::ValidateObjectStoreIdAndOptionalIndexId( |
276 int64 object_store_id, | 278 int64_t object_store_id, |
277 int64 index_id) const { | 279 int64_t index_id) const { |
278 if (!ValidateObjectStoreId(object_store_id)) | 280 if (!ValidateObjectStoreId(object_store_id)) |
279 return false; | 281 return false; |
280 const IndexedDBObjectStoreMetadata& object_store_metadata = | 282 const IndexedDBObjectStoreMetadata& object_store_metadata = |
281 metadata_.object_stores.find(object_store_id)->second; | 283 metadata_.object_stores.find(object_store_id)->second; |
282 if (index_id != IndexedDBIndexMetadata::kInvalidId && | 284 if (index_id != IndexedDBIndexMetadata::kInvalidId && |
283 !ContainsKey(object_store_metadata.indexes, index_id)) { | 285 !ContainsKey(object_store_metadata.indexes, index_id)) { |
284 DLOG(ERROR) << "Invalid index_id"; | 286 DLOG(ERROR) << "Invalid index_id"; |
285 return false; | 287 return false; |
286 } | 288 } |
287 return true; | 289 return true; |
288 } | 290 } |
289 | 291 |
290 bool IndexedDBDatabase::ValidateObjectStoreIdAndNewIndexId( | 292 bool IndexedDBDatabase::ValidateObjectStoreIdAndNewIndexId( |
291 int64 object_store_id, | 293 int64_t object_store_id, |
292 int64 index_id) const { | 294 int64_t index_id) const { |
293 if (!ValidateObjectStoreId(object_store_id)) | 295 if (!ValidateObjectStoreId(object_store_id)) |
294 return false; | 296 return false; |
295 const IndexedDBObjectStoreMetadata& object_store_metadata = | 297 const IndexedDBObjectStoreMetadata& object_store_metadata = |
296 metadata_.object_stores.find(object_store_id)->second; | 298 metadata_.object_stores.find(object_store_id)->second; |
297 if (ContainsKey(object_store_metadata.indexes, index_id)) { | 299 if (ContainsKey(object_store_metadata.indexes, index_id)) { |
298 DLOG(ERROR) << "Invalid index_id"; | 300 DLOG(ERROR) << "Invalid index_id"; |
299 return false; | 301 return false; |
300 } | 302 } |
301 return true; | 303 return true; |
302 } | 304 } |
303 | 305 |
304 void IndexedDBDatabase::CreateObjectStore(int64 transaction_id, | 306 void IndexedDBDatabase::CreateObjectStore(int64_t transaction_id, |
305 int64 object_store_id, | 307 int64_t object_store_id, |
306 const base::string16& name, | 308 const base::string16& name, |
307 const IndexedDBKeyPath& key_path, | 309 const IndexedDBKeyPath& key_path, |
308 bool auto_increment) { | 310 bool auto_increment) { |
309 IDB_TRACE1("IndexedDBDatabase::CreateObjectStore", "txn.id", transaction_id); | 311 IDB_TRACE1("IndexedDBDatabase::CreateObjectStore", "txn.id", transaction_id); |
310 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 312 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
311 if (!transaction) | 313 if (!transaction) |
312 return; | 314 return; |
313 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 315 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); |
314 | 316 |
315 if (ContainsKey(metadata_.object_stores, object_store_id)) { | 317 if (ContainsKey(metadata_.object_stores, object_store_id)) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 return; | 353 return; |
352 } | 354 } |
353 | 355 |
354 AddObjectStore(object_store_metadata, object_store_id); | 356 AddObjectStore(object_store_metadata, object_store_id); |
355 transaction->ScheduleAbortTask( | 357 transaction->ScheduleAbortTask( |
356 base::Bind(&IndexedDBDatabase::CreateObjectStoreAbortOperation, | 358 base::Bind(&IndexedDBDatabase::CreateObjectStoreAbortOperation, |
357 this, | 359 this, |
358 object_store_id)); | 360 object_store_id)); |
359 } | 361 } |
360 | 362 |
361 void IndexedDBDatabase::DeleteObjectStore(int64 transaction_id, | 363 void IndexedDBDatabase::DeleteObjectStore(int64_t transaction_id, |
362 int64 object_store_id) { | 364 int64_t object_store_id) { |
363 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStore", "txn.id", transaction_id); | 365 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStore", "txn.id", transaction_id); |
364 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 366 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
365 if (!transaction) | 367 if (!transaction) |
366 return; | 368 return; |
367 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 369 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); |
368 | 370 |
369 if (!ValidateObjectStoreId(object_store_id)) | 371 if (!ValidateObjectStoreId(object_store_id)) |
370 return; | 372 return; |
371 | 373 |
372 transaction->ScheduleTask( | 374 transaction->ScheduleTask( |
373 base::Bind(&IndexedDBDatabase::DeleteObjectStoreOperation, | 375 base::Bind(&IndexedDBDatabase::DeleteObjectStoreOperation, |
374 this, | 376 this, |
375 object_store_id)); | 377 object_store_id)); |
376 } | 378 } |
377 | 379 |
378 void IndexedDBDatabase::CreateIndex(int64 transaction_id, | 380 void IndexedDBDatabase::CreateIndex(int64_t transaction_id, |
379 int64 object_store_id, | 381 int64_t object_store_id, |
380 int64 index_id, | 382 int64_t index_id, |
381 const base::string16& name, | 383 const base::string16& name, |
382 const IndexedDBKeyPath& key_path, | 384 const IndexedDBKeyPath& key_path, |
383 bool unique, | 385 bool unique, |
384 bool multi_entry) { | 386 bool multi_entry) { |
385 IDB_TRACE1("IndexedDBDatabase::CreateIndex", "txn.id", transaction_id); | 387 IDB_TRACE1("IndexedDBDatabase::CreateIndex", "txn.id", transaction_id); |
386 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 388 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
387 if (!transaction) | 389 if (!transaction) |
388 return; | 390 return; |
389 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 391 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); |
390 | 392 |
(...skipping 29 matching lines...) Expand all Loading... |
420 | 422 |
421 AddIndex(object_store_id, index_metadata, index_id); | 423 AddIndex(object_store_id, index_metadata, index_id); |
422 transaction->ScheduleAbortTask( | 424 transaction->ScheduleAbortTask( |
423 base::Bind(&IndexedDBDatabase::CreateIndexAbortOperation, | 425 base::Bind(&IndexedDBDatabase::CreateIndexAbortOperation, |
424 this, | 426 this, |
425 object_store_id, | 427 object_store_id, |
426 index_id)); | 428 index_id)); |
427 } | 429 } |
428 | 430 |
429 void IndexedDBDatabase::CreateIndexAbortOperation( | 431 void IndexedDBDatabase::CreateIndexAbortOperation( |
430 int64 object_store_id, | 432 int64_t object_store_id, |
431 int64 index_id, | 433 int64_t index_id, |
432 IndexedDBTransaction* transaction) { | 434 IndexedDBTransaction* transaction) { |
433 DCHECK(!transaction); | 435 DCHECK(!transaction); |
434 IDB_TRACE("IndexedDBDatabase::CreateIndexAbortOperation"); | 436 IDB_TRACE("IndexedDBDatabase::CreateIndexAbortOperation"); |
435 RemoveIndex(object_store_id, index_id); | 437 RemoveIndex(object_store_id, index_id); |
436 } | 438 } |
437 | 439 |
438 void IndexedDBDatabase::DeleteIndex(int64 transaction_id, | 440 void IndexedDBDatabase::DeleteIndex(int64_t transaction_id, |
439 int64 object_store_id, | 441 int64_t object_store_id, |
440 int64 index_id) { | 442 int64_t index_id) { |
441 IDB_TRACE1("IndexedDBDatabase::DeleteIndex", "txn.id", transaction_id); | 443 IDB_TRACE1("IndexedDBDatabase::DeleteIndex", "txn.id", transaction_id); |
442 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 444 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
443 if (!transaction) | 445 if (!transaction) |
444 return; | 446 return; |
445 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 447 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); |
446 | 448 |
447 if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) | 449 if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) |
448 return; | 450 return; |
449 | 451 |
450 transaction->ScheduleTask( | 452 transaction->ScheduleTask( |
451 base::Bind(&IndexedDBDatabase::DeleteIndexOperation, | 453 base::Bind(&IndexedDBDatabase::DeleteIndexOperation, |
452 this, | 454 this, |
453 object_store_id, | 455 object_store_id, |
454 index_id)); | 456 index_id)); |
455 } | 457 } |
456 | 458 |
457 void IndexedDBDatabase::DeleteIndexOperation( | 459 void IndexedDBDatabase::DeleteIndexOperation( |
458 int64 object_store_id, | 460 int64_t object_store_id, |
459 int64 index_id, | 461 int64_t index_id, |
460 IndexedDBTransaction* transaction) { | 462 IndexedDBTransaction* transaction) { |
461 IDB_TRACE1( | 463 IDB_TRACE1( |
462 "IndexedDBDatabase::DeleteIndexOperation", "txn.id", transaction->id()); | 464 "IndexedDBDatabase::DeleteIndexOperation", "txn.id", transaction->id()); |
463 | 465 |
464 const IndexedDBIndexMetadata index_metadata = | 466 const IndexedDBIndexMetadata index_metadata = |
465 metadata_.object_stores[object_store_id].indexes[index_id]; | 467 metadata_.object_stores[object_store_id].indexes[index_id]; |
466 | 468 |
467 leveldb::Status s = | 469 leveldb::Status s = |
468 backing_store_->DeleteIndex(transaction->BackingStoreTransaction(), | 470 backing_store_->DeleteIndex(transaction->BackingStoreTransaction(), |
469 transaction->database()->id(), | 471 transaction->database()->id(), |
(...skipping 14 matching lines...) Expand all Loading... |
484 | 486 |
485 RemoveIndex(object_store_id, index_id); | 487 RemoveIndex(object_store_id, index_id); |
486 transaction->ScheduleAbortTask( | 488 transaction->ScheduleAbortTask( |
487 base::Bind(&IndexedDBDatabase::DeleteIndexAbortOperation, | 489 base::Bind(&IndexedDBDatabase::DeleteIndexAbortOperation, |
488 this, | 490 this, |
489 object_store_id, | 491 object_store_id, |
490 index_metadata)); | 492 index_metadata)); |
491 } | 493 } |
492 | 494 |
493 void IndexedDBDatabase::DeleteIndexAbortOperation( | 495 void IndexedDBDatabase::DeleteIndexAbortOperation( |
494 int64 object_store_id, | 496 int64_t object_store_id, |
495 const IndexedDBIndexMetadata& index_metadata, | 497 const IndexedDBIndexMetadata& index_metadata, |
496 IndexedDBTransaction* transaction) { | 498 IndexedDBTransaction* transaction) { |
497 DCHECK(!transaction); | 499 DCHECK(!transaction); |
498 IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation"); | 500 IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation"); |
499 AddIndex(object_store_id, index_metadata, IndexedDBIndexMetadata::kInvalidId); | 501 AddIndex(object_store_id, index_metadata, IndexedDBIndexMetadata::kInvalidId); |
500 } | 502 } |
501 | 503 |
502 void IndexedDBDatabase::Commit(int64 transaction_id) { | 504 void IndexedDBDatabase::Commit(int64_t transaction_id) { |
503 // The frontend suggests that we commit, but we may have previously initiated | 505 // The frontend suggests that we commit, but we may have previously initiated |
504 // an abort, and so have disposed of the transaction. on_abort has already | 506 // an abort, and so have disposed of the transaction. on_abort has already |
505 // been dispatched to the frontend, so it will find out about that | 507 // been dispatched to the frontend, so it will find out about that |
506 // asynchronously. | 508 // asynchronously. |
507 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 509 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
508 if (transaction) { | 510 if (transaction) { |
509 scoped_refptr<IndexedDBFactory> factory = factory_; | 511 scoped_refptr<IndexedDBFactory> factory = factory_; |
510 leveldb::Status s = transaction->Commit(); | 512 leveldb::Status s = transaction->Commit(); |
511 if (s.IsCorruption()) { | 513 if (s.IsCorruption()) { |
512 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 514 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
513 "Internal error committing transaction."); | 515 "Internal error committing transaction."); |
514 factory->HandleBackingStoreCorruption(identifier_.first, error); | 516 factory->HandleBackingStoreCorruption(identifier_.first, error); |
515 } | 517 } |
516 } | 518 } |
517 } | 519 } |
518 | 520 |
519 void IndexedDBDatabase::Abort(int64 transaction_id) { | 521 void IndexedDBDatabase::Abort(int64_t transaction_id) { |
520 // If the transaction is unknown, then it has already been aborted by the | 522 // If the transaction is unknown, then it has already been aborted by the |
521 // backend before this call so it is safe to ignore it. | 523 // backend before this call so it is safe to ignore it. |
522 IDB_TRACE1("IndexedDBDatabase::Abort", "txn.id", transaction_id); | 524 IDB_TRACE1("IndexedDBDatabase::Abort", "txn.id", transaction_id); |
523 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 525 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
524 if (transaction) | 526 if (transaction) |
525 transaction->Abort(); | 527 transaction->Abort(); |
526 } | 528 } |
527 | 529 |
528 void IndexedDBDatabase::Abort(int64 transaction_id, | 530 void IndexedDBDatabase::Abort(int64_t transaction_id, |
529 const IndexedDBDatabaseError& error) { | 531 const IndexedDBDatabaseError& error) { |
530 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); | 532 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); |
531 // If the transaction is unknown, then it has already been aborted by the | 533 // If the transaction is unknown, then it has already been aborted by the |
532 // backend before this call so it is safe to ignore it. | 534 // backend before this call so it is safe to ignore it. |
533 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 535 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
534 if (transaction) | 536 if (transaction) |
535 transaction->Abort(error); | 537 transaction->Abort(error); |
536 } | 538 } |
537 | 539 |
538 void IndexedDBDatabase::GetAll(int64 transaction_id, | 540 void IndexedDBDatabase::GetAll(int64_t transaction_id, |
539 int64 object_store_id, | 541 int64_t object_store_id, |
540 int64 index_id, | 542 int64_t index_id, |
541 scoped_ptr<IndexedDBKeyRange> key_range, | 543 scoped_ptr<IndexedDBKeyRange> key_range, |
542 bool key_only, | 544 bool key_only, |
543 int64 max_count, | 545 int64_t max_count, |
544 scoped_refptr<IndexedDBCallbacks> callbacks) { | 546 scoped_refptr<IndexedDBCallbacks> callbacks) { |
545 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); | 547 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); |
546 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 548 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
547 if (!transaction) | 549 if (!transaction) |
548 return; | 550 return; |
549 | 551 |
550 if (!ValidateObjectStoreId(object_store_id)) | 552 if (!ValidateObjectStoreId(object_store_id)) |
551 return; | 553 return; |
552 | 554 |
553 transaction->ScheduleTask(base::Bind( | 555 transaction->ScheduleTask(base::Bind( |
554 &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id, | 556 &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id, |
555 base::Passed(&key_range), | 557 base::Passed(&key_range), |
556 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 558 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, |
557 max_count, callbacks)); | 559 max_count, callbacks)); |
558 } | 560 } |
559 | 561 |
560 void IndexedDBDatabase::Get(int64 transaction_id, | 562 void IndexedDBDatabase::Get(int64_t transaction_id, |
561 int64 object_store_id, | 563 int64_t object_store_id, |
562 int64 index_id, | 564 int64_t index_id, |
563 scoped_ptr<IndexedDBKeyRange> key_range, | 565 scoped_ptr<IndexedDBKeyRange> key_range, |
564 bool key_only, | 566 bool key_only, |
565 scoped_refptr<IndexedDBCallbacks> callbacks) { | 567 scoped_refptr<IndexedDBCallbacks> callbacks) { |
566 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id); | 568 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id); |
567 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 569 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
568 if (!transaction) | 570 if (!transaction) |
569 return; | 571 return; |
570 | 572 |
571 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 573 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) |
572 return; | 574 return; |
573 | 575 |
574 transaction->ScheduleTask(base::Bind( | 576 transaction->ScheduleTask(base::Bind( |
575 &IndexedDBDatabase::GetOperation, this, object_store_id, index_id, | 577 &IndexedDBDatabase::GetOperation, this, object_store_id, index_id, |
576 base::Passed(&key_range), | 578 base::Passed(&key_range), |
577 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 579 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, |
578 callbacks)); | 580 callbacks)); |
579 } | 581 } |
580 | 582 |
581 void IndexedDBDatabase::GetOperation( | 583 void IndexedDBDatabase::GetOperation( |
582 int64 object_store_id, | 584 int64_t object_store_id, |
583 int64 index_id, | 585 int64_t index_id, |
584 scoped_ptr<IndexedDBKeyRange> key_range, | 586 scoped_ptr<IndexedDBKeyRange> key_range, |
585 indexed_db::CursorType cursor_type, | 587 indexed_db::CursorType cursor_type, |
586 scoped_refptr<IndexedDBCallbacks> callbacks, | 588 scoped_refptr<IndexedDBCallbacks> callbacks, |
587 IndexedDBTransaction* transaction) { | 589 IndexedDBTransaction* transaction) { |
588 IDB_TRACE1("IndexedDBDatabase::GetOperation", "txn.id", transaction->id()); | 590 IDB_TRACE1("IndexedDBDatabase::GetOperation", "txn.id", transaction->id()); |
589 | 591 |
590 DCHECK(metadata_.object_stores.find(object_store_id) != | 592 DCHECK(metadata_.object_stores.find(object_store_id) != |
591 metadata_.object_stores.end()); | 593 metadata_.object_stores.end()); |
592 const IndexedDBObjectStoreMetadata& object_store_metadata = | 594 const IndexedDBObjectStoreMetadata& object_store_metadata = |
593 metadata_.object_stores[object_store_id]; | 595 metadata_.object_stores[object_store_id]; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 } | 736 } |
735 if (object_store_metadata.auto_increment && | 737 if (object_store_metadata.auto_increment && |
736 !object_store_metadata.key_path.IsNull()) { | 738 !object_store_metadata.key_path.IsNull()) { |
737 value.primary_key = *primary_key; | 739 value.primary_key = *primary_key; |
738 value.key_path = object_store_metadata.key_path; | 740 value.key_path = object_store_metadata.key_path; |
739 } | 741 } |
740 callbacks->OnSuccess(&value); | 742 callbacks->OnSuccess(&value); |
741 } | 743 } |
742 | 744 |
743 void IndexedDBDatabase::GetAllOperation( | 745 void IndexedDBDatabase::GetAllOperation( |
744 int64 object_store_id, | 746 int64_t object_store_id, |
745 int64 index_id, | 747 int64_t index_id, |
746 scoped_ptr<IndexedDBKeyRange> key_range, | 748 scoped_ptr<IndexedDBKeyRange> key_range, |
747 indexed_db::CursorType cursor_type, | 749 indexed_db::CursorType cursor_type, |
748 int64 max_count, | 750 int64_t max_count, |
749 scoped_refptr<IndexedDBCallbacks> callbacks, | 751 scoped_refptr<IndexedDBCallbacks> callbacks, |
750 IndexedDBTransaction* transaction) { | 752 IndexedDBTransaction* transaction) { |
751 IDB_TRACE1("IndexedDBDatabase::GetAllOperation", "txn.id", transaction->id()); | 753 IDB_TRACE1("IndexedDBDatabase::GetAllOperation", "txn.id", transaction->id()); |
752 | 754 |
753 DCHECK_GT(max_count, 0); | 755 DCHECK_GT(max_count, 0); |
754 | 756 |
755 DCHECK(metadata_.object_stores.find(object_store_id) != | 757 DCHECK(metadata_.object_stores.find(object_store_id) != |
756 metadata_.object_stores.end()); | 758 metadata_.object_stores.end()); |
757 const IndexedDBObjectStoreMetadata& object_store_metadata = | 759 const IndexedDBObjectStoreMetadata& object_store_metadata = |
758 metadata_.object_stores[object_store_id]; | 760 metadata_.object_stores[object_store_id]; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 // hits JavaScript. | 810 // hits JavaScript. |
809 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); | 811 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); |
810 return; | 812 return; |
811 } | 813 } |
812 | 814 |
813 bool did_first_seek = false; | 815 bool did_first_seek = false; |
814 bool generated_key = object_store_metadata.auto_increment && | 816 bool generated_key = object_store_metadata.auto_increment && |
815 !object_store_metadata.key_path.IsNull(); | 817 !object_store_metadata.key_path.IsNull(); |
816 | 818 |
817 size_t response_size = kMaxIDBMessageOverhead; | 819 size_t response_size = kMaxIDBMessageOverhead; |
818 int64 num_found_items = 0; | 820 int64_t num_found_items = 0; |
819 while (num_found_items++ < max_count) { | 821 while (num_found_items++ < max_count) { |
820 bool cursor_valid; | 822 bool cursor_valid; |
821 if (did_first_seek) { | 823 if (did_first_seek) { |
822 cursor_valid = cursor->Continue(&s); | 824 cursor_valid = cursor->Continue(&s); |
823 } else { | 825 } else { |
824 cursor_valid = cursor->FirstSeek(&s); | 826 cursor_valid = cursor->FirstSeek(&s); |
825 did_first_seek = true; | 827 did_first_seek = true; |
826 } | 828 } |
827 if (!s.ok()) { | 829 if (!s.ok()) { |
828 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 830 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 // to return an array of keys - no need to create our own array of keys. | 875 // to return an array of keys - no need to create our own array of keys. |
874 callbacks->OnSuccess(IndexedDBKey(found_keys)); | 876 callbacks->OnSuccess(IndexedDBKey(found_keys)); |
875 } else { | 877 } else { |
876 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); | 878 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); |
877 } | 879 } |
878 } | 880 } |
879 | 881 |
880 static scoped_ptr<IndexedDBKey> GenerateKey( | 882 static scoped_ptr<IndexedDBKey> GenerateKey( |
881 IndexedDBBackingStore* backing_store, | 883 IndexedDBBackingStore* backing_store, |
882 IndexedDBTransaction* transaction, | 884 IndexedDBTransaction* transaction, |
883 int64 database_id, | 885 int64_t database_id, |
884 int64 object_store_id) { | 886 int64_t object_store_id) { |
885 const int64 max_generator_value = | 887 const int64_t max_generator_value = |
886 9007199254740992LL; // Maximum integer storable as ECMAScript number. | 888 9007199254740992LL; // Maximum integer storable as ECMAScript number. |
887 int64 current_number; | 889 int64_t current_number; |
888 leveldb::Status s = backing_store->GetKeyGeneratorCurrentNumber( | 890 leveldb::Status s = backing_store->GetKeyGeneratorCurrentNumber( |
889 transaction->BackingStoreTransaction(), | 891 transaction->BackingStoreTransaction(), |
890 database_id, | 892 database_id, |
891 object_store_id, | 893 object_store_id, |
892 ¤t_number); | 894 ¤t_number); |
893 if (!s.ok()) { | 895 if (!s.ok()) { |
894 LOG(ERROR) << "Failed to GetKeyGeneratorCurrentNumber"; | 896 LOG(ERROR) << "Failed to GetKeyGeneratorCurrentNumber"; |
895 return make_scoped_ptr(new IndexedDBKey()); | 897 return make_scoped_ptr(new IndexedDBKey()); |
896 } | 898 } |
897 if (current_number < 0 || current_number > max_generator_value) | 899 if (current_number < 0 || current_number > max_generator_value) |
898 return make_scoped_ptr(new IndexedDBKey()); | 900 return make_scoped_ptr(new IndexedDBKey()); |
899 | 901 |
900 return make_scoped_ptr(new IndexedDBKey(current_number, WebIDBKeyTypeNumber)); | 902 return make_scoped_ptr(new IndexedDBKey(current_number, WebIDBKeyTypeNumber)); |
901 } | 903 } |
902 | 904 |
903 static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store, | 905 static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store, |
904 IndexedDBTransaction* transaction, | 906 IndexedDBTransaction* transaction, |
905 int64 database_id, | 907 int64_t database_id, |
906 int64 object_store_id, | 908 int64_t object_store_id, |
907 const IndexedDBKey& key, | 909 const IndexedDBKey& key, |
908 bool check_current) { | 910 bool check_current) { |
909 DCHECK_EQ(WebIDBKeyTypeNumber, key.type()); | 911 DCHECK_EQ(WebIDBKeyTypeNumber, key.type()); |
910 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( | 912 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( |
911 transaction->BackingStoreTransaction(), | 913 transaction->BackingStoreTransaction(), database_id, object_store_id, |
912 database_id, | 914 static_cast<int64_t>(floor(key.number())) + 1, check_current); |
913 object_store_id, | |
914 static_cast<int64>(floor(key.number())) + 1, | |
915 check_current); | |
916 } | 915 } |
917 | 916 |
918 struct IndexedDBDatabase::PutOperationParams { | 917 struct IndexedDBDatabase::PutOperationParams { |
919 PutOperationParams() {} | 918 PutOperationParams() {} |
920 int64 object_store_id; | 919 int64_t object_store_id; |
921 IndexedDBValue value; | 920 IndexedDBValue value; |
922 ScopedVector<storage::BlobDataHandle> handles; | 921 ScopedVector<storage::BlobDataHandle> handles; |
923 scoped_ptr<IndexedDBKey> key; | 922 scoped_ptr<IndexedDBKey> key; |
924 blink::WebIDBPutMode put_mode; | 923 blink::WebIDBPutMode put_mode; |
925 scoped_refptr<IndexedDBCallbacks> callbacks; | 924 scoped_refptr<IndexedDBCallbacks> callbacks; |
926 std::vector<IndexKeys> index_keys; | 925 std::vector<IndexKeys> index_keys; |
927 | 926 |
928 private: | 927 private: |
929 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 928 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); |
930 }; | 929 }; |
931 | 930 |
932 void IndexedDBDatabase::Put(int64 transaction_id, | 931 void IndexedDBDatabase::Put(int64_t transaction_id, |
933 int64 object_store_id, | 932 int64_t object_store_id, |
934 IndexedDBValue* value, | 933 IndexedDBValue* value, |
935 ScopedVector<storage::BlobDataHandle>* handles, | 934 ScopedVector<storage::BlobDataHandle>* handles, |
936 scoped_ptr<IndexedDBKey> key, | 935 scoped_ptr<IndexedDBKey> key, |
937 blink::WebIDBPutMode put_mode, | 936 blink::WebIDBPutMode put_mode, |
938 scoped_refptr<IndexedDBCallbacks> callbacks, | 937 scoped_refptr<IndexedDBCallbacks> callbacks, |
939 const std::vector<IndexKeys>& index_keys) { | 938 const std::vector<IndexKeys>& index_keys) { |
940 IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id); | 939 IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id); |
941 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 940 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
942 if (!transaction) | 941 if (!transaction) |
943 return; | 942 return; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 return; | 1094 return; |
1096 } | 1095 } |
1097 } | 1096 } |
1098 { | 1097 { |
1099 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", | 1098 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", |
1100 transaction->id()); | 1099 transaction->id()); |
1101 params->callbacks->OnSuccess(*key); | 1100 params->callbacks->OnSuccess(*key); |
1102 } | 1101 } |
1103 } | 1102 } |
1104 | 1103 |
1105 void IndexedDBDatabase::SetIndexKeys(int64 transaction_id, | 1104 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, |
1106 int64 object_store_id, | 1105 int64_t object_store_id, |
1107 scoped_ptr<IndexedDBKey> primary_key, | 1106 scoped_ptr<IndexedDBKey> primary_key, |
1108 const std::vector<IndexKeys>& index_keys) { | 1107 const std::vector<IndexKeys>& index_keys) { |
1109 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); | 1108 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); |
1110 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1109 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1111 if (!transaction) | 1110 if (!transaction) |
1112 return; | 1111 return; |
1113 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 1112 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); |
1114 | 1113 |
1115 // TODO(alecflett): This method could be asynchronous, but we need to | 1114 // TODO(alecflett): This method could be asynchronous, but we need to |
1116 // evaluate if it's worth the extra complexity. | 1115 // evaluate if it's worth the extra complexity. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 for (size_t i = 0; i < index_writers.size(); ++i) { | 1170 for (size_t i = 0; i < index_writers.size(); ++i) { |
1172 IndexWriter* index_writer = index_writers[i]; | 1171 IndexWriter* index_writer = index_writers[i]; |
1173 index_writer->WriteIndexKeys(record_identifier, | 1172 index_writer->WriteIndexKeys(record_identifier, |
1174 backing_store_.get(), | 1173 backing_store_.get(), |
1175 transaction->BackingStoreTransaction(), | 1174 transaction->BackingStoreTransaction(), |
1176 id(), | 1175 id(), |
1177 object_store_id); | 1176 object_store_id); |
1178 } | 1177 } |
1179 } | 1178 } |
1180 | 1179 |
1181 void IndexedDBDatabase::SetIndexesReady(int64 transaction_id, | 1180 void IndexedDBDatabase::SetIndexesReady(int64_t transaction_id, |
1182 int64, | 1181 int64_t, |
1183 const std::vector<int64>& index_ids) { | 1182 const std::vector<int64_t>& index_ids) { |
1184 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1183 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1185 if (!transaction) | 1184 if (!transaction) |
1186 return; | 1185 return; |
1187 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 1186 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); |
1188 | 1187 |
1189 transaction->ScheduleTask( | 1188 transaction->ScheduleTask( |
1190 blink::WebIDBTaskTypePreemptive, | 1189 blink::WebIDBTaskTypePreemptive, |
1191 base::Bind(&IndexedDBDatabase::SetIndexesReadyOperation, | 1190 base::Bind(&IndexedDBDatabase::SetIndexesReadyOperation, |
1192 this, | 1191 this, |
1193 index_ids.size())); | 1192 index_ids.size())); |
1194 } | 1193 } |
1195 | 1194 |
1196 void IndexedDBDatabase::SetIndexesReadyOperation( | 1195 void IndexedDBDatabase::SetIndexesReadyOperation( |
1197 size_t index_count, | 1196 size_t index_count, |
1198 IndexedDBTransaction* transaction) { | 1197 IndexedDBTransaction* transaction) { |
1199 for (size_t i = 0; i < index_count; ++i) | 1198 for (size_t i = 0; i < index_count; ++i) |
1200 transaction->DidCompletePreemptiveEvent(); | 1199 transaction->DidCompletePreemptiveEvent(); |
1201 } | 1200 } |
1202 | 1201 |
1203 struct IndexedDBDatabase::OpenCursorOperationParams { | 1202 struct IndexedDBDatabase::OpenCursorOperationParams { |
1204 OpenCursorOperationParams() {} | 1203 OpenCursorOperationParams() {} |
1205 int64 object_store_id; | 1204 int64_t object_store_id; |
1206 int64 index_id; | 1205 int64_t index_id; |
1207 scoped_ptr<IndexedDBKeyRange> key_range; | 1206 scoped_ptr<IndexedDBKeyRange> key_range; |
1208 blink::WebIDBCursorDirection direction; | 1207 blink::WebIDBCursorDirection direction; |
1209 indexed_db::CursorType cursor_type; | 1208 indexed_db::CursorType cursor_type; |
1210 blink::WebIDBTaskType task_type; | 1209 blink::WebIDBTaskType task_type; |
1211 scoped_refptr<IndexedDBCallbacks> callbacks; | 1210 scoped_refptr<IndexedDBCallbacks> callbacks; |
1212 | 1211 |
1213 private: | 1212 private: |
1214 DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams); | 1213 DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams); |
1215 }; | 1214 }; |
1216 | 1215 |
1217 void IndexedDBDatabase::OpenCursor( | 1216 void IndexedDBDatabase::OpenCursor( |
1218 int64 transaction_id, | 1217 int64_t transaction_id, |
1219 int64 object_store_id, | 1218 int64_t object_store_id, |
1220 int64 index_id, | 1219 int64_t index_id, |
1221 scoped_ptr<IndexedDBKeyRange> key_range, | 1220 scoped_ptr<IndexedDBKeyRange> key_range, |
1222 blink::WebIDBCursorDirection direction, | 1221 blink::WebIDBCursorDirection direction, |
1223 bool key_only, | 1222 bool key_only, |
1224 blink::WebIDBTaskType task_type, | 1223 blink::WebIDBTaskType task_type, |
1225 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1224 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1226 IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id); | 1225 IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id); |
1227 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1226 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1228 if (!transaction) | 1227 if (!transaction) |
1229 return; | 1228 return; |
1230 | 1229 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 | 1318 |
1320 scoped_refptr<IndexedDBCursor> cursor = | 1319 scoped_refptr<IndexedDBCursor> cursor = |
1321 new IndexedDBCursor(backing_store_cursor.Pass(), | 1320 new IndexedDBCursor(backing_store_cursor.Pass(), |
1322 params->cursor_type, | 1321 params->cursor_type, |
1323 params->task_type, | 1322 params->task_type, |
1324 transaction); | 1323 transaction); |
1325 params->callbacks->OnSuccess( | 1324 params->callbacks->OnSuccess( |
1326 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); | 1325 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); |
1327 } | 1326 } |
1328 | 1327 |
1329 void IndexedDBDatabase::Count(int64 transaction_id, | 1328 void IndexedDBDatabase::Count(int64_t transaction_id, |
1330 int64 object_store_id, | 1329 int64_t object_store_id, |
1331 int64 index_id, | 1330 int64_t index_id, |
1332 scoped_ptr<IndexedDBKeyRange> key_range, | 1331 scoped_ptr<IndexedDBKeyRange> key_range, |
1333 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1332 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1334 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id); | 1333 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id); |
1335 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1334 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1336 if (!transaction) | 1335 if (!transaction) |
1337 return; | 1336 return; |
1338 | 1337 |
1339 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 1338 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) |
1340 return; | 1339 return; |
1341 | 1340 |
1342 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, | 1341 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, |
1343 this, | 1342 this, |
1344 object_store_id, | 1343 object_store_id, |
1345 index_id, | 1344 index_id, |
1346 base::Passed(&key_range), | 1345 base::Passed(&key_range), |
1347 callbacks)); | 1346 callbacks)); |
1348 } | 1347 } |
1349 | 1348 |
1350 void IndexedDBDatabase::CountOperation( | 1349 void IndexedDBDatabase::CountOperation( |
1351 int64 object_store_id, | 1350 int64_t object_store_id, |
1352 int64 index_id, | 1351 int64_t index_id, |
1353 scoped_ptr<IndexedDBKeyRange> key_range, | 1352 scoped_ptr<IndexedDBKeyRange> key_range, |
1354 scoped_refptr<IndexedDBCallbacks> callbacks, | 1353 scoped_refptr<IndexedDBCallbacks> callbacks, |
1355 IndexedDBTransaction* transaction) { | 1354 IndexedDBTransaction* transaction) { |
1356 IDB_TRACE1("IndexedDBDatabase::CountOperation", "txn.id", transaction->id()); | 1355 IDB_TRACE1("IndexedDBDatabase::CountOperation", "txn.id", transaction->id()); |
1357 uint32 count = 0; | 1356 uint32_t count = 0; |
1358 scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor; | 1357 scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor; |
1359 | 1358 |
1360 leveldb::Status s; | 1359 leveldb::Status s; |
1361 if (index_id == IndexedDBIndexMetadata::kInvalidId) { | 1360 if (index_id == IndexedDBIndexMetadata::kInvalidId) { |
1362 backing_store_cursor = backing_store_->OpenObjectStoreKeyCursor( | 1361 backing_store_cursor = backing_store_->OpenObjectStoreKeyCursor( |
1363 transaction->BackingStoreTransaction(), | 1362 transaction->BackingStoreTransaction(), |
1364 id(), | 1363 id(), |
1365 object_store_id, | 1364 object_store_id, |
1366 *key_range, | 1365 *key_range, |
1367 blink::WebIDBCursorDirectionNext, | 1366 blink::WebIDBCursorDirectionNext, |
(...skipping 25 matching lines...) Expand all Loading... |
1393 do { | 1392 do { |
1394 ++count; | 1393 ++count; |
1395 } while (backing_store_cursor->Continue(&s)); | 1394 } while (backing_store_cursor->Continue(&s)); |
1396 | 1395 |
1397 // TODO(cmumford): Check for database corruption. | 1396 // TODO(cmumford): Check for database corruption. |
1398 | 1397 |
1399 callbacks->OnSuccess(count); | 1398 callbacks->OnSuccess(count); |
1400 } | 1399 } |
1401 | 1400 |
1402 void IndexedDBDatabase::DeleteRange( | 1401 void IndexedDBDatabase::DeleteRange( |
1403 int64 transaction_id, | 1402 int64_t transaction_id, |
1404 int64 object_store_id, | 1403 int64_t object_store_id, |
1405 scoped_ptr<IndexedDBKeyRange> key_range, | 1404 scoped_ptr<IndexedDBKeyRange> key_range, |
1406 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1405 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1407 IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction_id); | 1406 IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction_id); |
1408 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1407 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1409 if (!transaction) | 1408 if (!transaction) |
1410 return; | 1409 return; |
1411 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1410 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
1412 | 1411 |
1413 if (!ValidateObjectStoreId(object_store_id)) | 1412 if (!ValidateObjectStoreId(object_store_id)) |
1414 return; | 1413 return; |
1415 | 1414 |
1416 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation, | 1415 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation, |
1417 this, | 1416 this, |
1418 object_store_id, | 1417 object_store_id, |
1419 base::Passed(&key_range), | 1418 base::Passed(&key_range), |
1420 callbacks)); | 1419 callbacks)); |
1421 } | 1420 } |
1422 | 1421 |
1423 void IndexedDBDatabase::DeleteRangeOperation( | 1422 void IndexedDBDatabase::DeleteRangeOperation( |
1424 int64 object_store_id, | 1423 int64_t object_store_id, |
1425 scoped_ptr<IndexedDBKeyRange> key_range, | 1424 scoped_ptr<IndexedDBKeyRange> key_range, |
1426 scoped_refptr<IndexedDBCallbacks> callbacks, | 1425 scoped_refptr<IndexedDBCallbacks> callbacks, |
1427 IndexedDBTransaction* transaction) { | 1426 IndexedDBTransaction* transaction) { |
1428 IDB_TRACE1( | 1427 IDB_TRACE1( |
1429 "IndexedDBDatabase::DeleteRangeOperation", "txn.id", transaction->id()); | 1428 "IndexedDBDatabase::DeleteRangeOperation", "txn.id", transaction->id()); |
1430 leveldb::Status s = | 1429 leveldb::Status s = |
1431 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), | 1430 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), |
1432 id(), | 1431 id(), |
1433 object_store_id, | 1432 object_store_id, |
1434 *key_range); | 1433 *key_range); |
1435 if (!s.ok()) { | 1434 if (!s.ok()) { |
1436 base::string16 error_string = | 1435 base::string16 error_string = |
1437 ASCIIToUTF16("Internal error deleting data in range"); | 1436 ASCIIToUTF16("Internal error deleting data in range"); |
1438 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1437 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1439 error_string); | 1438 error_string); |
1440 transaction->Abort(error); | 1439 transaction->Abort(error); |
1441 if (s.IsCorruption()) { | 1440 if (s.IsCorruption()) { |
1442 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1441 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), |
1443 error); | 1442 error); |
1444 } | 1443 } |
1445 return; | 1444 return; |
1446 } | 1445 } |
1447 callbacks->OnSuccess(); | 1446 callbacks->OnSuccess(); |
1448 } | 1447 } |
1449 | 1448 |
1450 void IndexedDBDatabase::Clear(int64 transaction_id, | 1449 void IndexedDBDatabase::Clear(int64_t transaction_id, |
1451 int64 object_store_id, | 1450 int64_t object_store_id, |
1452 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1451 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1453 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); | 1452 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); |
1454 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1453 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1455 if (!transaction) | 1454 if (!transaction) |
1456 return; | 1455 return; |
1457 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1456 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
1458 | 1457 |
1459 if (!ValidateObjectStoreId(object_store_id)) | 1458 if (!ValidateObjectStoreId(object_store_id)) |
1460 return; | 1459 return; |
1461 | 1460 |
1462 transaction->ScheduleTask(base::Bind( | 1461 transaction->ScheduleTask(base::Bind( |
1463 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); | 1462 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); |
1464 } | 1463 } |
1465 | 1464 |
1466 void IndexedDBDatabase::ClearOperation( | 1465 void IndexedDBDatabase::ClearOperation( |
1467 int64 object_store_id, | 1466 int64_t object_store_id, |
1468 scoped_refptr<IndexedDBCallbacks> callbacks, | 1467 scoped_refptr<IndexedDBCallbacks> callbacks, |
1469 IndexedDBTransaction* transaction) { | 1468 IndexedDBTransaction* transaction) { |
1470 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); | 1469 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); |
1471 leveldb::Status s = backing_store_->ClearObjectStore( | 1470 leveldb::Status s = backing_store_->ClearObjectStore( |
1472 transaction->BackingStoreTransaction(), id(), object_store_id); | 1471 transaction->BackingStoreTransaction(), id(), object_store_id); |
1473 if (!s.ok()) { | 1472 if (!s.ok()) { |
1474 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1473 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1475 "Internal error clearing object store"); | 1474 "Internal error clearing object store"); |
1476 callbacks->OnError(error); | 1475 callbacks->OnError(error); |
1477 if (s.IsCorruption()) { | 1476 if (s.IsCorruption()) { |
1478 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1477 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), |
1479 error); | 1478 error); |
1480 } | 1479 } |
1481 return; | 1480 return; |
1482 } | 1481 } |
1483 callbacks->OnSuccess(); | 1482 callbacks->OnSuccess(); |
1484 } | 1483 } |
1485 | 1484 |
1486 void IndexedDBDatabase::DeleteObjectStoreOperation( | 1485 void IndexedDBDatabase::DeleteObjectStoreOperation( |
1487 int64 object_store_id, | 1486 int64_t object_store_id, |
1488 IndexedDBTransaction* transaction) { | 1487 IndexedDBTransaction* transaction) { |
1489 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", | 1488 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", |
1490 "txn.id", | 1489 "txn.id", |
1491 transaction->id()); | 1490 transaction->id()); |
1492 | 1491 |
1493 const IndexedDBObjectStoreMetadata object_store_metadata = | 1492 const IndexedDBObjectStoreMetadata object_store_metadata = |
1494 metadata_.object_stores[object_store_id]; | 1493 metadata_.object_stores[object_store_id]; |
1495 leveldb::Status s = | 1494 leveldb::Status s = |
1496 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(), | 1495 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(), |
1497 transaction->database()->id(), | 1496 transaction->database()->id(), |
(...skipping 12 matching lines...) Expand all Loading... |
1510 } | 1509 } |
1511 | 1510 |
1512 RemoveObjectStore(object_store_id); | 1511 RemoveObjectStore(object_store_id); |
1513 transaction->ScheduleAbortTask( | 1512 transaction->ScheduleAbortTask( |
1514 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, | 1513 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, |
1515 this, | 1514 this, |
1516 object_store_metadata)); | 1515 object_store_metadata)); |
1517 } | 1516 } |
1518 | 1517 |
1519 void IndexedDBDatabase::VersionChangeOperation( | 1518 void IndexedDBDatabase::VersionChangeOperation( |
1520 int64 version, | 1519 int64_t version, |
1521 scoped_refptr<IndexedDBCallbacks> callbacks, | 1520 scoped_refptr<IndexedDBCallbacks> callbacks, |
1522 scoped_ptr<IndexedDBConnection> connection, | 1521 scoped_ptr<IndexedDBConnection> connection, |
1523 IndexedDBTransaction* transaction) { | 1522 IndexedDBTransaction* transaction) { |
1524 IDB_TRACE1( | 1523 IDB_TRACE1( |
1525 "IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id()); | 1524 "IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id()); |
1526 int64 old_version = metadata_.int_version; | 1525 int64_t old_version = metadata_.int_version; |
1527 DCHECK_GT(version, old_version); | 1526 DCHECK_GT(version, old_version); |
1528 | 1527 |
1529 if (!backing_store_->UpdateIDBDatabaseIntVersion( | 1528 if (!backing_store_->UpdateIDBDatabaseIntVersion( |
1530 transaction->BackingStoreTransaction(), id(), version)) { | 1529 transaction->BackingStoreTransaction(), id(), version)) { |
1531 IndexedDBDatabaseError error( | 1530 IndexedDBDatabaseError error( |
1532 blink::WebIDBDatabaseExceptionUnknownError, | 1531 blink::WebIDBDatabaseExceptionUnknownError, |
1533 ASCIIToUTF16( | 1532 ASCIIToUTF16( |
1534 "Internal error writing data to stable storage when " | 1533 "Internal error writing data to stable storage when " |
1535 "updating version.")); | 1534 "updating version.")); |
1536 callbacks->OnError(error); | 1535 callbacks->OnError(error); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 PendingOpenCallList pending_open_calls; | 1652 PendingOpenCallList pending_open_calls; |
1654 pending_open_calls_.swap(pending_open_calls); | 1653 pending_open_calls_.swap(pending_open_calls); |
1655 while (!pending_open_calls.empty()) { | 1654 while (!pending_open_calls.empty()) { |
1656 OpenConnection(pending_open_calls.front()); | 1655 OpenConnection(pending_open_calls.front()); |
1657 pending_open_calls.pop_front(); | 1656 pending_open_calls.pop_front(); |
1658 } | 1657 } |
1659 } | 1658 } |
1660 } | 1659 } |
1661 | 1660 |
1662 void IndexedDBDatabase::CreateTransaction( | 1661 void IndexedDBDatabase::CreateTransaction( |
1663 int64 transaction_id, | 1662 int64_t transaction_id, |
1664 IndexedDBConnection* connection, | 1663 IndexedDBConnection* connection, |
1665 const std::vector<int64>& object_store_ids, | 1664 const std::vector<int64_t>& object_store_ids, |
1666 blink::WebIDBTransactionMode mode) { | 1665 blink::WebIDBTransactionMode mode) { |
1667 IDB_TRACE1("IndexedDBDatabase::CreateTransaction", "txn.id", transaction_id); | 1666 IDB_TRACE1("IndexedDBDatabase::CreateTransaction", "txn.id", transaction_id); |
1668 DCHECK(connections_.count(connection)); | 1667 DCHECK(connections_.count(connection)); |
1669 DCHECK(transactions_.find(transaction_id) == transactions_.end()); | 1668 DCHECK(transactions_.find(transaction_id) == transactions_.end()); |
1670 if (transactions_.find(transaction_id) != transactions_.end()) | 1669 if (transactions_.find(transaction_id) != transactions_.end()) |
1671 return; | 1670 return; |
1672 | 1671 |
1673 UMA_HISTOGRAM_COUNTS_1000( | 1672 UMA_HISTOGRAM_COUNTS_1000( |
1674 "WebCore.IndexedDB.Database.OutstandingTransactionCount", | 1673 "WebCore.IndexedDB.Database.OutstandingTransactionCount", |
1675 transactions_.size()); | 1674 transactions_.size()); |
1676 | 1675 |
1677 // Throttle transaction creation so that a renderer in a tight loop can't | 1676 // Throttle transaction creation so that a renderer in a tight loop can't |
1678 // cause browser memory to grow unbounded by creating transactions faster | 1677 // cause browser memory to grow unbounded by creating transactions faster |
1679 // than they can be processed. | 1678 // than they can be processed. |
1680 const size_t kMaxTransactionCount = 256; | 1679 const size_t kMaxTransactionCount = 256; |
1681 if (transactions_.size() >= kMaxTransactionCount) { | 1680 if (transactions_.size() >= kMaxTransactionCount) { |
1682 connection->callbacks()->OnAbort( | 1681 connection->callbacks()->OnAbort( |
1683 transaction_id, IndexedDBDatabaseError( | 1682 transaction_id, IndexedDBDatabaseError( |
1684 blink::WebIDBDatabaseExceptionUnknownError, | 1683 blink::WebIDBDatabaseExceptionUnknownError, |
1685 "Internal error: Too many transactions queued.")); | 1684 "Internal error: Too many transactions queued.")); |
1686 return; | 1685 return; |
1687 } | 1686 } |
1688 | 1687 |
1689 // The transaction will add itself to this database's coordinator, which | 1688 // The transaction will add itself to this database's coordinator, which |
1690 // manages the lifetime of the object. | 1689 // manages the lifetime of the object. |
1691 TransactionCreated(IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( | 1690 TransactionCreated(IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( |
1692 transaction_id, connection->callbacks(), | 1691 transaction_id, connection->callbacks(), |
1693 std::set<int64>(object_store_ids.begin(), object_store_ids.end()), mode, | 1692 std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), mode, |
1694 this, new IndexedDBBackingStore::Transaction(backing_store_.get()))); | 1693 this, new IndexedDBBackingStore::Transaction(backing_store_.get()))); |
1695 } | 1694 } |
1696 | 1695 |
1697 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { | 1696 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { |
1698 transactions_[transaction->id()] = transaction; | 1697 transactions_[transaction->id()] = transaction; |
1699 } | 1698 } |
1700 | 1699 |
1701 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { | 1700 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { |
1702 return !pending_delete_calls_.empty() || | 1701 return !pending_delete_calls_.empty() || |
1703 transaction_coordinator_.IsRunningVersionChangeTransaction() || | 1702 transaction_coordinator_.IsRunningVersionChangeTransaction() || |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 // TODO(jsbell): DCHECK that not in unit tests. | 1752 // TODO(jsbell): DCHECK that not in unit tests. |
1754 DCHECK(is_new_database); | 1753 DCHECK(is_new_database); |
1755 connection.callbacks->OnSuccess( | 1754 connection.callbacks->OnSuccess( |
1756 CreateConnection(connection.database_callbacks, | 1755 CreateConnection(connection.database_callbacks, |
1757 connection.child_process_id), | 1756 connection.child_process_id), |
1758 this->metadata()); | 1757 this->metadata()); |
1759 return; | 1758 return; |
1760 } | 1759 } |
1761 | 1760 |
1762 // We may need to change the version. | 1761 // We may need to change the version. |
1763 int64 local_version = connection.version; | 1762 int64_t local_version = connection.version; |
1764 if (local_version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { | 1763 if (local_version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { |
1765 if (!is_new_database) { | 1764 if (!is_new_database) { |
1766 connection.callbacks->OnSuccess( | 1765 connection.callbacks->OnSuccess( |
1767 CreateConnection(connection.database_callbacks, | 1766 CreateConnection(connection.database_callbacks, |
1768 connection.child_process_id), | 1767 connection.child_process_id), |
1769 this->metadata()); | 1768 this->metadata()); |
1770 return; | 1769 return; |
1771 } | 1770 } |
1772 // Spec says: If no version is specified and no database exists, set | 1771 // Spec says: If no version is specified and no database exists, set |
1773 // database version to 1. | 1772 // database version to 1. |
(...skipping 20 matching lines...) Expand all Loading... |
1794 DCHECK_EQ(local_version, metadata_.int_version); | 1793 DCHECK_EQ(local_version, metadata_.int_version); |
1795 connection.callbacks->OnSuccess( | 1794 connection.callbacks->OnSuccess( |
1796 CreateConnection(connection.database_callbacks, | 1795 CreateConnection(connection.database_callbacks, |
1797 connection.child_process_id), | 1796 connection.child_process_id), |
1798 this->metadata()); | 1797 this->metadata()); |
1799 } | 1798 } |
1800 | 1799 |
1801 void IndexedDBDatabase::RunVersionChangeTransaction( | 1800 void IndexedDBDatabase::RunVersionChangeTransaction( |
1802 scoped_refptr<IndexedDBCallbacks> callbacks, | 1801 scoped_refptr<IndexedDBCallbacks> callbacks, |
1803 scoped_ptr<IndexedDBConnection> connection, | 1802 scoped_ptr<IndexedDBConnection> connection, |
1804 int64 transaction_id, | 1803 int64_t transaction_id, |
1805 int64 requested_version) { | 1804 int64_t requested_version) { |
1806 DCHECK(callbacks.get()); | 1805 DCHECK(callbacks.get()); |
1807 DCHECK(connections_.count(connection.get())); | 1806 DCHECK(connections_.count(connection.get())); |
1808 if (ConnectionCount() > 1) { | 1807 if (ConnectionCount() > 1) { |
1809 DCHECK_NE(blink::WebIDBDataLossTotal, callbacks->data_loss()); | 1808 DCHECK_NE(blink::WebIDBDataLossTotal, callbacks->data_loss()); |
1810 // Front end ensures the event is not fired at connections that have | 1809 // Front end ensures the event is not fired at connections that have |
1811 // close_pending set. | 1810 // close_pending set. |
1812 for (const auto* iter : connections_) { | 1811 for (const auto* iter : connections_) { |
1813 if (iter != connection.get()) { | 1812 if (iter != connection.get()) { |
1814 iter->callbacks()->OnVersionChange(metadata_.int_version, | 1813 iter->callbacks()->OnVersionChange(metadata_.int_version, |
1815 requested_version); | 1814 requested_version); |
1816 } | 1815 } |
1817 } | 1816 } |
1818 // OnBlocked will be fired at the request when one of the other | 1817 // OnBlocked will be fired at the request when one of the other |
1819 // connections acks that the OnVersionChange was ignored. | 1818 // connections acks that the OnVersionChange was ignored. |
1820 | 1819 |
1821 DCHECK(!pending_run_version_change_transaction_call_); | 1820 DCHECK(!pending_run_version_change_transaction_call_); |
1822 pending_run_version_change_transaction_call_.reset(new PendingUpgradeCall( | 1821 pending_run_version_change_transaction_call_.reset(new PendingUpgradeCall( |
1823 callbacks, connection.Pass(), transaction_id, requested_version)); | 1822 callbacks, connection.Pass(), transaction_id, requested_version)); |
1824 return; | 1823 return; |
1825 } | 1824 } |
1826 RunVersionChangeTransactionFinal( | 1825 RunVersionChangeTransactionFinal( |
1827 callbacks, connection.Pass(), transaction_id, requested_version); | 1826 callbacks, connection.Pass(), transaction_id, requested_version); |
1828 } | 1827 } |
1829 | 1828 |
1830 void IndexedDBDatabase::RunVersionChangeTransactionFinal( | 1829 void IndexedDBDatabase::RunVersionChangeTransactionFinal( |
1831 scoped_refptr<IndexedDBCallbacks> callbacks, | 1830 scoped_refptr<IndexedDBCallbacks> callbacks, |
1832 scoped_ptr<IndexedDBConnection> connection, | 1831 scoped_ptr<IndexedDBConnection> connection, |
1833 int64 transaction_id, | 1832 int64_t transaction_id, |
1834 int64 requested_version) { | 1833 int64_t requested_version) { |
1835 | 1834 std::vector<int64_t> object_store_ids; |
1836 std::vector<int64> object_store_ids; | |
1837 CreateTransaction(transaction_id, | 1835 CreateTransaction(transaction_id, |
1838 connection.get(), | 1836 connection.get(), |
1839 object_store_ids, | 1837 object_store_ids, |
1840 blink::WebIDBTransactionModeVersionChange); | 1838 blink::WebIDBTransactionModeVersionChange); |
1841 | 1839 |
1842 transactions_[transaction_id]->ScheduleTask( | 1840 transactions_[transaction_id]->ScheduleTask( |
1843 base::Bind(&IndexedDBDatabase::VersionChangeOperation, | 1841 base::Bind(&IndexedDBDatabase::VersionChangeOperation, |
1844 this, | 1842 this, |
1845 requested_version, | 1843 requested_version, |
1846 callbacks, | 1844 callbacks, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1878 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1881 "Internal error deleting database."); | 1879 "Internal error deleting database."); |
1882 callbacks->OnError(error); | 1880 callbacks->OnError(error); |
1883 if (s.IsCorruption()) { | 1881 if (s.IsCorruption()) { |
1884 GURL origin_url = backing_store_->origin_url(); | 1882 GURL origin_url = backing_store_->origin_url(); |
1885 backing_store_ = NULL; | 1883 backing_store_ = NULL; |
1886 factory_->HandleBackingStoreCorruption(origin_url, error); | 1884 factory_->HandleBackingStoreCorruption(origin_url, error); |
1887 } | 1885 } |
1888 return; | 1886 return; |
1889 } | 1887 } |
1890 int64 old_version = metadata_.int_version; | 1888 int64_t old_version = metadata_.int_version; |
1891 metadata_.version = kNoStringVersion; | 1889 metadata_.version = kNoStringVersion; |
1892 metadata_.id = kInvalidId; | 1890 metadata_.id = kInvalidId; |
1893 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; | 1891 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; |
1894 metadata_.object_stores.clear(); | 1892 metadata_.object_stores.clear(); |
1895 callbacks->OnSuccess(old_version); | 1893 callbacks->OnSuccess(old_version); |
1896 factory_->DatabaseDeleted(identifier_); | 1894 factory_->DatabaseDeleted(identifier_); |
1897 } | 1895 } |
1898 | 1896 |
1899 void IndexedDBDatabase::ForceClose() { | 1897 void IndexedDBDatabase::ForceClose() { |
1900 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. | 1898 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 DCHECK(transactions_.empty()); | 1954 DCHECK(transactions_.empty()); |
1957 | 1955 |
1958 const GURL origin_url = backing_store_->origin_url(); | 1956 const GURL origin_url = backing_store_->origin_url(); |
1959 backing_store_ = NULL; | 1957 backing_store_ = NULL; |
1960 | 1958 |
1961 factory_->ReleaseDatabase(identifier_, forced); | 1959 factory_->ReleaseDatabase(identifier_, forced); |
1962 } | 1960 } |
1963 } | 1961 } |
1964 | 1962 |
1965 void IndexedDBDatabase::CreateObjectStoreAbortOperation( | 1963 void IndexedDBDatabase::CreateObjectStoreAbortOperation( |
1966 int64 object_store_id, | 1964 int64_t object_store_id, |
1967 IndexedDBTransaction* transaction) { | 1965 IndexedDBTransaction* transaction) { |
1968 DCHECK(!transaction); | 1966 DCHECK(!transaction); |
1969 IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); | 1967 IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); |
1970 RemoveObjectStore(object_store_id); | 1968 RemoveObjectStore(object_store_id); |
1971 } | 1969 } |
1972 | 1970 |
1973 void IndexedDBDatabase::DeleteObjectStoreAbortOperation( | 1971 void IndexedDBDatabase::DeleteObjectStoreAbortOperation( |
1974 const IndexedDBObjectStoreMetadata& object_store_metadata, | 1972 const IndexedDBObjectStoreMetadata& object_store_metadata, |
1975 IndexedDBTransaction* transaction) { | 1973 IndexedDBTransaction* transaction) { |
1976 DCHECK(!transaction); | 1974 DCHECK(!transaction); |
1977 IDB_TRACE("IndexedDBDatabase::DeleteObjectStoreAbortOperation"); | 1975 IDB_TRACE("IndexedDBDatabase::DeleteObjectStoreAbortOperation"); |
1978 AddObjectStore(object_store_metadata, | 1976 AddObjectStore(object_store_metadata, |
1979 IndexedDBObjectStoreMetadata::kInvalidId); | 1977 IndexedDBObjectStoreMetadata::kInvalidId); |
1980 } | 1978 } |
1981 | 1979 |
1982 void IndexedDBDatabase::VersionChangeAbortOperation( | 1980 void IndexedDBDatabase::VersionChangeAbortOperation( |
1983 const base::string16& previous_version, | 1981 const base::string16& previous_version, |
1984 int64 previous_int_version, | 1982 int64_t previous_int_version, |
1985 IndexedDBTransaction* transaction) { | 1983 IndexedDBTransaction* transaction) { |
1986 DCHECK(!transaction); | 1984 DCHECK(!transaction); |
1987 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1985 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
1988 metadata_.version = previous_version; | 1986 metadata_.version = previous_version; |
1989 metadata_.int_version = previous_int_version; | 1987 metadata_.int_version = previous_int_version; |
1990 } | 1988 } |
1991 | 1989 |
1992 } // namespace content | 1990 } // namespace content |
OLD | NEW |