@@ -37,6 +37,30 @@ namespace firebase {
37
37
namespace firestore {
38
38
namespace api {
39
39
40
+ /* *
41
+ * An internal handle that encapsulates a user's ability to request that we
42
+ * stop listening to a query. When a user calls Remove(), ListenerRegistration
43
+ * will synchronously mute the listener and then send a request to the
44
+ * FirestoreClient to actually unlisten.
45
+ *
46
+ * ListenerRegistration will not automaticlaly stop listening if it is
47
+ * destroyed. We allow users to fire and forget listens if they never want to
48
+ * stop them.
49
+ *
50
+ * Getting shutdown code right is tricky so ListenerRegistration is very
51
+ * forgiving. It will tolerate:
52
+ *
53
+ * * Multiple calls to Remove(),
54
+ * * calls to Remove() after we send an error,
55
+ * * calls to Remove() even after deleting the App in which the listener was
56
+ * started.
57
+ *
58
+ * ListenerRegistration is default constructible to facilitate the pattern in
59
+ * DocumentReference::GetDocument, where the closure that implements a listener
60
+ * needs to be able to use the ListenerRegistration thats returned from
61
+ * starting the listener. The default ListenerRegistration acts as a shared
62
+ * placeholder that's filled in later once the listener is started.
63
+ */
40
64
class ListenerRegistration {
41
65
public:
42
66
ListenerRegistration () = default ;
@@ -49,18 +73,6 @@ class ListenerRegistration {
49
73
internal_listener_ (std::move (internal_listener)) {
50
74
}
51
75
52
- // Move-only to prevent copies from proliferating.
53
- ListenerRegistration (const ListenerRegistration&) = delete;
54
- ListenerRegistration (ListenerRegistration&&) noexcept = default ;
55
-
56
- ListenerRegistration& operator=(const ListenerRegistration&) = delete;
57
- ListenerRegistration& operator=(ListenerRegistration&& other) noexcept {
58
- client_ = std::move (other.client_ );
59
- async_listener_ = std::move (other.async_listener_ );
60
- internal_listener_ = std::move (other.internal_listener_ );
61
- return *this;
62
- };
63
-
64
76
/* *
65
77
* Removes the listener being tracked by this FIRListenerRegistration. After
66
78
* the initial call, subsequent calls have no effect.
@@ -69,10 +81,10 @@ class ListenerRegistration {
69
81
70
82
private:
71
83
/* * The client that was used to register this listen. */
72
- FSTFirestoreClient* client_;
84
+ FSTFirestoreClient* client_ = nil ;
73
85
74
86
/* * The async listener that is used to mute events synchronously. */
75
- FSTAsyncQueryListener* async_listener_;
87
+ FSTAsyncQueryListener* async_listener_ = nil ;
76
88
77
89
/* * The internal QueryListener that can be used to unlisten the query. */
78
90
std::weak_ptr<core::QueryListener> internal_listener_;
0 commit comments