1111#if FIREBASE_PLATFORM_ANDROID
1212#include " storage/src/android/list_result_android.h"
1313#include " storage/src/android/storage_internal_android.h"
14- // It's assumed storage_reference_android.h is included by list_result_android.h if needed for StorageReferenceInternal type
1514#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
1615#include " storage/src/ios/list_result_ios.h"
1716#include " storage/src/ios/storage_internal_ios.h"
18- // It's assumed storage_reference_ios.h is included by list_result_ios.h if needed for StorageReferenceInternal type
1917#else // Desktop
2018#include " storage/src/desktop/list_result_desktop.h"
2119#include " storage/src/desktop/storage_internal_desktop.h"
22- // It's assumed storage_reference_desktop.h is included by list_result_desktop.h if needed for StorageReferenceInternal type
2320#endif
2421
2522
2623namespace firebase {
2724namespace storage {
2825
2926// Forward declaration of the PIMPL class.
30- // The actual definition comes from one of the platform headers included above.
3127namespace internal {
3228class ListResultInternal ;
33- // StorageReferenceInternal is needed by ListResultInternal constructor,
34- // and StorageInternal by ListResultInternalCommon helpers.
35- // These should be defined by the platform headers like storage_internal_*.h and list_result_*.h
3629class StorageReferenceInternal ;
3730class StorageInternal ;
3831} // namespace internal
3932
4033namespace internal {
4134
4235// ListResultInternalCommon: Provides static helper methods for managing the
43- // lifecycle of the ListResultInternal PIMPL object, mirroring the pattern
44- // used by MetadataInternalCommon for Metadata.
36+ // lifecycle of the ListResultInternal PIMPL object.
4537class ListResultInternalCommon {
4638 public:
39+ // Retrieves the StorageInternal context from the ListResultInternal object.
4740 static StorageInternal* GetStorageInternalContext (
4841 ListResultInternal* pimpl_obj) {
49- if (!pimpl_obj) {
50- // LogDebug("GetStorageInternalContext: PIMPL object is null.");
51- return nullptr ;
52- }
53- // This relies on ListResultInternal (platform specific) having associated_storage_internal()
42+ if (!pimpl_obj) return nullptr ;
43+ // Relies on ListResultInternal having associated_storage_internal().
5444 StorageInternal* storage_ctx = pimpl_obj->associated_storage_internal ();
5545 if (storage_ctx == nullptr ) {
5646 LogWarning (" ListResultInternal %p has no associated StorageInternal for cleanup." , pimpl_obj);
5747 }
5848 return storage_ctx;
5949 }
6050
51+ // Callback for CleanupNotifier, invoked when the App is being destroyed.
6152 static void CleanupPublicListResultObject (void * public_obj_void) {
6253 ListResult* public_obj = reinterpret_cast <ListResult*>(public_obj_void);
6354 if (public_obj) {
64- LogDebug (" CleanupPublicListResultObject called for ListResult %p via app cleanup ." , public_obj);
55+ LogDebug (" CleanupNotifier: Cleaning up ListResult %p." , public_obj);
6556 DeleteInternalPimpl (public_obj);
6657 } else {
67- LogWarning (" CleanupPublicListResultObject called with null object." );
58+ LogWarning (" CleanupNotifier: CleanupPublicListResultObject called with null object." );
6859 }
6960 }
7061
7162 static void RegisterForCleanup (ListResult* public_obj,
7263 ListResultInternal* pimpl_obj) {
7364 FIREBASE_ASSERT (public_obj != nullptr );
74- if (!pimpl_obj) {
75- LogDebug (" Not registering ListResult %p for cleanup: PIMPL object is null." , public_obj);
76- return ;
77- }
65+ if (!pimpl_obj) return ;
7866 StorageInternal* storage_ctx = GetStorageInternalContext (pimpl_obj);
7967 if (storage_ctx) {
8068 storage_ctx->cleanup ().RegisterObject (public_obj, CleanupPublicListResultObject);
81- LogDebug (" ListResult %p (PIMPL %p) registered for cleanup with StorageInternal %p ." ,
82- public_obj, pimpl_obj, storage_ctx );
69+ LogDebug (" ListResult %p (PIMPL %p) registered for cleanup." ,
70+ public_obj, pimpl_obj);
8371 } else {
84- LogWarning (" Could not register ListResult %p for cleanup: no StorageInternal context from PIMPL %p ." ,
85- public_obj, pimpl_obj );
72+ LogWarning (" Could not register ListResult %p for cleanup: no StorageInternal context." ,
73+ public_obj);
8674 }
8775 }
8876
8977 static void UnregisterFromCleanup (ListResult* public_obj,
9078 ListResultInternal* pimpl_obj) {
9179 FIREBASE_ASSERT (public_obj != nullptr );
92- if (!pimpl_obj) {
93- LogDebug (" Not unregistering ListResult %p: PIMPL object for context is null." , public_obj);
94- return ;
95- }
80+ if (!pimpl_obj) return ;
9681 StorageInternal* storage_ctx = GetStorageInternalContext (pimpl_obj);
9782 if (storage_ctx) {
9883 storage_ctx->cleanup ().UnregisterObject (public_obj);
99- LogDebug (" ListResult %p (associated with PIMPL %p) unregistered from cleanup from StorageInternal %p ." ,
100- public_obj, pimpl_obj, storage_ctx );
84+ LogDebug (" ListResult %p (associated with PIMPL %p) unregistered from cleanup." ,
85+ public_obj, pimpl_obj);
10186 } else {
102- LogWarning (" Could not unregister ListResult %p: no StorageInternal context from PIMPL %p ." , public_obj, pimpl_obj );
87+ LogWarning (" Could not unregister ListResult %p: no StorageInternal context." , public_obj);
10388 }
10489 }
10590
91+ // Deletes the PIMPL object, unregisters from cleanup, and nulls the pointer in public_obj.
10692 static void DeleteInternalPimpl (ListResult* public_obj) {
10793 FIREBASE_ASSERT (public_obj != nullptr );
108- if (!public_obj->internal_ ) {
109- // LogDebug("DeleteInternalPimpl called for ListResult %p, but internal_ is already null.", public_obj);
110- return ;
111- }
94+ if (!public_obj->internal_ ) return ;
95+
11296 ListResultInternal* pimpl_to_delete = public_obj->internal_ ;
113- // LogDebug("ListResult %p: Preparing to delete PIMPL %p.", public_obj, pimpl_to_delete);
11497 UnregisterFromCleanup (public_obj, pimpl_to_delete);
11598 public_obj->internal_ = nullptr ;
11699 delete pimpl_to_delete;
117- // LogDebug("PIMPL object %p deleted for ListResult %p.", pimpl_to_delete, public_obj);
118100 }
119101};
120102
@@ -127,34 +109,25 @@ const std::vector<StorageReference> ListResult::s_empty_prefixes_;
127109const std::string ListResult::s_empty_page_token_;
128110
129111ListResult::ListResult () : internal_(nullptr ) {
130- LogDebug (" ListResult %p default constructed (invalid)." , this );
131112}
132113
133114ListResult::ListResult (internal::ListResultInternal* internal_pimpl)
134115 : internal_(internal_pimpl) {
135116 if (internal_) {
136117 internal::ListResultInternalCommon::RegisterForCleanup (this , internal_);
137- } else {
138- LogWarning (" ListResult %p constructed with null PIMPL." , this );
139118 }
140119}
141120
142121ListResult::~ListResult () {
143- LogDebug (" ListResult %p destructor, deleting PIMPL %p." , this , internal_);
144122 internal::ListResultInternalCommon::DeleteInternalPimpl (this );
145123}
146124
147125ListResult::ListResult (const ListResult& other) : internal_(nullptr ) {
148126 if (other.internal_ ) {
149127 internal::StorageReferenceInternal* sri_context =
150128 other.internal_ ->storage_reference_internal ();
151- // The second argument to ListResultInternal constructor is other.internal_ (for copying data)
152129 internal_ = new internal::ListResultInternal (sri_context, other.internal_ );
153130 internal::ListResultInternalCommon::RegisterForCleanup (this , internal_);
154- LogDebug (" ListResult %p copy constructed from %p (PIMPL %p copied to new PIMPL %p)." ,
155- this , &other, other.internal_ , internal_);
156- } else {
157- LogDebug (" ListResult %p copy constructed from invalid ListResult %p." , this , &other);
158131 }
159132}
160133
@@ -169,27 +142,17 @@ ListResult& ListResult::operator=(const ListResult& other) {
169142 other.internal_ ->storage_reference_internal ();
170143 internal_ = new internal::ListResultInternal (sri_context, other.internal_ );
171144 internal::ListResultInternalCommon::RegisterForCleanup (this , internal_);
172- LogDebug (" ListResult %p copy assigned from %p (PIMPL %p copied to new PIMPL %p)." ,
173- this , &other, other.internal_ , internal_);
174- } else {
175- LogDebug (" ListResult %p copy assigned from invalid ListResult %p." , this , &other);
176- // internal_ is already nullptr from DeleteInternalPimpl
177145 }
178146 return *this ;
179147}
180148
181149#if defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN)
182150ListResult::ListResult (ListResult&& other) : internal_(other.internal_) {
183- other.internal_ = nullptr ; // Other no longer owns the PIMPL.
151+ other.internal_ = nullptr ;
184152 if (internal_) {
185153 // New public object 'this' takes ownership. Unregister 'other', register 'this'.
186- // Pass 'internal_' (which is the original other.internal_) as context for unregistering 'other'.
187154 internal::ListResultInternalCommon::UnregisterFromCleanup (&other, internal_);
188155 internal::ListResultInternalCommon::RegisterForCleanup (this , internal_);
189- LogDebug (" ListResult %p move constructed from %p (PIMPL %p transferred)." ,
190- this , &other, internal_);
191- } else {
192- LogDebug (" ListResult %p move constructed from invalid ListResult %p." , this , &other);
193156 }
194157}
195158
@@ -199,17 +162,13 @@ ListResult& ListResult::operator=(ListResult&& other) {
199162 }
200163 internal::ListResultInternalCommon::DeleteInternalPimpl (this ); // Clean up current
201164
202- internal_ = other.internal_ ; // Take ownership of other's PIMPL.
203- other.internal_ = nullptr ; // Other no longer owns it.
165+ internal_ = other.internal_ ;
166+ other.internal_ = nullptr ;
204167
205168 if (internal_) {
206169 // Similar to move constructor: unregister 'other', register 'this'.
207170 internal::ListResultInternalCommon::UnregisterFromCleanup (&other, internal_);
208171 internal::ListResultInternalCommon::RegisterForCleanup (this , internal_);
209- LogDebug (" ListResult %p move assigned from %p (PIMPL %p transferred)." ,
210- this , &other, internal_);
211- } else {
212- LogDebug (" ListResult %p move assigned from invalid ListResult %p." , this , &other);
213172 }
214173 return *this ;
215174}
0 commit comments