OLD | NEW |
---|---|
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 | |
27 // Copied from binaries_installer_internal.cc | |
28 const wchar_t kAppHostAppId[] = L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}"; | |
25 | 29 |
26 // Copied from chrome_appid.cc. | 30 // Copied from chrome_appid.cc. |
27 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | 31 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
28 | 32 |
29 // Copied from google_chrome_distribution.cc. | 33 // Copied from google_chrome_distribution.cc. |
30 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 34 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
31 | 35 |
32 // Copied from util_constants.cc. | 36 // Copied from util_constants.cc. |
37 const wchar_t kChromeAppHostExe[] = L"app_host.exe"; | |
38 const wchar_t kChromeExe[] = L"chrome.exe"; | |
33 const wchar_t kUninstallStringField[] = L"UninstallString"; | 39 const wchar_t kUninstallStringField[] = L"UninstallString"; |
34 const wchar_t kChromeExe[] = L"chrome.exe"; | |
35 | 40 |
36 #ifndef OFFICIAL_BUILD | 41 #ifndef OFFICIAL_BUILD |
37 FilePath GetDevelopmentChrome() { | 42 FilePath GetDevelopmentExe(const wchar_t* exe_file) { |
38 FilePath current_directory; | 43 FilePath current_directory; |
39 if (PathService::Get(base::DIR_EXE, ¤t_directory)) { | 44 if (PathService::Get(base::DIR_EXE, ¤t_directory)) { |
40 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); | 45 FilePath chrome_exe_path(current_directory.Append(exe_file)); |
41 if (file_util::PathExists(chrome_exe_path)) | 46 if (file_util::PathExists(chrome_exe_path)) |
42 return chrome_exe_path; | 47 return chrome_exe_path; |
43 } | 48 } |
44 return FilePath(); | 49 return FilePath(); |
45 } | 50 } |
46 #endif | 51 #endif |
47 | 52 |
48 // Reads the path to setup.exe from the value "UninstallString" within the | 53 // Reads the path to setup.exe from the value "UninstallString" within the |
49 // specified product's "ClientState" registry key. Returns an empty FilePath if | 54 // 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. | 55 // an error occurs or the product is not installed at the specified level. |
51 FilePath GetSetupExeFromRegistry(InstallationLevel level, | 56 FilePath GetSetupExeFromRegistry(InstallationLevel level, |
52 const wchar_t* app_guid) { | 57 const wchar_t* app_guid) { |
53 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? | 58 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? |
54 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 59 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
55 string16 subkey(kGoogleRegClientStateKey); | 60 string16 subkey(kGoogleRegClientStateKey); |
56 subkey.append(app_guid); | 61 subkey.append(1, L'\\').append(app_guid); |
grt (UTC plus 2)
2012/10/05 02:53:05
this is here for the sake of the change on line 24
huangs
2012/10/05 19:46:08
I think k*Key[] variables should not end with '\\'
| |
57 base::win::RegKey reg_key; | 62 base::win::RegKey reg_key; |
58 if (reg_key.Open(root_key, subkey.c_str(), | 63 if (reg_key.Open(root_key, subkey.c_str(), |
59 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 64 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
60 string16 uninstall; | 65 string16 uninstall; |
61 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { | 66 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { |
62 FilePath setup_exe_path(uninstall); | 67 FilePath setup_exe_path(uninstall); |
63 if (file_util::PathExists(setup_exe_path)) | 68 if (file_util::PathExists(setup_exe_path)) |
64 return setup_exe_path; | 69 return setup_exe_path; |
65 } | 70 } |
66 } | 71 } |
67 return FilePath(); | 72 return FilePath(); |
68 } | 73 } |
69 | 74 |
75 // Returns the path to an installed |exe_file| (e.g. chrome.exe, app_host.exe) | |
76 // at the specified level, given |setup_exe_path| from Omaha client state. | |
77 // Returns empty FilePath if none found, or if |setup_exe_path| is empty. | |
78 FilePath FindExeRelativeToSetupExe(const FilePath setup_exe_path, | |
79 const wchar_t* exe_file) { | |
80 if (!setup_exe_path.empty()) { | |
81 // The uninstall path contains the path to setup.exe, which is two levels | |
82 // down from |exe_file|. Move up two levels (plus one to drop the file | |
83 // name) and look for chrome.exe from there. | |
84 FilePath exe_path( | |
85 setup_exe_path.DirName().DirName().DirName().Append(exe_file)); | |
86 if (file_util::PathExists(exe_path)) | |
87 return exe_path; | |
88 // By way of mild future proofing, look up one to see if there's a | |
89 // |exe_file| in the version directory | |
90 exe_path = setup_exe_path.DirName().DirName().Append(exe_file); | |
91 if (file_util::PathExists(exe_path)) | |
92 return exe_path; | |
93 } | |
94 return FilePath(); | |
95 } | |
96 | |
70 } // namespace | 97 } // namespace |
71 | 98 |
72 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { | 99 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { |
73 // Look in the registry for Chrome Binaries first. | 100 // Look in the registry for Chrome Binaries first. |
74 FilePath setup_exe_path(GetSetupExeFromRegistry(level, kBinariesAppGuid)); | 101 FilePath setup_exe_path(GetSetupExeFromRegistry(level, kBinariesAppGuid)); |
75 // If the above fails, look in the registry for Chrome next. | 102 // If the above fails, look in the registry for Chrome next. |
76 if (setup_exe_path.empty()) | 103 if (setup_exe_path.empty()) |
77 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid); | 104 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid); |
78 // If we fail again, then setup_exe_path would be empty. | 105 // If we fail again, then setup_exe_path would be empty. |
79 return setup_exe_path; | 106 return setup_exe_path; |
80 } | 107 } |
81 | 108 |
82 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { | 109 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { |
83 FilePath setup_exe_path(GetSetupExeForInstallationLevel(level)); | 110 return FindExeRelativeToSetupExe( |
84 if (!setup_exe_path.empty()) { | 111 GetSetupExeForInstallationLevel(level), kChromeExe); |
85 // The uninstall path contains the path to setup.exe which is two levels | 112 } |
86 // down from chrome.exe. Move up two levels (plus one to drop the file | 113 |
87 // name) and look for chrome.exe from there. | 114 FilePath GetAppHostPathForInstallationLevel(InstallationLevel level) { |
88 FilePath chrome_exe_path( | 115 return FindExeRelativeToSetupExe( |
89 setup_exe_path.DirName().DirName().DirName().Append(kChromeExe)); | 116 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 } | 117 } |
100 | 118 |
101 FilePath GetAnyChromePath() { | 119 FilePath GetAnyChromePath() { |
102 FilePath chrome_path; | 120 FilePath chrome_path; |
103 #ifndef OFFICIAL_BUILD | 121 #ifndef OFFICIAL_BUILD |
104 // For development mode, chrome.exe should be in same dir as the stub. | 122 // For development mode, chrome.exe should be in same dir as the stub. |
105 chrome_path = GetDevelopmentChrome(); | 123 chrome_path = GetDevelopmentExe(kChromeExe); |
106 #endif | 124 #endif |
107 if (chrome_path.empty()) | 125 if (chrome_path.empty()) |
108 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); | 126 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); |
109 if (chrome_path.empty()) | 127 if (chrome_path.empty()) |
110 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); | 128 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); |
111 return chrome_path; | 129 return chrome_path; |
112 } | 130 } |
113 | 131 |
132 FilePath GetAnyAppHostPath() { | |
133 FilePath app_host_path; | |
134 #ifndef OFFICIAL_BUILD | |
135 // For development mode, app_host.exe should be in same dir as chrome.exe. | |
136 app_host_path = GetDevelopmentExe(kChromeAppHostExe); | |
137 #endif | |
138 if (app_host_path.empty()) { | |
139 app_host_path = GetAppHostPathForInstallationLevel( | |
140 SYSTEM_LEVEL_INSTALLATION); | |
141 } | |
142 if (app_host_path.empty()) | |
143 app_host_path = GetAppHostPathForInstallationLevel(USER_LEVEL_INSTALLATION); | |
144 return app_host_path; | |
145 } | |
146 | |
147 bool IsAppHostPresent() { | |
148 FilePath app_host_exe = GetAnyAppHostPath(); | |
149 return !app_host_exe.empty() && file_util::PathExists(app_host_exe); | |
grt (UTC plus 2)
2012/10/05 02:53:05
is this call to PathExists not superfluous?
huangs
2012/10/05 19:46:08
Yes it is. Removed!
| |
150 } | |
151 | |
114 } // namespace chrome_launcher_support | 152 } // namespace chrome_launcher_support |
OLD | NEW |