Skip to content

Commit 2293345

Browse files
authored
Make the app check debug provider use an internal class (#1120)
* Make the debug provider use an internal class * Format files * Remove unnecessary conditions
1 parent 5c44ca3 commit 2293345

File tree

9 files changed

+202
-38
lines changed

9 files changed

+202
-38
lines changed

app_check/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
set(common_SRCS
1919
src/common/app_check.cc
2020
src/common/common.h
21+
src/common/debug_provider_common.cc
2122
src/include/firebase/app_check.h
2223
src/include/firebase/app_check/debug_provider.h
2324
src/include/firebase/app_check/play_integrity_provider.h
@@ -32,6 +33,7 @@ set(android_SRCS
3233
src/android/app_check_android.h
3334
# Supported providers
3435
src/android/debug_provider_android.cc
36+
src/android/debug_provider_android.h
3537
src/android/play_integrity_provider_android.cc
3638
src/android/safety_net_provider_android.cc
3739
# Unsupported providers
@@ -46,6 +48,7 @@ set(ios_SRCS
4648
# Supported providers
4749
src/ios/app_attest_provider_ios.mm
4850
src/ios/debug_provider_ios.mm
51+
src/ios/debug_provider_ios.h
4952
src/ios/device_check_provider_ios.mm
5053
# Unsupported providers
5154
src/stub/play_integrity_provider_stub.cc
@@ -58,6 +61,7 @@ set(desktop_SRCS
5861
src/desktop/app_check_desktop.h
5962
# Supported providers
6063
src/desktop/debug_provider_desktop.cc
64+
src/desktop/debug_provider_desktop.h
6165
# Unsupported providers
6266
src/stub/app_attest_provider_stub.cc
6367
src/stub/device_check_provider_stub.cc

app_check/src/android/debug_provider_android.cc

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "app_check/src/android/debug_provider_android.h"
16+
1517
#include "firebase/app_check/debug_provider.h"
1618

1719
namespace firebase {
1820
namespace app_check {
21+
namespace internal {
1922

20-
static DebugAppCheckProviderFactory* g_debug_app_check_provider_factory =
21-
nullptr;
22-
23-
DebugAppCheckProviderFactory* DebugAppCheckProviderFactory::GetInstance() {
24-
if (!g_debug_app_check_provider_factory) {
25-
g_debug_app_check_provider_factory = new DebugAppCheckProviderFactory();
26-
}
27-
return g_debug_app_check_provider_factory;
28-
}
29-
30-
DebugAppCheckProviderFactory::DebugAppCheckProviderFactory() {}
23+
DebugAppCheckProviderFactoryInternal::DebugAppCheckProviderFactoryInternal() {}
3124

32-
DebugAppCheckProviderFactory::~DebugAppCheckProviderFactory() {}
25+
DebugAppCheckProviderFactoryInternal::~DebugAppCheckProviderFactoryInternal() {}
3326

34-
AppCheckProvider* DebugAppCheckProviderFactory::CreateProvider(App* app) {
27+
AppCheckProvider* DebugAppCheckProviderFactoryInternal::CreateProvider(
28+
App* app) {
3529
return nullptr;
3630
}
3731

32+
} // namespace internal
3833
} // namespace app_check
3934
} // namespace firebase
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIREBASE_APP_CHECK_SRC_ANDROID_DEBUG_PROVIDER_ANDROID_H_
16+
#define FIREBASE_APP_CHECK_SRC_ANDROID_DEBUG_PROVIDER_ANDROID_H_
17+
18+
#include "firebase/app_check.h"
19+
20+
namespace firebase {
21+
namespace app_check {
22+
namespace internal {
23+
24+
class DebugAppCheckProviderFactoryInternal : public AppCheckProviderFactory {
25+
public:
26+
DebugAppCheckProviderFactoryInternal();
27+
28+
virtual ~DebugAppCheckProviderFactoryInternal();
29+
30+
AppCheckProvider* CreateProvider(App* app) override;
31+
};
32+
33+
} // namespace internal
34+
} // namespace app_check
35+
} // namespace firebase
36+
37+
#endif // FIREBASE_APP_CHECK_SRC_ANDROID_DEBUG_PROVIDER_ANDROID_H_
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "firebase/app_check/debug_provider.h"
16+
17+
// Include the header that matches the platform being used.
18+
#if FIREBASE_PLATFORM_ANDROID
19+
#include "app_check/src/android/debug_provider_android.h"
20+
#elif FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
21+
#include "app_check/src/ios/debug_provider_ios.h"
22+
#else
23+
#include "app_check/src/desktop/debug_provider_desktop.h"
24+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS,
25+
// FIREBASE_PLATFORM_TVOS
26+
27+
namespace firebase {
28+
namespace app_check {
29+
30+
static DebugAppCheckProviderFactory* g_debug_app_check_provider_factory =
31+
nullptr;
32+
33+
DebugAppCheckProviderFactory* DebugAppCheckProviderFactory::GetInstance() {
34+
if (!g_debug_app_check_provider_factory) {
35+
g_debug_app_check_provider_factory = new DebugAppCheckProviderFactory();
36+
}
37+
return g_debug_app_check_provider_factory;
38+
}
39+
40+
DebugAppCheckProviderFactory::DebugAppCheckProviderFactory()
41+
: internal_(new internal::DebugAppCheckProviderFactoryInternal()) {}
42+
43+
DebugAppCheckProviderFactory::~DebugAppCheckProviderFactory() {
44+
if (internal_) {
45+
delete internal_;
46+
internal_ = nullptr;
47+
}
48+
}
49+
50+
AppCheckProvider* DebugAppCheckProviderFactory::CreateProvider(App* app) {
51+
if (internal_) {
52+
return internal_->CreateProvider(app);
53+
}
54+
return nullptr;
55+
}
56+
57+
} // namespace app_check
58+
} // namespace firebase

app_check/src/desktop/debug_provider_desktop.cc

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "app_check/src/desktop/debug_provider_desktop.h"
16+
1517
#include "firebase/app_check/debug_provider.h"
1618

1719
namespace firebase {
1820
namespace app_check {
21+
namespace internal {
1922

20-
static DebugAppCheckProviderFactory* g_debug_app_check_provider_factory =
21-
nullptr;
22-
23-
DebugAppCheckProviderFactory* DebugAppCheckProviderFactory::GetInstance() {
24-
if (!g_debug_app_check_provider_factory) {
25-
g_debug_app_check_provider_factory = new DebugAppCheckProviderFactory();
26-
}
27-
return g_debug_app_check_provider_factory;
28-
}
29-
30-
DebugAppCheckProviderFactory::DebugAppCheckProviderFactory() {}
23+
DebugAppCheckProviderFactoryInternal::DebugAppCheckProviderFactoryInternal() {}
3124

32-
DebugAppCheckProviderFactory::~DebugAppCheckProviderFactory() {}
25+
DebugAppCheckProviderFactoryInternal::~DebugAppCheckProviderFactoryInternal() {}
3326

34-
AppCheckProvider* DebugAppCheckProviderFactory::CreateProvider(App* app) {
27+
AppCheckProvider* DebugAppCheckProviderFactoryInternal::CreateProvider(
28+
App* app) {
3529
return nullptr;
3630
}
3731

32+
} // namespace internal
3833
} // namespace app_check
3934
} // namespace firebase
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIREBASE_APP_CHECK_SRC_DESKTOP_DEBUG_PROVIDER_DESKTOP_H_
16+
#define FIREBASE_APP_CHECK_SRC_DESKTOP_DEBUG_PROVIDER_DESKTOP_H_
17+
18+
#include "firebase/app_check.h"
19+
20+
namespace firebase {
21+
namespace app_check {
22+
namespace internal {
23+
24+
class DebugAppCheckProviderFactoryInternal : public AppCheckProviderFactory {
25+
public:
26+
DebugAppCheckProviderFactoryInternal();
27+
28+
virtual ~DebugAppCheckProviderFactoryInternal();
29+
30+
AppCheckProvider* CreateProvider(App* app) override;
31+
};
32+
33+
} // namespace internal
34+
} // namespace app_check
35+
} // namespace firebase
36+
37+
#endif // FIREBASE_APP_CHECK_SRC_DESKTOP_DEBUG_PROVIDER_DESKTOP_H_

app_check/src/include/firebase/app_check/debug_provider.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
namespace firebase {
2121
namespace app_check {
2222

23+
namespace internal {
24+
class DebugAppCheckProviderFactoryInternal;
25+
}
26+
2327
/// Implementation of an {@link AppCheckProviderFactory} that builds
2428
/// DebugAppCheckProviders.
2529
///
@@ -43,6 +47,8 @@ class DebugAppCheckProviderFactory : public AppCheckProviderFactory {
4347

4448
private:
4549
DebugAppCheckProviderFactory();
50+
51+
internal::DebugAppCheckProviderFactoryInternal* internal_;
4652
};
4753

4854
} // namespace app_check
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIREBASE_APP_CHECK_SRC_IOS_DEBUG_PROVIDER_IOS_H_
16+
#define FIREBASE_APP_CHECK_SRC_IOS_DEBUG_PROVIDER_IOS_H_
17+
18+
#include "firebase/app_check.h"
19+
20+
namespace firebase {
21+
namespace app_check {
22+
namespace internal {
23+
24+
class DebugAppCheckProviderFactoryInternal : public AppCheckProviderFactory {
25+
public:
26+
DebugAppCheckProviderFactoryInternal();
27+
28+
virtual ~DebugAppCheckProviderFactoryInternal();
29+
30+
AppCheckProvider* CreateProvider(App* app) override;
31+
};
32+
33+
} // namespace internal
34+
} // namespace app_check
35+
} // namespace firebase
36+
37+
#endif // FIREBASE_APP_CHECK_SRC_IOS_DEBUG_PROVIDER_IOS_H_

app_check/src/ios/debug_provider_ios.mm

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,20 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "app_check/src/ios/debug_provider_ios.h"
16+
1517
#include "firebase/app_check/debug_provider.h"
1618

1719
namespace firebase {
1820
namespace app_check {
21+
namespace internal {
1922

20-
static DebugAppCheckProviderFactory* g_debug_app_check_provider_factory = nullptr;
21-
22-
DebugAppCheckProviderFactory* DebugAppCheckProviderFactory::GetInstance() {
23-
if (!g_debug_app_check_provider_factory) {
24-
g_debug_app_check_provider_factory = new DebugAppCheckProviderFactory();
25-
}
26-
return g_debug_app_check_provider_factory;
27-
}
28-
29-
DebugAppCheckProviderFactory::DebugAppCheckProviderFactory() {}
23+
DebugAppCheckProviderFactoryInternal::DebugAppCheckProviderFactoryInternal() {}
3024

31-
DebugAppCheckProviderFactory::~DebugAppCheckProviderFactory() {}
25+
DebugAppCheckProviderFactoryInternal::~DebugAppCheckProviderFactoryInternal() {}
3226

33-
AppCheckProvider* DebugAppCheckProviderFactory::CreateProvider(App* app) { return nullptr; }
27+
AppCheckProvider* DebugAppCheckProviderFactoryInternal::CreateProvider(App* app) { return nullptr; }
3428

29+
} // namespace internal
3530
} // namespace app_check
3631
} // namespace firebase

0 commit comments

Comments
 (0)