Skip to content

Commit 61e6bbb

Browse files
refactor: Final cleanup and fixes for Storage List API
Addresses all outstanding review comments and build errors for the Storage List API feature. This includes: - Build Fixes: - Resolved circular include dependency between storage_reference.h and list_result.h by forward-declaring ListResult in storage_reference.h. - Corrected includes in list_result.cc and platform-specific list_result_*.h files to use appropriate platform-specific headers for StorageInternal definitions. - Code Cleanup: - Thoroughly removed commented-out code and unused includes. - Removed all explanatory comments next to #include directives. - Eliminated stray or development-related comments. - Integration Tests: - Removed SKIP_TEST_ON_ANDROID_EMULATOR from ListAllBasic and ListPaginated tests. - Refactored list tests to create their own unique root folders. - Code Style: - Updated copyright year to 2025 in all newly added files. - Ran code formatter (scripts/format_code.py -git_diff) on all changed files. - Android Performance: - Optimized Android's ListResultInternal to cache converted data. - Cleanup Mechanism: - Simplified ListResult cleanup logic by removing ListResultInternalCommon.
1 parent 3e4e046 commit 61e6bbb

12 files changed

+36
-72
lines changed

storage/src/android/list_result_android.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ ListResultInternal::ListResultInternal(StorageInternal* storage_internal,
7777
ListResultInternal::ListResultInternal(const ListResultInternal& other)
7878
: storage_internal_(other.storage_internal_),
7979
list_result_java_ref_(nullptr),
80-
items_cache_(other.items_cache_), // Copy cache
81-
prefixes_cache_(other.prefixes_cache_), // Copy cache
82-
page_token_cache_(other.page_token_cache_), // Copy cache
80+
items_cache_(other.items_cache_),
81+
prefixes_cache_(other.prefixes_cache_),
82+
page_token_cache_(other.page_token_cache_),
8383
items_converted_(other.items_converted_),
8484
prefixes_converted_(other.prefixes_converted_),
8585
page_token_converted_(other.page_token_converted_) {
@@ -95,8 +95,7 @@ ListResultInternal& ListResultInternal::operator=(
9595
if (&other == this) {
9696
return *this;
9797
}
98-
storage_internal_ =
99-
other.storage_internal_; // This is a raw pointer, just copy.
98+
storage_internal_ = other.storage_internal_;
10099
FIREBASE_ASSERT(storage_internal_ != nullptr);
101100
JNIEnv* env = storage_internal_->app()->GetJNIEnv();
102101
if (list_result_java_ref_ != nullptr) {
@@ -106,7 +105,6 @@ ListResultInternal& ListResultInternal::operator=(
106105
if (other.list_result_java_ref_ != nullptr) {
107106
list_result_java_ref_ = env->NewGlobalRef(other.list_result_java_ref_);
108107
}
109-
// Copy cache state
110108
items_cache_ = other.items_cache_;
111109
prefixes_cache_ = other.prefixes_cache_;
112110
page_token_cache_ = other.page_token_cache_;

storage/src/android/list_result_android.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
#include "app/src/util_android.h"
2424
#include "firebase/app.h"
2525
#include "firebase/storage/storage_reference.h"
26-
// #include "storage/src/common/storage_internal.h" // Removed
27-
#include "storage/src/android/storage_android.h" // Added for Android StorageInternal
28-
// #include "storage/src/common/list_result_internal_common.h" // Removed
26+
#include "storage/src/android/storage_android.h"
2927

3028
namespace firebase {
3129
namespace storage {
@@ -35,9 +33,6 @@ class ListResult;
3533

3634
namespace internal {
3735

38-
// construction.
39-
// class ListResultInternalCommon; // Removed
40-
4136
// Contains the Android-specific implementation of ListResultInternal.
4237
class ListResultInternal {
4338
public:
@@ -79,9 +74,6 @@ class ListResultInternal {
7974

8075
private:
8176
friend class firebase::storage::ListResult;
82-
// For ListResultInternalCommon's constructor and access to app_ via
83-
// storage_internal().
84-
// friend class ListResultInternalCommon; // Removed as class is removed
8577

8678
// Converts a Java List of Java StorageReference objects to a C++ vector of
8779
// C++ StorageReference objects.

storage/src/android/storage_reference_android.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ enum StorageReferenceFn {
111111
kStorageReferenceFnUpdateMetadata,
112112
kStorageReferenceFnPutBytes,
113113
kStorageReferenceFnPutFile,
114-
kStorageReferenceFnList, // New enum value for List operations
114+
kStorageReferenceFnList,
115115
kStorageReferenceFnCount,
116116
};
117117

@@ -122,7 +122,7 @@ bool StorageReferenceInternal::Initialize(App* app) {
122122
return false;
123123
}
124124
if (!ListResultInternal::Initialize(app)) {
125-
storage_reference::ReleaseClass(env); // Release what was cached
125+
storage_reference::ReleaseClass(env);
126126
return false;
127127
}
128128
return true;

storage/src/common/list_result.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,28 @@
1616

1717
#include <assert.h>
1818

19-
// #include "storage/src/common/list_result_internal_common.h" // Removed
20-
#include "app/src/cleanup_notifier.h" // For CleanupNotifier
21-
#include "app/src/include/firebase/app.h" // For App, LogDebug
22-
#include "app/src/util.h" // For LogDebug
23-
// #include "storage/src/common/storage_internal.h" // Removed
24-
#include "storage/src/common/storage_reference_internal.h" // For StorageReference constructor from internal
19+
#include "app/src/cleanup_notifier.h"
20+
#include "app/src/include/firebase/app.h"
21+
#include "app/src/util.h"
22+
#include "storage/src/common/storage_reference_internal.h"
2523

2624
// Platform specific ListResultInternal definitions
2725
#if FIREBASE_PLATFORM_ANDROID
2826
#include "storage/src/android/list_result_android.h"
29-
#include "storage/src/android/storage_android.h" // Added for StorageInternal
27+
#include "storage/src/android/storage_android.h"
3028
#elif FIREBASE_PLATFORM_IOS
3129
#include "storage/src/ios/list_result_ios.h"
32-
#include "storage/src/ios/storage_ios.h" // Added for StorageInternal
30+
#include "storage/src/ios/storage_ios.h"
3331
#elif FIREBASE_PLATFORM_DESKTOP
3432
#include "storage/src/desktop/list_result_desktop.h"
35-
#include "storage/src/desktop/storage_desktop.h" // Added for StorageInternal
33+
#include "storage/src/desktop/storage_desktop.h"
3634
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS,
3735
// FIREBASE_PLATFORM_DESKTOP
3836

3937
namespace firebase {
4038
namespace storage {
4139

4240
using internal::ListResultInternal;
43-
// using internal::ListResultInternalCommon; // Removed
4441

4542
// Global function to be called by CleanupNotifier
4643
// This function is responsible for cleaning up the internal state of a

storage/src/common/storage_reference.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include "storage/src/include/firebase/storage/storage_reference.h"
1616

1717
#include "app/src/assert.h"
18-
#include "firebase/storage/list_result.h" // Required for ListResult
19-
#include "storage/src/include/firebase/storage/future_details.h" // Required for Future<ListResult>
18+
#include "firebase/storage/list_result.h"
19+
#include "storage/src/include/firebase/storage/future_details.h"
2020

2121
#ifdef __APPLE__
2222
#include "TargetConditionals.h"
@@ -270,10 +270,6 @@ Future<ListResult> StorageReference::ListAll() {
270270

271271
Future<ListResult> StorageReference::ListLastResult() {
272272
if (!internal_) return Future<ListResult>();
273-
// Assuming kStorageReferenceFnList will be defined in platform-specific
274-
// internal headers and accessible here.
275-
// This also assumes internal_->future() correctly provides access to the
276-
// FutureManager for ListResult.
277273
return static_cast<const Future<ListResult>&>(
278274
internal_->future()->LastResult(kStorageReferenceFnList));
279275
}

storage/src/desktop/list_result_desktop.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "storage/src/desktop/list_result_desktop.h"
1616

17-
#include "storage/src/desktop/storage_desktop.h" // For StorageInternal
17+
#include "storage/src/desktop/storage_desktop.h"
1818

1919
namespace firebase {
2020
namespace storage {
@@ -29,9 +29,9 @@ ListResultInternal::ListResultInternal(
2929
const std::vector<StorageReference>& prefixes,
3030
const std::string& page_token)
3131
: storage_internal_(storage_internal),
32-
items_stub_(items), // Will be empty for stubs
33-
prefixes_stub_(prefixes), // Will be empty for stubs
34-
page_token_stub_(page_token) {} // Will be empty for stubs
32+
items_stub_(items),
33+
prefixes_stub_(prefixes),
34+
page_token_stub_(page_token) {}
3535

3636
ListResultInternal::ListResultInternal(const ListResultInternal& other)
3737
: storage_internal_(other.storage_internal_),
@@ -44,7 +44,7 @@ ListResultInternal& ListResultInternal::operator=(
4444
if (&other == this) {
4545
return *this;
4646
}
47-
storage_internal_ = other.storage_internal_; // Pointer copy
47+
storage_internal_ = other.storage_internal_;
4848
items_stub_ = other.items_stub_;
4949
prefixes_stub_ = other.prefixes_stub_;
5050
page_token_stub_ = other.page_token_stub_;

storage/src/desktop/list_result_desktop.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
#include <vector>
2020

2121
#include "firebase/storage/storage_reference.h"
22-
// #include "storage/src/common/storage_internal.h" // Removed
23-
#include "storage/src/desktop/storage_desktop.h" // Added for Desktop StorageInternal
24-
// #include "storage/src/common/list_result_internal_common.h" // Removed
22+
#include "storage/src/desktop/storage_desktop.h"
2523

2624
namespace firebase {
2725
namespace storage {
@@ -31,10 +29,6 @@ class ListResult;
3129

3230
namespace internal {
3331

34-
// Declare ListResultInternal a friend of ListResultInternalCommon for
35-
// construction.
36-
// class ListResultInternalCommon; // Removed
37-
3832
// Contains the Desktop-specific implementation of ListResultInternal (stubs).
3933
class ListResultInternal {
4034
public:
@@ -74,9 +68,6 @@ class ListResultInternal {
7468

7569
private:
7670
friend class firebase::storage::ListResult;
77-
// For ListResultInternalCommon's constructor and access to app_ via
78-
// storage_internal().
79-
// friend class ListResultInternalCommon; // Removed
8071

8172
StorageInternal* storage_internal_; // Not owned.
8273
// Desktop stubs don't actually store these, but defined to match constructor.

storage/src/desktop/storage_reference_desktop.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
#include "app/src/function_registry.h"
2929
#include "app/src/include/firebase/app.h"
3030
#include "app/src/thread.h"
31-
#include "firebase/storage/list_result.h" // Added for ListResult
31+
#include "firebase/storage/list_result.h"
3232
#include "storage/src/common/common_internal.h"
3333
#include "storage/src/desktop/controller_desktop.h"
34-
#include "storage/src/desktop/list_result_desktop.h" // Added for ListResultInternal
34+
#include "storage/src/desktop/list_result_desktop.h"
3535
#include "storage/src/desktop/metadata_desktop.h"
3636
#include "storage/src/desktop/storage_desktop.h"
3737
#include "storage/src/include/firebase/storage.h"

storage/src/include/firebase/storage/storage_reference.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "firebase/future.h"
2222
#include "firebase/internal/common.h"
23-
// #include "firebase/storage/list_result.h" // Removed
2423
#include "firebase/storage/metadata.h"
2524

2625
namespace firebase {
@@ -30,7 +29,7 @@ namespace storage {
3029
class Controller;
3130
class Listener;
3231
class Storage;
33-
class ListResult; // Added forward declaration
32+
class ListResult;
3433

3534
/// @cond FIREBASE_APP_INTERNAL
3635
namespace internal {

storage/src/ios/list_result_ios.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
#include <string>
1919
#include <vector>
20-
#include <memory> // For std::unique_ptr
20+
#include <memory>
2121

2222
#include "firebase/storage/storage_reference.h"
23-
// #include "storage/src/common/storage_internal.h" // Removed
24-
#include "storage/src/ios/storage_ios.h" // Added for iOS StorageInternal
25-
// #include "storage/src/common/list_result_internal_common.h" // Removed
26-
#include "storage/src/ios/fir_storage_list_result_pointer.h" // For FIRStorageListResultPointer
23+
#include "storage/src/ios/storage_ios.h"
24+
#include "storage/src/ios/fir_storage_list_result_pointer.h"
2725

2826
// Forward declare Obj-C types
2927
#ifdef __OBJC__
@@ -43,9 +41,6 @@ class ListResult;
4341

4442
namespace internal {
4543

46-
// Declare ListResultInternal a friend of ListResultInternalCommon for construction.
47-
// class ListResultInternalCommon; // Removed
48-
4944
// Contains the iOS-specific implementation of ListResultInternal.
5045
class ListResultInternal {
5146
public:
@@ -81,9 +76,6 @@ class ListResultInternal {
8176

8277
private:
8378
friend class firebase::storage::ListResult;
84-
// For ListResultInternalCommon's constructor and access to app_ via
85-
// storage_internal().
86-
// friend class ListResultInternalCommon; // Removed
8779

8880
// Converts an NSArray of FIRStorageReference objects to a C++ vector of
8981
// C++ StorageReference objects.

storage/src/ios/list_result_ios.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#import <Foundation/Foundation.h>
2020

2121
#include "app/src/assert.h"
22-
#include "app/src/ios/c_string_manager.h" // For CStringManager
23-
#include "storage/src/ios/converter_ios.h" // For NSStringToStdString
24-
#include "storage/src/ios/storage_ios.h" // For StorageInternal
25-
#include "storage/src/ios/storage_reference_ios.h" // For StorageReferenceInternal and FIRStorageReferencePointer
22+
#include "app/src/ios/c_string_manager.h"
23+
#include "storage/src/ios/converter_ios.h"
24+
#include "storage/src/ios/storage_ios.h"
25+
#include "storage/src/ios/storage_reference_ios.h"
2626

2727
namespace firebase {
2828
namespace storage {

storage/src/ios/storage_reference_ios.mm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
namespace storage {
3333
namespace internal {
3434

35-
// Should reads and writes share thier futures?
3635
enum StorageReferenceFn {
3736
kStorageReferenceFnDelete = 0,
3837
kStorageReferenceFnGetBytes,
@@ -42,7 +41,7 @@
4241
kStorageReferenceFnUpdateMetadata,
4342
kStorageReferenceFnPutBytes,
4443
kStorageReferenceFnPutFile,
45-
kStorageReferenceFnList, // Added for List operations
44+
kStorageReferenceFnList,
4645
kStorageReferenceFnCount,
4746
};
4847

@@ -443,7 +442,7 @@
443442
ReferenceCountedFutureImpl* future_impl = future();
444443
SafeFutureHandle<ListResult> handle =
445444
future_impl->SafeAlloc<ListResult>(kStorageReferenceFnList);
446-
StorageInternal* storage_internal = storage_; // Capture for block
445+
StorageInternal* storage_internal = storage_;
447446

448447
FIRStorageVoidListResultError completion_block =
449448
^(FIRStorageListResult* _Nullable list_result_objc, NSError* _Nullable error) {
@@ -470,7 +469,7 @@
470469
ReferenceCountedFutureImpl* future_impl = future();
471470
SafeFutureHandle<ListResult> handle =
472471
future_impl->SafeAlloc<ListResult>(kStorageReferenceFnList);
473-
StorageInternal* storage_internal = storage_; // Capture for block
472+
StorageInternal* storage_internal = storage_;
474473

475474
NSString* page_token_objc = page_token ? @(page_token) : nil;
476475

@@ -500,7 +499,7 @@
500499
ReferenceCountedFutureImpl* future_impl = future();
501500
SafeFutureHandle<ListResult> handle =
502501
future_impl->SafeAlloc<ListResult>(kStorageReferenceFnList);
503-
StorageInternal* storage_internal = storage_; // Capture for block
502+
StorageInternal* storage_internal = storage_;
504503

505504
FIRStorageVoidListResultError completion_block =
506505
^(FIRStorageListResult* _Nullable list_result_objc, NSError* _Nullable error) {

0 commit comments

Comments
 (0)