Skip to content

Commit 4983f37

Browse files
cynthiajianga-maurice
authored andcommitted
[RemoteConfig]V2 - rename class RemoteConfigDesktop to RemoteConfigInternal, for PIMPL pattern refactor
The pattern will be remote_config.h - public class RemoteConfig, holds instance of RemoteConfigInternal, which is same class declare but different impl in different platforms. Add remote_config_android.h - declare RemoteConfigInternal Add remote_config_ios.h - declare RemoteConfigInternal In remote_config_desktop.h - this RemoteConfigDesktop class is basically doing exactly RemoteConfigInternal class supposed to do, so want to do rename as the first step. Basically following https://en.cppreference.com/w/cpp/language/pimpl and use storage as example. PiperOrigin-RevId: 283403688
1 parent 1051bc5 commit 4983f37

File tree

4 files changed

+48
-53
lines changed

4 files changed

+48
-53
lines changed

remote_config/src/desktop/remote_config.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace firebase {
2828
namespace remote_config {
2929

3030
static const char* kFilePath = "remote_config_data";
31-
static internal::RemoteConfigDesktop* g_remote_config_desktop_instance =
31+
static internal::RemoteConfigInternal* g_remote_config_desktop_instance =
3232
nullptr;
3333
static internal::RemoteConfigFileManager* g_file_manager = nullptr;
3434

@@ -46,7 +46,7 @@ InitResult Initialize(const App& app) {
4646
}
4747
FutureData::Create();
4848
g_remote_config_desktop_instance =
49-
new internal::RemoteConfigDesktop(app, *g_file_manager);
49+
new internal::RemoteConfigInternal(app, *g_file_manager);
5050
}
5151
internal::RegisterTerminateOnDefaultAppDestroy();
5252
return kInitResultSuccess;

remote_config/src/desktop/remote_config_desktop.cc

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ namespace firebase {
4040
namespace remote_config {
4141
namespace internal {
4242

43-
const char* const RemoteConfigDesktop::kDefaultNamespace = "configns:firebase";
44-
const char* const RemoteConfigDesktop::kDefaultValueForString = "";
45-
const int64_t RemoteConfigDesktop::kDefaultValueForLong = 0L;
46-
const double RemoteConfigDesktop::kDefaultValueForDouble = 0.0;
47-
const bool RemoteConfigDesktop::kDefaultValueForBool = false;
43+
const char* const RemoteConfigInternal::kDefaultNamespace = "configns:firebase";
44+
const char* const RemoteConfigInternal::kDefaultValueForString = "";
45+
const int64_t RemoteConfigInternal::kDefaultValueForLong = 0L;
46+
const double RemoteConfigInternal::kDefaultValueForDouble = 0.0;
47+
const bool RemoteConfigInternal::kDefaultValueForBool = false;
4848

49-
RemoteConfigDesktop::RemoteConfigDesktop(
49+
RemoteConfigInternal::RemoteConfigInternal(
5050
const firebase::App& app, const RemoteConfigFileManager& file_manager)
5151
: app_(app),
5252
file_manager_(file_manager),
@@ -56,7 +56,7 @@ RemoteConfigDesktop::RemoteConfigDesktop(
5656
AsyncFetch();
5757
}
5858

59-
RemoteConfigDesktop::~RemoteConfigDesktop() {
59+
RemoteConfigInternal::~RemoteConfigInternal() {
6060
fetch_channel_.Close();
6161
if (fetch_thread_.joinable()) {
6262
fetch_thread_.join();
@@ -68,7 +68,7 @@ RemoteConfigDesktop::~RemoteConfigDesktop() {
6868
}
6969
}
7070

71-
void RemoteConfigDesktop::AsyncSaveToFile() {
71+
void RemoteConfigInternal::AsyncSaveToFile() {
7272
save_thread_ = std::thread([this]() {
7373
while (save_channel_.Get()) {
7474
LayeredConfigs copy;
@@ -81,8 +81,8 @@ void RemoteConfigDesktop::AsyncSaveToFile() {
8181
});
8282
}
8383

84-
std::string RemoteConfigDesktop::VariantToString(const Variant& variant,
85-
bool* failure) {
84+
std::string RemoteConfigInternal::VariantToString(const Variant& variant,
85+
bool* failure) {
8686
if (variant.is_blob()) {
8787
const uint8_t* blob_data = variant.blob_data();
8888
size_t blob_size = variant.blob_size();
@@ -103,8 +103,8 @@ std::string RemoteConfigDesktop::VariantToString(const Variant& variant,
103103
}
104104

105105
#ifndef SWIG
106-
void RemoteConfigDesktop::SetDefaults(const ConfigKeyValueVariant* defaults,
107-
size_t number_of_defaults) {
106+
void RemoteConfigInternal::SetDefaults(const ConfigKeyValueVariant* defaults,
107+
size_t number_of_defaults) {
108108
if (defaults == nullptr) {
109109
return;
110110
}
@@ -121,8 +121,8 @@ void RemoteConfigDesktop::SetDefaults(const ConfigKeyValueVariant* defaults,
121121
}
122122
#endif // SWIG
123123

124-
void RemoteConfigDesktop::SetDefaults(const ConfigKeyValue* defaults,
125-
size_t number_of_defaults) {
124+
void RemoteConfigInternal::SetDefaults(const ConfigKeyValue* defaults,
125+
size_t number_of_defaults) {
126126
if (defaults == nullptr) {
127127
return;
128128
}
@@ -137,7 +137,7 @@ void RemoteConfigDesktop::SetDefaults(const ConfigKeyValue* defaults,
137137
SetDefaults(defaults_map);
138138
}
139139

140-
void RemoteConfigDesktop::SetDefaults(
140+
void RemoteConfigInternal::SetDefaults(
141141
const std::map<std::string, std::string>& defaults_map) {
142142
{
143143
std::unique_lock<std::mutex> lock(mutex_);
@@ -146,13 +146,13 @@ void RemoteConfigDesktop::SetDefaults(
146146
save_channel_.Put();
147147
}
148148

149-
std::string RemoteConfigDesktop::GetConfigSetting(ConfigSetting setting) {
149+
std::string RemoteConfigInternal::GetConfigSetting(ConfigSetting setting) {
150150
std::unique_lock<std::mutex> lock(mutex_);
151151
return configs_.metadata.GetSetting(setting);
152152
}
153153

154-
void RemoteConfigDesktop::SetConfigSetting(ConfigSetting setting,
155-
const char* value) {
154+
void RemoteConfigInternal::SetConfigSetting(ConfigSetting setting,
155+
const char* value) {
156156
if (value == nullptr) {
157157
return;
158158
}
@@ -163,19 +163,18 @@ void RemoteConfigDesktop::SetConfigSetting(ConfigSetting setting,
163163
save_channel_.Put();
164164
}
165165

166-
bool RemoteConfigDesktop::CheckValueInActiveAndDefault(const char* key,
167-
ValueInfo* info,
168-
std::string* value) {
166+
bool RemoteConfigInternal::CheckValueInActiveAndDefault(const char* key,
167+
ValueInfo* info,
168+
std::string* value) {
169169
return CheckValueInConfig(configs_.active, kValueSourceRemoteValue, key, info,
170170
value) ||
171171
CheckValueInConfig(configs_.defaults, kValueSourceDefaultValue, key,
172172
info, value);
173173
}
174174

175-
bool RemoteConfigDesktop::CheckValueInConfig(const NamespacedConfigData& config,
176-
ValueSource source,
177-
const char* key, ValueInfo* info,
178-
std::string* value) {
175+
bool RemoteConfigInternal::CheckValueInConfig(
176+
const NamespacedConfigData& config, ValueSource source, const char* key,
177+
ValueInfo* info, std::string* value) {
179178
if (!key) return false;
180179

181180
{
@@ -191,19 +190,19 @@ bool RemoteConfigDesktop::CheckValueInConfig(const NamespacedConfigData& config,
191190
return true;
192191
}
193192

194-
bool RemoteConfigDesktop::IsBoolTrue(const std::string& str) {
193+
bool RemoteConfigInternal::IsBoolTrue(const std::string& str) {
195194
// regex: ^(1|true|t|yes|y|on)$
196195
return str == "1" || str == "true" || str == "t" || str == "yes" ||
197196
str == "y" || str == "on";
198197
}
199198

200-
bool RemoteConfigDesktop::IsBoolFalse(const std::string& str) {
199+
bool RemoteConfigInternal::IsBoolFalse(const std::string& str) {
201200
// regex: ^(0|false|f|no|n|off)$
202201
return str == "0" || str == "false" || str == "f" || str == "no" ||
203202
str == "n" || str == "off";
204203
}
205204

206-
bool RemoteConfigDesktop::IsLong(const std::string& str) {
205+
bool RemoteConfigInternal::IsLong(const std::string& str) {
207206
// regex: ^[-+]?[0-9]+$
208207
// Don't allow empty string.
209208
if (str.length() == 0) return false;
@@ -214,7 +213,7 @@ bool RemoteConfigDesktop::IsLong(const std::string& str) {
214213
return (*endptr == '\0'); // Ensure we consumed the whole string.
215214
}
216215

217-
bool RemoteConfigDesktop::IsDouble(const std::string& str) {
216+
bool RemoteConfigInternal::IsDouble(const std::string& str) {
218217
// regex: ^[-+]?[0-9]*.?[0-9]+([eE][-+]?[0-9]+)?
219218
// Don't allow empty string.
220219
if (str.length() == 0) return false;
@@ -225,8 +224,7 @@ bool RemoteConfigDesktop::IsDouble(const std::string& str) {
225224
return (*endptr == '\0'); // Ensure we consumed the whole string.
226225
}
227226

228-
bool RemoteConfigDesktop::GetBoolean(const char* key,
229-
ValueInfo* info) {
227+
bool RemoteConfigInternal::GetBoolean(const char* key, ValueInfo* info) {
230228
std::string value;
231229
if (!CheckValueInActiveAndDefault(key, info, &value)) {
232230
if (info) {
@@ -248,8 +246,7 @@ bool RemoteConfigDesktop::GetBoolean(const char* key,
248246
return kDefaultValueForBool;
249247
}
250248

251-
std::string RemoteConfigDesktop::GetString(const char* key,
252-
ValueInfo* info) {
249+
std::string RemoteConfigInternal::GetString(const char* key, ValueInfo* info) {
253250
std::string value;
254251
if (!CheckValueInActiveAndDefault(key, info, &value)) {
255252
if (info) {
@@ -263,8 +260,7 @@ std::string RemoteConfigDesktop::GetString(const char* key,
263260
return value;
264261
}
265262

266-
int64_t RemoteConfigDesktop::GetLong(const char* key,
267-
ValueInfo* info) {
263+
int64_t RemoteConfigInternal::GetLong(const char* key, ValueInfo* info) {
268264
std::string value;
269265
if (!CheckValueInActiveAndDefault(key, info, &value)) {
270266
if (info) {
@@ -286,8 +282,7 @@ int64_t RemoteConfigDesktop::GetLong(const char* key,
286282
return convertation_failure ? kDefaultValueForLong : long_value;
287283
}
288284

289-
double RemoteConfigDesktop::GetDouble(const char* key,
290-
ValueInfo* info) {
285+
double RemoteConfigInternal::GetDouble(const char* key, ValueInfo* info) {
291286
std::string value;
292287
if (!CheckValueInActiveAndDefault(key, info, &value)) {
293288
if (info) {
@@ -309,8 +304,8 @@ double RemoteConfigDesktop::GetDouble(const char* key,
309304
return convertation_failure ? kDefaultValueForDouble : double_value;
310305
}
311306

312-
std::vector<unsigned char> RemoteConfigDesktop::GetData(const char* key,
313-
ValueInfo* info) {
307+
std::vector<unsigned char> RemoteConfigInternal::GetData(const char* key,
308+
ValueInfo* info) {
314309
std::string value;
315310
if (!CheckValueInActiveAndDefault(key, info, &value)) {
316311
if (info) {
@@ -329,11 +324,11 @@ std::vector<unsigned char> RemoteConfigDesktop::GetData(const char* key,
329324
return data_value;
330325
}
331326

332-
std::vector<std::string> RemoteConfigDesktop::GetKeys() {
327+
std::vector<std::string> RemoteConfigInternal::GetKeys() {
333328
return GetKeysByPrefix("");
334329
}
335330

336-
std::vector<std::string> RemoteConfigDesktop::GetKeysByPrefix(
331+
std::vector<std::string> RemoteConfigInternal::GetKeysByPrefix(
337332
const char* prefix) {
338333
if (prefix == nullptr) return std::vector<std::string>();
339334
std::set<std::string> unique_keys;
@@ -345,7 +340,7 @@ std::vector<std::string> RemoteConfigDesktop::GetKeysByPrefix(
345340
return std::vector<std::string>(unique_keys.begin(), unique_keys.end());
346341
}
347342

348-
bool RemoteConfigDesktop::ActivateFetched() {
343+
bool RemoteConfigInternal::ActivateFetched() {
349344
{
350345
std::unique_lock<std::mutex> lock(mutex_);
351346
// Fetched config not found or already activated.
@@ -357,12 +352,12 @@ bool RemoteConfigDesktop::ActivateFetched() {
357352
return true;
358353
}
359354

360-
const ConfigInfo& RemoteConfigDesktop::GetInfo() const {
355+
const ConfigInfo& RemoteConfigInternal::GetInfo() const {
361356
std::unique_lock<std::mutex> lock(mutex_);
362357
return configs_.metadata.info();
363358
}
364359

365-
void RemoteConfigDesktop::AsyncFetch() {
360+
void RemoteConfigInternal::AsyncFetch() {
366361
fetch_thread_ = std::thread([this]() {
367362
SafeFutureHandle<void> handle;
368363
while (fetch_channel_.Get()) {
@@ -404,7 +399,7 @@ void RemoteConfigDesktop::AsyncFetch() {
404399
});
405400
}
406401

407-
Future<void> RemoteConfigDesktop::Fetch(uint64_t cache_expiration_in_seconds) {
402+
Future<void> RemoteConfigInternal::Fetch(uint64_t cache_expiration_in_seconds) {
408403
std::unique_lock<std::mutex> lock(mutex_);
409404

410405
uint64_t milliseconds_since_epoch =
@@ -433,7 +428,7 @@ Future<void> RemoteConfigDesktop::Fetch(uint64_t cache_expiration_in_seconds) {
433428
return FetchLastResult();
434429
}
435430

436-
Future<void> RemoteConfigDesktop::FetchLastResult() {
431+
Future<void> RemoteConfigInternal::FetchLastResult() {
437432
ReferenceCountedFutureImpl* api = FutureData::Get()->api();
438433
return static_cast<const Future<void>&>(
439434
api->LastResult(kRemoteConfigFnFetch));

remote_config/src/desktop/remote_config_desktop.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace internal {
4343
//
4444
// This class implements functions from `firebase/remote_config.h` header.
4545
// See `firebase/remote_config.h` for all public functions documentation.
46-
class RemoteConfigDesktop {
46+
class RemoteConfigInternal {
4747
public:
4848
#ifdef FIREBASE_TESTING
4949
friend class RemoteConfigDesktopTest;
@@ -63,9 +63,9 @@ class RemoteConfigDesktop {
6363
FRIEND_TEST(RemoteConfigDesktopTest, Fetch);
6464
#endif // FIREBASE_TESTING
6565

66-
explicit RemoteConfigDesktop(const firebase::App& app,
67-
const RemoteConfigFileManager& file_manager);
68-
~RemoteConfigDesktop();
66+
explicit RemoteConfigInternal(const firebase::App& app,
67+
const RemoteConfigFileManager& file_manager);
68+
~RemoteConfigInternal();
6969

7070
#ifndef SWIG
7171
void SetDefaults(const ConfigKeyValueVariant* defaults,

remote_config/src/desktop/rest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void WaitForFuture(const Future<std::string>& future, Semaphore* future_sem,
100100
}
101101

102102
void RemoteConfigREST::TryGetInstanceIdAndToken(const App& app) {
103-
// Convert the app reference stored in RemoteConfigDesktop
103+
// Convert the app reference stored in RemoteConfigInternal
104104
// pointer for InstanceIdDesktopImpl.
105105
App* non_const_app = const_cast<App*>(&app);
106106
auto* iid_impl =

0 commit comments

Comments
 (0)