Skip to content

Commit f2b254b

Browse files
committed
Review feedback
1 parent 1011a72 commit f2b254b

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

Firestore/core/src/firebase/firestore/api/document_reference.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ ListenOptions options(
127127
/*include_document_metadata_changes=*/true,
128128
/*wait_for_sync_when_online=*/true);
129129

130+
// Create an empty ListenerRegistration captured in the closure below and
131+
// then, once the listen has started, assign to it and signal the listener
132+
// that we succeeded.
133+
//
130134
// TODO(varconst): replace with a synchronization primitive that doesn't
131135
// require libdispatch. See
132136
// https://github.com/firebase/firebase-ios-sdk/blob/3ccbdcdc65c93c4621c045c3c6d15de9dcefa23f/Firestore/Source/Core/FSTFirestoreClient.mm#L161

Firestore/core/src/firebase/firestore/api/listener_registration.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ namespace firebase {
3737
namespace firestore {
3838
namespace api {
3939

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+
*/
4064
class ListenerRegistration {
4165
public:
4266
ListenerRegistration() = default;
@@ -49,18 +73,6 @@ class ListenerRegistration {
4973
internal_listener_(std::move(internal_listener)) {
5074
}
5175

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-
6476
/**
6577
* Removes the listener being tracked by this FIRListenerRegistration. After
6678
* the initial call, subsequent calls have no effect.
@@ -69,10 +81,10 @@ class ListenerRegistration {
6981

7082
private:
7183
/** The client that was used to register this listen. */
72-
FSTFirestoreClient* client_;
84+
FSTFirestoreClient* client_ = nil;
7385

7486
/** The async listener that is used to mute events synchronously. */
75-
FSTAsyncQueryListener* async_listener_;
87+
FSTAsyncQueryListener* async_listener_ = nil;
7688

7789
/** The internal QueryListener that can be used to unlisten the query. */
7890
std::weak_ptr<core::QueryListener> internal_listener_;

Firestore/core/src/firebase/firestore/api/listener_registration.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
[client_ removeListener:listener];
3333
listener.reset();
3434
internal_listener_.reset();
35+
client_ = nil;
3536
}
3637
}
3738

0 commit comments

Comments
 (0)