Async service loading and initialization 16/78216/10
authorKamil Nowac <k.nowac@samsung.com>
Mon, 4 Jul 2016 12:05:34 +0000 (14:05 +0200)
committerjaekuk lee <juku1999@samsung.com>
Wed, 6 Jul 2016 04:15:34 +0000 (21:15 -0700)
[Issue]    N/A
[Problem]  Synchronous service loading
[Solution] Use of std::async interface

Change-Id: Idb89f090ecd132b5253bb6e81ed11e28334da4e9

core/ServiceManager/ServiceLoader.cpp
core/ServiceManager/ServiceManager.cpp
services/SimpleUI/SimpleUI.cpp
services/SimpleUI/SimpleUI.h

index 51ea54fb78791f625e0b8ec4fc27fdfb1e3e0f5f..cbb5bec54fd3daa5a67c2f7b0c99edf75742ff69 100644 (file)
@@ -44,7 +44,6 @@ void ServiceLoaderPrivate::loadService()
 ServiceLoader::ServiceLoader(const std::string& serviceFileName)
     : d(new ServiceLoaderPrivate(serviceFileName))
 {
-    BROWSER_LOGD( "%s %s", __PRETTY_FUNCTION__ , serviceFileName.c_str() );
 }
 
 
index 09666e963055861973221a651fa8f502cab20bd3..87f1b3bd5581520590c6ba226e68bc4db49649fe 100644 (file)
@@ -15,6 +15,7 @@
  */
 #include "browser_config.h"
 #include <unordered_map>
+#include <future>
 #include <boost/filesystem.hpp>
 #include "Config.h"
 #include "BrowserLogger.h"
@@ -30,7 +31,6 @@ ServiceManagerPrivate::ServiceManagerPrivate()
 {
     findServiceLibs();
     loadServiceLibs();
-    enumerateServices();
 }
 
 ServiceManagerPrivate::~ServiceManagerPrivate()
@@ -39,6 +39,7 @@ ServiceManagerPrivate::~ServiceManagerPrivate()
 void ServiceManagerPrivate::findServiceLibs()
 {
     try{
+        std::vector<std::future<void>> vt;
         boost::filesystem::path servicesDir(boost::any_cast<std::string>(tizen_browser::config::Config::getInstance().get("services/dir")));
         for( boost::filesystem::directory_iterator it(servicesDir);
                 it != boost::filesystem::directory_iterator();
@@ -48,13 +49,22 @@ void ServiceManagerPrivate::findServiceLibs()
                 if( (item.extension().string() == ".so" )
                     && (item.filename().string().find("lib") == 0)){
                     try{
-                        servicesLoaderMap[item.string()] = std::shared_ptr<ServiceLoader>(new ServiceLoader(item.string()));
+                        vt.push_back(
+                            std::async(
+                                std::launch::async,
+                                [this](boost::filesystem::path item){
+                                    servicesLoaderMap[item.string()] = std::shared_ptr<ServiceLoader>(new ServiceLoader(item.string()));
+                                },
+                            item)
+                        );
                     } catch (std::runtime_error & e){
                         BROWSER_LOGD(e.what() );
                     }
                 }
             }
         }
+        for(auto& th : vt)
+            th.get();
     } catch (const boost::filesystem::filesystem_error& ex){
         BROWSER_LOGD(ex.what() );
     }
@@ -84,7 +94,6 @@ void ServiceManagerPrivate::enumerateServices(){
 ServiceManager::ServiceManager()
     :d(new ServiceManagerPrivate)
 {
-
 }
 
 ServiceManager& ServiceManager::getInstance(void)
index 692758d7aa48e0d454ec23fe4e917eb48e0225a1..2cc5bb59e7ad4b63a68c7e336b418ba812a99049 100644 (file)
@@ -240,66 +240,132 @@ void SimpleUI::restoreLastSession()
     }
 }
 
-
 //TODO: Move all service creation here:
 void SimpleUI::loadUIServices()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    std::vector<std::future<void>> ft;
 
