Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/indexed_db/indexed_db_connection.h" | 5 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | |
| 9 #include "content/browser/indexed_db/indexed_db_observer.h" | |
| 10 #include "content/browser/indexed_db/indexed_db_transaction.h" | |
| 8 | 11 |
| 9 namespace content { | 12 namespace content { |
| 10 | 13 |
| 11 namespace { | 14 namespace { |
| 12 | 15 |
| 13 static int32_t next_id; | 16 static int32_t next_id; |
| 14 | 17 |
| 15 } // namespace | 18 } // namespace |
| 16 | 19 |
| 17 IndexedDBConnection::IndexedDBConnection( | 20 IndexedDBConnection::IndexedDBConnection( |
| 21 int child_process_id, | |
| 18 scoped_refptr<IndexedDBDatabase> database, | 22 scoped_refptr<IndexedDBDatabase> database, |
| 19 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) | 23 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) |
| 20 : id_(next_id++), | 24 : id_(next_id++), |
| 25 child_process_id_(child_process_id), | |
| 21 database_(database), | 26 database_(database), |
| 22 callbacks_(callbacks), | 27 callbacks_(callbacks), |
| 23 weak_factory_(this) {} | 28 weak_factory_(this) {} |
| 24 | 29 |
| 25 IndexedDBConnection::~IndexedDBConnection() {} | 30 IndexedDBConnection::~IndexedDBConnection() {} |
| 26 | 31 |
| 27 void IndexedDBConnection::Close() { | 32 void IndexedDBConnection::Close() { |
| 28 if (!callbacks_.get()) | 33 if (!callbacks_.get()) |
| 29 return; | 34 return; |
| 30 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); | 35 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 const auto& it = std::find_if( | 83 const auto& it = std::find_if( |
| 79 active_observers_.begin(), active_observers_.end(), | 84 active_observers_.begin(), active_observers_.end(), |
| 80 [&id_to_remove](const std::unique_ptr<IndexedDBObserver>& o) { | 85 [&id_to_remove](const std::unique_ptr<IndexedDBObserver>& o) { |
| 81 return o->id() == id_to_remove; | 86 return o->id() == id_to_remove; |
| 82 }); | 87 }); |
| 83 if (it != active_observers_.end()) | 88 if (it != active_observers_.end()) |
| 84 active_observers_.erase(it); | 89 active_observers_.erase(it); |
| 85 else | 90 else |
| 86 pending_observer_ids.push_back(id_to_remove); | 91 pending_observer_ids.push_back(id_to_remove); |
| 87 } | 92 } |
| 88 if (!pending_observer_ids.empty()) | 93 if (pending_observer_ids.empty()) |
| 89 database_->RemovePendingObservers(this, pending_observer_ids); | 94 return; |
| 95 | |
| 96 for (const auto& it : transactions_) { | |
| 97 it.second->RemovePendingObservers(pending_observer_ids); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 IndexedDBTransaction* IndexedDBConnection::CreateTransaction( | |
| 102 int64_t id, | |
| 103 const std::set<int64_t>& scope, | |
| 104 blink::WebIDBTransactionMode mode, | |
| 105 IndexedDBBackingStore::Transaction* backing_store_transaction) { | |
| 106 DCHECK_EQ(GetTransaction(id), nullptr); | |
| 107 std::unique_ptr<IndexedDBTransaction> transaction = | |
| 108 base::MakeUnique<IndexedDBTransaction>(id, this, scope, mode, | |
| 109 backing_store_transaction); | |
| 110 IndexedDBTransaction* transaction_ptr = transaction.get(); | |
| 111 transactions_[id] = std::move(transaction); | |
| 112 return transaction_ptr; | |
| 113 } | |
| 114 | |
| 115 IndexedDBTransaction* IndexedDBConnection::GetTransaction(int64_t id) { | |
| 116 auto it = transactions_.find(id); | |
| 117 if (it == transactions_.end()) | |
| 118 return nullptr; | |
| 119 return it->second.get(); | |
| 120 } | |
| 121 | |
| 122 IndexedDBTransaction* IndexedDBConnection::StoreTransactionForTesting( | |
| 123 std::unique_ptr<IndexedDBTransaction> transaction) { | |
| 124 DCHECK(transactions_.find(transaction->id()) == transactions_.end()); | |
|
jsbell
2016/11/04 17:48:19
base::ContainsKey
dmurph
2016/11/04 22:52:24
Done.
| |
| 125 IndexedDBTransaction* transaction_ptr = transaction.get(); | |
| 126 transactions_[transaction->id()] = std::move(transaction); | |
| 127 return transaction_ptr; | |
| 128 } | |
| 129 | |
| 130 void IndexedDBConnection::EraseTransaction(int64_t id) { | |
| 131 transactions_.erase(id); | |
| 132 } | |
| 133 | |
| 134 void IndexedDBConnection::AbortAllTransactions( | |
| 135 const IndexedDBDatabaseError& error) { | |
| 136 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>> temp_map; | |
|
cmumford
2016/11/04 23:33:12
Couldn't you also do this?
const auto temp_map
dmurph
2016/11/07 20:05:22
I could, but that leaves transactions_ in a techni
| |
| 137 std::swap(temp_map, transactions_); | |
| 138 for (const auto& pair : temp_map) { | |
| 139 pair.second->Abort(error); | |
| 140 } | |
| 90 } | 141 } |
| 91 | 142 |
| 92 } // namespace content | 143 } // namespace content |
| OLD | NEW |