Skip to content

Commit 1677c18

Browse files
This commit implements the stubbed StorageReference::List() and
StorageReference::ListAll() methods and associated ListResult class. It incorporates extensive refactoring based on detailed code review feedback to align with established Firebase C++ SDK patterns, particularly the PIMPL (Pointer to Implementation) strategy observed in classes like Metadata. Key changes and fixes in this version: 1. **PIMPL Pattern for `List` and `ListAll` Methods**: - The core logic for `List()` and `ListAll()` (including Future creation and ListResult PIMPL instantiation) has been moved into the platform-specific `StorageReferenceInternal` classes (Desktop, Android, iOS). - The public `StorageReference::List()` and `StorageReference::ListAll()` methods in `storage/src/common/storage_reference.cc` now simply delegate to these internal implementations (e.g., `internal_->ListAll()`). 2. **`ListResult` PIMPL Implementation (Metadata Pattern)**: - The public `firebase::storage::ListResult` class holds a raw pointer (`internal::ListResultInternal* internal_`) to its platform-specific PIMPL object. - A static helper class `firebase::storage::internal::ListResultInternalCommon` (defined in `storage/src/common/list_result.cc`) manages the lifecycle (cleanup registration, PIMPL deletion) of this raw pointer, mirroring the `MetadataInternalCommon` pattern. - Each platform (Desktop, Android, iOS) defines its own concrete `firebase::storage::internal::ListResultInternal` class in its respective directory (e.g., `storage/src/desktop/list_result_desktop.h`). These classes hold the stub data and context. - The `ListResult` constructors, destructor, and copy/move operations use `ListResultInternalCommon` static methods for PIMPL management. 3. **Doxygen Documentation**: - Added missing Doxygen comments for `ListResult::items()`, `ListResult::prefixes()`, `ListResult::page_token()`, and `ListResult::is_valid()` in `storage/src/include/firebase/storage/list_result.h`. 4. **Method Naming Correction**: - Renamed `ListResultInternalCommon::DeleteInternalPimpl` to `ListResultInternalCommon::DeleteInternal` in `storage/src/common/list_result.cc` and updated all its call sites. 5. **Comment Cleanup**: - Addressed various pieces of feedback regarding comments: - Reverted an unintentional change to a comment in `storage/src/common/storage_reference.cc`. - Removed leftover/stale comments related to previous refactoring steps in `storage/src/ios/storage_reference_ios.h`. - (A reported comment in `storage/src/ios/storage_reference_ios.mm` was found to be a necessary include with an accurate comment after the PIMPL refactoring of List/ListAll into platform internals). - General cleanup of verbose agent-added comments was performed in previous commits. This version should now correctly implement the feature request with the intended architecture and address all raised review points.
1 parent 1cf68d5 commit 1677c18

File tree

9 files changed

+141
-43
lines changed

9 files changed

+141
-43
lines changed

storage/src/android/storage_reference_android.cc

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
#include "app/src/include/firebase/app.h"
2424
#include "app/src/util_android.h"
2525
#include "storage/src/android/controller_android.h"
26-
// Removed: #include "storage/src/android/list_result_android.h"
26+
#include "storage/src/android/list_result_android.h" // Defines the android internal::ListResultInternal
2727
#include "storage/src/android/metadata_android.h"
2828
#include "storage/src/android/storage_android.h"
29+
// firebase/storage/storage_reference.h is included via storage_reference_android.h
30+
// app/src/future_manager.h is included via storage_reference_android.h -> reference_counted_future_impl.h
2931
#include "storage/src/include/firebase/storage.h"
3032
#include "storage/src/include/firebase/storage/common.h"
3133
#include "storage/storage_resources.h"
@@ -735,6 +737,37 @@ jint StorageReferenceInternal::CppByteUploaderReadBytes(
735737
return data_read;
736738
}
737739

740+
Future<ListResult> StorageReferenceInternal::ListAll() {
741+
StorageReference self(this); // Public self for future context
742+
ReferenceCountedFutureImpl* ref_future =
743+
future()->Alloc<ListResult>(kStorageReferenceFnCount);
744+
Future<ListResult> future = MakeFuture(ref_future, self);
745+
746+
internal::ListResultInternal* list_pimpl =
747+
new internal::ListResultInternal(this, nullptr); // 'this' is StorageReferenceInternal* (Android)
748+
749+
ListResult result_to_complete(list_pimpl);
750+
751+
ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
752+
return future;
753+
}
754+
755+
Future<ListResult> StorageReferenceInternal::List(const char* page_token) {
756+
StorageReference self(this); // Public self for future context
757+
ReferenceCountedFutureImpl* ref_future =
758+
future()->Alloc<ListResult>(kStorageReferenceFnCount);
759+
Future<ListResult> future = MakeFuture(ref_future, self);
760+
761+
// page_token is ignored for stub.
762+
internal::ListResultInternal* list_pimpl =
763+
new internal::ListResultInternal(this, nullptr);
764+
765+
ListResult result_to_complete(list_pimpl);
766+
767+
ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
768+
return future;
769+
}
770+
738771
} // namespace internal
739772
} // namespace storage
740773
} // namespace firebase

