11
11
#if FIREBASE_PLATFORM_ANDROID
12
12
#include " storage/src/android/list_result_android.h"
13
13
#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
15
14
#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
16
15
#include " storage/src/ios/list_result_ios.h"
17
16
#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
19
17
#else // Desktop
20
18
#include " storage/src/desktop/list_result_desktop.h"
21
19
#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
23
20
#endif
24
21
25
22
26
23
namespace firebase {
27
24
namespace storage {
28
25
29
26
// Forward declaration of the PIMPL class.
30
- // The actual definition comes from one of the platform headers included above.
31
27
namespace internal {
32
28
class 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
36
29
class StorageReferenceInternal ;
37
30
class StorageInternal ;
38
31
} // namespace internal
39
32
40
33
namespace internal {
41
34
42
35
// 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.
45
37
class ListResultInternalCommon {
46
38
public:
39
+ // Retrieves the StorageInternal context from the ListResultInternal object.
47
40
static StorageInternal* GetStorageInternalContext (
48
41
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().
54
44
StorageInternal* storage_ctx = pimpl_obj->associated_storage_internal ();
55
45
if (storage_ctx == nullptr ) {
56
46
LogWarning (" ListResultInternal %p has no associated StorageInternal for cleanup." , pimpl_obj);
57
47
}
58
48
return storage_ctx;
59
49
}
60
50
51
+ // Callback for CleanupNotifier, invoked when the App is being destroyed.
61
52
static void CleanupPublicListResultObject (void * public_obj_void) {
62
53
ListResult* public_obj = reinterpret_cast <ListResult*>(public_obj_void);
63
54
if (public_obj) {
64
- LogDebug (" CleanupPublicListResultObject called for ListResult %p via app cleanup ." , public_obj);
55
+ LogDebug (" CleanupNotifier: Cleaning up ListResult %p." , public_obj);
65
56
DeleteInternalPimpl (public_obj);
66
57
} else {
67
- LogWarning (" CleanupPublicListResultObject called with null object." );
58
+ LogWarning (" CleanupNotifier: CleanupPublicListResultObject called with null object." );
68
59
}
69
60
}
70
61
71
62
static void RegisterForCleanup (ListResult* public_obj,
72
63
ListResultInternal* pimpl_obj) {
73
64
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 ;
78
66
StorageInternal* storage_ctx = GetStorageInternalContext (pimpl_obj);
79
67
if (storage_ctx) {
80
68
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);
83
71
} 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);
86
74
}
87
75
}
88
76
89
77
static void UnregisterFromCleanup (ListResult* public_obj,
90
78
ListResultInternal* pimpl_obj) {
91
79
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 ;
96
81
StorageInternal* storage_ctx = GetStorageInternalContext (pimpl_obj);
97
82
if (storage_ctx) {
98
83
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);
101
86
} 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);
103
88
}
104
89
}
105
90
91
+ // Deletes the PIMPL object, unregisters from cleanup, and nulls the pointer in public_obj.
106
92
static void DeleteInternalPimpl (ListResult* public_obj) {
107
93
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
+
112
96
ListResultInternal* pimpl_to_delete = public_obj->internal_ ;
113
- // LogDebug("ListResult %p: Preparing to delete PIMPL %p.", public_obj, pimpl_to_delete);
114
97
UnregisterFromCleanup (public_obj, pimpl_to_delete);
115
98
public_obj->internal_ = nullptr ;
116
99
delete pimpl_to_delete;
117
- // LogDebug("PIMPL object %p deleted for ListResult %p.", pimpl_to_delete, public_obj);
118
100
}
119
101
};
120
102
@@ -127,34 +109,25 @@ const std::vector<StorageReference> ListResult::s_empty_prefixes_;
127
109
const std::string ListResult::s_empty_page_token_;
128
110
129
111
ListResult::ListResult () : internal_(nullptr ) {
130
- LogDebug (" ListResult %p default constructed (invalid)." , this );
131
112
}
132
113
133
114
ListResult::ListResult (internal::ListResultInternal* internal_pimpl)
134
115
: internal_(internal_pimpl) {
135
116
if (internal_) {
136
117
internal::ListResultInternalCommon::RegisterForCleanup (this , internal_);
137
- } else {
138
- LogWarning (" ListResult %p constructed with null PIMPL." , this );
139
118
}
140
119
}
141
120
142
121
ListResult::~ListResult () {
143
- LogDebug (" ListResult %p destructor, deleting PIMPL %p." , this , internal_);
144
122
internal::ListResultInternalCommon::DeleteInternalPimpl (this );
145
123
}
146
124
147
125
ListResult::ListResult (const ListResult& other) : internal_(nullptr ) {
148
126
if (other.internal_ ) {
149
127
internal::StorageReferenceInternal* sri_context =
150
128
other.internal_ ->storage_reference_internal ();
151
- // The second argument to ListResultInternal constructor is other.internal_ (for copying data)
152
129
internal_ = new internal::ListResultInternal (sri_context, other.internal_ );
153
130
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);
158
131
}
159
132
}
160
133
@@ -169,27 +142,17 @@ ListResult& ListResult::operator=(const ListResult& other) {
169
142
other.internal_ ->storage_reference_internal ();
170
143
internal_ = new internal::ListResultInternal (sri_context, other.internal_ );
171
144
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
177
145
}
178
146
return *this ;
179
147
}
180
148
181
149
#if defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN)
182
150
ListResult::ListResult (ListResult&& other) : internal_(other.internal_) {
183
- other.internal_ = nullptr ; // Other no longer owns the PIMPL.
151
+ other.internal_ = nullptr ;
184
152
if (internal_) {
185
153
// New public object 'this' takes ownership. Unregister 'other', register 'this'.
186
- // Pass 'internal_' (which is the original other.internal_) as context for unregistering 'other'.
187
154
internal::ListResultInternalCommon::UnregisterFromCleanup (&other, internal_);
188
155
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);
193
156
}
194
157
}
195
158
@@ -199,17 +162,13 @@ ListResult& ListResult::operator=(ListResult&& other) {
199
162
}
200
163
internal::ListResultInternalCommon::DeleteInternalPimpl (this ); // Clean up current
201
164
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 ;
204
167
205
168
if (internal_) {
206
169
// Similar to move constructor: unregister 'other', register 'this'.
207
170
internal::ListResultInternalCommon::UnregisterFromCleanup (&other, internal_);
208
171
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);
213
172
}
214
173
return *this ;
215
174
}
0 commit comments