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

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

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Expected test results changed Created 4 years, 5 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 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/indexed_db/indexed_db_database.h" 11 #include "content/browser/indexed_db/indexed_db_database.h"
12 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 12 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
13 #include "content/browser/indexed_db/indexed_db_observer.h"
13 14
14 namespace content { 15 namespace content {
15 class IndexedDBCallbacks; 16 class IndexedDBCallbacks;
cmumford 2016/07/01 18:35:00 This is unrelated to your change, but can you dele
palakj1 2016/07/02 00:48:13 Done.
16 class IndexedDBDatabaseError; 17 class IndexedDBDatabaseError;
17 18
18 class CONTENT_EXPORT IndexedDBConnection { 19 class CONTENT_EXPORT IndexedDBConnection {
19 public: 20 public:
20 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, 21 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db,
21 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); 22 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks);
22 virtual ~IndexedDBConnection(); 23 virtual ~IndexedDBConnection();
23 24
24 // These methods are virtual to allow subclassing in unit tests. 25 // These methods are virtual to allow subclassing in unit tests.
25 virtual void ForceClose(); 26 virtual void ForceClose();
26 virtual void Close(); 27 virtual void Close();
27 virtual bool IsConnected(); 28 virtual bool IsConnected();
28 29
29 void VersionChangeIgnored(); 30 void VersionChangeIgnored();
30 31
32 // The observers begin listening to changes only once they are activated.
cmumford 2016/07/01 18:35:00 Nit: I think this comment is better placed above a
palakj1 2016/07/02 00:48:13 Thanks for that nit. Change made.
33 virtual void ActivatePendingObservers(
cmumford 2016/07/01 18:35:00 Should pending_observers be a non-const reference
palakj1 2016/07/02 00:48:13 I am actually moving the argument vector not copyi
34 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers);
35 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids);
cmumford 2016/07/01 18:35:00 Maybe add a comment above RemoveObservers stating
palakj1 2016/07/02 00:48:13 Done.
36
31 IndexedDBDatabase* database() const { return database_.get(); } 37 IndexedDBDatabase* database() const { return database_.get(); }
32 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } 38 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); }
39 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers()
40 const {
41 return active_observers_;
42 }
43 base::WeakPtr<IndexedDBConnection> GetWeakPtr() {
44 return weak_factory_.GetWeakPtr();
45 }
33 46
34 private: 47 private:
35 // NULL in some unit tests, and after the connection is closed. 48 // NULL in some unit tests, and after the connection is closed.
36 scoped_refptr<IndexedDBDatabase> database_; 49 scoped_refptr<IndexedDBDatabase> database_;
37 50
38 // The callbacks_ member is cleared when the connection is closed. 51 // The callbacks_ member is cleared when the connection is closed.
39 // May be NULL in unit tests. 52 // May be NULL in unit tests.
40 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; 53 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_;
41 54 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_;
42 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; 55 base::WeakPtrFactory<IndexedDBConnection> weak_factory_;
43 56
44 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); 57 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection);
45 }; 58 };
46 59
47 } // namespace content 60 } // namespace content
48 61
49 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ 62 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698