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

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: rebase Created 4 years 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,
18 scoped_refptr<IndexedDBDatabase> database, 25 scoped_refptr<IndexedDBDatabase> database,
19 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) 26 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks)
20 : id_(next_id++), 27 : id_(next_id++),
28 child_process_id_(child_process_id),
21 database_(database), 29 database_(database),
22 callbacks_(callbacks), 30 callbacks_(callbacks),
23 weak_factory_(this) {} 31 weak_factory_(this) {}
24 32
25 IndexedDBConnection::~IndexedDBConnection() {} 33 IndexedDBConnection::~IndexedDBConnection() {}
26 34
27 void IndexedDBConnection::Close() { 35 void IndexedDBConnection::Close() {
28 if (!callbacks_.get()) 36 if (!callbacks_.get())
29 return; 37 return;
30 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); 38 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( 86 const auto& it = std::find_if(
79 active_observers_.begin(), active_observers_.end(), 87 active_observers_.begin(), active_observers_.end(),
80 [&id_to_remove](const std::unique_ptr<IndexedDBObserver>& o) { 88 [&id_to_remove](const std::unique_ptr<IndexedDBObserver>& o) {
81 return o->id() == id_to_remove; 89 return o->id() == id_to_remove;
82 }); 90 });
83 if (it != active_observers_.end()) 91 if (it != active_observers_.end())
84 active_observers_.erase(it); 92 active_observers_.erase(it);
85 else 93 else
86 pending_observer_ids.push_back(id_to_remove); 94 pending_observer_ids.push_back(id_to_remove);
87 } 95 }
88 if (!pending_observer_ids.empty()) 96 if (pending_observer_ids.empty())
89 database_->RemovePendingObservers(this, pending_observer_ids); 97 return;
98
99 for (const auto& it : transactions_) {
100 it.second->RemovePendingObservers(pending_observer_ids);
101 }
102 }
103
104 IndexedDBTransaction* IndexedDBConnection::CreateTransaction(
105 int64_t id,
106 const std::set<int64_t>& scope,
107 blink::WebIDBTransactionMode mode,
108 IndexedDBBackingStore::Transaction* backing_store_transaction) {
109 DCHECK_EQ(GetTransaction(id), nullptr) << "Duplicate transaction id." << id;
110 std::unique_ptr<IndexedDBTransaction> transaction =
111 IndexedDBClassFactory::Get()->CreateIndexedDBTransaction(
112 id, this, scope, mode, backing_store_transaction);
113 IndexedDBTransaction* transaction_ptr = transaction.get();
114 transactions_[id] = std::move(transaction);
115 return transaction_ptr;
116 }
117
118 void IndexedDBConnection::AbortTransaction(IndexedDBTransaction* transaction) {
119 IDB_TRACE1("IndexedDBDatabase::Abort", "txn.id", transaction->id());
120 transaction->Abort();
121 }
122
123 void IndexedDBConnection::AbortTransaction(
124 IndexedDBTransaction* transaction,
125 const IndexedDBDatabaseError& error) {
126 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction->id());
127 transaction->Abort(error);
128 }
129
130 void IndexedDBConnection::AbortAllTransactions(
131 const IndexedDBDatabaseError& error) {
132 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>> temp_map;
133 std::swap(temp_map, transactions_);
134 for (const auto& pair : temp_map) {
135 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", pair.second->id());
136 pair.second->Abort(error);
137 }
138 }
139
140 IndexedDBTransaction* IndexedDBConnection::GetTransaction(int64_t id) {
141 auto it = transactions_.find(id);
142 if (it == transactions_.end())
143 return nullptr;
144 return it->second.get();
145 }
146
147 base::WeakPtr<IndexedDBTransaction>
148 IndexedDBConnection::AddTransactionForTesting(
149 std::unique_ptr<IndexedDBTransaction> transaction) {
150 DCHECK(!base::ContainsKey(transactions_, transaction->id()));
151 base::WeakPtr<IndexedDBTransaction> transaction_ptr =
152 transaction->ptr_factory_.GetWeakPtr();
153 transactions_[transaction->id()] = std::move(transaction);
154 return transaction_ptr;
155 }
156
157 void IndexedDBConnection::RemoveTransaction(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