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