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

Side by Side Diff: chrome/installer/launcher_support/chrome_launcher_support.cc

Issue 11054006: Make application shortcuts point to app_host.exe, install App Host during app installation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moving quick-enable-app-host feature; adding App Host install code for unpacked extension installer. Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/installer/launcher_support/chrome_launcher_support.h" 5 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <tchar.h> 8 #include <tchar.h>
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string16.h"
13 #include "base/win/registry.h"
14
12 #ifndef OFFICIAL_BUILD 15 #ifndef OFFICIAL_BUILD
13 #include "base/path_service.h" 16 #include "base/path_service.h"
14 #endif 17 #endif
15 #include "base/string16.h"
16 #include "base/win/registry.h"
17 18
18 namespace chrome_launcher_support { 19 namespace chrome_launcher_support {
19 20
20 namespace { 21 namespace {
21 22
22 // TODO(huangs) Refactor the constants: http://crbug.com/148538 23 // TODO(huangs) Refactor the constants: http://crbug.com/148538
23 const wchar_t kGoogleRegClientStateKey[] = 24 const wchar_t kGoogleRegClientStateKey[] =
24 L"Software\\Google\\Update\\ClientState\\"; 25 L"Software\\Google\\Update\\ClientState";
26 const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients";
27
28 // Copied from binaries_installer_internal.cc
29 const wchar_t kAppHostAppId[] = L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}";
25 30
26 // Copied from chrome_appid.cc. 31 // Copied from chrome_appid.cc.
27 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; 32 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
28 33
29 // Copied from google_chrome_distribution.cc. 34 // Copied from google_chrome_distribution.cc.
30 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 35 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
31 36
37 // Copied from google_update_constants.cc
38 const wchar_t kRegCommandLineField[] = L"CommandLine";
39 const wchar_t kRegCommandsKey[] = L"Commands";
40
32 // Copied from util_constants.cc. 41 // Copied from util_constants.cc.
42 const wchar_t kChromeAppHostExe[] = L"app_host.exe";
43 const wchar_t kChromeExe[] = L"chrome.exe";
44 const wchar_t kCmdQuickEnableApplicationHost[] =
45 L"quick-enable-application-host";
33 const wchar_t kUninstallStringField[] = L"UninstallString"; 46 const wchar_t kUninstallStringField[] = L"UninstallString";
34 const wchar_t kChromeExe[] = L"chrome.exe";
35 47
36 #ifndef OFFICIAL_BUILD 48 #ifndef OFFICIAL_BUILD
37 FilePath GetDevelopmentChrome() { 49 FilePath GetDevelopmentExe(const wchar_t* exe_file) {
38 FilePath current_directory; 50 FilePath current_directory;
39 if (PathService::Get(base::DIR_EXE, &current_directory)) { 51 if (PathService::Get(base::DIR_EXE, &current_directory)) {
40 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); 52 FilePath chrome_exe_path(current_directory.Append(exe_file));
41 if (file_util::PathExists(chrome_exe_path)) 53 if (file_util::PathExists(chrome_exe_path))
42 return chrome_exe_path; 54 return chrome_exe_path;
43 } 55 }
44 return FilePath(); 56 return FilePath();
45 } 57 }
46 #endif 58 #endif
47 59
48 // Reads the path to setup.exe from the value "UninstallString" within the 60 // Reads the path to setup.exe from the value "UninstallString" within the
49 // specified product's "ClientState" registry key. Returns an empty FilePath if 61 // specified product's "ClientState" registry key. Returns an empty FilePath if
50 // an error occurs or the product is not installed at the specified level. 62 // an error occurs or the product is not installed at the specified level.
51 FilePath GetSetupExeFromRegistry(InstallationLevel level, 63 FilePath GetSetupExeFromRegistry(InstallationLevel level,
52 const wchar_t* app_guid) { 64 const wchar_t* app_guid) {
53 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? 65 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ?
54 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 66 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
55 string16 subkey(kGoogleRegClientStateKey); 67 string16 subkey(kGoogleRegClientStateKey);
56 subkey.append(app_guid); 68 subkey.append(1, L'\\').append(app_guid);
57 base::win::RegKey reg_key; 69 base::win::RegKey reg_key;
58 if (reg_key.Open(root_key, subkey.c_str(), 70 if (reg_key.Open(root_key, subkey.c_str(),
59 KEY_QUERY_VALUE) == ERROR_SUCCESS) { 71 KEY_QUERY_VALUE) == ERROR_SUCCESS) {
60 string16 uninstall; 72 string16 uninstall;
61 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { 73 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) {
62 FilePath setup_exe_path(uninstall); 74 FilePath setup_exe_path(uninstall);
63 if (file_util::PathExists(setup_exe_path)) 75 if (file_util::PathExists(setup_exe_path))
64 return setup_exe_path; 76 return setup_exe_path;
65 } 77 }
66 } 78 }
67 return FilePath(); 79 return FilePath();
68 } 80 }
69 81
82 // Returns the path to an installed |exe_file| (e.g. chrome.exe, app_host.exe)
83 // at the specified level, given |setup_exe_path| from Omaha client state.
84 // Returns empty FilePath if none found, or if |setup_exe_path| is empty.
85 FilePath FindExeRelativeToSetupExe(const FilePath setup_exe_path,
86 const wchar_t* exe_file) {
87 if (!setup_exe_path.empty()) {
88 // The uninstall path contains the path to setup.exe, which is two levels
89 // down from |exe_file|. Move up two levels (plus one to drop the file
90 // name) and look for chrome.exe from there.
91 FilePath exe_path(
92 setup_exe_path.DirName().DirName().DirName().Append(exe_file));
93 if (file_util::PathExists(exe_path))
94 return exe_path;
95 // By way of mild future proofing, look up one to see if there's a
96 // |exe_file| in the version directory
97 exe_path = setup_exe_path.DirName().DirName().Append(exe_file);
98 if (file_util::PathExists(exe_path))
99 return exe_path;
100 }
101 return FilePath();
102 }
103
70 } // namespace 104 } // namespace
71 105
72 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { 106 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) {
73 // Look in the registry for Chrome Binaries first. 107 // Look in the registry for Chrome Binaries first.
74 FilePath setup_exe_path(GetSetupExeFromRegistry(level, kBinariesAppGuid)); 108 FilePath setup_exe_path(GetSetupExeFromRegistry(level, kBinariesAppGuid));
75 // If the above fails, look in the registry for Chrome next. 109 // If the above fails, look in the registry for Chrome next.
76 if (setup_exe_path.empty()) 110 if (setup_exe_path.empty())
77 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid); 111 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid);
78 // If we fail again, then setup_exe_path would be empty. 112 // If we fail again, then setup_exe_path would be empty.
79 return setup_exe_path; 113 return setup_exe_path;
80 } 114 }
81 115
82 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { 116 FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
83 FilePath setup_exe_path(GetSetupExeForInstallationLevel(level)); 117 return FindExeRelativeToSetupExe(
84 if (!setup_exe_path.empty()) { 118 GetSetupExeForInstallationLevel(level), kChromeExe);
85 // The uninstall path contains the path to setup.exe which is two levels 119 }
86 // down from chrome.exe. Move up two levels (plus one to drop the file 120
87 // name) and look for chrome.exe from there. 121 FilePath GetAppHostPathForInstallationLevel(InstallationLevel level) {
88 FilePath chrome_exe_path( 122 return FindExeRelativeToSetupExe(
89 setup_exe_path.DirName().DirName().DirName().Append(kChromeExe)); 123 GetSetupExeFromRegistry(level, kAppHostAppId), kChromeAppHostExe);
90 if (!file_util::PathExists(chrome_exe_path)) {
91 // By way of mild future proofing, look up one to see if there's a
92 // chrome.exe in the version directory
93 chrome_exe_path = chrome_exe_path.DirName().DirName().Append(kChromeExe);
94 }
95 if (file_util::PathExists(chrome_exe_path))
96 return chrome_exe_path;
97 }
98 return FilePath();
99 } 124 }
100 125
101 FilePath GetAnyChromePath() { 126 FilePath GetAnyChromePath() {
102 FilePath chrome_path; 127 FilePath chrome_path;
103 #ifndef OFFICIAL_BUILD 128 #ifndef OFFICIAL_BUILD
104 // For development mode, chrome.exe should be in same dir as the stub. 129 // For development mode, chrome.exe should be in same dir as the stub.
105 chrome_path = GetDevelopmentChrome(); 130 chrome_path = GetDevelopmentExe(kChromeExe);
106 #endif 131 #endif
107 if (chrome_path.empty()) 132 if (chrome_path.empty())
108 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 133 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
109 if (chrome_path.empty()) 134 if (chrome_path.empty())
110 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); 135 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
111 return chrome_path; 136 return chrome_path;
112 } 137 }
113 138
139 FilePath GetAnyAppHostPath() {
140 FilePath app_host_path;
141 #ifndef OFFICIAL_BUILD
142 // For development mode, app_host.exe should be in same dir as the stub.
143 app_host_path = GetDevelopmentExe(kChromeAppHostExe);
144 #endif
145 if (app_host_path.empty()) {
146 app_host_path = GetAppHostPathForInstallationLevel(
147 SYSTEM_LEVEL_INSTALLATION);
148 }
149 if (app_host_path.empty())
150 app_host_path = GetAppHostPathForInstallationLevel(USER_LEVEL_INSTALLATION);
151 return app_host_path;
152 }
153
154 bool IsAppHostPresent() {
155 FilePath app_host_exe = GetAnyAppHostPath();
156 return !app_host_exe.empty() && file_util::PathExists(app_host_exe);
157 }
158
159 string16 GetQuickEnableAppHostCommand(InstallationLevel level) {
erikwright (departed) 2012/10/03 20:57:07 This does not belong here. Where you are calling
huangs 2012/10/04 00:53:14 Moved code to app_host_installer.cc, but using App
160 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ?
161 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
162 string16 subkey(kGoogleRegClientsKey);
163 subkey.append(1, L'\\').append(kBinariesAppGuid)
164 .append(1, L'\\').append(kRegCommandsKey)
165 .append(1, L'\\').append(kCmdQuickEnableApplicationHost);
166 base::win::RegKey reg_key;
167 string16 cmd;
168 if (reg_key.Open(root_key, subkey.c_str(),
169 KEY_QUERY_VALUE) == ERROR_SUCCESS) {
170 // If read is unsuccessful, |cmd| remains empty.
171 reg_key.ReadValue(kRegCommandLineField, &cmd);
172 }
173 return cmd;
174 }
175
114 } // namespace chrome_launcher_support 176 } // namespace chrome_launcher_support
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698