Add preload manager and invoke preloadable objects in prelaunch phase 15/176815/12
authorsurya.kumar7 <surya.kumar7@samsung.com>
Mon, 7 May 2018 11:36:57 +0000 (17:06 +0530)
committerjaekuk lee <juku1999@samsung.com>
Wed, 16 May 2018 09:45:51 +0000 (09:45 +0000)
Preloading the below engine independent components is giving ~50ms improvement
in app launch:
xwalk extension server
AtomContentClient
AtomBrowserClient

Change-Id: Iee9bc108aeed0414962b301345c799807dfd043d
Signed-off-by: surya.kumar7 <surya.kumar7@samsung.com>
atom/app/atom_main_delegate.cc
atom/app/atom_main_delegate.h
atom/app/ui_runtime.cc
atom/browser/atom_browser_main_parts.cc
filenames.gypi
tizen/browser/preload_manager.cc [new file with mode: 0644]
tizen/browser/preload_manager.h [new file with mode: 0644]
tizen/src/wrt_main.cc

index 32e6ecf..b88049f 100644 (file)
@@ -48,8 +48,13 @@ void InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*,
 }
 #endif
 
+bool g_prelaunch_ = false;
+std::unique_ptr<AtomContentClient> g_atom_content_client_;
+std::unique_ptr<AtomBrowserClient> g_atom_browser_client_;
+
 }  // namespace
 
+
 AtomMainDelegate::AtomMainDelegate() {
 }
 
@@ -162,7 +167,9 @@ void AtomMainDelegate::PreSandboxStartup() {
 }
 
 content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
-  browser_client_.reset(new AtomBrowserClient);
+  if (!g_prelaunch_)
+    browser_client_.reset(new AtomBrowserClient);
+  else browser_client_.reset(g_atom_browser_client_.release());
   return browser_client_.get();
 }
 
@@ -205,7 +212,16 @@ bool AtomMainDelegate::DelaySandboxInitialization(
 
 std::unique_ptr<brightray::ContentClient>
 AtomMainDelegate::CreateContentClient() {
-  return std::unique_ptr<brightray::ContentClient>(new AtomContentClient);
+  if (!g_prelaunch_)
+    return std::unique_ptr<brightray::ContentClient>(new AtomContentClient);
+  else return std::unique_ptr<brightray::ContentClient>(g_atom_content_client_.release());
+}
+
+// static
+void AtomMainDelegate::Preload() {
+  g_atom_content_client_.reset(new AtomContentClient);
+  g_atom_browser_client_.reset(new AtomBrowserClient);
+  g_prelaunch_ = true;
 }
 
 }  // namespace atom
index 64207ae..d768ddf 100644 (file)
@@ -17,6 +17,8 @@ class AtomMainDelegate : public brightray::MainDelegate {
   AtomMainDelegate();
   ~AtomMainDelegate();
 
+  static void Preload();
+
  protected:
   // content::ContentMainDelegate:
   bool BasicStartupComplete(int* exit_code) override;
index e13e1bf..27f7e0e 100644 (file)
@@ -39,6 +39,8 @@ namespace runtime {
 UiRuntime::UiRuntime(content::ContentMainParams *params) {
   _params = params;
 
+  // This line's position is essential as this creates the Browser
+  // object which is needed later on by ui_runtime in its ui_loop callbacks
   atom::AtomBrowserMainParts::SetNodeEnvironment();
 }
 
index f718f86..3ea0c3e 100644 (file)
@@ -61,11 +61,8 @@ void Erase(T* container, typename T::iterator iter) {
   container->erase(iter);
 }
 
-}  // namespace
-
-// static
+// static - lines have been moved to limit their visibility only to this file
 bool g_prelaunch = false;
-AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr;
 node::Environment* env_ = nullptr;
 scoped_refptr<BridgeTaskRunner> self_bridge_task_runner;
 std::unique_ptr<Browser> self_browser;
@@ -75,6 +72,10 @@ std::unique_ptr<AtomBindings> self_atom_bindings;
 std::unique_ptr<NodeEnvironment> self_node_env;
 std::unique_ptr<NodeDebugger> self_node_debugger;
 
+}  // namespace
+
+AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr;
+
 AtomBrowserMainParts::AtomBrowserMainParts()
     : fake_browser_process_(new BrowserProcess),
       exit_code_(nullptr),
index 8408b27..0535fab 100644 (file)
       'chromium_src/net/test/embedded_test_server/stream_listen_socket.h',
       'chromium_src/net/test/embedded_test_server/tcp_listen_socket.cc',
       'chromium_src/net/test/embedded_test_server/tcp_listen_socket.h',
+      'tizen/browser/preload_manager.cc',
+      'tizen/browser/preload_manager.h',
       '<@(native_mate_files)',
       '<(SHARED_INTERMEDIATE_DIR)/atom_natives.h',
       '<(SHARED_INTERMEDIATE_DIR)/grit/pdf_viewer_resources_map.cc',
diff --git a/tizen/browser/preload_manager.cc b/tizen/browser/preload_manager.cc
new file mode 100644 (file)
index 0000000..18c645d
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "tizen/browser/preload_manager.h"
+
+#include "atom/app/atom_main_delegate.h"
+#include "extensions/common/xwalk_extension_server.h"
+
+namespace tizen {
+
+PreloadManager* PreloadManager::GetInstance() {
+  static PreloadManager instance;
+  return &instance;
+}
+
+PreloadManager::PreloadManager() {
+}
+
+void PreloadManager::CreateCacheComponent() {
+  // Load extensions in the preload step
+  auto extension_server = extensions::XWalkExtensionServer::GetInstance();
+  extension_server->Preload();
+
+  atom::AtomMainDelegate::Preload();
+}
+
+}  //  namespace tizen
diff --git a/tizen/browser/preload_manager.h b/tizen/browser/preload_manager.h
new file mode 100644 (file)
index 0000000..4f06612
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef TIZEN_BROWSER_PRELOAD_MANAGER_H_
+#define TIZEN_BROWSER_PRELOAD_MANAGER_H_
+
+#include <memory>
+
+
+namespace tizen {
+class PreloadManager {
+ public:
+  static PreloadManager* GetInstance();
+  void CreateCacheComponent();
+
+ private:
+  PreloadManager();
+};
+
+}  // namespace tizen
+
+#endif   // TIZEN_BROWSER_PRELOAD_MANAGER_H_
index 0bf3635..8c8052b 100644 (file)
@@ -44,6 +44,7 @@
 #include "tizen/common/application_data.h"
 #include "tizen/common/command_line.h"
 #include "tizen/loader/prelauncher.h"
+#include "tizen/browser/preload_manager.h"
 #endif
 
 namespace {
@@ -236,6 +237,7 @@ int main(int argc, const char* argv[]) {
       params.argv = const_cast<const char**>(argv);
       atom::AtomCommandLine::Init(argc, argv);
       runtime_ = runtime::Runtime::MakeRuntime(nullptr);
+      tizen::PreloadManager::GetInstance()->CreateCacheComponent();
       return 0;
     };
     auto did_launch = [](const std::string& app_path) {