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..2ed9ee6a5243da5a6fd7efafe9fc42db6950a34e 100644 |
--- a/chrome/app/chrome_exe_main_win.cc |
+++ b/chrome/app/chrome_exe_main_win.cc |
@@ -5,15 +5,25 @@ |
#include <windows.h> |
#include <tchar.h> |
+#include <algorithm> |
+#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" |
+namespace { |
+ |
int RunChrome(HINSTANCE instance) { |
bool exit_now = true; |
// We restarted because of a previous crash. Ask user if we should relaunch. |
@@ -34,12 +44,54 @@ int RunChrome(HINSTANCE instance) { |
return rc; |
} |
+ |
+bool IsFastStartSwitch(const std::string& command_line_switch) { |
+ // List of switches that it's safe to rendezvous early with. Fast start should |
+ // not be done if a command line contains a switch not in this set. |
+ static const char* kFastStartSwitches[] = { |
grt (UTC plus 2)
2013/05/13 13:32:07
Use the extra const to keep the whole structure in
koz (OOO until 15th September)
2013/05/14 08:39:54
Done.
|
+ switches::kProfileDirectory, |
+ switches::kShowAppList, |
+ }; |
+ for (size_t i = 0; i < arraysize(kFastStartSwitches); ++i) |
gab
2013/05/13 13:27:43
nit: wrap for loop in {} since content is multiple
grt (UTC plus 2)
2013/05/13 13:32:07
braces on the "for" loop
koz (OOO until 15th September)
2013/05/14 08:39:54
Done.
koz (OOO until 15th September)
2013/05/14 08:39:54
Done.
|
+ if (command_line_switch == kFastStartSwitches[i]) |
+ return true; |
+ return false; |
+} |
+ |
+bool ContainsNonFastStartFlag(CommandLine* command_line) { |
gab
2013/05/13 13:27:43
This algorithm is O(m*n), where:
m is the number o
koz (OOO until 15th September)
2013/05/14 08:39:54
I added the comment and the size check.
|
+ const CommandLine::SwitchMap& switches = command_line->GetSwitches(); |
gab
2013/05/13 13:27:43
Hmmm... GetSwitches is confusing, it says "// Get
koz (OOO until 15th September)
2013/05/14 08:39:54
Done.
|
+ for (CommandLine::SwitchMap::const_iterator it = switches.begin(); |
+ it != switches.end(); it++) { |
gab
2013/05/13 13:27:43
nit: ++it
koz (OOO until 15th September)
2013/05/14 08:39:54
Done.
|
+ 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); |
+ return chrome && chrome::AttemptToNotifyRunningChrome(chrome); |
+} |
+ |
+} // namespace |
+ |
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); |