From: surya.kumar7 Date: Mon, 7 May 2018 11:36:57 +0000 (+0530) Subject: Add preload manager and invoke preloadable objects in prelaunch phase X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4739f2e776784e72a8eace33defb27e85f161b63;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Add preload manager and invoke preloadable objects in prelaunch phase 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 --- diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 32e6ecf70..b88049f2b 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -48,8 +48,13 @@ void InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*, } #endif +bool g_prelaunch_ = false; +std::unique_ptr g_atom_content_client_; +std::unique_ptr 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 AtomMainDelegate::CreateContentClient() { - return std::unique_ptr(new AtomContentClient); + if (!g_prelaunch_) + return std::unique_ptr(new AtomContentClient); + else return std::unique_ptr(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 diff --git a/atom/app/atom_main_delegate.h b/atom/app/atom_main_delegate.h index 64207ae79..d768ddf96 100644 --- a/atom/app/atom_main_delegate.h +++ b/atom/app/atom_main_delegate.h @@ -17,6 +17,8 @@ class AtomMainDelegate : public brightray::MainDelegate { AtomMainDelegate(); ~AtomMainDelegate(); + static void Preload(); + protected: // content::ContentMainDelegate: bool BasicStartupComplete(int* exit_code) override; diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc index e13e1bf83..27f7e0ed5 100644 --- a/atom/app/ui_runtime.cc +++ b/atom/app/ui_runtime.cc @@ -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(); } diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index f718f86de..3ea0c3e1a 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -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 self_bridge_task_runner; std::unique_ptr self_browser; @@ -75,6 +72,10 @@ std::unique_ptr self_atom_bindings; std::unique_ptr self_node_env; std::unique_ptr self_node_debugger; +} // namespace + +AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr; + AtomBrowserMainParts::AtomBrowserMainParts() : fake_browser_process_(new BrowserProcess), exit_code_(nullptr), diff --git a/filenames.gypi b/filenames.gypi index 8408b273e..0535fab19 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -636,6 +636,8 @@ '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 index 000000000..18c645daa --- /dev/null +++ b/tizen/browser/preload_manager.cc @@ -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 index 000000000..4f06612ef --- /dev/null +++ b/tizen/browser/preload_manager.h @@ -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 + + +namespace tizen { +class PreloadManager { + public: + static PreloadManager* GetInstance(); + void CreateCacheComponent(); + + private: + PreloadManager(); +}; + +} // namespace tizen + +#endif // TIZEN_BROWSER_PRELOAD_MANAGER_H_ diff --git a/tizen/src/wrt_main.cc b/tizen/src/wrt_main.cc index 0bf3635ef..8c8052bb7 100644 --- a/tizen/src/wrt_main.cc +++ b/tizen/src/wrt_main.cc @@ -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(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) {