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 // This file contains helper functions which provide information about the | 4 // This file contains helper functions which provide information about the |
5 // current version of Chrome. This includes channel information, version | 5 // current version of Chrome. This includes channel information, version |
6 // information etc. This functionality is provided by using functions in | 6 // information etc. This functionality is provided by using functions in |
7 // kernel32 and advapi32. No other dependencies are allowed in this file. | 7 // kernel32 and advapi32. No other dependencies are allowed in this file. |
8 | 8 |
9 #ifndef CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ | 9 #ifndef CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ |
10 #define CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ | 10 #define CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/strings/string16.h" | |
16 | |
17 namespace install_static { | 15 namespace install_static { |
18 | 16 |
19 enum class ProcessType { | 17 enum class ProcessType { |
20 UNINITIALIZED, | 18 UNINITIALIZED, |
21 NON_BROWSER_PROCESS, | 19 NON_BROWSER_PROCESS, |
22 BROWSER_PROCESS, | 20 BROWSER_PROCESS, |
23 }; | 21 }; |
24 | 22 |
25 // TODO(ananta) | 23 // TODO(ananta) |
26 // https://crbug.com/604923 | 24 // https://crbug.com/604923 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Returns true if current installation of Chrome is a multi-install. | 69 // Returns true if current installation of Chrome is a multi-install. |
72 bool IsMultiInstall(bool is_system_install); | 70 bool IsMultiInstall(bool is_system_install); |
73 | 71 |
74 // Returns true if usage stats collecting is enabled for this user for the | 72 // Returns true if usage stats collecting is enabled for this user for the |
75 // current executable. | 73 // current executable. |
76 bool GetCollectStatsConsent(); | 74 bool GetCollectStatsConsent(); |
77 | 75 |
78 // Returns true if usage stats collecting is enabled for this user for the | 76 // Returns true if usage stats collecting is enabled for this user for the |
79 // executable passed in as |exe_path|. | 77 // executable passed in as |exe_path|. |
80 // Only used by tests. | 78 // Only used by tests. |
81 bool GetCollectStatsConsentForTesting(const base::string16& exe_path); | 79 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path); |
82 | 80 |
83 // Returns true if if usage stats reporting is controlled by a mandatory | 81 // Returns true if if usage stats reporting is controlled by a mandatory |
84 // policy. |metrics_is_enforced_by_policy| will be set to true accordingly. | 82 // policy. |metrics_is_enforced_by_policy| will be set to true accordingly. |
85 // TODO(ananta) | 83 // TODO(ananta) |
86 // Make this function private to install_util. | 84 // Make this function private to install_util. |
87 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy); | 85 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy); |
88 | 86 |
89 // Initializes |g_process_type| which stores whether or not the current | 87 // Initializes |g_process_type| which stores whether or not the current |
90 // process is the main browser process. | 88 // process is the main browser process. |
91 void InitializeProcessType(); | 89 void InitializeProcessType(); |
92 | 90 |
93 // Returns true if invoked in a Chrome process other than the main browser | 91 // Returns true if invoked in a Chrome process other than the main browser |
94 // process. False otherwise. | 92 // process. False otherwise. |
95 bool IsNonBrowserProcess(); | 93 bool IsNonBrowserProcess(); |
96 | 94 |
97 // Populates |result| with the default User Data directory for the current | 95 // Populates |result| with the default User Data directory for the current |
98 // user.This may be overidden by a command line option.Returns false if all | 96 // user.This may be overidden by a command line option.Returns false if all |
99 // attempts at locating a User Data directory fail | 97 // attempts at locating a User Data directory fail |
100 // TODO(ananta) | 98 // TODO(ananta) |
101 // http://crbug.com/604923 | 99 // http://crbug.com/604923 |
102 // Unify this with the Browser Distribution code. | 100 // Unify this with the Browser Distribution code. |
103 bool GetDefaultUserDataDirectory(base::string16* result); | 101 bool GetDefaultUserDataDirectory(std::wstring* result); |
104 | 102 |
105 // Populates |crash_dir| with the default crash dump location regardless of | 103 // Populates |crash_dir| with the default crash dump location regardless of |
106 // whether DIR_USER_DATA or DIR_CRASH_DUMPS has been overridden. | 104 // whether DIR_USER_DATA or DIR_CRASH_DUMPS has been overridden. |
107 // TODO(ananta) | 105 // TODO(ananta) |
108 // http://crbug.com/604923 | 106 // http://crbug.com/604923 |
109 // Unify this with the Browser Distribution code. | 107 // Unify this with the Browser Distribution code. |
110 bool GetDefaultCrashDumpLocation(base::string16* crash_dir); | 108 bool GetDefaultCrashDumpLocation(std::wstring* crash_dir); |
111 | 109 |
112 // Returns the contents of the specified |variable_name| from the environment | 110 // Returns the contents of the specified |variable_name| from the environment |
113 // block of the calling process. Returns an empty string if the variable does | 111 // block of the calling process. Returns an empty string if the variable does |
114 // not exist. | 112 // not exist. |
115 std::string GetEnvironmentString(const std::string& variable_name); | 113 std::string GetEnvironmentString(const std::string& variable_name); |
116 base::string16 GetEnvironmentString16(const base::string16& variable_name); | 114 std::wstring GetEnvironmentString16(const std::wstring& variable_name); |
117 | 115 |
118 // Sets the environment variable identified by |variable_name| to the value | 116 // Sets the environment variable identified by |variable_name| to the value |
119 // identified by |new_value|. | 117 // identified by |new_value|. |
120 bool SetEnvironmentString(const std::string& variable_name, | 118 bool SetEnvironmentString(const std::string& variable_name, |
121 const std::string& new_value); | 119 const std::string& new_value); |
122 bool SetEnvironmentString16(const base::string16& variable_name, | 120 bool SetEnvironmentString16(const std::wstring& variable_name, |
123 const base::string16& new_value); | 121 const std::wstring& new_value); |
124 | 122 |
125 // Returns true if the environment variable identified by |variable_name| | 123 // Returns true if the environment variable identified by |variable_name| |
126 // exists. | 124 // exists. |
127 bool HasEnvironmentVariable(const std::string& variable_name); | 125 bool HasEnvironmentVariable(const std::string& variable_name); |
128 bool HasEnvironmentVariable16(const base::string16& variable_name); | 126 bool HasEnvironmentVariable16(const std::wstring& variable_name); |
129 | 127 |
130 // Gets the exe version details like the |product_name|, |version|, | 128 // Gets the exe version details like the |product_name|, |version|, |
131 // |special_build|, |channel_name|, etc. Most of this information is read | 129 // |special_build|, |channel_name|, etc. Most of this information is read |
132 // from the version resource. |exe_path| is the path of chrome.exe. | 130 // from the version resource. |exe_path| is the path of chrome.exe. |
133 // TODO(ananta) | 131 // TODO(ananta) |
134 // http://crbug.com/604923 | 132 // http://crbug.com/604923 |
135 // Unify this with the Browser Distribution code. | 133 // Unify this with the Browser Distribution code. |
136 bool GetExecutableVersionDetails(const base::string16& exe_path, | 134 bool GetExecutableVersionDetails(const std::wstring& exe_path, |
137 base::string16* product_name, | 135 std::wstring* product_name, |
138 base::string16* version, | 136 std::wstring* version, |
139 base::string16* special_build, | 137 std::wstring* special_build, |
140 base::string16* channel_name); | 138 std::wstring* channel_name); |
141 | 139 |
142 // Gets the channel name for the current Chrome process. | 140 // Gets the channel name for the current Chrome process. |
143 // If |add_modifier| is true the channel name is returned with the modifier | 141 // If |add_modifier| is true the channel name is returned with the modifier |
144 // prepended to it. Currently this is only done for multi installs, i.e (-m) | 142 // prepended to it. Currently this is only done for multi installs, i.e (-m) |
145 // is the only modifier supported. | 143 // is the only modifier supported. |
146 // TODO(ananta) | 144 // TODO(ananta) |
147 // http://crbug.com/604923 | 145 // http://crbug.com/604923 |
148 // Unify this with the Browser Distribution code. | 146 // Unify this with the Browser Distribution code. |
149 void GetChromeChannelName(bool is_per_user_install, | 147 void GetChromeChannelName(bool is_per_user_install, |
150 bool add_modifier, | 148 bool add_modifier, |
151 base::string16* channel_name); | 149 std::wstring* channel_name); |
152 | |
153 | 150 |
154 // Returns the version of Google Update that is installed. | 151 // Returns the version of Google Update that is installed. |
155 // TODO(ananta) | 152 // TODO(ananta) |
156 // http://crbug.com/604923 | 153 // http://crbug.com/604923 |
157 // Unify this with the Browser Distribution code. | 154 // Unify this with the Browser Distribution code. |
158 std::string GetGoogleUpdateVersion(); | 155 std::string GetGoogleUpdateVersion(); |
159 | 156 |
160 // Returns the Chrome installation subdirectory, i.e. Google Chrome\Chromium, | 157 // Returns the Chrome installation subdirectory, i.e. Google Chrome\Chromium, |
161 // etc. | 158 // etc. |
162 // TODO(ananta) | 159 // TODO(ananta) |
163 // http://crbug.com/604923 | 160 // http://crbug.com/604923 |
164 // Unify this with the Browser Distribution code. | 161 // Unify this with the Browser Distribution code. |
165 base::string16 GetChromeInstallSubDirectory(); | 162 std::wstring GetChromeInstallSubDirectory(); |
166 | 163 |
167 // Returns the registry path where the browser crash dumps metrics need to be | 164 // Returns the registry path where the browser crash dumps metrics need to be |
168 // written to. | 165 // written to. |
169 // TODO(ananta) | 166 // TODO(ananta) |
170 // http://crbug.com/604923 | 167 // http://crbug.com/604923 |
171 // Unify this with the version in | 168 // Unify this with the version in |
172 // chrome\common\metrics_constants_util_win.cc | 169 // chrome\common\metrics_constants_util_win.cc |
173 base::string16 GetBrowserCrashDumpAttemptsRegistryPath(); | 170 std::wstring GetBrowserCrashDumpAttemptsRegistryPath(); |
174 | 171 |
175 // Returns true if the |source| string matches the |pattern|. The pattern | 172 // Returns true if the |source| string matches the |pattern|. The pattern |
176 // may contain wildcards like '?', which matches one character or a '*' | 173 // may contain wildcards like '?', which matches one character or a '*' |
177 // which matches 0 or more characters. | 174 // which matches 0 or more characters. |
178 // Please note that pattern matches the whole string. If you want to find | 175 // Please note that pattern matches the whole string. If you want to find |
179 // something in the middle of the string then you need to specify the pattern | 176 // something in the middle of the string then you need to specify the pattern |
180 // as '*xyz*'. | 177 // as '*xyz*'. |
181 bool MatchPattern(const base::string16& source, const base::string16& pattern); | 178 bool MatchPattern(const std::wstring& source, const std::wstring& pattern); |
182 | 179 |
183 // UTF8 to UTF16 and vice versa conversion helpers. | 180 // UTF8 to UTF16 and vice versa conversion helpers. |
184 base::string16 UTF8ToUTF16(const std::string& source); | 181 std::wstring UTF8ToUTF16(const std::string& source); |
185 | 182 |
186 std::string UTF16ToUTF8(const base::string16& source); | 183 std::string UTF16ToUTF8(const std::wstring& source); |
187 | 184 |
188 // Tokenizes a string |str| based on single character delimiter. | 185 // Tokenizes a string |str| based on single character delimiter. |
189 // The tokens are returned in a vector. The |trim_spaces| parameter indicates | 186 // The tokens are returned in a vector. The |trim_spaces| parameter indicates |
190 // whether the function should optionally trim spaces throughout the string. | 187 // whether the function should optionally trim spaces throughout the string. |
191 std::vector<std::string> TokenizeString(const std::string& str, | 188 std::vector<std::string> TokenizeString(const std::string& str, |
192 char delimiter, | 189 char delimiter, |
193 bool trim_spaces); | 190 bool trim_spaces); |
194 std::vector<base::string16> TokenizeString16(const base::string16& str, | 191 std::vector<std::wstring> TokenizeString16(const std::wstring& str, |
195 base::char16 delimiter, | 192 wchar_t delimiter, |
196 bool trim_spaces); | 193 bool trim_spaces); |
197 | 194 |
198 // Compares version strings of the form "X.X.X.X" and returns the result of the | 195 // Compares version strings of the form "X.X.X.X" and returns the result of the |
199 // comparison in the |result| parameter. The result is as below: | 196 // comparison in the |result| parameter. The result is as below: |
200 // 0 if the versions are equal. | 197 // 0 if the versions are equal. |
201 // -1 if version1 < version2. | 198 // -1 if version1 < version2. |
202 // 1 if version1 > version2. | 199 // 1 if version1 > version2. |
203 // Returns true on success, false on invalid strings being passed, etc. | 200 // Returns true on success, false on invalid strings being passed, etc. |
204 bool CompareVersionStrings(const std::string& version1, | 201 bool CompareVersionStrings(const std::string& version1, |
205 const std::string& version2, | 202 const std::string& version2, |
206 int* result); | 203 int* result); |
207 | 204 |
208 // We assume that the command line |command_line| contains multiple switches | 205 // We assume that the command line |command_line| contains multiple switches |
209 // with the format --<switch name>=<switch value>. This function returns the | 206 // with the format --<switch name>=<switch value>. This function returns the |
210 // value of the |switch_name| passed in. | 207 // value of the |switch_name| passed in. |
211 std::string GetSwitchValueFromCommandLine(const std::string& command_line, | 208 std::string GetSwitchValueFromCommandLine(const std::string& command_line, |
212 const std::string& switch_name); | 209 const std::string& switch_name); |
213 | 210 |
214 // Caches the |ProcessType| of the current process. | 211 // Caches the |ProcessType| of the current process. |
215 extern ProcessType g_process_type; | 212 extern ProcessType g_process_type; |
216 | 213 |
217 } // namespace install_static | 214 } // namespace install_static |
218 | 215 |
219 #endif // CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ | 216 #endif // CHROME_INSTALL_STATIC_INSTALL_UTIL_H_ |
OLD | NEW |