Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/browser_main_win.cc

Issue 6462024: Register Application Restart with Windows Restart Manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use GetFunctionPointer to avoid XP link and run errors. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/browser_main_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/browser_main.h" 5 #include "chrome/browser/browser_main.h"
6 #include "chrome/browser/browser_main_win.h" 6 #include "chrome/browser/browser_main_win.h"
7 7
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/environment.h" 14 #include "base/environment.h"
15 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
16 #include "base/nss_util.h" 16 #include "base/nss_util.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/scoped_native_library.h"
18 #include "base/scoped_ptr.h" 19 #include "base/scoped_ptr.h"
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
21 #include "chrome/browser/browser_list.h" 22 #include "chrome/browser/browser_list.h"
22 #include "chrome/browser/first_run/first_run.h" 23 #include "chrome/browser/first_run/first_run.h"
23 #include "chrome/browser/metrics/metrics_service.h" 24 #include "chrome/browser/metrics/metrics_service.h"
24 #include "chrome/browser/ui/views/uninstall_view.h" 25 #include "chrome/browser/ui/views/uninstall_view.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/env_vars.h" 27 #include "chrome/common/env_vars.h"
27 #include "chrome/common/main_function_params.h" 28 #include "chrome/common/main_function_params.h"
28 #include "chrome/common/result_codes.h" 29 #include "chrome/common/result_codes.h"
29 #include "chrome/installer/util/browser_distribution.h" 30 #include "chrome/installer/util/browser_distribution.h"
30 #include "chrome/installer/util/helper.h" 31 #include "chrome/installer/util/helper.h"
31 #include "chrome/installer/util/install_util.h" 32 #include "chrome/installer/util/install_util.h"
32 #include "chrome/installer/util/shell_util.h" 33 #include "chrome/installer/util/shell_util.h"
33 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
34 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
35 #include "net/base/winsock_init.h" 36 #include "net/base/winsock_init.h"
36 #include "net/socket/ssl_client_socket_nss_factory.h" 37 #include "net/socket/ssl_client_socket_nss_factory.h"
37 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/l10n/l10n_util_win.h" 39 #include "ui/base/l10n/l10n_util_win.h"
39 #include "ui/base/message_box_win.h" 40 #include "ui/base/message_box_win.h"
40 #include "views/focus/accelerator_handler.h" 41 #include "views/focus/accelerator_handler.h"
41 #include "views/window/window.h" 42 #include "views/window/window.h"
42 43
44 namespace {
45 typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *RAR)(
Ben Goodger (Google) 2011/02/18 23:41:51 STDAPICALLTYPE*
msw 2011/02/18 23:57:36 Done.
46 const wchar_t *pwzCommandline,
Ben Goodger (Google) 2011/02/18 23:41:51 we don't use hungarian... const wchar_t* command_
msw 2011/02/18 23:57:36 Done.
47 DWORD dwFlags);
Ben Goodger (Google) 2011/02/18 23:41:51 flags
msw 2011/02/18 23:57:36 Done.
48 } // namespace
49
43 void DidEndMainMessageLoop() { 50 void DidEndMainMessageLoop() {
44 OleUninitialize(); 51 OleUninitialize();
45 } 52 }
46 53
47 void RecordBreakpadStatusUMA(MetricsService* metrics) { 54 void RecordBreakpadStatusUMA(MetricsService* metrics) {
48 DWORD len = ::GetEnvironmentVariableW( 55 DWORD len = ::GetEnvironmentVariableW(
49 ASCIIToWide(env_vars::kNoOOBreakpad).c_str() , NULL, 0); 56 ASCIIToWide(env_vars::kNoOOBreakpad).c_str() , NULL, 0);
50 metrics->RecordBreakpadRegistration((len == 0)); 57 metrics->RecordBreakpadRegistration((len == 0));
51 metrics->RecordBreakpadHasDebugger(TRUE == ::IsDebuggerPresent()); 58 metrics->RecordBreakpadHasDebugger(TRUE == ::IsDebuggerPresent());
52 } 59 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ShellUtil::CURRENT_USER)) 114 ShellUtil::CURRENT_USER))
108 VLOG(1) << "Failed to delete quick launch shortcut."; 115 VLOG(1) << "Failed to delete quick launch shortcut.";
109 } 116 }
110 return ret; 117 return ret;
111 } 118 }
112 119
113 // Prepares the localized strings that are going to be displayed to 120 // Prepares the localized strings that are going to be displayed to
114 // the user if the browser process dies. These strings are stored in the 121 // the user if the browser process dies. These strings are stored in the
115 // environment block so they are accessible in the early stages of the 122 // environment block so they are accessible in the early stages of the
116 // chrome executable's lifetime. 123 // chrome executable's lifetime.
117 void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { 124 void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) {
118 // Clear this var so child processes don't show the dialog by default. 125 // Clear this var so child processes don't show the dialog by default.
119 scoped_ptr<base::Environment> env(base::Environment::Create()); 126 scoped_ptr<base::Environment> env(base::Environment::Create());
120 env->UnSetVar(env_vars::kShowRestart); 127 env->UnSetVar(env_vars::kShowRestart);
121 128
122 // For non-interactive tests we don't restart on crash. 129 // For non-interactive tests we don't restart on crash.
123 if (env->HasVar(env_vars::kHeadless)) 130 if (env->HasVar(env_vars::kHeadless))
124 return; 131 return;
125 132
126 // If the known command-line test options are used we don't create the 133 // If the known command-line test options are used we don't create the
127 // environment block which means we don't get the restart dialog. 134 // environment block which means we don't get the restart dialog.
(...skipping 11 matching lines...) Expand all
139 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT)); 146 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT));
140 base::i18n::AdjustStringForLocaleDirection(&adjusted_string); 147 base::i18n::AdjustStringForLocaleDirection(&adjusted_string);
141 dlg_strings.append(adjusted_string); 148 dlg_strings.append(adjusted_string);
142 dlg_strings.push_back('|'); 149 dlg_strings.push_back('|');
143 dlg_strings.append(ASCIIToUTF16( 150 dlg_strings.append(ASCIIToUTF16(
144 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale)); 151 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale));
145 152
146 env->SetVar(env_vars::kRestartInfo, UTF16ToUTF8(dlg_strings)); 153 env->SetVar(env_vars::kRestartInfo, UTF16ToUTF8(dlg_strings));
147 } 154 }
148 155
156 bool RegisterApplicationRestart(const CommandLine& parsed_command_line) {
157 // Define the type of RegisterApplicationRestart as RAR.
158 DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA);
159 base::ScopedNativeLibrary library(FilePath(L"kernel32.dll"));
160 // Get the function pointer for RegisterApplicationRestart.
161 RAR register_application_restart = static_cast<RAR>(
162 library.GetFunctionPointer("RegisterApplicationRestart"));
Ben Goodger (Google) 2011/02/18 23:41:51 4-space indent
msw 2011/02/18 23:57:36 Done.
163 if (!register_application_restart)
164 return false;
165
166 // The Windows Restart Manager expects a string of command line flags only,
167 // without the program.
168 CommandLine command_line(CommandLine::NO_PROGRAM);
169 command_line.AppendSwitches(parsed_command_line);
170 command_line.AppendArgs(parsed_command_line);
171 // Ensure restore last session is set.
172 if (!command_line.HasSwitch(switches::kRestoreLastSession))
173 command_line.AppendSwitch(switches::kRestoreLastSession);
174 const wchar_t *command_string = command_line.command_line_string().c_str();
175
176 // Restart Chrome if the computer is restarted as the result of an update.
177 // This could be extended to handle crashes, hangs, and patches.
178 HRESULT hr = register_application_restart(command_string,
179 RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH);
180 DCHECK(SUCCEEDED(hr)) << "RegisterApplicationRestart failed.";
181 return SUCCEEDED(hr);
182 }
183
149 // This method handles the --hide-icons and --show-icons command line options 184 // This method handles the --hide-icons and --show-icons command line options
150 // for chrome that get triggered by Windows from registry entries 185 // for chrome that get triggered by Windows from registry entries
151 // HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons 186 // HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons
152 // functionality so we just ask the users if they want to uninstall Chrome. 187 // functionality so we just ask the users if they want to uninstall Chrome.
153 int HandleIconsCommands(const CommandLine &parsed_command_line) { 188 int HandleIconsCommands(const CommandLine& parsed_command_line) {
154 if (parsed_command_line.HasSwitch(switches::kHideIcons)) { 189 if (parsed_command_line.HasSwitch(switches::kHideIcons)) {
155 string16 cp_applet; 190 string16 cp_applet;
156 base::win::Version version = base::win::GetVersion(); 191 base::win::Version version = base::win::GetVersion();
157 if (version >= base::win::VERSION_VISTA) { 192 if (version >= base::win::VERSION_VISTA) {
158 cp_applet.assign(L"Programs and Features"); // Windows Vista and later. 193 cp_applet.assign(L"Programs and Features"); // Windows Vista and later.
159 } else if (version >= base::win::VERSION_XP) { 194 } else if (version >= base::win::VERSION_XP) {
160 cp_applet.assign(L"Add/Remove Programs"); // Windows XP. 195 cp_applet.assign(L"Add/Remove Programs"); // Windows XP.
161 } else { 196 } else {
162 return ResultCodes::UNSUPPORTED_PARAM; // Not supported 197 return ResultCodes::UNSUPPORTED_PARAM; // Not supported
163 } 198 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 base::EnsureNSPRInit(); 280 base::EnsureNSPRInit();
246 } 281 }
247 } 282 }
248 }; 283 };
249 284
250 // static 285 // static
251 BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( 286 BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
252 const MainFunctionParams& parameters) { 287 const MainFunctionParams& parameters) {
253 return new BrowserMainPartsWin(parameters); 288 return new BrowserMainPartsWin(parameters);
254 } 289 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_main_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698