From: Sangyoon Jang Date: Tue, 16 Jun 2020 06:44:45 +0000 (+0900) Subject: Refactor theme plugin X-Git-Tag: submit/tizen/20200618.082339~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e1cd34a57fd5000ca1224b8b51ebe23e697fc1b;p=platform%2Fcore%2Fappfw%2Ftizen-theme-manager.git Refactor theme plugin Remove duplicated code. Change-Id: I8c2dc9464f27d5adeda9aa6d3c28d3e8ed84b94e Signed-off-by: Sangyoon Jang --- diff --git a/src/theme_plugin/theme_metadata_plugin.cc b/src/theme_plugin/theme_metadata_plugin.cc index d004781..c97a52c 100644 --- a/src/theme_plugin/theme_metadata_plugin.cc +++ b/src/theme_plugin/theme_metadata_plugin.cc @@ -15,8 +15,12 @@ #include "theme/utils/glist_range.h" #include "theme/utils/logging.h" +#include "theme/loader/theme_info.h" #include "theme_plugin/theme_parser.h" +using ttm::loader::ThemeInfo; +using ttm::plugin::ThemeParser; + namespace { const char kThemeMetadataKey[] = "http://tizen.org/metadata/theme"; @@ -40,27 +44,27 @@ std::string GetThemeFilePath(const char* pkgid) { return path; } -} // namespace - -bool InstallTheme(const std::string& id, const std::string& pkgid, - const std::string& path) { +bool ParseAndCommitTheme(ThemeParser::ThemeOperation op, const std::string& id, + const std::string& pkgid, const std::string& path) { uid_t uid; int r = pkgmgr_installer_info_get_target_uid(&uid); if (r < 0) { LOG(ERROR) << "Failed to get target uid"; return false; } - ttm::plugin::ThemeParser parser(path); - ttm::loader::ThemeInfo theme = parser.Inflate(id, pkgid, uid); + ThemeParser parser(path); + ThemeInfo theme = parser.Inflate(id, pkgid, uid); if (!theme.IsValid()) { LOG(ERROR) << "Failed to parse theme"; return false; } - if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::ADD, theme)) + if (!parser.Commit(op, theme)) return false; return true; } +} // namespace + extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL( const char* pkgid, const char* appid, GList* metadata) { std::string root_path = GetThemeFilePath(pkgid); @@ -69,32 +73,14 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL( for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) { if (!strcmp(md->key, kThemeMetadataKey)) { - if (!InstallTheme(appid, pkgid, (root_path + md->value))) + if (!ParseAndCommitTheme(ThemeParser::ThemeOperation::ADD, appid, pkgid, + (root_path + md->value))) return -1; } } return 0; } -bool UpgradeTheme(const std::string& id, const std::string& pkgid, - const std::string& path) { - uid_t uid; - int r = pkgmgr_installer_info_get_target_uid(&uid); - if (r < 0) { - LOG(ERROR) << "Failed to get target uid"; - return false; - } - ttm::plugin::ThemeParser parser(path); - ttm::loader::ThemeInfo theme = parser.Inflate(id, pkgid, uid); - if (!theme.IsValid()) { - LOG(ERROR) << "Failed to parse theme"; - return false; - } - if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::UPDATE, theme)) - return false; - return true; -} - extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE( const char* pkgid, const char* appid, GList* metadata) { std::string root_path = GetThemeFilePath(pkgid); @@ -103,32 +89,14 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE( for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) { if (!strcmp(md->key, kThemeMetadataKey)) { - if (!UpgradeTheme(appid, pkgid, (root_path + md->value))) + if (!ParseAndCommitTheme(ThemeParser::ThemeOperation::UPDATE, appid, + pkgid, (root_path + md->value))) return -1; } } return 0; } -bool UninstallTheme(const std::string& id, const std::string& pkgid, - const std::string& path) { - uid_t uid; - int r = pkgmgr_installer_info_get_target_uid(&uid); - if (r < 0) { - LOG(ERROR) << "Failed to get target uid"; - return false; - } - ttm::plugin::ThemeParser parser(path); - ttm::loader::ThemeInfo theme = parser.Inflate(id, pkgid, uid); - if (!theme.IsValid()) { - LOG(ERROR) << "Failed to parse theme"; - return false; - } - if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::REMOVE, theme)) - return false; - return true; -} - extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL( const char* pkgid, const char* appid, GList* metadata) { std::string root_path = GetThemeFilePath(pkgid); @@ -137,7 +105,8 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL( for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) { if (!strcmp(md->key, kThemeMetadataKey)) { - if (!UninstallTheme(appid, pkgid, (root_path + md->value))) + if (!ParseAndCommitTheme(ThemeParser::ThemeOperation::REMOVE, appid, + pkgid, (root_path + md->value))) return -1; } }