-    m_webPageUI =
+    ft.push_back(make_async_future([this](){
+        m_webPageUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::WebPageUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webpageui"));
-
-    m_quickAccess =
+        <tizen_browser::base_ui::WebPageUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webpageui"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_quickAccess =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::QuickAccess,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.quickaccess"));
-
-    m_tabUI =
+        <tizen_browser::base_ui::QuickAccess,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.quickaccess"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_tabUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::TabUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.tabui"));
-
-    m_historyUI =
+        <tizen_browser::base_ui::TabUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.tabui"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_historyUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::HistoryUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyui"));
-
-    m_settingsUI =
+        <tizen_browser::base_ui::HistoryUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyui"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_settingsUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::SettingsUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.settingsui"));
-
-    m_moreMenuUI =
+        <tizen_browser::base_ui::SettingsUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.settingsui"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_moreMenuUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::MoreMenuUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.moremenuui"));
-
-    m_bookmarkDetailsUI =
+        <tizen_browser::base_ui::MoreMenuUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.moremenuui"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_bookmarkDetailsUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::BookmarkDetailsUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkdetailsui"));
-#if PROFILE_MOBILE
-    m_bookmarkFlowUI =
+        <tizen_browser::base_ui::BookmarkDetailsUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkdetailsui"));
+    }));
+    #if PROFILE_MOBILE
+    ft.push_back(make_async_future([this](){
+        m_bookmarkFlowUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::BookmarkFlowUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkflowui"));
-
-    m_findOnPageUI =
+        <tizen_browser::base_ui::BookmarkFlowUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkflowui"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_findOnPageUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::FindOnPageUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.findonpageui"));
+        <tizen_browser::base_ui::FindOnPageUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.findonpageui"));
+    }));
 #else
-    m_zoomUI =
+    ft.push_back(make_async_future([this](){
+        m_zoomUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::ZoomUI, tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.zoomui"));
+        <tizen_browser::base_ui::ZoomUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.zoomui"));
+    }));
 #endif
-    m_bookmarkManagerUI =
+    ft.push_back(make_async_future([this](){
+        m_bookmarkManagerUI =
         std::dynamic_pointer_cast
-        <tizen_browser::base_ui::BookmarkManagerUI,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkmanagerui"));
+        <tizen_browser::base_ui::BookmarkManagerUI,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkmanagerui"));
+    }));
+    for(auto& th : ft)
+        th.get();
+}
+
+void SimpleUI::loadModelServices()
+{
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    std::vector<std::future<void>> ft;
+    ft.push_back(make_async_future([this](){
+        m_webEngine =
+        std::dynamic_pointer_cast
+        <basic_webengine::AbstractWebEngine<Evas_Object>,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webengineservice"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_storageService =
+        std::dynamic_pointer_cast
+        <tizen_browser::services::StorageService,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.storageservice"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_favoriteService =
+        std::dynamic_pointer_cast
+        <tizen_browser::interfaces::AbstractFavoriteService,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_historyService =
+        std::dynamic_pointer_cast
+        <tizen_browser::services::HistoryService,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyservice"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_tabService = std::dynamic_pointer_cast<
+        tizen_browser::services::TabService,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.tabservice"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_platformInputManager =
+        std::dynamic_pointer_cast
+        <tizen_browser::services::PlatformInputManager,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.platforminputmanager"));
+    }));
+    ft.push_back(make_async_future([this](){
+        m_certificateContents =
+        std::dynamic_pointer_cast
+        <tizen_browser::services::CertificateContents,
+        tizen_browser::core::AbstractService>(tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.certificateservice"));
+    }));
+    for(auto& th : ft)
+        th.get();
 }
 
 void SimpleUI::connectUISignals()
@@ -436,47 +502,6 @@ void SimpleUI::connectUISignals()
 #endif
 }
 
