Change pkgname to appid and add package id PART 1.
[framework/web/wrt-commons.git] / modules / security_origin_dao / dao / security_origin_dao.cpp
index 33093dc..dda13e6 100644 (file)
@@ -29,6 +29,7 @@
 #include <dpl/wrt-dao-ro/WrtDatabase.h>
 #include <dpl/wrt-dao-ro/widget_config.h>
 #include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
 #include <sys/stat.h>
 #include <fstream>
 
@@ -55,25 +56,32 @@ const char* const SECURITY_ORIGIN_DB_NAME = ".security_origin.db";
 const char* const SECURITY_ORIGIN_DB_SQL_PATH =
     "/usr/share/wrt-engine/security_origin_db.sql";
 
+std::string createDatabasePath(const WrtDB::WidgetPkgName &pkgName)
+{
+        std::stringstream filename;
+
+        filename << WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(pkgName)
+                 << "/"
+                 << SECURITY_ORIGIN_DB_NAME;
+        return filename.str();
+}
+
 std::string createDatabasePath(int widgetHandle)
 {
     using namespace DPL::DB::ORM;
     using namespace WrtDB::WidgetConfig;
     using namespace WrtDB::GlobalConfig;
 
-    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
-    {
-        std::stringstream filename;
-        WrtDB::WidgetDAOReadOnly widgetDAO(widgetHandle);
-        DPL::Optional<DPL::String> pkgname = widgetDAO.getPkgname();
+    WrtDB::TizenAppId appid;
 
-        filename << GetWidgetPersistentStoragePath(*pkgname)
-                 << "/"
-                 << SECURITY_ORIGIN_DB_NAME;
-        return filename.str();
+    Try
+    {
+        appid = WrtDB::WidgetDAOReadOnly::getTzAppId(widgetHandle);
     }
-    SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to get database Path")
-
+    Catch(DPL::DB::SqlConnection::Exception::Base) {
+        LogError("Failed to get database Path");
+    }
+    return createDatabasePath(appid);
 }
 
 void checkDatabase(std::string databasePath)
@@ -121,6 +129,14 @@ SecurityOriginDAO::SecurityOriginDAO(int handle) :
     m_securityOriginDBInterface.AttachToThread(SECURITY_ORIGIN_DB_OPTION);
 }
 
+SecurityOriginDAO::SecurityOriginDAO(const WrtDB::WidgetPkgName &pkgName) :
+    m_securityOriginDBPath(createDatabasePath(pkgName)),
+    m_securityOriginDBInterface(m_securityOriginDBPath, SECURITY_ORIGIN_DB_TYPE)
+{
+    checkDatabase(m_securityOriginDBPath);
+    m_securityOriginDBInterface.AttachToThread(SECURITY_ORIGIN_DB_OPTION);
+}
+
 SecurityOriginDAO::~SecurityOriginDAO()
 {
     m_securityOriginDBInterface.DetachFromThread();
@@ -221,6 +237,19 @@ void SecurityOriginDAO::removeSecurityOriginData(
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set security origin data")
 }
 
+void SecurityOriginDAO::removeSecurityOriginData(const Result result)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        ScopedTransaction transaction(&m_securityOriginDBInterface);
+        SECURITY_ORIGIN_DB_DELETE(del, SecurityOriginInfo, &m_securityOriginDBInterface)
+        del->Where(Equals<SecurityOriginInfo::result>(result));
+        del->Execute();
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to remove data by result")
+}
+
 bool SecurityOriginDAO::hasResult(const SecurityOriginData &securityOriginData)
 {
     Result res=getResult(securityOriginData);