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

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

Issue 686383002: launcher_support: Gets the correct executable path for Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comments to not mention Omaha or ClientState. Created 6 years, 1 month 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
« no previous file with comments | « chrome/installer/launcher_support/chrome_launcher_support.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/win/registry.h" 12 #include "base/win/registry.h"
13 13
14 namespace chrome_launcher_support { 14 namespace chrome_launcher_support {
15 15
16 namespace { 16 namespace {
17 17
18 // TODO(huangs) Refactor the constants: http://crbug.com/148538 18 // TODO(huangs) Refactor the constants: http://crbug.com/148538
19 const wchar_t kGoogleRegClientStateKey[] = 19 #if defined(GOOGLE_CHROME_BUILD)
20 const wchar_t kInstallationRegKey[] =
20 L"Software\\Google\\Update\\ClientState"; 21 L"Software\\Google\\Update\\ClientState";
21 22
22 // Copied from chrome_appid.cc. 23 // Copied from chrome_appid.cc.
23 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; 24 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
24 25
25 // Copied from google_chrome_distribution.cc. 26 // Copied from google_chrome_distribution.cc.
26 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 27 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
27 28
28 // Copied frome google_chrome_sxs_distribution.cc. 29 // Copied frome google_chrome_sxs_distribution.cc.
29 const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; 30 const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
31 #else
32 const wchar_t kInstallationRegKey[] = L"Software\\Chromium";
Matt Giuca 2014/10/30 05:20:07 Note: The \Software\Chromium registry key contains
33 #endif
30 34
31 // Copied from util_constants.cc. 35 // Copied from util_constants.cc.
32 const wchar_t kChromeExe[] = L"chrome.exe"; 36 const wchar_t kChromeExe[] = L"chrome.exe";
33 const wchar_t kUninstallStringField[] = L"UninstallString"; 37 const wchar_t kUninstallStringField[] = L"UninstallString";
34 38
35 // Reads a string value from the specified product's "ClientState" registry key. 39 // Reads a string value from the specified product's registry key. Returns true
36 // Returns true iff the value is present and successfully read. 40 // iff the value is present and successfully read.
37 bool GetClientStateValue(InstallationLevel level, 41 bool GetClientStateValue(InstallationLevel level,
38 const wchar_t* app_guid, 42 const wchar_t* app_guid,
39 const wchar_t* value_name, 43 const wchar_t* value_name,
40 base::string16* value) { 44 base::string16* value) {
41 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? 45 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ?
42 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 46 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
43 base::string16 subkey(kGoogleRegClientStateKey); 47 base::string16 subkey(kInstallationRegKey);
44 subkey.append(1, L'\\').append(app_guid); 48 if (app_guid)
49 subkey.append(1, L'\\').append(app_guid);
45 base::win::RegKey reg_key; 50 base::win::RegKey reg_key;
46 // Google Update always uses 32bit hive. 51 // Google Update always uses 32bit hive.
47 if (reg_key.Open(root_key, subkey.c_str(), 52 if (reg_key.Open(root_key, subkey.c_str(),
48 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { 53 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
49 if (reg_key.ReadValue(value_name, value) == ERROR_SUCCESS) { 54 if (reg_key.ReadValue(value_name, value) == ERROR_SUCCESS) {
50 return true; 55 return true;
51 } 56 }
52 } 57 }
53 return false; 58 return false;
54 } 59 }
55 60
56 // Reads the path to setup.exe from the value "UninstallString" within the 61 // Reads the path to setup.exe from the value "UninstallString" within the
57 // specified product's "ClientState" registry key. Returns an empty FilePath if 62 // specified product's registry key. Returns an empty FilePath if an error
58 // an error occurs or the product is not installed at the specified level. 63 // occurs or the product is not installed at the specified level.
59 base::FilePath GetSetupExeFromRegistry(InstallationLevel level, 64 base::FilePath GetSetupExeFromRegistry(InstallationLevel level,
60 const wchar_t* app_guid) { 65 const wchar_t* app_guid) {
61 base::string16 uninstall; 66 base::string16 uninstall;
62 if (GetClientStateValue(level, app_guid, kUninstallStringField, &uninstall)) { 67 if (GetClientStateValue(level, app_guid, kUninstallStringField, &uninstall)) {
63 base::FilePath setup_exe_path(uninstall); 68 base::FilePath setup_exe_path(uninstall);
64 if (base::PathExists(setup_exe_path)) 69 if (base::PathExists(setup_exe_path))
65 return setup_exe_path; 70 return setup_exe_path;
66 } 71 }
67 return base::FilePath(); 72 return base::FilePath();
68 } 73 }
69 74
70 // Returns the path to an existing setup.exe at the specified level, if it can 75 // Returns the path to an existing setup.exe at the specified level, if it can
71 // be found via Omaha client state. 76 // be found via the registry.
72 base::FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { 77 base::FilePath GetSetupExeForInstallationLevel(InstallationLevel level) {
78 base::FilePath setup_exe_path;
79 #if defined(GOOGLE_CHROME_BUILD)
73 // Look in the registry for Chrome Binaries first. 80 // Look in the registry for Chrome Binaries first.
74 base::FilePath setup_exe_path( 81 setup_exe_path = GetSetupExeFromRegistry(level, kBinariesAppGuid);
75 GetSetupExeFromRegistry(level, kBinariesAppGuid));
76 // If the above fails, look in the registry for Chrome next. 82 // If the above fails, look in the registry for Chrome next.
77 if (setup_exe_path.empty()) 83 if (setup_exe_path.empty())
78 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid); 84 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid);
79 // If we fail again, then setup_exe_path would be empty. 85 // If we fail again, then setup_exe_path would be empty.
86 #else
87 // For Chromium, there are no GUIDs. Just look in the Chromium registry key.
88 setup_exe_path = GetSetupExeFromRegistry(level, nullptr);
89 #endif
90
80 return setup_exe_path; 91 return setup_exe_path;
81 } 92 }
82 93
83 // Returns the path to an installed |exe_file| (e.g. chrome.exe) at the 94 // Returns the path to an installed |exe_file| (e.g. chrome.exe) at the
84 // specified level, given |setup_exe_path| from Omaha client state. Returns 95 // specified level, given |setup_exe_path| from the registry. Returns empty
85 // empty base::FilePath if none found, or if |setup_exe_path| is empty. 96 // base::FilePath if none found, or if |setup_exe_path| is empty.
86 base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path, 97 base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path,
87 const wchar_t* exe_file) { 98 const wchar_t* exe_file) {
88 if (!setup_exe_path.empty()) { 99 if (!setup_exe_path.empty()) {
89 // The uninstall path contains the path to setup.exe, which is two levels 100 // The uninstall path contains the path to setup.exe, which is two levels
90 // down from |exe_file|. Move up two levels (plus one to drop the file 101 // down from |exe_file|. Move up two levels (plus one to drop the file
91 // name) and look for chrome.exe from there. 102 // name) and look for chrome.exe from there.
92 base::FilePath exe_path( 103 base::FilePath exe_path(
93 setup_exe_path.DirName().DirName().DirName().Append(exe_file)); 104 setup_exe_path.DirName().DirName().DirName().Append(exe_file));
94 if (base::PathExists(exe_path)) 105 if (base::PathExists(exe_path))
95 return exe_path; 106 return exe_path;
96 // By way of mild future proofing, look up one to see if there's a 107 // By way of mild future proofing, look up one to see if there's a
97 // |exe_file| in the version directory 108 // |exe_file| in the version directory
98 exe_path = setup_exe_path.DirName().DirName().Append(exe_file); 109 exe_path = setup_exe_path.DirName().DirName().Append(exe_file);
99 if (base::PathExists(exe_path)) 110 if (base::PathExists(exe_path))
100 return exe_path; 111 return exe_path;
101 } 112 }
102 return base::FilePath(); 113 return base::FilePath();
103 } 114 }
104 115
105 // Returns the path to an installed SxS chrome.exe at the specified level, if 116 // Returns the path to an installed SxS chrome.exe at the specified level, if
106 // it can be found via Omaha client state. 117 // it can be found via the registry.
107 base::FilePath GetChromeSxSPathForInstallationLevel(InstallationLevel level) { 118 base::FilePath GetChromeSxSPathForInstallationLevel(InstallationLevel level) {
119 #if defined(GOOGLE_CHROME_BUILD)
108 return FindExeRelativeToSetupExe( 120 return FindExeRelativeToSetupExe(
109 GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe); 121 GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe);
122 #else
123 // There is no SxS build for Chromium.
124 return base::FilePath();
125 #endif
110 } 126 }
111 127
112 } // namespace 128 } // namespace
113 129
114 base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) { 130 base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
115 return FindExeRelativeToSetupExe( 131 return FindExeRelativeToSetupExe(
116 GetSetupExeForInstallationLevel(level), kChromeExe); 132 GetSetupExeForInstallationLevel(level), kChromeExe);
117 } 133 }
118 134
119 base::FilePath GetAnyChromePath() { 135 base::FilePath GetAnyChromePath() {
120 base::FilePath chrome_path; 136 base::FilePath chrome_path;
121 if (chrome_path.empty()) 137 if (chrome_path.empty())
122 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 138 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
123 if (chrome_path.empty()) 139 if (chrome_path.empty())
124 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); 140 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
125 return chrome_path; 141 return chrome_path;
126 } 142 }
127 143
128 base::FilePath GetAnyChromeSxSPath() { 144 base::FilePath GetAnyChromeSxSPath() {
129 base::FilePath path = 145 base::FilePath path =
130 GetChromeSxSPathForInstallationLevel(USER_LEVEL_INSTALLATION); 146 GetChromeSxSPathForInstallationLevel(USER_LEVEL_INSTALLATION);
131 if (path.empty()) 147 if (path.empty())
132 path = GetChromeSxSPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 148 path = GetChromeSxSPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
133 return path; 149 return path;
134 } 150 }
135 151
136 } // namespace chrome_launcher_support 152 } // namespace chrome_launcher_support
OLDNEW
« no previous file with comments | « chrome/installer/launcher_support/chrome_launcher_support.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698