-void SimpleUI::loadModelServices()
-{
-    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-
-    m_webEngine =
-        std::dynamic_pointer_cast
-        <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webengineservice"));
-
-    m_storageService =
-        std::dynamic_pointer_cast
-        <tizen_browser::services::StorageService,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.storageservice"));
-
-    m_favoriteService =
-        std::dynamic_pointer_cast
-        <tizen_browser::interfaces::AbstractFavoriteService,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
-
-    m_historyService =
-        std::dynamic_pointer_cast
-        <tizen_browser::services::HistoryService,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyservice"));
-
-    m_tabService = std::dynamic_pointer_cast<
-            tizen_browser::services::TabService,
-            tizen_browser::core::AbstractService>(
-            tizen_browser::core::ServiceManager::getInstance().getService(
-                    "org.tizen.browser.tabservice"));
-
-    m_platformInputManager =
-        std::dynamic_pointer_cast
-        <tizen_browser::services::PlatformInputManager,tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.platforminputmanager"));
-
-    m_certificateContents =
-        std::dynamic_pointer_cast
-        <tizen_browser::services::CertificateContents, tizen_browser::core::AbstractService>
-        (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.certificateservice"));
-}
-
 void SimpleUI::initUIServices()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
@@ -523,28 +548,32 @@ void SimpleUI::initUIServices()
     m_bookmarkManagerUI->setFoldersId(m_storageService->getFoldersStorage().AllFolder, m_storageService->getFoldersStorage().SpecialFolder);
 }
 
+std::future<void> SimpleUI::make_async_future(std::function<void()> f){
+    return std::async(std::launch::async, f);
+}
+
 void SimpleUI::initModelServices()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-
-    M_ASSERT(m_webEngine);
-    M_ASSERT(m_webPageUI->getContent());
-    m_webEngine->init(m_webPageUI->getContent());
-
+    std::vector<std::future<void>> ft;
+    M_ASSERT(m_webEngine.get());
+    M_ASSERT(m_webPageUI.get());
+    M_ASSERT(m_favoriteService.get());
+    M_ASSERT(m_platformInputManager.get());
+    M_ASSERT(m_certificateContents.get());
 #if PROFILE_MOBILE
-    M_ASSERT(m_storageService->getSettingsStorage());
-    M_ASSERT(m_storageService->getFoldersStorage());
-    m_storageService->getSettingsStorage().initWebEngineSettingsFromDB();
+    M_ASSERT(m_storageService.get());
 #endif
+    ft.push_back(make_async_future([this](){m_webEngine->init(m_webPageUI->getContent());}));
+    ft.push_back(make_async_future([this](){m_favoriteService->getBookmarks();}));
+    ft.push_back(make_async_future([this](){m_platformInputManager->init(m_window.get());}));
+    ft.push_back(make_async_future([this](){m_certificateContents->init();}));
 
-    M_ASSERT(m_favoriteService);
-    m_favoriteService->getBookmarks();
-
-    M_ASSERT(m_platformInputManager);
-    m_platformInputManager->init(m_window.get());
-
-    M_ASSERT(m_certificateContents.get());
-    m_certificateContents->init();
+#if PROFILE_MOBILE
+    ft.push_back(make_async_future([this](){m_storageService->getSettingsStorage().initWebEngineSettingsFromDB();}));
+#endif
+    for(auto& th : ft)
+        th.get();
 }
 
 void SimpleUI::connectModelSignals()
index d148027ff9e6ab70663b76ffff474cc3d6a15bf9..1c9acfe7bab318a460c84769828f88bff816b2d2 100644 (file)
 #define SIMPLEUI_H_
 
 #include <Evas.h>
-
+#include <future>
+#include <functional>
 #include "AbstractMainWindow.h"
 #include "AbstractService.h"
 #include "AbstractFavoriteService.h"
 #include "ServiceFactory.h"
 #include "service_macros.h"
 
+
 // components
 #include "WebPageUI.h"
 #include "AbstractWebEngine.h"
@@ -123,6 +125,7 @@ private:
     void updateView();
     void windowCreated();
     void minimizeBrowser();
+    std::future<void> make_async_future(std::function<void()> f);
 
 #if PROFILE_MOBILE
     void openNewTab(const std::string &uri, const std::string& title =