Check existence of Widevince CDM/Adapter on load failure on Win.
[chromium-blink-merge.git] / chrome / app / chrome_exe_main_win.cc
blobde2ba11db48d31aedb8975e61868a0d5b138cf6f
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <windows.h>
6 #include <tchar.h>
8 #include <string>
10 #include "base/at_exit.h"
11 #include "base/command_line.h"
12 #include "base/files/file_path.h"
13 #include "chrome/app/client_util.h"
14 #include "chrome/browser/chrome_process_finder_win.h"
15 #include "chrome/browser/policy/policy_path_parser.h"
16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths_internal.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome_elf/chrome_elf_main.h"
20 #include "components/startup_metric_utils/startup_metric_utils.h"
21 #include "content/public/common/result_codes.h"
22 #include "ui/gfx/win/dpi.h"
24 namespace {
26 void CheckSafeModeLaunch() {
27 unsigned short k1 = ::GetAsyncKeyState(VK_CONTROL);
28 unsigned short k2 = ::GetAsyncKeyState(VK_MENU);
29 const unsigned short kPressedMask = 0x8000;
30 if ((k1 & kPressedMask) && (k2 & kPressedMask))
31 ::SetEnvironmentVariableA(chrome::kSafeModeEnvVar, "1");
34 // List of switches that it's safe to rendezvous early with. Fast start should
35 // not be done if a command line contains a switch not in this set.
36 // Note this is currently stored as a list of two because it's probably faster
37 // to iterate over this small array than building a map for constant time
38 // lookups.
39 const char* const kFastStartSwitches[] = {
40 switches::kProfileDirectory,
41 switches::kShowAppList,
44 bool IsFastStartSwitch(const std::string& command_line_switch) {
45 for (size_t i = 0; i < arraysize(kFastStartSwitches); ++i) {
46 if (command_line_switch == kFastStartSwitches[i])
47 return true;
49 return false;
52 bool ContainsNonFastStartFlag(const CommandLine& command_line) {
53 const CommandLine::SwitchMap& switches = command_line.GetSwitches();
54 if (switches.size() > arraysize(kFastStartSwitches))
55 return true;
56 for (CommandLine::SwitchMap::const_iterator it = switches.begin();
57 it != switches.end(); ++it) {
58 if (!IsFastStartSwitch(it->first))
59 return true;
61 return false;
64 bool AttemptFastNotify(const CommandLine& command_line) {
65 if (ContainsNonFastStartFlag(command_line))
66 return false;
68 base::FilePath user_data_dir;
69 if (!chrome::GetDefaultUserDataDirectory(&user_data_dir))
70 return false;
71 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
73 HWND chrome = chrome::FindRunningChromeWindow(user_data_dir);
74 if (!chrome)
75 return false;
76 return chrome::AttemptToNotifyRunningChrome(chrome, true) ==
77 chrome::NOTIFY_SUCCESS;
80 } // namespace
82 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
83 startup_metric_utils::RecordExeMainEntryTime();
85 // Signal Chrome Elf that Chrome has begun to start.
86 SignalChromeElf();
88 // Initialize the commandline singleton from the environment.
89 CommandLine::Init(0, NULL);
90 // The exit manager is in charge of calling the dtors of singletons.
91 base::AtExitManager exit_manager;
93 gfx::EnableHighDPISupport();
95 if (AttemptFastNotify(*CommandLine::ForCurrentProcess()))
96 return 0;
98 CheckSafeModeLaunch();
100 // Load and launch the chrome dll. *Everything* happens inside.
101 MainDllLoader* loader = MakeMainDllLoader();
102 int rc = loader->Launch(instance);
103 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
104 delete loader;
105 return rc;