[WRTjs][VD] Reduce IS_TIZEN_TV compile flag 68/305568/9
authorDongHyun Song <dh81.song@samsung.com>
Mon, 5 Feb 2024 06:37:55 +0000 (15:37 +0900)
committerBot Blink <blinkbot@samsung.com>
Thu, 8 Feb 2024 01:58:54 +0000 (01:58 +0000)
Reduce IS_TIZEN_TV compile flag of ApplicationData class
for code readability

Change-Id: I614018414f9b30c3478ab7c9a2fc829fd09e9936
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt/src/browser/tv/splash_screen_delegate_tv.cc [changed mode: 0644->0755]
wrt/src/browser/tv/video_splash_screen.cc
wrt/src/common/application_data.cc
wrt/src/common/application_data.h
wrt/src/common/tv/application_data_tv.cc [changed mode: 0644->0755]
wrt/src/common/tv/application_data_tv.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 3df9ff5..b2b459a
@@ -8,7 +8,7 @@
 
 #include "tizen_src/chromium_impl/tizen/vconf_handle.h"
 #include "wrt/src/browser/tv/video_splash_screen.h"
-#include "wrt/src/common/application_data.h"
+#include "wrt/src/common/tv/application_data_tv.h"
 
 namespace wrt {
 
@@ -39,7 +39,7 @@ std::string SplashScreenDelegateTV::ConvertAliasPath(std::string& image_path) {
 }
 
 bool SplashScreenDelegateTV::IsVideoPlaying() {
-  auto& app_data = ApplicationData::GetInstance();
+  auto& app_data = ApplicationDataTV::GetInstance();
   return app_data.video_splash_screen_info().HasVideoSplashScreenData() &&
          VideoSplashScreen::IsVSSPlaying();
 }
index 2e3f89a..63849eb 100644 (file)
@@ -10,6 +10,7 @@
 #include "wrt/src/browser/native_web_runtime.h"
 #include "wrt/src/browser/tv/widget_state.h"
 #include "wrt/src/browser/tv/wrt_native_window_tv.h"
+#include "wrt/src/common/tv/application_data_tv.h"
 
 namespace wrt {
 
@@ -72,7 +73,7 @@ int OnSplashScreenMessage(const char* endpoint,
 }
 
 bool ReleaseVSSCom() {
-  auto& app_data = ApplicationData::GetInstance();
+  auto& app_data = ApplicationDataTV::GetInstance();
 
   return (app_data.video_splash_screen_info().HasVideoSplashScreenData() &&
           !!aul_app_com_connection_ &&
@@ -103,7 +104,7 @@ void VideoSplashScreen::FinalizeVSS() {
 
 // static
 void VideoSplashScreen::InitializeVSS() {
-  auto& app_data = ApplicationData::GetInstance();
+  auto& app_data = ApplicationDataTV::GetInstance();
   if (!app_data.video_splash_screen_info().HasVideoSplashScreenData())
     return;
 
@@ -141,7 +142,7 @@ void VideoSplashScreen::Hide() {
 }
 
 wgt::parse::ReadyWhen VideoSplashScreen::GetReadyWhen() {
-  auto& app_data = ApplicationData::GetInstance();
+  auto& app_data = ApplicationDataTV::GetInstance();
   return app_data.video_splash_screen_info().ready_when();
 }
 
index ad1ddf5..696b825 100755 (executable)
@@ -23,7 +23,6 @@
 #include <tzplatform_config.h>
 #include <vector>
 #include <wgt_manifest_handlers/application_manifest_constants.h>
-#include <wgt_manifest_handlers/widget_config_parser.h>
 
 #include "base/command_line.h"
 #include "base/files/file_util.h"
 #if BUILDFLAG(IS_TIZEN_TV)
 #include "wrt/src/browser/tv/native_web_runtime_delegate_tv.h"
 #include "wrt/src/common/tv/application_data_tv.h"
+
+using ApplicationDataType = wrt::ApplicationDataTV;
+#else
+using ApplicationDataType = wrt::ApplicationData;
 #endif
 
 namespace wrt {
@@ -163,11 +166,7 @@ ApplicationData& ApplicationData::GetInstance() {
   if (!instance) {
     base::AutoLock lock(instance_lock_);
     if (!instance)  // double check to avoid create instance again
-#if BUILDFLAG(IS_TIZEN_TV)
-      instance = new ApplicationDataTV;
-#else
-      instance = new ApplicationData;
-#endif
+      instance = new ApplicationDataType;
   }
   return *instance;
 }
@@ -175,19 +174,10 @@ ApplicationData& ApplicationData::GetInstance() {
 // static
 ApplicationData* ApplicationData::Create(const std::string& service_id,
                                          const std::string& pkg_path) {
-#if BUILDFLAG(IS_TIZEN_TV)
-  return new ApplicationDataTV(service_id, pkg_path);
-#else
-  return new ApplicationData(service_id, pkg_path);
-#endif
+  return new ApplicationDataType(service_id, pkg_path);
 }
 
-bool ApplicationData::Initialize() {
-  if (initialized_)
-    return true;
-
-  SCOPE_PROFILE();
-  base::AutoLock lock(data_lock_);
+void ApplicationData::ParseAndSetManifestData() {
   base::FilePath config_xml_path;
   if (!backup_config_xml_.empty()) {
     config_xml_path = backup_config_xml_;
@@ -196,7 +186,7 @@ bool ApplicationData::Initialize() {
     if (!base::PathExists(config_xml_path)) {
       LOG(ERROR) << "Failed to load manifest data : No such file '"
                  << config_xml_path << "'.";
-      return false;
+      return;
     }
   }
 
@@ -205,7 +195,7 @@ bool ApplicationData::Initialize() {
   if (!widget_config_parser->ParseManifest(config_xml_path.value())) {
     LOG(ERROR) << "Failed to load widget config parser data: "
                   << widget_config_parser->GetErrorMessage();
-    return false;
+    return;
   }
 
   tizen_application_info_.SetImpl(
@@ -252,13 +242,6 @@ bool ApplicationData::Initialize() {
           widget_config_parser->GetManifestData(
               wgt::parse::LaunchScreenInfo::Key())));
 
-#if BUILDFLAG(IS_TIZEN_TV)
-  video_splash_screen_info_.SetImpl(
-      std::static_pointer_cast<const wgt::parse::VideoSplashScreenInfo>(
-          widget_config_parser->GetManifestData(
-              wgt::parse::VideoSplashScreenInfo::Key())));
-#endif
-
   meta_data_info_.SetImpl(
       std::static_pointer_cast<const wgt::parse::MetaDataInfo>(
           widget_config_parser->GetManifestData(
@@ -291,6 +274,17 @@ bool ApplicationData::Initialize() {
   widget_info_.SetImpl(std::static_pointer_cast<const wgt::parse::WidgetInfo>(
       widget_config_parser->GetManifestData(wgt::parse::WidgetInfo::Key())));
 
+  if (delegate_)
+    delegate_->ParseAndSetManifestData(widget_config_parser.get());
+}
+
+bool ApplicationData::Initialize() {
+  if (initialized_)
+    return true;
+
+  SCOPE_PROFILE();
+  base::AutoLock lock(data_lock_);
+  ParseAndSetManifestData();
   app_type_ = GetAppType();
 
   std::string src = content_info_.src();
@@ -470,17 +464,23 @@ const std::string ApplicationData::GetServiceID(const std::string& internal_id)
 }
 
 // static
+const std::string ApplicationData::GetUpgradableWrtjsPath() {
+  std::string wrt_upgraded_tpk_res_path =
+      std::string(tzplatform_getenv(TZ_SYS_RW_APP)) + kWrtUpgradedTpkResPath;
+  if (utils::Exists(wrt_upgraded_tpk_res_path.c_str()))
+    return wrt_upgraded_tpk_res_path;
+  else
+    return std::string();
+}
+
+// static
 const std::string ApplicationData::GetWrtResPath() {
-#if BUILDFLAG(IS_TIZEN_TV)
-  wrt_res_path_ = ApplicationDataTV::GetWrtResPath();
-#endif
   if (wrt_res_path_.empty()) {
-    std::string wrt_upgraded_tpk_res_path =
-        std::string(tzplatform_getenv(TZ_SYS_RW_APP)) + kWrtUpgradedTpkResPath;
-    if (utils::Exists(wrt_upgraded_tpk_res_path.c_str())) {
-      return wrt_res_path_ = wrt_upgraded_tpk_res_path;
-    }
-    wrt_res_path_ = kWrtPreloadedResPath;
+    auto upgradable_wrtjs_path = ApplicationDataType::GetUpgradableWrtjsPath();
+    if (upgradable_wrtjs_path.empty())
+      wrt_res_path_ = kWrtPreloadedResPath;
+    else
+      wrt_res_path_ = upgradable_wrtjs_path;
   }
   return wrt_res_path_;
 }
index 82ca909..291a375 100755 (executable)
@@ -19,6 +19,8 @@
 
 #include <unordered_map>
 
+#include <wgt_manifest_handlers/widget_config_parser.h>
+
 #include "base/files/file_path.h"
 #include "wrt/src/common/application_data_wrapper.h"
 
@@ -26,6 +28,14 @@ namespace wrt {
 
 class NativeAppControl;
 
+class ApplicationDataDelegate {
+ public:
+  ApplicationDataDelegate() = default;
+  ~ApplicationDataDelegate() = default;
+
+  virtual void ParseAndSetManifestData(wgt::parse::WidgetConfigParser* parser) {}
+};
+
 class ApplicationData {
  public:
   enum AppType { UI = 0, IME, WATCH, SERVICE };
@@ -39,6 +49,10 @@ class ApplicationData {
   static ApplicationData* Create(const std::string& service_id,
                                  const std::string& pkg_path);
   bool Initialize();
+  void ParseAndSetManifestData();
+  void SetDelegate(ApplicationDataDelegate* delegate) {
+    delegate_ = delegate;
+  }
 
   const AllowedNavigationInfo& allowed_navigation_info() const {
     return allowed_navigation_info_;
@@ -61,11 +75,6 @@ class ApplicationData {
   const LaunchScreenInfo& launch_screen_info() const {
     return launch_screen_info_;
   }
-#if BUILDFLAG(IS_TIZEN_TV)
-  const VideoSplashScreenInfo& video_splash_screen_info() const {
-    return video_splash_screen_info_;
-  }
-#endif
   const MetaDataInfo& meta_data_info() const {
     return meta_data_info_;
   }
@@ -114,6 +123,7 @@ class ApplicationData {
 
   static const std::string GetPackagePath(const std::string& app_id);
   static const std::string GetServiceID(const std::string& internal_id);
+  static const std::string GetUpgradableWrtjsPath();
   static const std::string GetWrtResPath();
   static bool IsServiceApp();
   static void SetServiceApp();
@@ -181,10 +191,8 @@ class ApplicationData {
   mutable std::string pkg_id_;
   ApplicationData::AppType app_type_;
   std::unordered_map<std::string, std::string> metadata_;
-#if BUILDFLAG(IS_TIZEN_TV)
-  VideoSplashScreenInfo video_splash_screen_info_;
-#endif
   base::FilePath backup_config_xml_;
+  ApplicationDataDelegate* delegate_ = nullptr;
 };
 
 }  // namespace wrt
old mode 100644 (file)
new mode 100755 (executable)
index c5172a5..b97cc37
@@ -43,7 +43,9 @@ ApplicationDataTV::ApplicationDataTV() {
 
   LOG(INFO) << "user_data_path_ : " << user_data_path_;
   LOG(INFO) << "backup_config_xml_ : " << backup_config_xml_;
+  SetDelegate(this);
   Initialize();
+  SetDelegate(nullptr);
 }
 
 ApplicationDataTV::ApplicationDataTV(const std::string& app_id,
@@ -56,8 +58,15 @@ ApplicationDataTV::ApplicationDataTV(const std::string& app_id,
   backup_config_xml_ = GetBackupConfigXml(application_path_);
 }
 
+void ApplicationDataTV::ParseAndSetManifestData(
+    wgt::parse::WidgetConfigParser* parser) {
+  video_splash_screen_info_.SetImpl(
+      std::static_pointer_cast<const wgt::parse::VideoSplashScreenInfo>(
+          parser->GetManifestData(wgt::parse::VideoSplashScreenInfo::Key())));
+}
+
 // static
-std::string ApplicationDataTV::GetWrtResPath() {
+const std::string ApplicationDataTV::GetUpgradableWrtjsPath() {
   std::string wrt_upgraded_tpk_res_path =
       std::string(CHROMIUM_RO_ROOT_DIR) + kWrtUpgradedTpkResPath;
   base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
@@ -78,16 +87,14 @@ std::string ApplicationDataTV::GetWrtResPath() {
 bool ApplicationDataTV::HasWidgetLicense() {
   if (widget_license_exist_.has_value())
     return widget_license_exist_.value();
-  auto application_path = ApplicationData::GetInstance().application_path();
   auto path =
-      base::FilePath(application_path).DirName().Append(kWidgetLicense);
+      base::FilePath(application_path()).DirName().Append(kWidgetLicense);
   widget_license_exist_ = base::PathExists(path);
   return widget_license_exist_.value();
 }
 
 std::string ApplicationDataTV::PointDeviceOption() {
-  auto& setting_info = ApplicationData::GetInstance().setting_info();
-  return setting_info.pointing_device_option();
+  return setting_info().pointing_device_option();
 }
 
 // static
old mode 100644 (file)
new mode 100755 (executable)
index 28d5e19..16b8ea0
 
 namespace wrt {
 
-class ApplicationDataTV : public ApplicationData {
+class ApplicationDataTV : public ApplicationData,
+                          public ApplicationDataDelegate {
  public:
   static ApplicationDataTV& GetInstance();
-  static std::string GetWrtResPath();
+  static const std::string GetUpgradableWrtjsPath();
 
   ApplicationDataTV();
   explicit ApplicationDataTV(const std::string& app_id,
@@ -24,8 +25,16 @@ class ApplicationDataTV : public ApplicationData {
   bool HasWidgetLicense();
   std::string PointDeviceOption();
 
+  const VideoSplashScreenInfo& video_splash_screen_info() const {
+    return video_splash_screen_info_;
+  }
+
  private:
+  // ApplicationDataDelegate
+  void ParseAndSetManifestData(wgt::parse::WidgetConfigParser* parser) override;
+
   absl::optional<bool> widget_license_exist_;
+  VideoSplashScreenInfo video_splash_screen_info_;
 };
 
 }  // namespace wrt