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

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

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: comments & rebase Created 4 years, 1 month 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 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 "base/stl_util.h"
9 #include "content/browser/indexed_db/indexed_db_class_factory.h"
10 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
11 #include "content/browser/indexed_db/indexed_db_observer.h"
12 #include "content/browser/indexed_db/indexed_db_tracing.h"
13 #include "content/browser/indexed_db/indexed_db_transaction.h"
8 14
9 namespace content { 15 namespace content {
10 16
11 namespace { 17 namespace {
12 18
13 static int32_t next_id; 19 static int32_t next_id;
14 20
15 } // namespace 21 } // namespace
16 22
17 IndexedDBConnection::IndexedDBConnection( 23 IndexedDBConnection::IndexedDBConnection(
24 int child_process_id,
25 const url::Origin& origin,
18 scoped_refptr<IndexedDBDatabase> database, 26 scoped_refptr<IndexedDBDatabase> database,
19 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) 27 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks)
20 : id_(next_id++), 28 : id_(next_id++),
29 child_process_id_(child_process_id),
30 origin_(origin),
21 database_(database), 31 database_(database),
22 callbacks_(callbacks), 32 callbacks_(callbacks),
23 weak_factory_(this) {} 33 weak_factory_(this) {}
24 34
25 IndexedDBConnection::~IndexedDBConnection() {} 35 IndexedDBConnection::~IndexedDBConnection() {}
26 36
27 void IndexedDBConnection::Close() { 37 void IndexedDBConnection::Close() {
28 if (!callbacks_.get()) 38 if (!callbacks_.get())
29 return; 39 return;
30 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); 40 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const auto& it = std::find_if( 88 const auto& it = std::find_if(
79 active_observers_.begin(), active_observers_.end(), 89 active_observers_.begin(), active_observers_.end(),
80 [&id_to_remove](const std::unique_ptr<IndexedDBObserver>& o) { 90 [&id_to_remove](const std::unique_ptr<IndexedDBObserver>& o) {
81 return o->id() == id_to_remove; 91 return o->id() == id_to_remove;
82 }); 92 });
83 if (it != active_observers_.end()) 93 if (it != active_observers_.end())
84 active_observers_.erase(it); 94 active_observers_.erase(it);
85 else 95 else
86 pending_observer_ids.push_back(id_to_remove); 96 pending_observer_ids.push_back(id_to_remove);
87 } 97 }
88 if (!pending_observer_ids.empty()) 98 if (pending_observer_ids.empty())
89 database_->RemovePendingObservers(this, pending_observer_ids); 99 return;
100
101 for (const auto& it : transactions_) {
102 it.second->RemovePendingObservers(pending_observer_ids);
103 }
104 }
105
106 IndexedDBTransaction* IndexedDBConnection::CreateTransaction(
107 int64_t id,
108 const std::set<int64_t>& scope,
109 blink::WebIDBTransactionMode mode,
110 IndexedDBBackingStore::Transaction* backing_store_transaction) {
111 DCHECK_EQ(GetTransaction(id), nullptr);
112 std::unique_ptr<IndexedDBTransaction> transaction =
113 IndexedDBClassFactory::Get()->CreateIndexedDBTransaction(
114 id, this, scope, mode, backing_store_transaction);
115 IndexedDBTransaction* transaction_ptr = transaction.get();
116 transactions_[id] = std::move(transaction);
117 return transaction_ptr;
118 }
119
120 void IndexedDBConnection::AbortTransaction(IndexedDBTransaction* transaction) {
121 IDB_TRACE1("IndexedDBDatabase::Abort", "txn.id", transaction->id());
122 transaction->Abort();
123 }
124
125 void IndexedDBConnection::AbortTransaction(
126 IndexedDBTransaction* transaction,
127 const IndexedDBDatabaseError& error) {
128 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction->id());
129 transaction->Abort(error);
130 }
131
132 void IndexedDBConnection::AbortAllTransactions(
133 const IndexedDBDatabaseError& error) {
134 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>> temp_map;
135 std::swap(temp_map, transactions_);
136 for (const auto& pair : temp_map) {
137 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", pair.second->id());
138 pair.second->Abort(error);
139 }
140 }
141
142 IndexedDBTransaction* IndexedDBConnection::GetTransaction(int64_t id) {
143 auto it = transactions_.find(id);
144 if (it == transactions_.end())
145 return nullptr;
146 return it->second.get();
147 }
148
149 IndexedDBTransaction* IndexedDBConnection::StoreTransactionForTesting(
150 std::unique_ptr<IndexedDBTransaction> transaction) {
151 DCHECK(!base::ContainsKey(transactions_, transaction->id()));
152 IndexedDBTransaction* transaction_ptr = transaction.get();
153 transactions_[transaction->id()] = std::move(transaction);
154 return transaction_ptr;
155 }
156
157 void IndexedDBConnection::EraseTransaction(int64_t id) {
158 transactions_.erase(id);
90 } 159 }
91 160
92 } // namespace content 161 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698