This source file includes following definitions.
- CheckSafeModeLaunch
- IsFastStartSwitch
- ContainsNonFastStartFlag
- AttemptFastNotify
- wWinMain
#include <windows.h>
#include <tchar.h>
#include <string>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "chrome/app/client_util.h"
#include "chrome/browser/chrome_process_finder_win.h"
#include "chrome/browser/policy/policy_path_parser.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#include "chrome_elf/chrome_elf_main.h"
#include "components/startup_metric_utils/startup_metric_utils.h"
#include "content/public/common/result_codes.h"
#include "ui/gfx/win/dpi.h"
namespace {
void CheckSafeModeLaunch() {
unsigned short k1 = ::GetAsyncKeyState(VK_CONTROL);
unsigned short k2 = ::GetAsyncKeyState(VK_MENU);
const unsigned short kPressedMask = 0x8000;
if ((k1 & kPressedMask) && (k2 & kPressedMask))
::SetEnvironmentVariableA(chrome::kSafeModeEnvVar, "1");
}
const char* const kFastStartSwitches[] = {
switches::kProfileDirectory,
switches::kShowAppList,
};
bool IsFastStartSwitch(const std::string& command_line_switch) {
for (size_t i = 0; i < arraysize(kFastStartSwitches); ++i) {
if (command_line_switch == kFastStartSwitches[i])
return true;
}
return false;
}
bool ContainsNonFastStartFlag(const CommandLine& command_line) {
const CommandLine::SwitchMap& switches = command_line.GetSwitches();
if (switches.size() > arraysize(kFastStartSwitches))
return true;
for (CommandLine::SwitchMap::const_iterator it = switches.begin();
it != switches.end(); ++it) {
if (!IsFastStartSwitch(it->first))
return true;
}
return false;
}
bool AttemptFastNotify(const CommandLine& command_line) {
if (ContainsNonFastStartFlag(command_line))
return false;
base::FilePath user_data_dir;
if (!chrome::GetDefaultUserDataDirectory(&user_data_dir))
return false;
policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
HWND chrome = chrome::FindRunningChromeWindow(user_data_dir);
if (!chrome)
return false;
return chrome::AttemptToNotifyRunningChrome(chrome, true) ==
chrome::NOTIFY_SUCCESS;
}
}
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
startup_metric_utils::RecordExeMainEntryTime();
SignalChromeElf();
CommandLine::Init(0, NULL);
base::AtExitManager exit_manager;
gfx::EnableHighDPISupport();
if (AttemptFastNotify(*CommandLine::ForCurrentProcess()))
return 0;
CheckSafeModeLaunch();
MainDllLoader* loader = MakeMainDllLoader();
int rc = loader->Launch(instance);
loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
delete loader;
return rc;
}