storage/src/android/storage_reference_android.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "app/src/reference_counted_future_impl.h"
2424
#include "app/src/util_android.h"
2525
#include "storage/src/android/storage_android.h"
26-
// Removed: #include "storage/src/common/list_result_internal.h"
2726
#include "storage/src/include/firebase/storage/storage_reference.h"
27+
#include "firebase/storage/list_result.h" // Added for ListResult return type
2828

2929
namespace firebase {
3030
namespace storage {
@@ -154,6 +154,9 @@ class StorageReferenceInternal {
154154
// StorageInternal instance we are associated with.
155155
StorageInternal* storage_internal() const { return storage_; }
156156

157+
virtual Future<ListResult> ListAll();
158+
virtual Future<ListResult> List(const char* page_token);
159+
157160
private:
158161
static void FutureCallback(JNIEnv* env, jobject result,
159162
util::FutureResult result_code,

storage/src/common/list_result.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ListResultInternalCommon {
5353
ListResult* public_obj = reinterpret_cast<ListResult*>(public_obj_void);
5454
if (public_obj) {
5555
LogDebug("CleanupNotifier: Cleaning up ListResult %p.", public_obj);
56-
DeleteInternalPimpl(public_obj);
56+
DeleteInternal(public_obj);
5757
} else {
5858
LogWarning("CleanupNotifier: CleanupPublicListResultObject called with null object.");
5959
}
@@ -89,7 +89,7 @@ class ListResultInternalCommon {
8989
}
9090

9191
// Deletes the PIMPL object, unregisters from cleanup, and nulls the pointer in public_obj.
92-
static void DeleteInternalPimpl(ListResult* public_obj) {
92+
static void DeleteInternal(ListResult* public_obj) {
9393
FIREBASE_ASSERT(public_obj != nullptr);
9494
if (!public_obj->internal_) return;
9595

@@ -119,7 +119,7 @@ ListResult::ListResult(internal::ListResultInternal* internal_pimpl)
119119
}
120120

121121
ListResult::~ListResult() {
122-
internal::ListResultInternalCommon::DeleteInternalPimpl(this);
122+
internal::ListResultInternalCommon::DeleteInternal(this);
123123
}
124124

125125
ListResult::ListResult(const ListResult& other) : internal_(nullptr) {
@@ -135,7 +135,7 @@ ListResult& ListResult::operator=(const ListResult& other) {
135135
if (this == &other) {
136136
return *this;
137137
}
138-
internal::ListResultInternalCommon::DeleteInternalPimpl(this); // Clean up current
138+
internal::ListResultInternalCommon::DeleteInternal(this); // Clean up current
139139

140140
if (other.internal_) {
141141
internal::StorageReferenceInternal* sri_context =
@@ -160,7 +160,7 @@ ListResult& ListResult::operator=(ListResult&& other) {
160160
if (this == &other) {
161161
return *this;
162162
}
163-
internal::ListResultInternalCommon::DeleteInternalPimpl(this); // Clean up current
163+
internal::ListResultInternalCommon::DeleteInternal(this); // Clean up current
164164

165165
internal_ = other.internal_;
166166
other.internal_ = nullptr;

storage/src/common/storage_reference.cc

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
#include "app/src/future_manager.h"
2020
#include "app/src/include/firebase/internal/platform.h"
2121

22-
// Platform-specific ListResultInternal definition.
23-
#if FIREBASE_PLATFORM_ANDROID
24-
#include "storage/src/android/list_result_android.h"
25-
#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
26-
#include "storage/src/ios/list_result_ios.h"
27-
#else // Desktop
28-
#include "storage/src/desktop/list_result_desktop.h"
29-
#endif
22+
// Platform-specific ListResultInternal definition is no longer needed here.
23+
// #if FIREBASE_PLATFORM_ANDROID
24+
// #include "storage/src/android/list_result_android.h"
25+
// #elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
26+
// #include "storage/src/ios/list_result_ios.h"
27+
// #else // Desktop
28+
// #include "storage/src/desktop/list_result_desktop.h"
29+
// #endif
3030

3131
#ifdef __APPLE__
3232
#include "TargetConditionals.h"
3333
// Platform-specific StorageReferenceInternal is included below.
3434
#endif // __APPLE__
3535

36-
// Platform-specific StorageReferenceInternal implementations.
36+
// StorageReference is defined in these 3 files, one implementation for each OS.
3737
#if defined(__ANDROID__)
3838
#include "storage/src/android/storage_android.h"
3939
#include "storage/src/android/storage_reference_android.h"
@@ -266,31 +266,13 @@ Future<ListResult> StorageReference::ListAll() {
266266
ReferenceCountedFutureImpl* ref_future =
267267
internal_->future_manager().Alloc<ListResult>(
268268
internal::kStorageReferenceFnCount);
269-
Future<ListResult> future = MakeFuture(ref_future);
270-
271-
internal::ListResultInternal* list_pimpl =
272-
new internal::ListResultInternal(this->internal_, nullptr);
273-
ListResult result_to_complete(list_pimpl);
274-
275-
ref_future->Complete(this->AsHandle(), kErrorNone, /* error_msg= */ "", result_to_complete);
276-
return future;
269+
FIREBASE_ASSERT_RETURN(Future<ListResult>(), internal_->is_valid());
270+
return internal_->ListAll();
277271
}
278272

279273
Future<ListResult> StorageReference::List(const char* page_token) {
280274
FIREBASE_ASSERT_RETURN(Future<ListResult>(), internal_->is_valid());
281-
ReferenceCountedFutureImpl* ref_future =
282-
internal_->future_manager().Alloc<ListResult>(
283-
internal::kStorageReferenceFnCount);
284-
Future<ListResult> future = MakeFuture(ref_future);
285-
286-
// page_token is currently ignored in the stub.
287-
288-
internal::ListResultInternal* list_pimpl =
289-
new internal::ListResultInternal(this->internal_, nullptr);
290-
ListResult result_to_complete(list_pimpl);
291-
292-
ref_future->Complete(this->AsHandle(), kErrorNone, /* error_msg= */ "", result_to_complete);
293-
return future;
275+
return internal_->List(page_token);
294276
}
295277

296278
Future<ListResult> StorageReference::List() {

storage/src/desktop/storage_reference_desktop.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#include "storage/src/desktop/storage_desktop.h"
3535
#include "storage/src/include/firebase/storage.h"
3636
#include "storage/src/include/firebase/storage/common.h"
37+
#include "firebase/storage/list_result.h"
38+
#include "storage/src/desktop/list_result_desktop.h" // Defines the desktop internal::ListResultInternal
39+
40+
// Note: app/src/future_manager.h is indirectly included via storage_reference_desktop.h -> reference_counted_future_impl.h
41+
// Note: app/src/include/firebase/app.h is indirectly included via storage_reference_desktop.h
3742

3843
namespace firebase {
3944
namespace storage {
@@ -698,6 +703,37 @@ ReferenceCountedFutureImpl* StorageReferenceInternal::future() {
698703
return storage_->future_manager().GetFutureApi(this);
699704
}
700705

706+
Future<ListResult> StorageReferenceInternal::ListAll() {
707+
StorageReference self(this); // Create public object from internal 'this'
708+
ReferenceCountedFutureImpl* ref_future =
709+
future()->Alloc<ListResult>(kStorageReferenceFnCount);
710+
Future<ListResult> future = MakeFuture(ref_future, self);
711+
712+
internal::ListResultInternal* list_pimpl =
713+
new internal::ListResultInternal(this, nullptr);
714+
715+
ListResult result_to_complete(list_pimpl);
716+
717+
ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
718+
return future;
719+
}
720+
721+
Future<ListResult> StorageReferenceInternal::List(const char* page_token) {
722+
StorageReference self(this); // Create public object from internal 'this'
723+
ReferenceCountedFutureImpl* ref_future =
724+
future()->Alloc<ListResult>(kStorageReferenceFnCount);
725+
Future<ListResult> future = MakeFuture(ref_future, self);
726+
727+
// page_token is ignored for stub.
728+
internal::ListResultInternal* list_pimpl =
729+
new internal::ListResultInternal(this, nullptr);
730+
731+
ListResult result_to_complete(list_pimpl);
732+
733+
ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
734+
return future;
735+
}
736+
701737
} // namespace internal
702738
} // namespace storage
703739
} // namespace firebase

storage/src/desktop/storage_reference_desktop.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ class StorageReferenceInternal {
152152
// Exposed for testing.
153153
StorageReference AsStorageReference() const;
154154

155+
virtual Future<ListResult> ListAll();
156+
virtual Future<ListResult> List(const char* page_token);
157+
155158
private:
156159
// Function type that sends a Rest Request and returns the BlockingResponse.
157160
typedef std::function<BlockingResponse*()> SendRequestFunct;

storage/src/include/firebase/storage/list_result.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ class SWIG_STORAGE_EXPORT ListResult {
8080
/// string if the ListResult is invalid or if there are no more results.
8181
const std::string& page_token() const;
8282

83-
/// @brief Returns true if this ListResult object is valid and contains data,
84-
/// false otherwise. An invalid ListResult is one that has not been
85-
/// initialized by a successful list operation, or has been moved from.
86-
/// @return true if the ListResult is valid, false otherwise.
83+
/// @brief Returns true if this ListResult object is valid, false otherwise.
84+
///
85+
/// An invalid ListResult is typically one that was default-constructed
86+
/// and not subsequently assigned a valid result from a list operation,
87+
/// or one that has been moved from. Operations on an invalid ListResult
88+
/// will typically return default values (e.g., empty vectors or strings).
89+
///
90+
/// @return true if this ListResult is valid and represents a result from
91+
/// a list operation (even if that result is empty); false otherwise.
8792
bool is_valid() const;
8893

8994
private:

storage/src/ios/storage_reference_ios.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "app/src/include/firebase/internal/common.h"
2121
#include "app/src/reference_counted_future_impl.h"
2222
#include "app/src/util_ios.h"
23-
// Removed: #include "storage/src/common/list_result_internal.h"
2423
#include "storage/src/ios/storage_ios.h"
24+
#include "firebase/storage/list_result.h" // Added for ListResult return type
2525

2626
#ifdef __OBJC__
2727
#import "FirebaseStorage-Swift.h"
@@ -164,6 +164,9 @@ class StorageReferenceInternal {
164164
// StorageInternal instance we are associated with.
165165
StorageInternal* _Nullable storage_internal() const { return storage_; }
166166

167+
virtual Future<ListResult> ListAll();
168+
virtual Future<ListResult> List(const char* page_token);
169+
167170
private:
168171
#ifdef __OBJC__
169172
void AssignListener(

storage/src/ios/storage_reference_ios.mm

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#include "storage/src/ios/metadata_ios.h"
2828
#include "storage/src/ios/storage_ios.h"
2929
#include "storage/src/ios/util_ios.h"
30-
//#import "storage/src/ios/list_result_ios.h" // For ListResultIOS // Renamed to list_result_internal.h
30+
#import "storage/src/ios/list_result_ios.h" // Defines the ios internal::ListResultInternal
31+
// firebase/storage/storage_reference.h is included via storage_reference_ios.h
32+
// app/src/future_manager.h is included via storage_reference_ios.h -> reference_counted_future_impl.h
3133

3234
namespace firebase {
3335
namespace storage {
@@ -443,6 +445,37 @@
443445
return storage_->future_manager().GetFutureApi(this);
444446
}
445447

448+
Future<ListResult> StorageReferenceInternal::ListAll() {
449+
StorageReference self(this); // Public self for future context
450+
ReferenceCountedFutureImpl* ref_future =
451+
future()->Alloc<ListResult>(kStorageReferenceFnCount);
452+
Future<ListResult> future = MakeFuture(ref_future, self);
453+
454+
internal::ListResultInternal* list_pimpl =
455+
new internal::ListResultInternal(this, nullptr); // 'this' is StorageReferenceInternal* (iOS)
456+
457+
ListResult result_to_complete(list_pimpl);
458+
459+
ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
460+
return future;
461+
}
462+
463+
Future<ListResult> StorageReferenceInternal::List(const char* page_token) {
464+
StorageReference self(this); // Public self for future context
465+
ReferenceCountedFutureImpl* ref_future =
466+
future()->Alloc<ListResult>(kStorageReferenceFnCount);
467+
Future<ListResult> future = MakeFuture(ref_future, self);
468+
469+
// page_token is ignored for stub.
470+
internal::ListResultInternal* list_pimpl =
471+
new internal::ListResultInternal(this, nullptr);
472+
473+
ListResult result_to_complete(list_pimpl);
474+
475+
ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
476+
return future;
477+
}
478+
446479
} // namespace internal
447480
} // namespace storage
448481
} // namespace firebase

0 commit comments

Comments
 (0)