#include <windows.h>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/logging/logging_settings.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "chrome/common/chrome_switches.h"
namespace {
constexpr base::FilePath::CharType kChromeExecutable[] =
FILE_PATH_LITERAL("chrome.exe");
constexpr base::FilePath::CharType kChromeProxyExecutable[] =
FILE_PATH_LITERAL("chrome_proxy.exe");
}
int WINAPI wWinMain(HINSTANCE instance,
HINSTANCE prev_instance,
wchar_t* ,
int show_command) {
base::CommandLine::Init(0, nullptr);
logging::LoggingSettings logging_settings;
logging_settings.logging_dest =
logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
logging::InitLogging(logging_settings);
base::FilePath chrome_dir;
CHECK(base::PathService::Get(base::DIR_EXE, &chrome_dir));
base::CommandLine chrome_command_line(chrome_dir.Append(kChromeExecutable));
const std::vector<std::wstring>& argv =
base::CommandLine::ForCurrentProcess()->argv();
CHECK(argv.size() > 0);
CHECK_EQ(base::FilePath(argv[0]).BaseName().value(), kChromeProxyExecutable);
for (size_t i = 1; i < argv.size(); ++i)
chrome_command_line.AppendArgNative(argv[i]);
STARTUPINFOW si = {sizeof(si)};
::GetStartupInfoW(&si);
if (si.dwFlags & STARTF_TITLEISLINKNAME) {
chrome_command_line.AppendSwitchNative(switches::kSourceShortcut,
si.lpTitle);
} else if (si.dwFlags & STARTF_TITLEISAPPID) {
chrome_command_line.AppendSwitch(switches::kSourceAppId);
}
base::LaunchOptions launch_options;
launch_options.current_directory = chrome_dir;
launch_options.grant_foreground_privilege = true;
CHECK(base::LaunchProcess(chrome_command_line, launch_options).IsValid());
return 0;
}