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