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