Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 #include <tchar.h> | 6 #include <tchar.h> |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 8 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | |
| 10 #include "chrome/app/breakpad_win.h" | 13 #include "chrome/app/breakpad_win.h" |
| 11 #include "chrome/app/client_util.h" | 14 #include "chrome/app/client_util.h" |
| 12 #include "chrome/app/metro_driver_win.h" | 15 #include "chrome/app/metro_driver_win.h" |
| 16 #include "chrome/browser/chrome_process_finder_win.h" | |
| 17 #include "chrome/browser/policy/policy_path_parser.h" | |
| 18 #include "chrome/common/chrome_paths_internal.h" | |
| 19 #include "chrome/common/chrome_switches.h" | |
| 13 #include "content/public/app/startup_helper_win.h" | 20 #include "content/public/app/startup_helper_win.h" |
| 14 #include "content/public/common/result_codes.h" | 21 #include "content/public/common/result_codes.h" |
| 15 #include "sandbox/win/src/sandbox_factory.h" | 22 #include "sandbox/win/src/sandbox_factory.h" |
| 16 | 23 |
| 17 int RunChrome(HINSTANCE instance) { | 24 int RunChrome(HINSTANCE instance) { |
|
grt (UTC plus 2)
2013/05/09 16:10:44
put this and all of your new code into an unnamed
koz (OOO until 15th September)
2013/05/10 01:46:48
Done.
| |
| 18 bool exit_now = true; | 25 bool exit_now = true; |
| 19 // We restarted because of a previous crash. Ask user if we should relaunch. | 26 // We restarted because of a previous crash. Ask user if we should relaunch. |
| 20 if (ShowRestartDialogIfCrashed(&exit_now)) { | 27 if (ShowRestartDialogIfCrashed(&exit_now)) { |
| 21 if (exit_now) | 28 if (exit_now) |
| 22 return content::RESULT_CODE_NORMAL_EXIT; | 29 return content::RESULT_CODE_NORMAL_EXIT; |
| 23 } | 30 } |
| 24 | 31 |
| 25 // Initialize the sandbox services. | 32 // Initialize the sandbox services. |
| 26 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 33 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 27 content::InitializeSandboxInfo(&sandbox_info); | 34 content::InitializeSandboxInfo(&sandbox_info); |
| 28 | 35 |
| 29 // Load and launch the chrome dll. *Everything* happens inside. | 36 // Load and launch the chrome dll. *Everything* happens inside. |
| 30 MainDllLoader* loader = MakeMainDllLoader(); | 37 MainDllLoader* loader = MakeMainDllLoader(); |
| 31 int rc = loader->Launch(instance, &sandbox_info); | 38 int rc = loader->Launch(instance, &sandbox_info); |
| 32 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 39 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 33 delete loader; | 40 delete loader; |
| 34 return rc; | 41 return rc; |
| 35 } | 42 } |
| 36 | 43 |
| 44 // List of switches that it's safe to rendezvous early with. | |
| 45 const std::string kFastStartSwitches[] = { | |
|
grt (UTC plus 2)
2013/05/09 16:10:44
this will create exit-time dtors, which is banned.
koz (OOO until 15th September)
2013/05/10 01:46:48
Done.
| |
| 46 switches::kProfileDirectory, | |
| 47 switches::kShowAppList, | |
| 48 }; | |
| 49 | |
| 50 bool IsFastStartSwitch(const std::string& command_line_switch) { | |
| 51 for (size_t i = 0; i < arraysize(kFastStartSwitches); i++) | |
| 52 if (kFastStartSwitches[i] == command_line_switch) | |
| 53 return true; | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 bool ContainsNonFastStartFlag(CommandLine* command_line) { | |
| 58 const CommandLine::SwitchMap& switches = command_line->GetSwitches(); | |
|
grt (UTC plus 2)
2013/05/09 16:10:44
i think you're better off with:
static const cha
koz (OOO until 15th September)
2013/05/10 01:46:48
I think the code you've given will return true iff
grt (UTC plus 2)
2013/05/10 16:53:04
oops. i see. apologies for the bad suggestion.
| |
| 59 for (CommandLine::SwitchMap::const_iterator it = switches.begin(); | |
| 60 it != switches.end(); it++) { | |
| 61 if (!IsFastStartSwitch(it->first)) | |
| 62 return true; | |
| 63 } | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 bool AttemptFastNotify(CommandLine* command_line) { | |
| 68 if (ContainsNonFastStartFlag(command_line)) | |
| 69 return false; | |
| 70 | |
| 71 base::FilePath user_data_dir; | |
| 72 if (!chrome::GetDefaultUserDataDirectory(&user_data_dir)) | |
| 73 return false; | |
| 74 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); | |
| 75 | |
| 76 HWND chrome = chrome::FindRunningChromeWindow(user_data_dir); | |
| 77 if (chrome && chrome::AttemptToNotifyRunningChrome(chrome)) | |
|
grt (UTC plus 2)
2013/05/09 16:10:44
return chrome && chrome::AttemptToNotifyRunningChr
koz (OOO until 15th September)
2013/05/10 01:46:48
Done.
| |
| 78 return true; | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 37 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 82 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
| 38 // Initialize the commandline singleton from the environment. | 83 // Initialize the commandline singleton from the environment. |
| 39 CommandLine::Init(0, NULL); | 84 CommandLine::Init(0, NULL); |
| 40 // The exit manager is in charge of calling the dtors of singletons. | 85 // The exit manager is in charge of calling the dtors of singletons. |
| 41 base::AtExitManager exit_manager; | 86 base::AtExitManager exit_manager; |
| 42 | 87 |
| 88 if (AttemptFastNotify(CommandLine::ForCurrentProcess())) | |
| 89 return 0; | |
| 90 | |
| 43 MetroDriver metro_driver; | 91 MetroDriver metro_driver; |
| 44 if (metro_driver.in_metro_mode()) | 92 if (metro_driver.in_metro_mode()) |
| 45 return metro_driver.RunInMetro(instance, &RunChrome); | 93 return metro_driver.RunInMetro(instance, &RunChrome); |
| 46 // Not in metro mode, proceed as normal. | 94 // Not in metro mode, proceed as normal. |
| 47 return RunChrome(instance); | 95 return RunChrome(instance); |
| 48 } | 96 } |
| OLD | NEW |