| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/install_static/install_util.h" | 5 #include "chrome/install_static/install_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <iterator> |
| 13 #include <limits> | 14 #include <limits> |
| 14 #include <memory> | 15 #include <memory> |
| 15 #include <sstream> | 16 #include <sstream> |
| 16 | 17 |
| 17 #include "chrome/install_static/install_details.h" | 18 #include "chrome/install_static/install_details.h" |
| 18 #include "chrome/install_static/install_modes.h" | 19 #include "chrome/install_static/install_modes.h" |
| 19 #include "chrome/install_static/policy_path_parser.h" | 20 #include "chrome/install_static/policy_path_parser.h" |
| 20 #include "chrome/install_static/user_data_dir.h" | 21 #include "chrome/install_static/user_data_dir.h" |
| 21 #include "chrome_elf/nt_registry/nt_registry.h" | 22 #include "chrome_elf/nt_registry/nt_registry.h" |
| 22 | 23 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 51 // Chrome channel display names. | 52 // Chrome channel display names. |
| 52 constexpr wchar_t kChromeChannelDev[] = L"dev"; | 53 constexpr wchar_t kChromeChannelDev[] = L"dev"; |
| 53 constexpr wchar_t kChromeChannelBeta[] = L"beta"; | 54 constexpr wchar_t kChromeChannelBeta[] = L"beta"; |
| 54 constexpr wchar_t kChromeChannelStableExplicit[] = L"stable"; | 55 constexpr wchar_t kChromeChannelStableExplicit[] = L"stable"; |
| 55 | 56 |
| 56 // TODO(ananta) | 57 // TODO(ananta) |
| 57 // http://crbug.com/604923 | 58 // http://crbug.com/604923 |
| 58 // These constants are defined in the chrome/installer directory as well. We | 59 // These constants are defined in the chrome/installer directory as well. We |
| 59 // need to unify them. | 60 // need to unify them. |
| 60 constexpr wchar_t kRegValueAp[] = L"ap"; | 61 constexpr wchar_t kRegValueAp[] = L"ap"; |
| 62 constexpr wchar_t kRegValueName[] = L"name"; |
| 61 constexpr wchar_t kRegValueUsageStats[] = L"usagestats"; | 63 constexpr wchar_t kRegValueUsageStats[] = L"usagestats"; |
| 62 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; | 64 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; |
| 63 | 65 |
| 64 void Trace(const wchar_t* format_string, ...) { | 66 void Trace(const wchar_t* format_string, ...) { |
| 65 static const int kMaxLogBufferSize = 1024; | 67 static const int kMaxLogBufferSize = 1024; |
| 66 static wchar_t buffer[kMaxLogBufferSize] = {}; | 68 static wchar_t buffer[kMaxLogBufferSize] = {}; |
| 67 | 69 |
| 68 va_list args = {}; | 70 va_list args = {}; |
| 69 | 71 |
| 70 va_start(args, format_string); | 72 va_start(args, format_string); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 std::vector<StringType> tokens; | 245 std::vector<StringType> tokens; |
| 244 std::basic_istringstream<typename StringType::value_type> buffer(str); | 246 std::basic_istringstream<typename StringType::value_type> buffer(str); |
| 245 for (StringType token; std::getline(buffer, token, delimiter);) { | 247 for (StringType token; std::getline(buffer, token, delimiter);) { |
| 246 if (trim_spaces) | 248 if (trim_spaces) |
| 247 TrimT<StringType>(&token); | 249 TrimT<StringType>(&token); |
| 248 tokens.push_back(token); | 250 tokens.push_back(token); |
| 249 } | 251 } |
| 250 return tokens; | 252 return tokens; |
| 251 } | 253 } |
| 252 | 254 |
| 255 // Returns Chrome's update channel name based on the contents of the given "ap" |
| 256 // value from Chrome's ClientState key. |
| 253 std::wstring ChannelFromAdditionalParameters(const InstallConstants& mode, | 257 std::wstring ChannelFromAdditionalParameters(const InstallConstants& mode, |
| 254 bool system_level, | 258 const std::wstring& ap_value) { |
| 255 bool from_binaries) { | |
| 256 assert(kUseGoogleUpdateIntegration); | 259 assert(kUseGoogleUpdateIntegration); |
| 257 // InitChannelInfo in google_update_settings.cc only reports a failure when | |
| 258 // Chrome's ClientState key exists but that the "ap" value therein cannot be | |
| 259 // read due to some reason *other* than it not being present. This should be | |
| 260 // exceedingly rare. For simplicity's sake, use an empty |value| in case of | |
| 261 // any error whatsoever here. | |
| 262 std::wstring value; | |
| 263 nt::QueryRegValueSZ(system_level ? nt::HKLM : nt::HKCU, nt::WOW6432, | |
| 264 from_binaries | |
| 265 ? GetBinariesClientStateKeyPath().c_str() | |
| 266 : GetClientStateKeyPath(mode.app_guid).c_str(), | |
| 267 kRegValueAp, &value); | |
| 268 | 260 |
| 269 static constexpr wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; | 261 static constexpr wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; |
| 270 static constexpr wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; | 262 static constexpr wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; |
| 271 static constexpr wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; | 263 static constexpr wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; |
| 272 static constexpr wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; | 264 static constexpr wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; |
| 273 | 265 |
| 274 std::transform(value.begin(), value.end(), value.begin(), ::tolower); | 266 std::wstring value; |
| 267 value.reserve(ap_value.size()); |
| 268 std::transform(ap_value.begin(), ap_value.end(), std::back_inserter(value), |
| 269 ::tolower); |
| 275 | 270 |
| 276 // Empty channel names or those containing "stable" should be reported as | 271 // Empty channel names or those containing "stable" should be reported as |
| 277 // an empty string. | 272 // an empty string. |
| 278 std::wstring channel_name; | |
| 279 if (value.empty() || | 273 if (value.empty() || |
| 280 (value.find(kChromeChannelStableExplicit) != std::wstring::npos)) { | 274 (value.find(kChromeChannelStableExplicit) != std::wstring::npos)) { |
| 281 } else if (MatchPattern(value, kChromeChannelDevPattern) || | 275 return std::wstring(); |
| 282 MatchPattern(value, kChromeChannelDevX64Pattern)) { | 276 } |
| 283 channel_name.assign(kChromeChannelDev); | 277 if (MatchPattern(value, kChromeChannelDevPattern) || |
| 284 } else if (MatchPattern(value, kChromeChannelBetaPattern) || | 278 MatchPattern(value, kChromeChannelDevX64Pattern)) { |
| 285 MatchPattern(value, kChromeChannelBetaX64Pattern)) { | 279 return kChromeChannelDev; |
| 286 channel_name.assign(kChromeChannelBeta); | 280 } |
| 281 if (MatchPattern(value, kChromeChannelBetaPattern) || |
| 282 MatchPattern(value, kChromeChannelBetaX64Pattern)) { |
| 283 return kChromeChannelBeta; |
| 287 } | 284 } |
| 288 // Else report values with garbage as stable since they will match the stable | 285 // Else report values with garbage as stable since they will match the stable |
| 289 // rules in the update configs. ChannelInfo::GetChannelName painstakingly | 286 // rules in the update configs. |
| 290 // strips off known modifiers (e.g., "-full") to see if the empty string | 287 return std::wstring(); |
| 291 // remains, returning channel "unknown" if not. This differs here in that some | |
| 292 // clients will tag crashes as "stable" rather than "unknown" via this | |
| 293 // codepath, but it is an accurate reflection of which update channel the | |
| 294 // client is on according to the server-side rules. | |
| 295 | |
| 296 return channel_name; | |
| 297 } | 288 } |
| 298 | 289 |
| 299 } // namespace | 290 } // namespace |
| 300 | 291 |
| 301 bool IsSystemInstall() { | 292 bool IsSystemInstall() { |
| 302 return InstallDetails::Get().system_level(); | 293 return InstallDetails::Get().system_level(); |
| 303 } | 294 } |
| 304 | 295 |
| 305 std::wstring GetChromeInstallSubDirectory() { | 296 std::wstring GetChromeInstallSubDirectory() { |
| 306 std::wstring result; | 297 std::wstring result; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 return false; | 779 return false; |
| 789 } | 780 } |
| 790 } | 781 } |
| 791 return true; | 782 return true; |
| 792 } | 783 } |
| 793 | 784 |
| 794 // This function takes these inputs rather than accessing the module's | 785 // This function takes these inputs rather than accessing the module's |
| 795 // InstallDetails instance since it is used to bootstrap InstallDetails. | 786 // InstallDetails instance since it is used to bootstrap InstallDetails. |
| 796 std::wstring DetermineChannel(const InstallConstants& mode, | 787 std::wstring DetermineChannel(const InstallConstants& mode, |
| 797 bool system_level, | 788 bool system_level, |
| 798 bool from_binaries) { | 789 bool from_binaries, |
| 790 std::wstring* update_ap, |
| 791 std::wstring* update_cohort_name) { |
| 799 if (!kUseGoogleUpdateIntegration) | 792 if (!kUseGoogleUpdateIntegration) |
| 800 return std::wstring(); | 793 return std::wstring(); |
| 801 | 794 |
| 795 // Read the "ap" value and cache it if requested. |
| 796 std::wstring client_state(from_binaries |
| 797 ? GetBinariesClientStateKeyPath() |
| 798 : GetClientStateKeyPath(mode.app_guid)); |
| 799 std::wstring ap_value; |
| 800 // An empty |ap_value| is used in case of error. |
| 801 nt::QueryRegValueSZ(system_level ? nt::HKLM : nt::HKCU, nt::WOW6432, |
| 802 client_state.c_str(), kRegValueAp, &ap_value); |
| 803 if (update_ap) |
| 804 *update_ap = ap_value; |
| 805 |
| 806 // Cache the cohort name if requested. |
| 807 if (update_cohort_name) { |
| 808 nt::QueryRegValueSZ(system_level ? nt::HKLM : nt::HKCU, nt::WOW6432, |
| 809 client_state.append(L"\\cohort").c_str(), kRegValueName, |
| 810 update_cohort_name); |
| 811 } |
| 812 |
| 802 switch (mode.channel_strategy) { | 813 switch (mode.channel_strategy) { |
| 803 case ChannelStrategy::UNSUPPORTED: | 814 case ChannelStrategy::UNSUPPORTED: |
| 804 assert(false); | 815 assert(false); |
| 805 break; | 816 break; |
| 806 case ChannelStrategy::ADDITIONAL_PARAMETERS: | 817 case ChannelStrategy::ADDITIONAL_PARAMETERS: |
| 807 return ChannelFromAdditionalParameters(mode, system_level, from_binaries); | 818 return ChannelFromAdditionalParameters(mode, ap_value); |
| 808 case ChannelStrategy::FIXED: | 819 case ChannelStrategy::FIXED: |
| 809 return mode.default_channel_name; | 820 return mode.default_channel_name; |
| 810 } | 821 } |
| 811 | 822 |
| 812 return std::wstring(); | 823 return std::wstring(); |
| 813 } | 824 } |
| 814 | 825 |
| 815 } // namespace install_static | 826 } // namespace install_static |
| OLD | NEW |