Componentize ShortcutsBackend
[chromium-blink-merge.git] / chrome / browser / chrome_browser_main_win.cc
blobe7f36d65ac23198948907c4f3ce5720d37124ae3
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_browser_main_win.h"
7 #include <windows.h>
8 #include <shellapi.h>
10 #include <algorithm>
12 #include "base/command_line.h"
13 #include "base/environment.h"
14 #include "base/files/file_enumerator.h"
15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h"
17 #include "base/i18n/rtl.h"
18 #include "base/location.h"
19 #include "base/macros.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/metrics/histogram.h"
22 #include "base/path_service.h"
23 #include "base/scoped_native_library.h"
24 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "base/win/metro.h"
27 #include "base/win/registry.h"
28 #include "base/win/win_util.h"
29 #include "base/win/windows_version.h"
30 #include "base/win/wrapped_window_proc.h"
31 #include "chrome/browser/browser_util_win.h"
32 #include "chrome/browser/chrome_elf_init_win.h"
33 #include "chrome/browser/first_run/first_run.h"
34 #include "chrome/browser/install_verification/win/install_verification.h"
35 #include "chrome/browser/profiles/profile_info_cache.h"
36 #include "chrome/browser/profiles/profile_shortcut_manager.h"
37 #include "chrome/browser/shell_integration.h"
38 #include "chrome/browser/ui/simple_message_box.h"
39 #include "chrome/browser/ui/uninstall_browser_prompt.h"
40 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
41 #include "chrome/common/chrome_constants.h"
42 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/chrome_result_codes.h"
44 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/chrome_utility_messages.h"
46 #include "chrome/common/chrome_version_info.h"
47 #include "chrome/common/env_vars.h"
48 #include "chrome/grit/chromium_strings.h"
49 #include "chrome/grit/generated_resources.h"
50 #include "chrome/installer/util/browser_distribution.h"
51 #include "chrome/installer/util/helper.h"
52 #include "chrome/installer/util/install_util.h"
53 #include "chrome/installer/util/installer_util_strings.h"
54 #include "chrome/installer/util/l10n_string_util.h"
55 #include "chrome/installer/util/shell_util.h"
56 #include "content/public/browser/browser_thread.h"
57 #include "content/public/browser/utility_process_host.h"
58 #include "content/public/browser/utility_process_host_client.h"
59 #include "content/public/common/content_switches.h"
60 #include "content/public/common/dwrite_font_platform_win.h"
61 #include "content/public/common/main_function_params.h"
62 #include "ui/base/cursor/cursor_loader_win.h"
63 #include "ui/base/l10n/l10n_util.h"
64 #include "ui/base/l10n/l10n_util_win.h"
65 #include "ui/base/ui_base_switches.h"
66 #include "ui/base/win/message_box_win.h"
67 #include "ui/gfx/platform_font_win.h"
68 #include "ui/gfx/switches.h"
69 #include "ui/gfx/win/direct_write.h"
70 #include "ui/strings/grit/app_locale_settings.h"
72 #if defined(GOOGLE_CHROME_BUILD)
73 #include "chrome/browser/google/did_run_updater_win.h"
74 #endif
76 #if defined(KASKO)
77 #include "syzygy/kasko/api/reporter.h"
78 #endif
80 namespace {
82 typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)(
83 const wchar_t* command_line,
84 DWORD flags);
86 void InitializeWindowProcExceptions() {
87 // Get the breakpad pointer from chrome.exe
88 base::win::WinProcExceptionFilter exception_filter =
89 reinterpret_cast<base::win::WinProcExceptionFilter>(
90 ::GetProcAddress(::GetModuleHandle(
91 chrome::kBrowserProcessExecutableName),
92 "CrashForException"));
93 exception_filter = base::win::SetWinProcExceptionFilter(exception_filter);
94 DCHECK(!exception_filter);
97 // gfx::Font callbacks
98 void AdjustUIFont(LOGFONT* logfont) {
99 l10n_util::AdjustUIFont(logfont);
102 int GetMinimumFontSize() {
103 int min_font_size;
104 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE),
105 &min_font_size);
106 return min_font_size;
109 class TranslationDelegate : public installer::TranslationDelegate {
110 public:
111 base::string16 GetLocalizedString(int installer_string_id) override;
114 void ExecuteFontCacheBuildTask(const base::FilePath& path) {
115 base::WeakPtr<content::UtilityProcessHost> utility_process_host(
116 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr());
117 utility_process_host->SetName(l10n_util::GetStringUTF16(
118 IDS_UTILITY_PROCESS_FONT_CACHE_BUILDER_NAME));
119 utility_process_host->DisableSandbox();
120 utility_process_host->Send(
121 new ChromeUtilityHostMsg_BuildDirectWriteFontCache(path));
124 #if defined(KASKO)
125 void ObserveFailedCrashReportDirectory(const base::FilePath& path, bool error) {
126 DCHECK(!error);
127 if (error)
128 return;
129 base::FileEnumerator enumerator(path, true, base::FileEnumerator::FILES);
130 for (base::FilePath report_file = enumerator.Next(); !report_file.empty();
131 report_file = enumerator.Next()) {
132 if (report_file.Extension() ==
133 kasko::api::kPermanentFailureMinidumpExtension) {
134 UMA_HISTOGRAM_BOOLEAN("CrashReport.PermanentUploadFailure", true);
136 bool result = base::DeleteFile(report_file, false);
137 DCHECK(result);
141 void StartFailedKaskoCrashReportWatcher(base::FilePathWatcher* watcher) {
142 base::FilePath watcher_data_directory;
143 if (!PathService::Get(chrome::DIR_WATCHER_DATA, &watcher_data_directory)) {
144 NOTREACHED();
145 } else {
146 base::FilePath permanent_failure_directory =
147 watcher_data_directory.Append(kPermanentlyFailedReportsSubdir);
148 if (!watcher->Watch(permanent_failure_directory, true,
149 base::Bind(&ObserveFailedCrashReportDirectory))) {
150 NOTREACHED();
153 // Call it once to observe any files present prior to the Watch() call.
154 ObserveFailedCrashReportDirectory(permanent_failure_directory, false);
157 #endif
159 void DetectFaultTolerantHeap() {
160 enum FTHFlags {
161 FTH_HKLM = 1,
162 FTH_HKCU = 2,
163 FTH_ACLAYERS_LOADED = 4,
164 FTH_ACXTRNAL_LOADED = 8,
165 FTH_FLAGS_COUNT = 16
168 // The Fault Tolerant Heap (FTH) is enabled on some customer machines and is
169 // affecting their performance. We need to know how many machines are
170 // affected in order to decide what to do.
172 // The main way that the FTH is enabled is by having a value set in
173 // HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
174 // whose name is the full path to the executable and whose data is the
175 // string FaultTolerantHeap. Some documents suggest that this data may also
176 // be found in HKCU. There have also been cases observed where this registry
177 // key is set but the FTH is not enabled, so we also look for AcXtrnal.dll
178 // and AcLayers.dll which are used to implement the FTH on Windows 7 and 8
179 // respectively.
181 // Get the module path so that we can look for it in the registry.
182 wchar_t module_path[MAX_PATH];
183 GetModuleFileName(NULL, module_path, ARRAYSIZE(module_path));
184 // Force null-termination, necessary on Windows XP.
185 module_path[ARRAYSIZE(module_path)-1] = 0;
187 const wchar_t* const kRegPath = L"Software\\Microsoft\\Windows NT\\"
188 L"CurrentVersion\\AppCompatFlags\\Layers";
189 const wchar_t* const kFTHData = L"FaultTolerantHeap";
190 // We always want to read from the 64-bit version of the registry if present,
191 // since that is what the OS looks at, even for 32-bit processes.
192 const DWORD kRegFlags = KEY_READ | KEY_WOW64_64KEY;
194 base::win::RegKey FTH_HKLM_reg(HKEY_LOCAL_MACHINE, kRegPath, kRegFlags);
195 FTHFlags detected = FTHFlags();
196 base::string16 chrome_app_compat;
197 if (FTH_HKLM_reg.ReadValue(module_path, &chrome_app_compat) == 0) {
198 // This *usually* indicates that the fault tolerant heap is enabled.
199 if (wcsicmp(chrome_app_compat.c_str(), kFTHData) == 0)
200 detected = static_cast<FTHFlags>(detected | FTH_HKLM);
203 base::win::RegKey FTH_HKCU_reg(HKEY_CURRENT_USER, kRegPath, kRegFlags);
204 if (FTH_HKCU_reg.ReadValue(module_path, &chrome_app_compat) == 0) {
205 if (wcsicmp(chrome_app_compat.c_str(), kFTHData) == 0)
206 detected = static_cast<FTHFlags>(detected | FTH_HKCU);
209 // Look for the DLLs used to implement the FTH and other compat hacks.
210 if (GetModuleHandleW(L"AcLayers.dll") != NULL)
211 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED);
212 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL)
213 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED);
215 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT);
218 } // namespace
220 void ShowCloseBrowserFirstMessageBox() {
221 int message_id = IDS_UNINSTALL_CLOSE_APP;
222 if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
223 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) {
224 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE;
226 chrome::ShowMessageBox(NULL,
227 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
228 l10n_util::GetStringUTF16(message_id),
229 chrome::MESSAGE_BOX_TYPE_WARNING);
232 int DoUninstallTasks(bool chrome_still_running) {
233 // We want to show a warning to user (and exit) if Chrome is already running
234 // *before* we show the uninstall confirmation dialog box. But while the
235 // uninstall confirmation dialog is up, user might start Chrome, so we
236 // check once again after user acknowledges Uninstall dialog.
237 if (chrome_still_running) {
238 ShowCloseBrowserFirstMessageBox();
239 return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE;
241 int result = chrome::ShowUninstallBrowserPrompt();
242 if (browser_util::IsBrowserAlreadyRunning()) {
243 ShowCloseBrowserFirstMessageBox();
244 return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE;
247 if (result != chrome::RESULT_CODE_UNINSTALL_USER_CANCEL) {
248 // The following actions are just best effort.
249 // TODO(gab): Look into removing this code which is now redundant with the
250 // work done by setup.exe on uninstall.
251 VLOG(1) << "Executing uninstall actions";
252 base::FilePath chrome_exe;
253 if (PathService::Get(base::FILE_EXE, &chrome_exe)) {
254 ShellUtil::ShortcutLocation user_shortcut_locations[] = {
255 ShellUtil::SHORTCUT_LOCATION_DESKTOP,
256 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
257 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
258 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
260 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
261 for (size_t i = 0; i < arraysize(user_shortcut_locations); ++i) {
262 if (!ShellUtil::RemoveShortcuts(user_shortcut_locations[i], dist,
263 ShellUtil::CURRENT_USER, chrome_exe)) {
264 VLOG(1) << "Failed to delete shortcut at location "
265 << user_shortcut_locations[i];
268 } else {
269 NOTREACHED();
272 return result;
275 // ChromeBrowserMainPartsWin ---------------------------------------------------
277 ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin(
278 const content::MainFunctionParams& parameters)
279 : ChromeBrowserMainParts(parameters) {
280 if (base::win::IsMetroProcess()) {
281 typedef const wchar_t* (*GetMetroSwitches)(void);
282 GetMetroSwitches metro_switches_proc = reinterpret_cast<GetMetroSwitches>(
283 GetProcAddress(base::win::GetMetroModule(),
284 "GetMetroCommandLineSwitches"));
285 if (metro_switches_proc) {
286 base::string16 metro_switches = (*metro_switches_proc)();
287 if (!metro_switches.empty()) {
288 base::CommandLine extra_switches(base::CommandLine::NO_PROGRAM);
289 extra_switches.ParseFromString(metro_switches);
290 base::CommandLine::ForCurrentProcess()->AppendArguments(extra_switches,
291 false);
297 ChromeBrowserMainPartsWin::~ChromeBrowserMainPartsWin() {
300 void ChromeBrowserMainPartsWin::ToolkitInitialized() {
301 ChromeBrowserMainParts::ToolkitInitialized();
302 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
303 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
304 ui::CursorLoaderWin::SetCursorResourceModule(chrome::kBrowserResourcesDll);
307 void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() {
308 // installer_util references strings that are normally compiled into
309 // setup.exe. In Chrome, these strings are in the locale files.
310 SetupInstallerUtilStrings();
312 ChromeBrowserMainParts::PreMainMessageLoopStart();
313 if (!parameters().ui_task) {
314 // Make sure that we know how to handle exceptions from the message loop.
315 InitializeWindowProcExceptions();
319 int ChromeBrowserMainPartsWin::PreCreateThreads() {
320 int rv = ChromeBrowserMainParts::PreCreateThreads();
322 // TODO(viettrungluu): why don't we run this earlier?
323 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs) &&
324 base::win::GetVersion() < base::win::VERSION_XP) {
325 chrome::ShowMessageBox(NULL,
326 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
327 l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP),
328 chrome::MESSAGE_BOX_TYPE_WARNING);
331 return rv;
334 void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() {
335 ui::MessageBox(NULL,
336 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage),
337 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle),
338 MB_OK | MB_ICONERROR | MB_TOPMOST);
341 void ChromeBrowserMainPartsWin::PostProfileInit() {
342 ChromeBrowserMainParts::PostProfileInit();
344 // DirectWrite support is mainly available Windows 7 and up.
345 if (gfx::win::ShouldUseDirectWrite()) {
346 base::FilePath path(
347 profile()->GetPath().AppendASCII(content::kFontCacheSharedSectionName));
348 // This function will create a read only section if cache file exists
349 // otherwise it will spawn utility process to build cache file, which will
350 // be used during next browser start/postprofileinit.
351 if (!content::LoadFontCache(path)) {
352 // We delay building of font cache until first startup page loads.
353 // During first renderer start there are lot of things happening
354 // simultaneously some of them are:
355 // - Renderer is going through all font files on the system to create
356 // a font collection.
357 // - Renderer loading up startup URL, accessing HTML/JS File cache,
358 // net activity etc.
359 // - Extension initialization.
360 // We delay building of cache mainly to avoid parallel font file
361 // loading along with Renderer. Some systems have significant number of
362 // font files which takes long time to process.
363 // Related information is at http://crbug.com/436195.
364 const int kBuildFontCacheDelaySec = 30;
365 content::BrowserThread::PostDelayedTask(
366 content::BrowserThread::IO,
367 FROM_HERE,
368 base::Bind(ExecuteFontCacheBuildTask, path),
369 base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec));
374 void ChromeBrowserMainPartsWin::PostBrowserStart() {
375 ChromeBrowserMainParts::PostBrowserStart();
377 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice());
379 // Set up a task to verify installed modules in the current process.
380 content::BrowserThread::PostAfterStartupTask(
381 FROM_HERE, content::BrowserThread::GetBlockingPool(),
382 base::Bind(&VerifyInstallation));
384 InitializeChromeElf();
386 #if defined(KASKO)
387 content::BrowserThread::PostDelayedTask(
388 content::BrowserThread::FILE, FROM_HERE,
389 base::Bind(&StartFailedKaskoCrashReportWatcher,
390 base::Unretained(&failed_kasko_crash_report_watcher_)),
391 base::TimeDelta::FromMinutes(5));
392 #endif
394 #if defined(GOOGLE_CHROME_BUILD)
395 did_run_updater_.reset(new DidRunUpdater);
396 #endif
398 // Record UMA data about whether the fault-tolerant heap is enabled.
399 // Use a delayed task to minimize the impact on startup time.
400 content::BrowserThread::PostDelayedTask(
401 content::BrowserThread::UI,
402 FROM_HERE,
403 base::Bind(&DetectFaultTolerantHeap),
404 base::TimeDelta::FromMinutes(1));
407 // static
408 void ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
409 const base::CommandLine& parsed_command_line) {
410 // Clear this var so child processes don't show the dialog by default.
411 scoped_ptr<base::Environment> env(base::Environment::Create());
412 env->UnSetVar(env_vars::kShowRestart);
414 // For non-interactive tests we don't restart on crash.
415 if (env->HasVar(env_vars::kHeadless))
416 return;
418 // If the known command-line test options are used we don't create the
419 // environment block which means we don't get the restart dialog.
420 if (parsed_command_line.HasSwitch(switches::kBrowserCrashTest) ||
421 parsed_command_line.HasSwitch(switches::kNoErrorDialogs))
422 return;
424 // The encoding we use for the info is "title|context|direction" where
425 // direction is either env_vars::kRtlLocale or env_vars::kLtrLocale depending
426 // on the current locale.
427 base::string16 dlg_strings(
428 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_TITLE));
429 dlg_strings.push_back('|');
430 base::string16 adjusted_string(
431 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT));
432 base::i18n::AdjustStringForLocaleDirection(&adjusted_string);
433 dlg_strings.append(adjusted_string);
434 dlg_strings.push_back('|');
435 dlg_strings.append(base::ASCIIToUTF16(
436 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale));
438 env->SetVar(env_vars::kRestartInfo, base::UTF16ToUTF8(dlg_strings));
441 // static
442 void ChromeBrowserMainPartsWin::RegisterApplicationRestart(
443 const base::CommandLine& parsed_command_line) {
444 DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA);
445 base::ScopedNativeLibrary library(base::FilePath(L"kernel32.dll"));
446 // Get the function pointer for RegisterApplicationRestart.
447 RegisterApplicationRestartProc register_application_restart =
448 reinterpret_cast<RegisterApplicationRestartProc>(
449 library.GetFunctionPointer("RegisterApplicationRestart"));
450 if (!register_application_restart) {
451 LOG(WARNING) << "Cannot find RegisterApplicationRestart in kernel32.dll";
452 return;
454 // The Windows Restart Manager expects a string of command line flags only,
455 // without the program.
456 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
457 command_line.AppendArguments(parsed_command_line, false);
458 if (!command_line.HasSwitch(switches::kRestoreLastSession))
459 command_line.AppendSwitch(switches::kRestoreLastSession);
461 // Restart Chrome if the computer is restarted as the result of an update.
462 // This could be extended to handle crashes, hangs, and patches.
463 HRESULT hr = register_application_restart(
464 command_line.GetCommandLineString().c_str(),
465 RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH);
466 if (FAILED(hr)) {
467 if (hr == E_INVALIDARG) {
468 LOG(WARNING) << "Command line too long for RegisterApplicationRestart";
469 } else {
470 NOTREACHED() << "RegisterApplicationRestart failed. hr: " << hr <<
471 ", command_line: " << command_line.GetCommandLineString();
476 // static
477 int ChromeBrowserMainPartsWin::HandleIconsCommands(
478 const base::CommandLine& parsed_command_line) {
479 if (parsed_command_line.HasSwitch(switches::kHideIcons)) {
480 base::string16 cp_applet;
481 base::win::Version version = base::win::GetVersion();
482 if (version >= base::win::VERSION_VISTA) {
483 cp_applet.assign(L"Programs and Features"); // Windows Vista and later.
484 } else if (version >= base::win::VERSION_XP) {
485 cp_applet.assign(L"Add/Remove Programs"); // Windows XP.
486 } else {
487 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; // Not supported
490 const base::string16 msg =
491 l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet);
492 const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
493 const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST;
494 if (IDOK == ui::MessageBox(NULL, msg, caption, flags))
495 ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL);
497 // Exit as we are not launching the browser.
498 return content::RESULT_CODE_NORMAL_EXIT;
500 // We don't hide icons so we shouldn't do anything special to show them
501 return chrome::RESULT_CODE_UNSUPPORTED_PARAM;
504 // static
505 bool ChromeBrowserMainPartsWin::CheckMachineLevelInstall() {
506 // TODO(tommi): Check if using the default distribution is always the right
507 // thing to do.
508 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
509 Version version;
510 InstallUtil::GetChromeVersion(dist, true, &version);
511 if (version.IsValid()) {
512 base::FilePath exe_path;
513 PathService::Get(base::DIR_EXE, &exe_path);
514 std::wstring exe = exe_path.value();
515 base::FilePath user_exe_path(installer::GetChromeInstallPath(false, dist));
516 if (base::FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) {
517 bool is_metro = base::win::IsMetroProcess();
518 if (!is_metro) {
519 // The dialog cannot be shown in Win8 Metro as doing so hangs Chrome on
520 // an invisible dialog.
521 // TODO (gab): Get rid of this dialog altogether and auto-launch
522 // system-level Chrome instead.
523 const base::string16 text =
524 l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT);
525 const base::string16 caption =
526 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
527 const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST;
528 ui::MessageBox(NULL, text, caption, flags);
530 base::CommandLine uninstall_cmd(
531 InstallUtil::GetChromeUninstallCmd(false, dist->GetType()));
532 if (!uninstall_cmd.GetProgram().empty()) {
533 uninstall_cmd.AppendSwitch(installer::switches::kSelfDestruct);
534 uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall);
535 uninstall_cmd.AppendSwitch(
536 installer::switches::kDoNotRemoveSharedItems);
538 // Trigger Active Setup for the system-level Chrome to make sure
539 // per-user shortcuts to the system-level Chrome are created. Skip this
540 // if the system-level Chrome will undergo first run anyway, as Active
541 // Setup is triggered on system-level Chrome's first run.
542 // TODO(gab): Instead of having callers of Active Setup think about
543 // other callers, have Active Setup itself register when it ran and
544 // no-op otherwise (http://crbug.com/346843).
545 if (!first_run::IsChromeFirstRun())
546 uninstall_cmd.AppendSwitch(installer::switches::kTriggerActiveSetup);
548 const base::FilePath setup_exe(uninstall_cmd.GetProgram());
549 const base::string16 params(uninstall_cmd.GetArgumentsString());
551 SHELLEXECUTEINFO sei = { sizeof(sei) };
552 sei.fMask = SEE_MASK_NOASYNC;
553 sei.nShow = SW_SHOWNORMAL;
554 sei.lpFile = setup_exe.value().c_str();
555 sei.lpParameters = params.c_str();
556 // On Windows 8 SEE_MASK_FLAG_LOG_USAGE is necessary to guarantee we
557 // flip to the Desktop when launching.
558 if (is_metro)
559 sei.fMask |= SEE_MASK_FLAG_LOG_USAGE;
561 if (!::ShellExecuteEx(&sei))
562 DPCHECK(false);
564 return true;
567 return false;
570 base::string16 TranslationDelegate::GetLocalizedString(
571 int installer_string_id) {
572 int resource_id = 0;
573 switch (installer_string_id) {
574 // HANDLE_STRING is used by the DO_INSTALLER_STRING_MAPPING macro which is in
575 // the generated header installer_util_strings.h.
576 #define HANDLE_STRING(base_id, chrome_id) \
577 case base_id: \
578 resource_id = chrome_id; \
579 break;
580 DO_INSTALLER_STRING_MAPPING
581 #undef HANDLE_STRING
582 default:
583 NOTREACHED();
585 if (resource_id)
586 return l10n_util::GetStringUTF16(resource_id);
587 return base::string16();
590 // static
591 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() {
592 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ());
593 installer::SetTranslationDelegate(&delegate);