Skip to content

Commit 904c183

Browse files
authored
Prep for forward declarations (#4859)
* Remove rarely used template argumnets from SortedMap/SortedSet * Remove unused STATUS_CHECK_OK * Rename QuerySnapshot::Listener to QuerySnapshotListener This makes the type something that can be forward declared. * Rename DocumentSnapshot::Listener to DocumentSnapshotListener This makes the type something that can be forward declared. * Rename ViewSnapshot::Listener to ViewSnapshotListener This makes the type something that can be forward declared. * Put most QueryListener implementation in .cc * Actually use sync_engine_callback.h
1 parent 2e9bc30 commit 904c183

23 files changed

+116
-138
lines changed

Firestore/Source/API/FIRDocumentReference.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2017 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@
4545
using firebase::firestore::api::CollectionReference;
4646
using firebase::firestore::api::DocumentReference;
4747
using firebase::firestore::api::DocumentSnapshot;
48+
using firebase::firestore::api::DocumentSnapshotListener;
4849
using firebase::firestore::api::Firestore;
4950
using firebase::firestore::api::ListenerRegistration;
5051
using firebase::firestore::api::Source;
@@ -213,7 +214,7 @@ - (void)getDocumentWithSource:(FIRFirestoreSource)source
213214
return [[FSTListenerRegistration alloc] initWithRegistration:std::move(result)];
214215
}
215216

