From 37b8b649de1af305354621931218a37b8b381d50 Mon Sep 17 00:00:00 2001 From: "ws29.jung" Date: Wed, 19 Sep 2018 19:59:44 +0900 Subject: [PATCH] Remove redundant CommandLine class Electron-efl had 3 different CommandLine classes which do the job not very different and they weren't a inherited class of any other. From this patch, common::CommandLine class is removed and only AtomCommandLine and base::CommandLine are left. Change-Id: Ic6a85e29a153461771f2441fc3321141f0ce3624 Signed-off-by: ws29.jung --- atom/common/atom_command_line.cc | 19 ++++++++++++++++++- atom/common/atom_command_line.h | 3 ++- tizen/common/common.gyp | 2 -- tizen/src/browser/api/wrt_api_core.cc | 7 ++----- tizen/src/wrt_main.cc | 11 +++-------- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/atom/common/atom_command_line.cc b/atom/common/atom_command_line.cc index 08880ff..4a5bfe9 100644 --- a/atom/common/atom_command_line.cc +++ b/atom/common/atom_command_line.cc @@ -11,7 +11,7 @@ namespace atom { // static std::vector AtomCommandLine::argv_; - +int AtomCommandLine::argc_; #if defined(OS_WIN) // static std::vector AtomCommandLine::wargv_; @@ -20,6 +20,7 @@ std::vector AtomCommandLine::wargv_; // static void AtomCommandLine::Init(int argc, const char* const* argv) { // Hack around with the argv pointer. Used for process.title = "blah" + argc_ = argc; char** new_argv = uv_setup_args(argc, const_cast(argv)); for (int i = 0; i < argc; ++i) { argv_.push_back(new_argv[i]); @@ -42,4 +43,20 @@ void AtomCommandLine::InitializeFromCommandLine() { } #endif +std::string AtomCommandLine::GetAppIdFromCommandLine(const std::string& program) { + if (argc_ > 0) { + std::string tmp = argv_[0]; + if (tmp == program) { + if (argv_.size() > 0) { + // Suppose that appid is at the first of arguments_ + return argv_[0]; + } + } else { + return tmp; + } + } + return std::string(); +} + + } // namespace atom diff --git a/atom/common/atom_command_line.h b/atom/common/atom_command_line.h index a834ce9..3b6d689 100644 --- a/atom/common/atom_command_line.h +++ b/atom/common/atom_command_line.h @@ -29,9 +29,10 @@ class AtomCommandLine { // it is using zygote. static void InitializeFromCommandLine(); #endif - + static std::string GetAppIdFromCommandLine(const std::string& program); private: static std::vector argv_; + static int argc_; #if defined(OS_WIN) static std::vector wargv_; diff --git a/tizen/common/common.gyp b/tizen/common/common.gyp index 637f5c4..7dbb07d 100644 --- a/tizen/common/common.gyp +++ b/tizen/common/common.gyp @@ -7,8 +7,6 @@ 'target_name': 'wrt_common', 'type': 'shared_library', 'sources': [ - 'command_line.h', - 'command_line.cc', 'constants.h', 'constants.cc', 'file_utils.h', diff --git a/tizen/src/browser/api/wrt_api_core.cc b/tizen/src/browser/api/wrt_api_core.cc index e58d525..c63f6b8 100755 --- a/tizen/src/browser/api/wrt_api_core.cc +++ b/tizen/src/browser/api/wrt_api_core.cc @@ -3,12 +3,12 @@ #include #include "atom/browser/browser.h" +#include "atom/common/atom_command_line.h" #include "atom/common/node_includes.h" #include "base/files/file_path.h" #include "base/logging.h" #include "native_mate/dictionary.h" #include "tizen/common/application_data.h" -#include "tizen/common/command_line.h" #include "tizen/src/browser/native_web_runtime.h" #include "tizen/src/browser/wrt_service.h" @@ -77,10 +77,7 @@ std::string WebRuntime::GetPath() const { } bool WebRuntime::isTizenWebApp() const { - common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); - if (!runtime_cmd) - return false; - std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron"); + std::string appid = atom::AtomCommandLine::GetAppIdFromCommandLine("/usr/bin/electron"); if (appid != "electron") { // TODO: Any better distinguishing feature? return true; } else { diff --git a/tizen/src/wrt_main.cc b/tizen/src/wrt_main.cc index 38ccdfa..87fd3e8 100644 --- a/tizen/src/wrt_main.cc +++ b/tizen/src/wrt_main.cc @@ -20,7 +20,6 @@ #if defined(OS_TIZEN) #include "atom/app/runtime.h" #include "tizen/common/application_data.h" -#include "tizen/common/command_line.h" #include "tizen/loader/prelauncher.h" #include "tizen/browser/preload_manager.h" #endif @@ -42,19 +41,14 @@ int real_main(int argc, char* argv[]) { for (int i = 0; i < argc; ++i) LOG(INFO) << "argv[" << i << "] : " << argv[i]; - if (!common::CommandLine::Init(argc, argv)) { - common::CommandLine::Reset(); - common::CommandLine::Init(argc, argv); - } - if (base::CommandLine::InitializedForCurrentProcess()) { base::CommandLine::ForCurrentProcess()->SetProgram(base::FilePath(argv[0])); } else { base::CommandLine::Init(argc, argv); } - common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); - std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/wrt"); + atom::AtomCommandLine::Init(argc, argv); + std::string appid = atom::AtomCommandLine::GetAppIdFromCommandLine("/usr/bin/wrt"); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); bool is_browser_process = @@ -100,6 +94,7 @@ int main(int argc, const char* argv[]) { LOG(INFO) << "run with wrt-loader"; for (int i = 0; i < argc; ++i) LOG(INFO) << "argv[" << i << "] : " << argv[i]; + int no_argument_count = 1; atom::AtomCommandLine::Init(no_argument_count, argv); -- 2.7.4