Fix WrtAccess singleton deinitialize issue
authorLongXiang <xiang.long@intel.com>
Tue, 29 Jan 2013 06:56:34 +0000 (14:56 +0800)
committerGerrit Code Review <gerrit2@kim11>
Wed, 30 Jan 2013 10:16:55 +0000 (19:16 +0900)
[Issue#] N/A
[Problem] If an iframe or opened window closed, the main frame or opener
window will fail to access device APIs.
[Cause] When iframe or child window be closed, the WrtAccess singleton
will be deinitialized, later ace check calls will fail the WrtAccess
initialized assertion.
[Solution] Count initialized plugins in WrtAccess.

Change-Id: Icd9c5eb0488912225d8dcf4bd222b0bd26ea29c8

src/Commons/WrtAccess/WrtAccess.cpp
src/Commons/WrtAccess/WrtAccess.h

index b1f5850..cfda0f1 100644 (file)
@@ -112,8 +112,8 @@ namespace WrtDeviceApis {
 namespace Commons {
 
 WrtAccess::WrtAccess() :
-        m_initialized(false),
-        m_sessionId(GenerateSessionId())
+        m_sessionId(GenerateSessionId()),
+        m_pluginOwners(0)
 {
 }
 
@@ -151,18 +151,22 @@ void WrtAccess::initialize(int widgetId)
         LogDebug("Invalid widget id");
         Throw(Exception);
     }
-    ace_return_t ret = ace_client_initialize(Wrt::Popup::run_popup);
-    Assert(ACE_OK == ret);
-    m_initialized = true;
-    m_widgetId = widgetId;
+
+    if (!m_pluginOwners++) {
+        ace_return_t ret = ace_client_initialize(Wrt::Popup::run_popup);
+        Assert(ACE_OK == ret);
+        m_widgetId = widgetId;
+    }
 }
 
 void WrtAccess::deinitialize(int /*widgetId*/)
 {
     LogDebug("deinitialize");
-    m_initialized = false;
-    ace_return_t ret = ace_client_shutdown();
-    Assert(ACE_OK == ret);
+
+    if (!--m_pluginOwners) {
+        ace_return_t ret = ace_client_shutdown();
+        Assert(ACE_OK == ret);
+    }
 }
 
 int WrtAccess::getWidgetId() const
@@ -172,7 +176,7 @@ int WrtAccess::getWidgetId() const
 
 bool WrtAccess::checkAccessControl(const AceFunction& aceFunction) const
 {
-    Assert(m_initialized && "WrtAccessSingleton needs to be initialized with"
+    Assert(m_pluginOwners && "WrtAccessSingleton needs to be initialized with"
             "WidgetId during on_widget_start_callback in each plugin");
     size_t deviceCount = aceFunction.deviceCapabilities.size();
 
index 574324f..2011a77 100644 (file)
@@ -46,8 +46,8 @@ private:
     WrtAccess();
     virtual ~WrtAccess();
 
-    bool m_initialized;
     int m_widgetId;
+    size_t m_pluginOwners;
     SessionId m_sessionId;
 
     friend class DPL::Singleton<WrtAccess>;