216-
- (DocumentSnapshot::Listener)wrapDocumentSnapshotBlock:(FIRDocumentSnapshotBlock)block {
217+
- (DocumentSnapshotListener)wrapDocumentSnapshotBlock:(FIRDocumentSnapshotBlock)block {
217218
class Converter : public EventListener<DocumentSnapshot> {
218219
public:
219220
explicit Converter(FIRDocumentSnapshotBlock block) : block_(block) {

Firestore/Source/API/FIRQuery.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2017 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@
3636

3737
#include "Firestore/core/src/firebase/firestore/api/query_core.h"
3838
#include "Firestore/core/src/firebase/firestore/api/query_listener_registration.h"
39+
#include "Firestore/core/src/firebase/firestore/api/query_snapshot.h"
3940
#include "Firestore/core/src/firebase/firestore/core/bound.h"
4041
#include "Firestore/core/src/firebase/firestore/core/direction.h"
4142
#include "Firestore/core/src/firebase/firestore/core/filter.h"
@@ -59,6 +60,7 @@
5960
using firebase::firestore::api::Query;
6061
using firebase::firestore::api::QueryListenerRegistration;
6162
using firebase::firestore::api::QuerySnapshot;
63+
using firebase::firestore::api::QuerySnapshotListener;
6264
using firebase::firestore::api::SnapshotMetadata;
6365
using firebase::firestore::api::Source;
6466
using firebase::firestore::core::AsyncEventListener;
@@ -446,7 +448,7 @@ - (FieldValue)parsedQueryValue:(id)value allowArrays:(bool)allowArrays {
446448
return [self.firestore.dataConverter parsedQueryValue:value allowArrays:allowArrays];
447449
}
448450

449-
- (QuerySnapshot::Listener)wrapQuerySnapshotBlock:(FIRQuerySnapshotBlock)block {
451+
- (QuerySnapshotListener)wrapQuerySnapshotBlock:(FIRQuerySnapshotBlock)block {
450452
class Converter : public EventListener<QuerySnapshot> {
451453
public:
452454
explicit Converter(FIRQuerySnapshotBlock block) : block_(block) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -110,7 +110,7 @@ void DocumentReference::DeleteDocument(util::StatusCallback callback) {
110110
}
111111

112112
void DocumentReference::GetDocument(Source source,
113-
DocumentSnapshot::Listener&& callback) {
113+
DocumentSnapshotListener&& callback) {
114114
if (source == Source::Cache) {
115115
firestore_->client()->GetDocumentFromLocalCache(*this, std::move(callback));
116116
return;
@@ -123,7 +123,7 @@ void DocumentReference::GetDocument(Source source,
123123

124124
class ListenOnce : public EventListener<DocumentSnapshot> {
125125
public:
126-
ListenOnce(Source source, DocumentSnapshot::Listener&& listener)
126+
ListenOnce(Source source, DocumentSnapshotListener&& listener)
127127
: source_(source), listener_(std::move(listener)) {
128128
}
129129

@@ -173,7 +173,7 @@ void DocumentReference::GetDocument(Source source,
173173

174174
private:
175175
Source source_;
176-
DocumentSnapshot::Listener listener_;
176+
DocumentSnapshotListener listener_;
177177

178178
std::promise<std::unique_ptr<ListenerRegistration>> registration_promise_;
179179
};
@@ -187,12 +187,12 @@ void DocumentReference::GetDocument(Source source,
187187
}
188188

189189
std::unique_ptr<ListenerRegistration> DocumentReference::AddSnapshotListener(
190-
ListenOptions options, DocumentSnapshot::Listener&& user_listener) {
190+
ListenOptions options, DocumentSnapshotListener&& user_listener) {
191191
// Convert from ViewSnapshots to DocumentSnapshots.
192192
class Converter : public EventListener<ViewSnapshot> {
193193
public:
194194
Converter(DocumentReference* parent,
195-
DocumentSnapshot::Listener&& user_listener)
195+
DocumentSnapshotListener&& user_listener)
196196
: firestore_(parent->firestore_),
197197
key_(parent->key_),
198198
user_listener_(std::move(user_listener)) {
@@ -224,7 +224,7 @@ std::unique_ptr<ListenerRegistration> DocumentReference::AddSnapshotListener(
224224
private:
225225
std::shared_ptr<Firestore> firestore_;
226226
DocumentKey key_;
227-
DocumentSnapshot::Listener user_listener_;
227+
DocumentSnapshotListener user_listener_;
228228
};
229229
auto view_listener =
230230
absl::make_unique<Converter>(this, std::move(user_listener));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,10 +80,10 @@ class DocumentReference {
8080

8181
void DeleteDocument(util::StatusCallback callback);
8282

83-
void GetDocument(Source source, DocumentSnapshot::Listener&& callback);
83+
void GetDocument(Source source, DocumentSnapshotListener&& callback);
8484

8585
std::unique_ptr<ListenerRegistration> AddSnapshotListener(
86-
core::ListenOptions options, DocumentSnapshot::Listener&& listener);
86+
core::ListenOptions options, DocumentSnapshotListener&& listener);
8787

8888
private:
8989
std::shared_ptr<Firestore> firestore_;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,8 +38,6 @@ class Firestore;
3838

3939
class DocumentSnapshot {
4040
public:
41-
using Listener = std::unique_ptr<core::EventListener<DocumentSnapshot>>;
42-
4341
DocumentSnapshot() = default;
4442

4543
static DocumentSnapshot FromDocument(std::shared_ptr<Firestore> firestore,
@@ -90,6 +88,9 @@ class DocumentSnapshot {
9088
SnapshotMetadata metadata_;
9189
};
9290

91+
using DocumentSnapshotListener =
92+
std::unique_ptr<core::EventListener<DocumentSnapshot>>;
93+
9394
inline bool operator!=(const DocumentSnapshot& lhs,
9495
const DocumentSnapshot& rhs) {
9596
return !(lhs == rhs);

Firestore/core/src/firebase/firestore/api/query_core.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ size_t Query::Hash() const {
6969
return util::Hash(firestore_.get(), query());
7070
}
7171

72-
void Query::GetDocuments(Source source, QuerySnapshot::Listener&& callback) {
72+
void Query::GetDocuments(Source source, QuerySnapshotListener&& callback) {
7373
ValidateHasExplicitOrderByForLimitToLast();
7474
if (source == Source::Cache) {
7575
firestore_->client()->GetDocumentsFromLocalCache(*this,
@@ -84,7 +84,7 @@ void Query::GetDocuments(Source source, QuerySnapshot::Listener&& callback) {
8484

8585
class ListenOnce : public EventListener<QuerySnapshot> {
8686
public:
87-
ListenOnce(Source source, QuerySnapshot::Listener&& listener)
87+
ListenOnce(Source source, QuerySnapshotListener&& listener)
8888
: source_(source), listener_(std::move(listener)) {
8989
}
9090

@@ -119,7 +119,7 @@ void Query::GetDocuments(Source source, QuerySnapshot::Listener&& callback) {
119119

120120
private:
121121
Source source_;
122-
QuerySnapshot::Listener listener_;
122+
QuerySnapshotListener listener_;
123123

124124
std::promise<std::unique_ptr<ListenerRegistration>> registration_promise_;
125125
};
@@ -134,12 +134,12 @@ void Query::GetDocuments(Source source, QuerySnapshot::Listener&& callback) {
134134
}
135135

136136
std::unique_ptr<ListenerRegistration> Query::AddSnapshotListener(
137-
ListenOptions options, QuerySnapshot::Listener&& user_listener) {
137+
ListenOptions options, QuerySnapshotListener&& user_listener) {
138138
ValidateHasExplicitOrderByForLimitToLast();
139139
// Convert from ViewSnapshots to QuerySnapshots.
140140
class Converter : public EventListener<ViewSnapshot> {
141141
public:
142-
Converter(Query* parent, QuerySnapshot::Listener&& user_listener)
142+
Converter(Query* parent, QuerySnapshotListener&& user_listener)
143143
: firestore_(parent->firestore()),
144144
query_(parent->query()),
145145
user_listener_(std::move(user_listener)) {
@@ -164,7 +164,7 @@ std::unique_ptr<ListenerRegistration> Query::AddSnapshotListener(
164164
private:
165165
std::shared_ptr<Firestore> firestore_;
166166
core::Query query_;
167-
QuerySnapshot::Listener user_listener_;
167+
QuerySnapshotListener user_listener_;
168168
};
169169
auto view_listener =
170170
absl::make_unique<Converter>(this, std::move(user_listener));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ class Query {
6666
* @param callback a callback to execute once the documents have been
6767
* successfully read.
6868
*/
69-
void GetDocuments(Source source, QuerySnapshot::Listener&& callback);
69+
void GetDocuments(Source source, QuerySnapshotListener&& callback);
7070

7171
/**
7272
* Attaches a listener for QuerySnapshot events.
@@ -78,7 +78,7 @@ class Query {
7878
* @return A ListenerRegistration that can be used to remove this listener.
7979
*/
8080
std::unique_ptr<ListenerRegistration> AddSnapshotListener(
81-
core::ListenOptions options, QuerySnapshot::Listener&& listener);
81+
core::ListenOptions options, QuerySnapshotListener&& listener);
8282

8383
/**
8484
* Creates and returns a new `Query` with the additional filter that documents

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,8 +40,6 @@ class Query;
4040
*/
4141
class QuerySnapshot {
4242
public:
43-
using Listener = std::unique_ptr<core::EventListener<QuerySnapshot>>;
44-
4543
QuerySnapshot(std::shared_ptr<Firestore> firestore,
4644
core::Query query,
4745
core::ViewSnapshot&& snapshot,
@@ -97,6 +95,9 @@ class QuerySnapshot {
9795
SnapshotMetadata metadata_;
9896
};
9997

98+
using QuerySnapshotListener =
99+
std::unique_ptr<core::EventListener<QuerySnapshot>>;
100+
100101
} // namespace api
101102
} // namespace firestore
102103
} // namespace firebase

Firestore/core/src/firebase/firestore/core/event_manager.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <utility>
1818

1919
#include "Firestore/core/src/firebase/firestore/core/event_manager.h"
20+
#include "Firestore/core/src/firebase/firestore/core/sync_engine.h"
2021
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
2122

2223
namespace firebase {

Firestore/core/src/firebase/firestore/core/event_manager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424

2525
#include "Firestore/core/src/firebase/firestore/core/query.h"
2626
#include "Firestore/core/src/firebase/firestore/core/query_listener.h"
27-
#include "Firestore/core/src/firebase/firestore/core/sync_engine.h"
27+
#include "Firestore/core/src/firebase/firestore/core/sync_engine_callback.h"
2828
#include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
2929
#include "Firestore/core/src/firebase/firestore/model/types.h"
3030
#include "Firestore/core/src/firebase/firestore/util/empty.h"
@@ -37,6 +37,8 @@ namespace firebase {
3737
namespace firestore {
3838
namespace core {
3939

40+
class QueryEventSource;
41+
4042
/**
4143
* EventManager is responsible for mapping queries to query event listeners.
4244
* It handles "fan-out". (Identical queries will re-use the same watch on the

0 commit comments

Comments
 (0)