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

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

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (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 #include <utility>
10 11
11 #include "base/auto_reset.h" 12 #include "base/auto_reset.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
16 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the 74 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the
74 // in-progress connection. 75 // in-progress connection.
75 class IndexedDBDatabase::PendingUpgradeCall { 76 class IndexedDBDatabase::PendingUpgradeCall {
76 public: 77 public:
77 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, 78 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks,
78 scoped_ptr<IndexedDBConnection> connection, 79 scoped_ptr<IndexedDBConnection> connection,
79 int64_t transaction_id, 80 int64_t transaction_id,
80 int64_t version) 81 int64_t version)
81 : callbacks_(callbacks), 82 : callbacks_(callbacks),
82 connection_(connection.Pass()), 83 connection_(std::move(connection)),
83 version_(version), 84 version_(version),
84 transaction_id_(transaction_id) {} 85 transaction_id_(transaction_id) {}
85 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } 86 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; }
86 // Takes ownership of the connection object. 87 // Takes ownership of the connection object.
87 scoped_ptr<IndexedDBConnection> ReleaseConnection() WARN_UNUSED_RESULT { 88 scoped_ptr<IndexedDBConnection> ReleaseConnection() WARN_UNUSED_RESULT {
88 return connection_.Pass(); 89 return std::move(connection_);
89 } 90 }
90 int64_t version() const { return version_; } 91 int64_t version() const { return version_; }
91 int64_t transaction_id() const { return transaction_id_; } 92 int64_t transaction_id() const { return transaction_id_; }
92 93
93 private: 94 private:
94 scoped_refptr<IndexedDBCallbacks> callbacks_; 95 scoped_refptr<IndexedDBCallbacks> callbacks_;
95 scoped_ptr<IndexedDBConnection> connection_; 96 scoped_ptr<IndexedDBConnection> connection_;
96 int64_t version_; 97 int64_t version_;
97 const int64_t transaction_id_; 98 const int64_t transaction_id_;
98 }; 99 };
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 return kMaxIDBMessageSizeInBytes; 234 return kMaxIDBMessageSizeInBytes;
234 } 235 }
235 236
236 scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( 237 scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection(
237 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 238 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
238 int child_process_id) { 239 int child_process_id) {
239 scoped_ptr<IndexedDBConnection> connection( 240 scoped_ptr<IndexedDBConnection> connection(
240 new IndexedDBConnection(this, database_callbacks)); 241 new IndexedDBConnection(this, database_callbacks));
241 connections_.insert(connection.get()); 242 connections_.insert(connection.get());
242 backing_store_->GrantChildProcessPermissions(child_process_id); 243 backing_store_->GrantChildProcessPermissions(child_process_id);
243 return connection.Pass(); 244 return connection;
244 } 245 }
245 246
246 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( 247 IndexedDBTransaction* IndexedDBDatabase::GetTransaction(
247 int64_t transaction_id) const { 248 int64_t transaction_id) const {
248 TransactionMap::const_iterator trans_iterator = 249 TransactionMap::const_iterator trans_iterator =
249 transactions_.find(transaction_id); 250 transactions_.find(transaction_id);
250 if (trans_iterator == transactions_.end()) 251 if (trans_iterator == transactions_.end())
251 return NULL; 252 return NULL;
252 return trans_iterator->second; 253 return trans_iterator->second;
253 } 254 }
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 945
945 if (!ValidateObjectStoreId(object_store_id)) 946 if (!ValidateObjectStoreId(object_store_id))
946 return; 947 return;
947 948
948 DCHECK(key); 949 DCHECK(key);
949 DCHECK(value); 950 DCHECK(value);
950 scoped_ptr<PutOperationParams> params(new PutOperationParams()); 951 scoped_ptr<PutOperationParams> params(new PutOperationParams());
951 params->object_store_id = object_store_id; 952 params->object_store_id = object_store_id;
952 params->value.swap(*value); 953 params->value.swap(*value);
953 params->handles.swap(*handles); 954 params->handles.swap(*handles);
954 params->key = key.Pass(); 955 params->key = std::move(key);
955 params->put_mode = put_mode; 956 params->put_mode = put_mode;
956 params->callbacks = callbacks; 957 params->callbacks = callbacks;
957 params->index_keys = index_keys; 958 params->index_keys = index_keys;
958 transaction->ScheduleTask(base::Bind( 959 transaction->ScheduleTask(base::Bind(
959 &IndexedDBDatabase::PutOperation, this, base::Passed(&params))); 960 &IndexedDBDatabase::PutOperation, this, base::Passed(&params)));
960 } 961 }
961 962
962 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, 963 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params,
963 IndexedDBTransaction* transaction) { 964 IndexedDBTransaction* transaction) {
964 IDB_TRACE1("IndexedDBDatabase::PutOperation", "txn.id", transaction->id()); 965 IDB_TRACE1("IndexedDBDatabase::PutOperation", "txn.id", transaction->id());
(...skipping 11 matching lines...) Expand all
976 object_store.auto_increment && !params->key->IsValid()) { 977 object_store.auto_increment && !params->key->IsValid()) {
977 scoped_ptr<IndexedDBKey> auto_inc_key = GenerateKey( 978 scoped_ptr<IndexedDBKey> auto_inc_key = GenerateKey(
978 backing_store_.get(), transaction, id(), params->object_store_id); 979 backing_store_.get(), transaction, id(), params->object_store_id);
979 key_was_generated = true; 980 key_was_generated = true;
980 if (!auto_inc_key->IsValid()) { 981 if (!auto_inc_key->IsValid()) {
981 params->callbacks->OnError( 982 params->callbacks->OnError(
982 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError, 983 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError,
983 "Maximum key generator value reached.")); 984 "Maximum key generator value reached."));
984 return; 985 return;
985 } 986 }
986 key = auto_inc_key.Pass(); 987 key = std::move(auto_inc_key);
987 } else { 988 } else {
988 key = params->key.Pass(); 989 key = std::move(params->key);
989 } 990 }
990 991
991 DCHECK(key->IsValid()); 992 DCHECK(key->IsValid());
992 993
993 IndexedDBBackingStore::RecordIdentifier record_identifier; 994 IndexedDBBackingStore::RecordIdentifier record_identifier;
994 if (params->put_mode == blink::WebIDBPutModeAddOnly) { 995 if (params->put_mode == blink::WebIDBPutModeAddOnly) {
995 bool found = false; 996 bool found = false;
996 leveldb::Status s = backing_store_->KeyExistsInObjectStore( 997 leveldb::Status s = backing_store_->KeyExistsInObjectStore(
997 transaction->BackingStoreTransaction(), 998 transaction->BackingStoreTransaction(),
998 id(), 999 id(),
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1227 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1227 if (!transaction) 1228 if (!transaction)
1228 return; 1229 return;
1229 1230
1230 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) 1231 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id))
1231 return; 1232 return;
1232 1233
1233 scoped_ptr<OpenCursorOperationParams> params(new OpenCursorOperationParams()); 1234 scoped_ptr<OpenCursorOperationParams> params(new OpenCursorOperationParams());
1234 params->object_store_id = object_store_id; 1235 params->object_store_id = object_store_id;
1235 params->index_id = index_id; 1236 params->index_id = index_id;
1236 params->key_range = key_range.Pass(); 1237 params->key_range = std::move(key_range);
1237 params->direction = direction; 1238 params->direction = direction;
1238 params->cursor_type = 1239 params->cursor_type =
1239 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE; 1240 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE;
1240 params->task_type = task_type; 1241 params->task_type = task_type;
1241 params->callbacks = callbacks; 1242 params->callbacks = callbacks;
1242 transaction->ScheduleTask(base::Bind( 1243 transaction->ScheduleTask(base::Bind(
1243 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(&params))); 1244 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(&params)));
1244 } 1245 }
1245 1246
1246 void IndexedDBDatabase::OpenCursorOperation( 1247 void IndexedDBDatabase::OpenCursorOperation(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 } 1311 }
1311 } 1312 }
1312 1313
1313 if (!backing_store_cursor) { 1314 if (!backing_store_cursor) {
1314 // Why is Success being called? 1315 // Why is Success being called?
1315 params->callbacks->OnSuccess(nullptr); 1316 params->callbacks->OnSuccess(nullptr);
1316 return; 1317 return;
1317 } 1318 }
1318 1319
1319 scoped_refptr<IndexedDBCursor> cursor = 1320 scoped_refptr<IndexedDBCursor> cursor =
1320 new IndexedDBCursor(backing_store_cursor.Pass(), 1321 new IndexedDBCursor(std::move(backing_store_cursor), params->cursor_type,
1321 params->cursor_type, 1322 params->task_type, transaction);
1322 params->task_type,
1323 transaction);
1324 params->callbacks->OnSuccess( 1323 params->callbacks->OnSuccess(
1325 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); 1324 cursor, cursor->key(), cursor->primary_key(), cursor->Value());
1326 } 1325 }
1327 1326
1328 void IndexedDBDatabase::Count(int64_t transaction_id, 1327 void IndexedDBDatabase::Count(int64_t transaction_id,
1329 int64_t object_store_id, 1328 int64_t object_store_id,
1330 int64_t index_id, 1329 int64_t index_id,
1331 scoped_ptr<IndexedDBKeyRange> key_range, 1330 scoped_ptr<IndexedDBKeyRange> key_range,
1332 scoped_refptr<IndexedDBCallbacks> callbacks) { 1331 scoped_refptr<IndexedDBCallbacks> callbacks) {
1333 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id); 1332 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation, 1540 base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation,
1542 this, 1541 this,
1543 metadata_.version, 1542 metadata_.version,
1544 metadata_.int_version)); 1543 metadata_.int_version));
1545 metadata_.int_version = version; 1544 metadata_.int_version = version;
1546 metadata_.version = kNoStringVersion; 1545 metadata_.version = kNoStringVersion;
1547 1546
1548 DCHECK(!pending_second_half_open_); 1547 DCHECK(!pending_second_half_open_);
1549 pending_second_half_open_.reset( 1548 pending_second_half_open_.reset(
1550 new PendingSuccessCall(callbacks, connection.get(), version)); 1549 new PendingSuccessCall(callbacks, connection.get(), version));
1551 callbacks->OnUpgradeNeeded(old_version, connection.Pass(), metadata()); 1550 callbacks->OnUpgradeNeeded(old_version, std::move(connection), metadata());
1552 } 1551 }
1553 1552
1554 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction, 1553 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction,
1555 bool committed) { 1554 bool committed) {
1556 IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", id()); 1555 IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", id());
1557 DCHECK(transactions_.find(transaction->id()) != transactions_.end()); 1556 DCHECK(transactions_.find(transaction->id()) != transactions_.end());
1558 DCHECK_EQ(transactions_[transaction->id()], transaction); 1557 DCHECK_EQ(transactions_[transaction->id()], transaction);
1559 transactions_.erase(transaction->id()); 1558 transactions_.erase(transaction->id());
1560 1559
1561 if (transaction->mode() == blink::WebIDBTransactionModeVersionChange) { 1560 if (transaction->mode() == blink::WebIDBTransactionModeVersionChange) {
1562 if (pending_second_half_open_) { 1561 if (pending_second_half_open_) {
1563 if (committed) { 1562 if (committed) {
1564 DCHECK_EQ(pending_second_half_open_->version(), metadata_.int_version); 1563 DCHECK_EQ(pending_second_half_open_->version(), metadata_.int_version);
1565 DCHECK(metadata_.id != kInvalidId); 1564 DCHECK(metadata_.id != kInvalidId);
1566 1565
1567 // Connection was already minted for OnUpgradeNeeded callback. 1566 // Connection was already minted for OnUpgradeNeeded callback.
1568 scoped_ptr<IndexedDBConnection> connection; 1567 scoped_ptr<IndexedDBConnection> connection;
1569 pending_second_half_open_->callbacks()->OnSuccess(connection.Pass(), 1568 pending_second_half_open_->callbacks()->OnSuccess(std::move(connection),
1570 this->metadata()); 1569 this->metadata());
1571 } else { 1570 } else {
1572 pending_second_half_open_->callbacks()->OnError( 1571 pending_second_half_open_->callbacks()->OnError(
1573 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, 1572 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
1574 "Version change transaction was aborted in " 1573 "Version change transaction was aborted in "
1575 "upgradeneeded event handler.")); 1574 "upgradeneeded event handler."));
1576 } 1575 }
1577 pending_second_half_open_.reset(); 1576 pending_second_half_open_.reset();
1578 } 1577 }
1579 1578
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 1611
1613 size_t IndexedDBDatabase::PendingDeleteCount() const { 1612 size_t IndexedDBDatabase::PendingDeleteCount() const {
1614 return pending_delete_calls_.size(); 1613 return pending_delete_calls_.size();
1615 } 1614 }
1616 1615
1617 void IndexedDBDatabase::ProcessPendingCalls() { 1616 void IndexedDBDatabase::ProcessPendingCalls() {
1618 if (pending_run_version_change_transaction_call_ && ConnectionCount() == 1) { 1617 if (pending_run_version_change_transaction_call_ && ConnectionCount() == 1) {
1619 DCHECK(pending_run_version_change_transaction_call_->version() > 1618 DCHECK(pending_run_version_change_transaction_call_->version() >
1620 metadata_.int_version); 1619 metadata_.int_version);
1621 scoped_ptr<PendingUpgradeCall> pending_call = 1620 scoped_ptr<PendingUpgradeCall> pending_call =
1622 pending_run_version_change_transaction_call_.Pass(); 1621 std::move(pending_run_version_change_transaction_call_);
1623 RunVersionChangeTransactionFinal(pending_call->callbacks(), 1622 RunVersionChangeTransactionFinal(pending_call->callbacks(),
1624 pending_call->ReleaseConnection(), 1623 pending_call->ReleaseConnection(),
1625 pending_call->transaction_id(), 1624 pending_call->transaction_id(),
1626 pending_call->version()); 1625 pending_call->version());
1627 DCHECK_EQ(1u, ConnectionCount()); 1626 DCHECK_EQ(1u, ConnectionCount());
1628 // Fall through would be a no-op, since transaction must complete 1627 // Fall through would be a no-op, since transaction must complete
1629 // asynchronously. 1628 // asynchronously.
1630 DCHECK(IsDeleteDatabaseBlocked()); 1629 DCHECK(IsDeleteDatabaseBlocked());
1631 DCHECK(IsOpenConnectionBlocked()); 1630 DCHECK(IsOpenConnectionBlocked());
1632 return; 1631 return;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 if (iter != connection.get()) { 1811 if (iter != connection.get()) {
1813 iter->callbacks()->OnVersionChange(metadata_.int_version, 1812 iter->callbacks()->OnVersionChange(metadata_.int_version,
1814 requested_version); 1813 requested_version);
1815 } 1814 }
1816 } 1815 }
1817 // OnBlocked will be fired at the request when one of the other 1816 // OnBlocked will be fired at the request when one of the other
1818 // connections acks that the OnVersionChange was ignored. 1817 // connections acks that the OnVersionChange was ignored.
1819 1818
1820 DCHECK(!pending_run_version_change_transaction_call_); 1819 DCHECK(!pending_run_version_change_transaction_call_);
1821 pending_run_version_change_transaction_call_.reset(new PendingUpgradeCall( 1820 pending_run_version_change_transaction_call_.reset(new PendingUpgradeCall(
1822 callbacks, connection.Pass(), transaction_id, requested_version)); 1821 callbacks, std::move(connection), transaction_id, requested_version));
1823 return; 1822 return;
1824 } 1823 }
1825 RunVersionChangeTransactionFinal( 1824 RunVersionChangeTransactionFinal(callbacks, std::move(connection),
1826 callbacks, connection.Pass(), transaction_id, requested_version); 1825 transaction_id, requested_version);
1827 } 1826 }
1828 1827
1829 void IndexedDBDatabase::RunVersionChangeTransactionFinal( 1828 void IndexedDBDatabase::RunVersionChangeTransactionFinal(
1830 scoped_refptr<IndexedDBCallbacks> callbacks, 1829 scoped_refptr<IndexedDBCallbacks> callbacks,
1831 scoped_ptr<IndexedDBConnection> connection, 1830 scoped_ptr<IndexedDBConnection> connection,
1832 int64_t transaction_id, 1831 int64_t transaction_id,
1833 int64_t requested_version) { 1832 int64_t requested_version) {
1834 std::vector<int64_t> object_store_ids; 1833 std::vector<int64_t> object_store_ids;
1835 CreateTransaction(transaction_id, 1834 CreateTransaction(transaction_id,
1836 connection.get(), 1835 connection.get(),
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 const base::string16& previous_version, 1980 const base::string16& previous_version,
1982 int64_t previous_int_version, 1981 int64_t previous_int_version,
1983 IndexedDBTransaction* transaction) { 1982 IndexedDBTransaction* transaction) {
1984 DCHECK(!transaction); 1983 DCHECK(!transaction);
1985 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 1984 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1986 metadata_.version = previous_version; 1985 metadata_.version = previous_version;
1987 metadata_.int_version = previous_int_version; 1986 metadata_.int_version = previous_int_version;
1988 } 1987 }
1989 1988
1990 } // namespace content 1989 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_cursor.cc ('k') | content/browser/indexed_db/indexed_db_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698