Index: chrome/app/chrome_exe_main_win.cc |
diff --git a/chrome/app/chrome_exe_main_win.cc b/chrome/app/chrome_exe_main_win.cc |
index 237784d5649622f84f7821ae38db1fe21b19d090..aeb8cde39320b7394876a468f6eaa5f3fc15c18d 100644 |
--- a/chrome/app/chrome_exe_main_win.cc |
+++ b/chrome/app/chrome_exe_main_win.cc |
@@ -5,11 +5,18 @@ |
#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/breakpad_win.h" |
#include "chrome/app/client_util.h" |
#include "chrome/app/metro_driver_win.h" |
+#include "chrome/browser/chrome_process_finder_win.h" |
+#include "chrome/browser/policy/policy_path_parser.h" |
+#include "chrome/common/chrome_paths_internal.h" |
+#include "chrome/common/chrome_switches.h" |
#include "content/public/app/startup_helper_win.h" |
#include "content/public/common/result_codes.h" |
#include "sandbox/win/src/sandbox_factory.h" |
@@ -34,12 +41,53 @@ int RunChrome(HINSTANCE instance) { |
return rc; |
} |
+// List of switches that it's safe to rendezvous early with. |
+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.
|
+ switches::kProfileDirectory, |
+ switches::kShowAppList, |
+}; |
+ |
+bool IsFastStartSwitch(const std::string& command_line_switch) { |
+ for (size_t i = 0; i < arraysize(kFastStartSwitches); i++) |
+ if (kFastStartSwitches[i] == command_line_switch) |
+ return true; |
+ return false; |
+} |
+ |
+bool ContainsNonFastStartFlag(CommandLine* command_line) { |
+ 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.
|
+ for (CommandLine::SwitchMap::const_iterator it = switches.begin(); |
+ it != switches.end(); it++) { |
+ if (!IsFastStartSwitch(it->first)) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool AttemptFastNotify(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 && 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.
|
+ return true; |
+ return false; |
+} |
+ |
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
// Initialize the commandline singleton from the environment. |
CommandLine::Init(0, NULL); |
// The exit manager is in charge of calling the dtors of singletons. |
base::AtExitManager exit_manager; |
+ if (AttemptFastNotify(CommandLine::ForCurrentProcess())) |
+ return 0; |
+ |
MetroDriver metro_driver; |
if (metro_driver.in_metro_mode()) |
return metro_driver.RunInMetro(instance, &RunChrome); |