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 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
| 11 namespace { |
| 12 |
| 13 static int32_t next_id; |
| 14 |
| 15 } // namespace |
| 16 |
11 IndexedDBConnection::IndexedDBConnection( | 17 IndexedDBConnection::IndexedDBConnection( |
12 scoped_refptr<IndexedDBDatabase> database, | 18 scoped_refptr<IndexedDBDatabase> database, |
13 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) | 19 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) |
14 : database_(database), callbacks_(callbacks), weak_factory_(this) {} | 20 : id_(next_id++), |
| 21 database_(database), |
| 22 callbacks_(callbacks), |
| 23 weak_factory_(this) {} |
15 | 24 |
16 IndexedDBConnection::~IndexedDBConnection() {} | 25 IndexedDBConnection::~IndexedDBConnection() {} |
17 | 26 |
18 void IndexedDBConnection::set_id(int32_t id) { | |
19 DCHECK_EQ(id_, kInvalidId); | |
20 id_ = id; | |
21 } | |
22 | |
23 void IndexedDBConnection::Close() { | 27 void IndexedDBConnection::Close() { |
24 if (!callbacks_.get()) | 28 if (!callbacks_.get()) |
25 return; | 29 return; |
26 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); | 30 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); |
27 database_->Close(this, false /* forced */); | 31 database_->Close(this, false /* forced */); |
28 if (this_obj) { | 32 if (this_obj) { |
29 database_ = nullptr; | 33 database_ = nullptr; |
30 callbacks_ = nullptr; | 34 callbacks_ = nullptr; |
31 active_observers_.clear(); | 35 active_observers_.clear(); |
32 } | 36 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (it != active_observers_.end()) | 83 if (it != active_observers_.end()) |
80 active_observers_.erase(it); | 84 active_observers_.erase(it); |
81 else | 85 else |
82 pending_observer_ids.push_back(id_to_remove); | 86 pending_observer_ids.push_back(id_to_remove); |
83 } | 87 } |
84 if (!pending_observer_ids.empty()) | 88 if (!pending_observer_ids.empty()) |
85 database_->RemovePendingObservers(this, pending_observer_ids); | 89 database_->RemovePendingObservers(this, pending_observer_ids); |
86 } | 90 } |
87 | 91 |
88 } // namespace content | 92 } // namespace content |
OLD | NEW |