Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / lifetime / application_lifetime_win.cc
blob2d39984f59846c8d103d49ef34df61fd2923ced3
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/lifetime/application_lifetime.h"
7 #include "base/bind.h"
8 #include "base/environment.h"
9 #include "base/files/file_path.h"
10 #include "base/path_service.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/win/metro.h"
13 #include "base/win/windows_version.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/first_run/upgrade_util.h"
16 #include "chrome/browser/metro_utils/metro_chrome_win.h"
17 #include "chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.h"
18 #include "chrome/browser/shell_integration.h"
19 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/pref_names.h"
22 #include "chrome/installer/util/util_constants.h"
23 #include "content/public/browser/web_contents.h"
24 #include "ui/views/widget/widget.h"
26 namespace chrome {
28 // Following set of functions, which are used to switch chrome mode after
29 // restart are used for in places where either user explicitly wants to switch
30 // mode or some functionality is not available in either mode and we ask user
31 // to switch mode.
32 // Here mode refers to Windows 8 modes such as Metro (also called immersive)
33 // and desktop mode (Classic or traditional).
35 void ActivateDesktopHelper(AshExecutionStatus ash_execution_status) {
36 scoped_ptr<base::Environment> env(base::Environment::Create());
37 std::string version_str;
39 // Get the version variable and remove it from the environment.
40 if (!env->GetVar(chrome::kChromeVersionEnvVar, &version_str))
41 version_str.clear();
43 base::FilePath exe_path;
44 if (!PathService::Get(base::FILE_EXE, &exe_path))
45 return;
47 base::FilePath path(exe_path.DirName());
49 // The relauncher is ordinarily in the version directory. When running in a
50 // build tree however (where CHROME_VERSION is not set in the environment)
51 // look for it in Chrome's directory.
52 if (!version_str.empty())
53 path = path.AppendASCII(version_str);
55 path = path.Append(installer::kDelegateExecuteExe);
57 // Actually launching the process needs to happen in the metro viewer,
58 // otherwise it won't automatically transition to desktop. So we have
59 // to send an IPC to the viewer to do the ShellExecute.
60 ChromeMetroViewerProcessHost::HandleActivateDesktop(
61 path, ash_execution_status == ASH_TERMINATE);
64 void AttemptRestartToDesktopMode() {
65 PrefService* prefs = g_browser_process->local_state();
66 prefs->SetString(prefs::kRelaunchMode,
67 upgrade_util::kRelaunchModeDesktop);
69 AttemptRestart();
72 void AttemptRestartToMetroMode() {
73 PrefService* prefs = g_browser_process->local_state();
74 prefs->SetString(prefs::kRelaunchMode,
75 upgrade_util::kRelaunchModeMetro);
76 AttemptRestart();
79 } // namespace chrome