[Cherry-pick] Improve performance 95/88495/2
authorm.kawonczyk <m.kawonczyk@samsung.com>
Mon, 1 Aug 2016 08:25:16 +0000 (10:25 +0200)
committerKamil Nowa? <k.nowac@samsung.com>
Mon, 19 Sep 2016 10:17:54 +0000 (03:17 -0700)
[Issue]        N/A
[Problem]      Performance slowed down by 100ms.
[Solution]     Moved initialization of the download control to the
               lazy loading function.
[Verify]       Open browser and dlogutil. Check it time is improved
               and if download is working as intended.

Change-Id: Id3c898f7e2e489e26f0acae4e1f59def8f2fb64b

services/WebEngineService/WebEngineService.cpp
services/WebEngineService/WebEngineService.h

index e9f36909f198d092c23f03043143ae47b1b4acb3..5e3ab2d2e80f27bbe90607959654cdb05c73cbb5 100755 (executable)
@@ -26,7 +26,6 @@
 #include "BrowserAssert.h"
 #include "BrowserLogger.h"
 #include "Config/Config.h"
-#include "WebView.h"
 
 namespace tizen_browser {
 namespace basic_webengine {
@@ -44,7 +43,6 @@ WebEngineService::WebEngineService()
     , m_currentWebView(nullptr)
     , m_stateStruct(&m_normalStateStruct)
     , m_tabIdCreated(-1)
-    , m_tabIdSecret(0)
     , m_downloadControl(nullptr)
 {
     m_stateStruct->mostRecentTab.clear();
@@ -65,9 +63,6 @@ WebEngineService::WebEngineService()
 WebEngineService::~WebEngineService()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    #if PROFILE_MOBILE
-        delete m_downloadControl;
-    #endif
 }
 
 void WebEngineService::destroyTabs()
@@ -107,12 +102,12 @@ void WebEngineService::init(Evas_Object* guiParent)
         m_guiParent = guiParent;
         m_initialised = true;
     }
+}
 
-#if PROFILE_MOBILE
-    Ewk_Context *context = ewk_context_default_get();
+void WebEngineService::initializeDownloadControl(Ewk_Context* context)
+{
     ewk_context_did_start_download_callback_set(context , _download_request_cb, this);
-    m_downloadControl = new DownloadControl();
-#endif
+    m_downloadControl = std::make_shared<DownloadControl>();
 }
 
 void WebEngineService::preinitializeWebViewCache()
@@ -121,7 +116,11 @@ void WebEngineService::preinitializeWebViewCache()
     if (!m_webViewCacheInitialized) {
         m_webViewCacheInitialized = true;
         Ewk_Context* context = ewk_context_default_get();
-        Evas_Object* ewk_view = ewk_view_add_with_context(m_guiParent, context);
+
+        initializeDownloadControl(context);
+
+        Evas_Object* ewk_view = ewk_view_add_with_context(evas_object_evas_get(
+                reinterpret_cast<Evas_Object *>(m_guiParent)), context);
         ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
         ewk_view_orientation_send(ewk_view, 0);
         evas_object_del(ewk_view);
@@ -510,7 +509,10 @@ TabId WebEngineService::addTab(const std::string & uri, const boost::optional<in
         newTabId = TabId(m_tabIdSecret);
     }
 
-    m_webViewCacheInitialized = true;
+    if (!m_webViewCacheInitialized) {
+        initializeDownloadControl();
+        m_webViewCacheInitialized = true;
+    }
     WebViewPtr p = std::make_shared<WebView>(m_guiParent, newTabId, title, m_state == State::SECRET);
     p->init(desktopMode, origin);
 
index bafec280f3112e4d697e12f7d5784999b705b5f2..8972fd4cc9e1fcccbd6d1461759f5f133cda1055 100644 (file)
@@ -33,6 +33,7 @@
 #include "SnapshotType.h"
 #include "BrowserImage.h"
 #include "DownloadControl/DownloadControl.h"
+#include "WebView.h"
 
 namespace tizen_browser {
 namespace basic_webengine {
@@ -266,6 +267,7 @@ private:
     void connectSignals(WebViewPtr);
 
     int createTabId();
+    void initializeDownloadControl(Ewk_Context* context = ewk_context_default_get());
 
 private:
     struct StateStruct {
@@ -290,7 +292,7 @@ private:
     int m_tabIdSecret;
 
     std::map<WebEngineSettings, bool>  m_settings;
-    DownloadControl *m_downloadControl;
+    std::shared_ptr<DownloadControl> m_downloadControl;
 };
 
 } /* end of webengine_service */