1414 * limitations under the License.
1515 */
1616
17+ #include " app/src/app_desktop.h"
18+
1719#include < string.h>
1820
1921#include < fstream>
22+ #include < memory>
23+ #include < string>
2024
2125#include " app/src/app_common.h"
2226#include " app/src/function_registry.h"
27+ #include " app/src/heartbeat/heartbeat_controller_desktop.h"
2328#include " app/src/include/firebase/app.h"
2429#include " app/src/include/firebase/internal/common.h"
2530#include " app/src/include/firebase/version.h"
2934namespace firebase {
3035DEFINE_FIREBASE_VERSION_STRING (Firebase);
3136
32- namespace internal {
33-
34- class AppInternal {
35- public:
36- // A registry that modules can use to expose functions to each other, without
37- // requiring a linkage dependency.
38- // todo - make all the implementations use something like this, for internal
39- // or implementation-specific code. b/70229654
40- FunctionRegistry function_registry;
41- };
42-
43- // When Create() is invoked without arguments, it checks for a file named
44- // google-services-desktop.json, to load options from. This specifies the
45- // path to search.
46- static std::string g_default_config_path; // NOLINT
47-
48- } // namespace internal
49-
5037namespace {
5138
5239// Size is arbitrary, just making sure that there is a sane limit.
@@ -150,6 +137,15 @@ App* App::Create(const AppOptions& options, const char* name) { // NOLINT
150137 app->name_ = name;
151138 app->options_ = options_with_defaults;
152139 app = app_common::AddApp (app, &app->init_results_ );
140+ app->internal_ ->heartbeat_controller_ =
141+ std::make_shared<heartbeat::HeartbeatController>(
142+ name, *app_common::FindAppLoggerByName (name),
143+ app->internal_ ->date_provider_ );
144+ #ifndef SWIG
145+ // Log a heartbeat after creating an App. In the Unity SDK this will happen
146+ // at a later time, after additional user agents have been registered.
147+ app->internal_ ->heartbeat_controller_ ->LogHeartbeat ();
148+ #endif // SWIG
153149 }
154150 return app;
155151}
@@ -166,7 +162,7 @@ App* App::GetInstance(const char* name) { // NOLINT
166162internal::FunctionRegistry* App::function_registry () {
167163 return &internal_->function_registry ;
168164}
169- #endif
165+ #endif // INTERNAL_EXPERIMENTAL
170166
171167void App::RegisterLibrary (const char * library, const char * version) {
172168 app_common::RegisterLibrary (library, version);
@@ -191,6 +187,21 @@ void App::SetDefaultConfigPath(const char* path) {
191187 }
192188}
193189
190+ void App::LogHeartbeat () const {
191+ if (internal_ != nullptr && internal_->heartbeat_controller_ ) {
192+ internal_->heartbeat_controller_ ->LogHeartbeat ();
193+ }
194+ }
195+
196+ std::shared_ptr<heartbeat::HeartbeatController> App::GetHeartbeatController ()
197+ const {
198+ if (internal_ != nullptr ) {
199+ return internal_->heartbeat_controller_ ;
200+ } else {
201+ return std::shared_ptr<heartbeat::HeartbeatController>();
202+ }
203+ }
204+
194205// Desktop support is for developer workflow only, so automatic data collection
195206// is always enabled.
196207void App::SetDataCollectionDefaultEnabled (bool /* enabled */ ) {}
0 commit comments