From 5debe6c68bdfd1d07163e121d905ac9ac8406f01 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Thu, 6 Jul 2017 10:37:02 +0200 Subject: [PATCH] Remove fetching pkgLabel twice Creating popup message unnecessarily fetched pkg label from pkg label. Change-Id: Ie98a9e5e170a2d86a68856c39153c7581f598c42 --- src/notification-daemon/Logic.cpp | 8 ++++---- src/notification-daemon/Logic.h | 2 +- src/notification-daemon/event/Event.h | 8 ++++---- src/notification-daemon/ui/Po.cpp | 9 ++------- src/notification-daemon/ui/Po.h | 2 +- src/notification-daemon/ui/Popupper.cpp | 6 +++--- src/notification-daemon/ui/Popupper.h | 2 +- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/notification-daemon/Logic.cpp b/src/notification-daemon/Logic.cpp index c0841dd..dafdd2c 100644 --- a/src/notification-daemon/Logic.cpp +++ b/src/notification-daemon/Logic.cpp @@ -46,9 +46,9 @@ void Logic::addChannelFd(Protocol::ConnectionFd fd, const Protocol::Credentials return; } - std::string appId, pkgId; - identifyApp(creds.label, appId, pkgId); - ConnectionInfo connInfo{appId, pkgId, creds.uid}; + std::string appId, pkgLabel; + identifyApp(creds.label, appId, pkgLabel); + ConnectionInfo connInfo{appId, pkgLabel, creds.uid}; m_connToInfo.insert(it, std::make_pair(fd, connInfo)); } @@ -162,7 +162,7 @@ void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std:: return; } - auto &pkgId = it->second.pkgId; + auto &pkgId = it->second.pkgLabel; addEvent({fd, id}, new EventPopupCheck(&m_popupper, pkgId, privilege)); } diff --git a/src/notification-daemon/Logic.h b/src/notification-daemon/Logic.h index 41712e5..f8eeb6b 100644 --- a/src/notification-daemon/Logic.h +++ b/src/notification-daemon/Logic.h @@ -106,7 +106,7 @@ private: struct ConnectionInfo { std::string appId; - std::string pkgId; + std::string pkgLabel; std::string user; }; diff --git a/src/notification-daemon/event/Event.h b/src/notification-daemon/event/Event.h index 2327569..239d91a 100644 --- a/src/notification-daemon/event/Event.h +++ b/src/notification-daemon/event/Event.h @@ -40,8 +40,8 @@ protected: class EventPopupCheck : public IUIEvent { public: - EventPopupCheck(Popupper *popupper, const std::string &pkgName, const std::string &privilege) - : IUIEvent(popupper), m_pkgName(pkgName), m_privilege(privilege) + EventPopupCheck(Popupper *popupper, const std::string &pkgLabel, const std::string &privilege) + : IUIEvent(popupper), m_pkgLabel(pkgLabel), m_privilege(privilege) {} std::string getPrivilege() { @@ -49,10 +49,10 @@ public: } virtual void process() { - m_popupper->popupCheck(m_pkgName, m_privilege); + m_popupper->popupCheck(m_pkgLabel, m_privilege); } private: - std::string m_pkgName; + std::string m_pkgLabel; std::string m_privilege; }; diff --git a/src/notification-daemon/ui/Po.cpp b/src/notification-daemon/ui/Po.cpp index 7ee8218..4da2d52 100644 --- a/src/notification-daemon/ui/Po.cpp +++ b/src/notification-daemon/ui/Po.cpp @@ -90,17 +90,12 @@ const char *getFormat(enum MsgType type) { return dgettext(PROJECT_NAME, MSG_PO[type]); } -std::string getPkgLabel(const std::string &pkgName) { - PkgInfo pkgInfo(pkgName, geteuid()); - return pkgInfo.pkgLabel(); -} - } // namespace anonymous namespace Notification { namespace Po { -std::string createPopupCheckMsg(const std::string &pkgName, const std::string &priv) { - return makeFromFormat(getFormat(MsgType::MSG_POPUP_TEXT), getPkgLabel(pkgName).c_str(), +std::string createPopupCheckMsg(const std::string &pkgLabel, const std::string &priv) { + return makeFromFormat(getFormat(MsgType::MSG_POPUP_TEXT), pkgLabel.c_str(), PrivilegeInfo::getPrivacyDisplayName(priv).c_str()); } diff --git a/src/notification-daemon/ui/Po.h b/src/notification-daemon/ui/Po.h index b702c93..d4cb8bd 100644 --- a/src/notification-daemon/ui/Po.h +++ b/src/notification-daemon/ui/Po.h @@ -26,7 +26,7 @@ namespace AskUser { namespace Notification { namespace Po { -std::string createPopupCheckMsg(const std::string &pkgName, const std::string &priv); +std::string createPopupCheckMsg(const std::string &pkgLabel, const std::string &priv); std::string createPrivilegeDescr(const std::string &priv); std::string getPopupTitleMsg(); diff --git a/src/notification-daemon/ui/Popupper.cpp b/src/notification-daemon/ui/Popupper.cpp index e8194bb..97f9e34 100644 --- a/src/notification-daemon/ui/Popupper.cpp +++ b/src/notification-daemon/ui/Popupper.cpp @@ -154,16 +154,16 @@ void Popupper::show() { evas_object_show(m_win); } -void Popupper::popupCheck(const std::string &pkgId, const std::string &priv) { +void Popupper::popupCheck(const std::string &pkgLabel, const std::string &priv) { std::string profileName = getProfileName(); PopupCheck *popup; try { if (profileName[0] != 'w' && profileName[0] != 'W') { // Not wearable - popup = new PopupCheckMobile(m_win, Po::createPopupCheckMsg(pkgId, priv)); + popup = new PopupCheckMobile(m_win, Po::createPopupCheckMsg(pkgLabel, priv)); } else { // Wearable - popup = new PopupCheckWearable(m_win, Po::createPopupCheckMsg(pkgId, priv)); + popup = new PopupCheckWearable(m_win, Po::createPopupCheckMsg(pkgLabel, priv)); } popup->create(); } catch (const std::exception &e) { diff --git a/src/notification-daemon/ui/Popupper.h b/src/notification-daemon/ui/Popupper.h index 5855d53..c818a0d 100644 --- a/src/notification-daemon/ui/Popupper.h +++ b/src/notification-daemon/ui/Popupper.h @@ -47,7 +47,7 @@ public: void registerPopupResponseHandler(PopupHandler handler); void start(); - void popupCheck(const std::string &pkgId, const std::string &priv); + void popupCheck(const std::string &pkgLabel, const std::string &priv); void popupClose(); void stop(); -- 2.7.4