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

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

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Observer moved to connection Created 4 years, 6 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 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 #include "content/browser/indexed_db/indexed_db_observer.h"
6 7
7 namespace content { 8 namespace content {
8 9
9 IndexedDBConnection::IndexedDBConnection( 10 IndexedDBConnection::IndexedDBConnection(
10 scoped_refptr<IndexedDBDatabase> database, 11 scoped_refptr<IndexedDBDatabase> database,
11 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) 12 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks)
12 : database_(database), callbacks_(callbacks), weak_factory_(this) {} 13 : database_(database), callbacks_(callbacks), weak_factory_(this) {}
13 14
14 IndexedDBConnection::~IndexedDBConnection() {} 15 IndexedDBConnection::~IndexedDBConnection() {}
15 16
16 void IndexedDBConnection::Close() { 17 void IndexedDBConnection::Close() {
17 if (!callbacks_.get()) 18 if (!callbacks_.get())
18 return; 19 return;
19 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); 20 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr();
20 database_->Close(this, false /* forced */); 21 database_->Close(this, false /* forced */);
21 if (this_obj) { 22 if (this_obj) {
22 database_ = nullptr; 23 database_ = nullptr;
23 callbacks_ = nullptr; 24 callbacks_ = nullptr;
25 // Is this needed?
dmurph 2016/06/22 01:09:48 Yes, this makes sense here.
26 active_observers_.clear();
24 } 27 }
25 } 28 }
26 29
27 void IndexedDBConnection::ForceClose() { 30 void IndexedDBConnection::ForceClose() {
28 if (!callbacks_.get()) 31 if (!callbacks_.get())
29 return; 32 return;
30 33
31 // IndexedDBDatabase::Close() can delete this instance. 34 // IndexedDBDatabase::Close() can delete this instance.
32 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); 35 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr();
33 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks(callbacks_); 36 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks(callbacks_);
34 database_->Close(this, true /* forced */); 37 database_->Close(this, true /* forced */);
35 if (this_obj) { 38 if (this_obj) {
36 database_ = nullptr; 39 database_ = nullptr;
37 callbacks_ = nullptr; 40 callbacks_ = nullptr;
41 // TODO(palakj):Is this needed?
dmurph 2016/06/22 01:09:48 Yes, looks good.
42 active_observers_.clear();
38 } 43 }
39 callbacks->OnForcedClose(); 44 callbacks->OnForcedClose();
40 } 45 }
41 46
42 void IndexedDBConnection::VersionChangeIgnored() { 47 void IndexedDBConnection::VersionChangeIgnored() {
43 if (!database_.get()) 48 if (!database_.get())
44 return; 49 return;
45 database_->VersionChangeIgnored(); 50 database_->VersionChangeIgnored();
46 } 51 }
47 52
48 bool IndexedDBConnection::IsConnected() { 53 bool IndexedDBConnection::IsConnected() {
49 return database_.get() != NULL; 54 return database_.get() != NULL;
50 } 55 }
51 56
57 void IndexedDBConnection::Unobserve(std::vector<int32_t> observersToRemove) {
58 for (uint32_t i = 0; i < observersToRemove.size(); i++) {
59 for (uint32_t j = 0; j < active_observers_.size(); j++) {
60 if (active_observers_[j]->id() == observersToRemove[i])
61 active_observers_.erase(active_observers_.begin() + j);
62 observersToRemove.erase(observersToRemove.begin() + i);
dmurph 2016/06/22 01:09:49 ? Dont need this line, it breaks your algorithm.
63 }
64 }
65 if (!observersToRemove.empty())
66 database_->RemovePendingObservers(this, observersToRemove);
dmurph 2016/06/22 01:09:48 Hm, I see what you're doing here. Let's create a n
palakj1 2016/06/23 20:56:29 I get your point. And the observersToRemove should
67 }
68
52 } // namespace content 69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698