Index: chrome/browser/browser_main_win.cc |
diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc |
index cf5e78391ae5659d3b7bfa8f752d8398dacf0365..583dc610c5d5c464f5bb3f0a578ba696ac3128cc 100644 |
--- a/chrome/browser/browser_main_win.cc |
+++ b/chrome/browser/browser_main_win.cc |
@@ -15,6 +15,7 @@ |
#include "base/i18n/rtl.h" |
#include "base/nss_util.h" |
#include "base/path_service.h" |
+#include "base/scoped_native_library.h" |
#include "base/scoped_ptr.h" |
#include "base/utf_string_conversions.h" |
#include "base/win/windows_version.h" |
@@ -40,6 +41,12 @@ |
#include "views/focus/accelerator_handler.h" |
#include "views/window/window.h" |
+namespace { |
+typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE* RAR)( |
+ const wchar_t* command_line, |
+ DWORD flags); |
+} // namespace |
+ |
void DidEndMainMessageLoop() { |
OleUninitialize(); |
} |
@@ -114,7 +121,7 @@ int DoUninstallTasks(bool chrome_still_running) { |
// the user if the browser process dies. These strings are stored in the |
// environment block so they are accessible in the early stages of the |
// chrome executable's lifetime. |
-void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { |
+void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { |
// Clear this var so child processes don't show the dialog by default. |
scoped_ptr<base::Environment> env(base::Environment::Create()); |
env->UnSetVar(env_vars::kShowRestart); |
@@ -146,11 +153,39 @@ void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { |
env->SetVar(env_vars::kRestartInfo, UTF16ToUTF8(dlg_strings)); |
} |
+bool RegisterApplicationRestart(const CommandLine& parsed_command_line) { |
+ // Define the type of RegisterApplicationRestart as RAR. |
+ DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA); |
+ base::ScopedNativeLibrary library(FilePath(L"kernel32.dll")); |
+ // Get the function pointer for RegisterApplicationRestart. |
+ RAR register_application_restart = static_cast<RAR>( |
+ library.GetFunctionPointer("RegisterApplicationRestart")); |
+ if (!register_application_restart) |
+ return false; |
+ |
+ // The Windows Restart Manager expects a string of command line flags only, |
+ // without the program. |
+ CommandLine command_line(CommandLine::NO_PROGRAM); |
+ command_line.AppendSwitches(parsed_command_line); |
+ command_line.AppendArgs(parsed_command_line); |
+ // Ensure restore last session is set. |
+ if (!command_line.HasSwitch(switches::kRestoreLastSession)) |
+ command_line.AppendSwitch(switches::kRestoreLastSession); |
+ const wchar_t *command_string = command_line.command_line_string().c_str(); |
+ |
+ // Restart Chrome if the computer is restarted as the result of an update. |
+ // This could be extended to handle crashes, hangs, and patches. |
+ HRESULT hr = register_application_restart(command_string, |
+ RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH); |
+ DCHECK(SUCCEEDED(hr)) << "RegisterApplicationRestart failed."; |
+ return SUCCEEDED(hr); |
+} |
+ |
// This method handles the --hide-icons and --show-icons command line options |
// for chrome that get triggered by Windows from registry entries |
// HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons |
// functionality so we just ask the users if they want to uninstall Chrome. |
-int HandleIconsCommands(const CommandLine &parsed_command_line) { |
+int HandleIconsCommands(const CommandLine& parsed_command_line) { |
if (parsed_command_line.HasSwitch(switches::kHideIcons)) { |
string16 cp_applet; |
base::win::Version version = base::win::GetVersion(); |