OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | |
5 // This file contains helper functions which provide information about the | 4 // This file contains helper functions which provide information about the |
6 // current version of Chrome. This includes channel information, version | 5 // current version of Chrome. This includes channel information, version |
7 // information etc. This functionality is provided by using functions in | 6 // information etc. This functionality is provided by using functions in |
8 // kernel32 and advapi32. No other dependencies are allowed in this file. | 7 // kernel32 and advapi32. No other dependencies are allowed in this file. |
9 | 8 |
10 #ifndef CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ | 9 #ifndef CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ |
11 #define CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ | 10 #define CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ |
12 | 11 |
13 #include <string> | 12 #include <string> |
14 #include <vector> | 13 #include <vector> |
15 | 14 |
16 namespace install_static { | 15 namespace install_static { |
17 | 16 |
18 struct InstallConstants; | |
19 | |
20 enum class ProcessType { | 17 enum class ProcessType { |
21 UNINITIALIZED, | 18 UNINITIALIZED, |
22 NON_BROWSER_PROCESS, | 19 NON_BROWSER_PROCESS, |
23 BROWSER_PROCESS, | 20 BROWSER_PROCESS, |
24 }; | 21 }; |
25 | 22 |
| 23 // TODO(ananta) |
| 24 // https://crbug.com/604923 |
| 25 // The constants defined in this file are also defined in chrome/installer and |
| 26 // other places. we need to unify them. |
| 27 extern const wchar_t kChromeChannelUnknown[]; |
| 28 extern const wchar_t kChromeChannelCanary[]; |
| 29 extern const wchar_t kChromeChannelDev[]; |
| 30 extern const wchar_t kChromeChannelBeta[]; |
| 31 extern const wchar_t kChromeChannelStable[]; |
| 32 extern const wchar_t kChromeChannelStableExplicit[]; |
| 33 extern const wchar_t kRegPathClientState[]; |
| 34 extern const wchar_t kRegPathClientStateMedium[]; |
| 35 extern const wchar_t kRegPathChromePolicy[]; |
| 36 extern const wchar_t kRegApField[]; |
26 // Registry key to store the stats/crash sampling state of Chrome. If set to 1, | 37 // Registry key to store the stats/crash sampling state of Chrome. If set to 1, |
27 // stats and crash reports will be uploaded in line with the user's consent, | 38 // stats and crash reports will be uploaded in line with the user's consent, |
28 // otherwise, uploads will be disabled. It is used to sample clients, to reduce | 39 // otherwise, uploads will be disabled. It is used to sample clients, to reduce |
29 // server load for metics and crashes. This is controlled by the | 40 // server load for metics and crashes. This is controlled by the |
30 // MetricsReporting feature in chrome_metrics_services_manager_client.cc and is | 41 // MetricsReporting feature in chrome_metrics_services_manager_client.cc and is |
31 // written when metrics services are started up and when consent changes. | 42 // written when metrics services are started up and when consent changes. |
32 extern const wchar_t kRegValueChromeStatsSample[]; | 43 extern const wchar_t kRegValueChromeStatsSample[]; |
| 44 // Used to retrieve consent for uploading crashes and metrics. |
| 45 extern const wchar_t kRegValueUsageStats[]; |
| 46 extern const wchar_t kUninstallArgumentsField[]; |
| 47 extern const wchar_t kMetricsReportingEnabled[]; |
| 48 extern const wchar_t kAppGuidCanary[]; |
| 49 extern const wchar_t kAppGuidGoogleChrome[]; |
| 50 extern const wchar_t kAppGuidGoogleBinaries[]; |
33 | 51 |
34 // TODO(ananta) | 52 // TODO(ananta) |
35 // https://crbug.com/604923 | 53 // https://crbug.com/604923 |
36 // Unify these constants with env_vars.h. | 54 // Unify these constants with env_vars.h. |
37 extern const wchar_t kHeadless[]; | 55 extern const wchar_t kHeadless[]; |
38 extern const wchar_t kShowRestart[]; | 56 extern const wchar_t kShowRestart[]; |
39 extern const wchar_t kRestartInfo[]; | 57 extern const wchar_t kRestartInfo[]; |
40 extern const wchar_t kRtlLocale[]; | 58 extern const wchar_t kRtlLocale[]; |
41 | 59 |
42 // TODO(ananta) | 60 // TODO(ananta) |
43 // https://crbug.com/604923 | 61 // https://crbug.com/604923 |
44 // Unify these constants with those defined in content_switches.h. | 62 // Unify these constants with those defined in content_switches.h. |
45 extern const char kGpuProcess[]; | 63 extern const char kGpuProcess[]; |
46 extern const char kPpapiPluginProcess[]; | 64 extern const char kPpapiPluginProcess[]; |
47 extern const char kRendererProcess[]; | 65 extern const char kRendererProcess[]; |
48 extern const char kUtilityProcess[]; | 66 extern const char kUtilityProcess[]; |
49 extern const char kProcessType[]; | 67 extern const char kProcessType[]; |
50 extern const char kCrashpadHandler[]; | 68 extern const char kCrashpadHandler[]; |
51 | 69 |
52 // Returns true if Chrome is running at system level. | 70 // Returns true if |exe_path| points to a Chrome installed in an SxS |
53 bool IsSystemInstall(); | 71 // installation. |
| 72 bool IsSxSChrome(const wchar_t* exe_path); |
| 73 |
| 74 // Returns true if |exe_path| points to a per-user level Chrome installation. |
| 75 bool IsSystemInstall(const wchar_t* exe_path); |
54 | 76 |
55 // Returns true if current installation of Chrome is a multi-install. | 77 // Returns true if current installation of Chrome is a multi-install. |
56 bool IsMultiInstall(); | 78 bool IsMultiInstall(bool is_system_install); |
57 | 79 |
58 // Returns true if usage stats collecting is enabled for this user for the | 80 // Returns true if usage stats collecting is enabled for this user for the |
59 // current executable. | 81 // current executable. |
60 bool GetCollectStatsConsent(); | 82 bool GetCollectStatsConsent(); |
61 | 83 |
| 84 // Returns true if usage stats collecting is enabled for this user for the |
| 85 // executable passed in as |exe_path|. |
| 86 // Only used by tests. |
| 87 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path); |
| 88 |
62 // Returns true if the current executable is currently in the chosen sample that | 89 // Returns true if the current executable is currently in the chosen sample that |
63 // will report stats and crashes. | 90 // will report stats and crashes. |
64 bool GetCollectStatsInSample(); | 91 bool GetCollectStatsInSample(); |
65 | 92 |
66 // Sets the registry value used for checking if Chrome is in the chosen sample | 93 // Sets the registry value used for checking if Chrome is in the chosen sample |
67 // that will report stats and crashes. Returns true if writing was successful. | 94 // that will report stats and crashes. Returns true if writing was successful. |
68 bool SetCollectStatsInSample(bool in_sample); | 95 bool SetCollectStatsInSample(bool in_sample); |
69 | 96 |
70 // Returns true if if usage stats reporting is controlled by a mandatory | 97 // Returns true if if usage stats reporting is controlled by a mandatory |
71 // policy. |crash_reporting_enabled| determines whether it's enabled (true) or | 98 // policy. |crash_reporting_enabled| determines whether it's enabled (true) or |
(...skipping 20 matching lines...) Expand all Loading... |
92 // whether DIR_USER_DATA or DIR_CRASH_DUMPS has been overridden. | 119 // whether DIR_USER_DATA or DIR_CRASH_DUMPS has been overridden. |
93 // TODO(ananta) | 120 // TODO(ananta) |
94 // http://crbug.com/604923 | 121 // http://crbug.com/604923 |
95 // Unify this with the Browser Distribution code. | 122 // Unify this with the Browser Distribution code. |
96 bool GetDefaultCrashDumpLocation(std::wstring* crash_dir); | 123 bool GetDefaultCrashDumpLocation(std::wstring* crash_dir); |
97 | 124 |
98 // Returns the contents of the specified |variable_name| from the environment | 125 // Returns the contents of the specified |variable_name| from the environment |
99 // block of the calling process. Returns an empty string if the variable does | 126 // block of the calling process. Returns an empty string if the variable does |
100 // not exist. | 127 // not exist. |
101 std::string GetEnvironmentString(const std::string& variable_name); | 128 std::string GetEnvironmentString(const std::string& variable_name); |
102 std::wstring GetEnvironmentString16(const wchar_t* variable_name); | 129 std::wstring GetEnvironmentString16(const std::wstring& variable_name); |
103 | 130 |
104 // Sets the environment variable identified by |variable_name| to the value | 131 // Sets the environment variable identified by |variable_name| to the value |
105 // identified by |new_value|. | 132 // identified by |new_value|. |
106 bool SetEnvironmentString(const std::string& variable_name, | 133 bool SetEnvironmentString(const std::string& variable_name, |
107 const std::string& new_value); | 134 const std::string& new_value); |
108 bool SetEnvironmentString16(const std::wstring& variable_name, | 135 bool SetEnvironmentString16(const std::wstring& variable_name, |
109 const std::wstring& new_value); | 136 const std::wstring& new_value); |
110 | 137 |
111 // Returns true if the environment variable identified by |variable_name| | 138 // Returns true if the environment variable identified by |variable_name| |
112 // exists. | 139 // exists. |
113 bool HasEnvironmentVariable(const std::string& variable_name); | 140 bool HasEnvironmentVariable(const std::string& variable_name); |
114 bool HasEnvironmentVariable16(const std::wstring& variable_name); | 141 bool HasEnvironmentVariable16(const std::wstring& variable_name); |
115 | 142 |
116 // Gets the exe version details like the |product_name|, |version|, | 143 // Gets the exe version details like the |product_name|, |version|, |
117 // |special_build|, |channel_name|, etc. Most of this information is read | 144 // |special_build|, |channel_name|, etc. Most of this information is read |
118 // from the version resource. |exe_path| is the path of chrome.exe. | 145 // from the version resource. |exe_path| is the path of chrome.exe. |
119 // TODO(ananta) | 146 // TODO(ananta) |
120 // http://crbug.com/604923 | 147 // http://crbug.com/604923 |
121 // Unify this with the Browser Distribution code. | 148 // Unify this with the Browser Distribution code. |
122 void GetExecutableVersionDetails(const std::wstring& exe_path, | 149 bool GetExecutableVersionDetails(const std::wstring& exe_path, |
123 std::wstring* product_name, | 150 std::wstring* product_name, |
124 std::wstring* version, | 151 std::wstring* version, |
125 std::wstring* special_build, | 152 std::wstring* special_build, |
126 std::wstring* channel_name); | 153 std::wstring* channel_name); |
127 | 154 |
128 // Gets the channel name for the current Chrome process. | 155 // Gets the channel name for the current Chrome process. |
129 // If |add_modifier| is true the channel name is returned with the modifier | 156 // If |add_modifier| is true the channel name is returned with the modifier |
130 // prepended to it. Currently this is only done for multi installs, i.e (-m) | 157 // prepended to it. Currently this is only done for multi installs, i.e (-m) |
131 // is the only modifier supported. | 158 // is the only modifier supported. |
132 // TODO(ananta) | 159 // TODO(ananta) |
133 // http://crbug.com/604923 | 160 // http://crbug.com/604923 |
134 // Unify this with the Browser Distribution code. | 161 // Unify this with the Browser Distribution code. |
135 std::wstring GetChromeChannelName(bool add_modifier); | 162 void GetChromeChannelName(bool is_per_user_install, |
| 163 bool add_modifier, |
| 164 std::wstring* channel_name); |
| 165 |
| 166 // Returns the version of Google Update that is installed. |
| 167 // TODO(ananta) |
| 168 // http://crbug.com/604923 |
| 169 // Unify this with the Browser Distribution code. |
| 170 std::string GetGoogleUpdateVersion(); |
| 171 |
| 172 // Returns the Chrome installation subdirectory, i.e. Google Chrome\Chromium, |
| 173 // etc. |
| 174 // TODO(ananta) |
| 175 // http://crbug.com/604923 |
| 176 // Unify this with the Browser Distribution code. |
| 177 std::wstring GetChromeInstallSubDirectory(); |
136 | 178 |
137 // Returns the registry path where the browser crash dumps metrics need to be | 179 // Returns the registry path where the browser crash dumps metrics need to be |
138 // written to. | 180 // written to. |
139 // TODO(ananta) | 181 // TODO(ananta) |
140 // http://crbug.com/604923 | 182 // http://crbug.com/604923 |
141 // Unify this with the version in | 183 // Unify this with the version in |
142 // chrome\common\metrics_constants_util_win.cc | 184 // chrome\common\metrics_constants_util_win.cc |
143 std::wstring GetBrowserCrashDumpAttemptsRegistryPath(); | 185 std::wstring GetBrowserCrashDumpAttemptsRegistryPath(); |
144 | 186 |
145 // Returns true if the |source| string matches the |pattern|. The pattern | 187 // Returns true if the |source| string matches the |pattern|. The pattern |
(...skipping 12 matching lines...) Expand all Loading... |
158 // Tokenizes a string |str| based on single character delimiter. | 200 // Tokenizes a string |str| based on single character delimiter. |
159 // The tokens are returned in a vector. The |trim_spaces| parameter indicates | 201 // The tokens are returned in a vector. The |trim_spaces| parameter indicates |
160 // whether the function should optionally trim spaces throughout the string. | 202 // whether the function should optionally trim spaces throughout the string. |
161 std::vector<std::string> TokenizeString(const std::string& str, | 203 std::vector<std::string> TokenizeString(const std::string& str, |
162 char delimiter, | 204 char delimiter, |
163 bool trim_spaces); | 205 bool trim_spaces); |
164 std::vector<std::wstring> TokenizeString16(const std::wstring& str, | 206 std::vector<std::wstring> TokenizeString16(const std::wstring& str, |
165 wchar_t delimiter, | 207 wchar_t delimiter, |
166 bool trim_spaces); | 208 bool trim_spaces); |
167 | 209 |
| 210 // Compares version strings of the form "X.X.X.X" and returns the result of the |
| 211 // comparison in the |result| parameter. The result is as below: |
| 212 // 0 if the versions are equal. |
| 213 // -1 if version1 < version2. |
| 214 // 1 if version1 > version2. |
| 215 // Returns true on success, false on invalid strings being passed, etc. |
| 216 bool CompareVersionStrings(const std::string& version1, |
| 217 const std::string& version2, |
| 218 int* result); |
| 219 |
168 // We assume that the command line |command_line| contains multiple switches | 220 // We assume that the command line |command_line| contains multiple switches |
169 // with the format --<switch name>=<switch value>. This function returns the | 221 // with the format --<switch name>=<switch value>. This function returns the |
170 // value of the |switch_name| passed in. | 222 // value of the |switch_name| passed in. |
171 std::string GetSwitchValueFromCommandLine(const std::string& command_line, | 223 std::string GetSwitchValueFromCommandLine(const std::string& command_line, |
172 const std::string& switch_name); | 224 const std::string& switch_name); |
173 | 225 |
174 // Returns the unadorned channel name based on the channel strategy for the | |
175 // install mode. | |
176 std::wstring DetermineChannel(const InstallConstants& mode, | |
177 bool system_level, | |
178 bool multi_install); | |
179 | |
180 // Caches the |ProcessType| of the current process. | 226 // Caches the |ProcessType| of the current process. |
181 extern ProcessType g_process_type; | 227 extern ProcessType g_process_type; |
182 | 228 |
183 } // namespace install_static | 229 } // namespace install_static |
184 | 230 |
185 #endif // CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ | 231 #endif // CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ |
OLD | NEW |