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> |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 std::basic_istringstream<typename StringType::value_type> buffer(str); | 250 std::basic_istringstream<typename StringType::value_type> buffer(str); |
251 for (StringType token; std::getline(buffer, token, delimiter);) { | 251 for (StringType token; std::getline(buffer, token, delimiter);) { |
252 if (trim_spaces) | 252 if (trim_spaces) |
253 TrimT<StringType>(&token); | 253 TrimT<StringType>(&token); |
254 tokens.push_back(token); | 254 tokens.push_back(token); |
255 } | 255 } |
256 return tokens; | 256 return tokens; |
257 } | 257 } |
258 | 258 |
259 std::wstring ChannelFromAdditionalParameters(const InstallConstants& mode, | 259 std::wstring ChannelFromAdditionalParameters(const InstallConstants& mode, |
260 bool system_level, | 260 bool system_level) { |
261 bool binaries) { | |
262 assert(kUseGoogleUpdateIntegration); | 261 assert(kUseGoogleUpdateIntegration); |
263 // InitChannelInfo in google_update_settings.cc only reports a failure in the | 262 // InitChannelInfo in google_update_settings.cc only reports a failure when |
264 // case of multi-install Chrome where the binaries' ClientState key exists, | 263 // Chrome's ClientState key exists but that the "ap" value therein cannot be |
265 // but that the "ap" value therein cannot be read due to some reason *other* | 264 // read due to some reason *other* than it not being present. This should be |
266 // than it not being present. This should be exceedingly rare. For | 265 // exceedingly rare. For simplicity's sake, use an empty |value| in case of |
267 // simplicity's sake, use an empty |value| in case of any error whatsoever | 266 // any error whatsoever here. |
268 // here. | |
269 std::wstring value; | 267 std::wstring value; |
270 nt::QueryRegValueSZ(system_level ? nt::HKLM : nt::HKCU, nt::WOW6432, | 268 nt::QueryRegValueSZ(system_level ? nt::HKLM : nt::HKCU, nt::WOW6432, |
271 (binaries ? GetBinariesClientStateKeyPath() | 269 GetClientStateKeyPath(mode.app_guid).c_str(), kRegValueAp, |
272 : GetClientStateKeyPath(mode.app_guid)) | 270 &value); |
273 .c_str(), | |
274 kRegValueAp, &value); | |
275 | 271 |
276 static constexpr wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; | 272 static constexpr wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; |
277 static constexpr wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; | 273 static constexpr wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; |
278 static constexpr wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; | 274 static constexpr wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; |
279 static constexpr wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; | 275 static constexpr wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; |
280 | 276 |
281 std::transform(value.begin(), value.end(), value.begin(), ::tolower); | 277 std::transform(value.begin(), value.end(), value.begin(), ::tolower); |
282 | 278 |
283 // Empty channel names or those containing "stable" should be reported as | 279 // Empty channel names or those containing "stable" should be reported as |
284 // an empty string. | 280 // an empty string. |
285 std::wstring channel_name; | 281 std::wstring channel_name; |
286 if (value.empty() || | 282 if (value.empty() || |
287 (value.find(kChromeChannelStableExplicit) != std::wstring::npos)) { | 283 (value.find(kChromeChannelStableExplicit) != std::wstring::npos)) { |
288 } else if (MatchPattern(value, kChromeChannelDevPattern) || | 284 } else if (MatchPattern(value, kChromeChannelDevPattern) || |
289 MatchPattern(value, kChromeChannelDevX64Pattern)) { | 285 MatchPattern(value, kChromeChannelDevX64Pattern)) { |
290 channel_name.assign(kChromeChannelDev); | 286 channel_name.assign(kChromeChannelDev); |
291 } else if (MatchPattern(value, kChromeChannelBetaPattern) || | 287 } else if (MatchPattern(value, kChromeChannelBetaPattern) || |
292 MatchPattern(value, kChromeChannelBetaX64Pattern)) { | 288 MatchPattern(value, kChromeChannelBetaX64Pattern)) { |
293 channel_name.assign(kChromeChannelBeta); | 289 channel_name.assign(kChromeChannelBeta); |
294 } | 290 } |
295 // Else report values with garbage as stable since they will match the stable | 291 // Else report values with garbage as stable since they will match the stable |
296 // rules in the update configs. ChannelInfo::GetChannelName painstakingly | 292 // rules in the update configs. ChannelInfo::GetChannelName painstakingly |
297 // strips off known modifiers (e.g., "-multi-full") to see if the empty string | 293 // strips off known modifiers (e.g., "-multi-full") to see if the empty string |
huangs
2016/12/27 20:04:22
Update comment re. "-multi-full"?
grt (UTC plus 2)
2017/01/02 12:58:45
Done.
| |
298 // remains, returning channel "unknown" if not. This differs here in that some | 294 // remains, returning channel "unknown" if not. This differs here in that some |
299 // clients will tag crashes as "stable" rather than "unknown" via this | 295 // clients will tag crashes as "stable" rather than "unknown" via this |
300 // codepath, but it is an accurate reflection of which update channel the | 296 // codepath, but it is an accurate reflection of which update channel the |
301 // client is on according to the server-side rules. | 297 // client is on according to the server-side rules. |
302 | 298 |
303 return channel_name; | 299 return channel_name; |
304 } | 300 } |
305 | 301 |
306 } // namespace | 302 } // namespace |
307 | 303 |
308 bool IsSystemInstall() { | 304 bool IsSystemInstall() { |
309 return InstallDetails::Get().system_level(); | 305 return InstallDetails::Get().system_level(); |
310 } | 306 } |
311 | 307 |
312 bool IsMultiInstall() { | |
313 return InstallDetails::Get().multi_install(); | |
314 } | |
315 | |
316 bool GetCollectStatsConsent() { | 308 bool GetCollectStatsConsent() { |
317 bool enabled = true; | 309 bool enabled = true; |
318 | 310 |
319 if (ReportingIsEnforcedByPolicy(&enabled)) | 311 if (ReportingIsEnforcedByPolicy(&enabled)) |
320 return enabled; | 312 return enabled; |
321 | 313 |
322 const bool system_install = IsSystemInstall(); | 314 const bool system_install = IsSystemInstall(); |
323 | 315 |
324 DWORD out_value = 0; | 316 DWORD out_value = 0; |
325 | 317 |
326 // If system_install, first try ClientStateMedium in HKLM. | 318 // If system_install, first try ClientStateMedium in HKLM. |
327 if (system_install && | 319 if (system_install && |
328 nt::QueryRegValueDWORD( | 320 nt::QueryRegValueDWORD( |
329 nt::HKLM, nt::WOW6432, | 321 nt::HKLM, nt::WOW6432, |
330 InstallDetails::Get().GetClientStateMediumKeyPath(true).c_str(), | 322 InstallDetails::Get().GetClientStateMediumKeyPath().c_str(), |
331 kRegValueUsageStats, &out_value)) { | 323 kRegValueUsageStats, &out_value)) { |
332 return (out_value == 1); | 324 return (out_value == 1); |
333 } | 325 } |
334 | 326 |
335 // Second, try ClientState. | 327 // Second, try ClientState. |
336 return (nt::QueryRegValueDWORD( | 328 return (nt::QueryRegValueDWORD( |
337 system_install ? nt::HKLM : nt::HKCU, nt::WOW6432, | 329 system_install ? nt::HKLM : nt::HKCU, nt::WOW6432, |
338 InstallDetails::Get().GetClientStateKeyPath(true).c_str(), | 330 InstallDetails::Get().GetClientStateKeyPath().c_str(), |
339 kRegValueUsageStats, &out_value) && | 331 kRegValueUsageStats, &out_value) && |
340 out_value == 1); | 332 out_value == 1); |
341 } | 333 } |
342 | 334 |
343 bool GetCollectStatsInSample() { | 335 bool GetCollectStatsInSample() { |
344 std::wstring registry_path = GetChromeInstallRegistryPath(); | 336 std::wstring registry_path = GetChromeInstallRegistryPath(); |
345 | 337 |
346 DWORD out_value = 0; | 338 DWORD out_value = 0; |
347 if (!nt::QueryRegValueDWORD(nt::HKCU, nt::WOW6432, registry_path.c_str(), | 339 if (!nt::QueryRegValueDWORD(nt::HKCU, nt::WOW6432, registry_path.c_str(), |
348 kRegValueChromeStatsSample, &out_value)) { | 340 kRegValueChromeStatsSample, &out_value)) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 std::wstring official_build; | 498 std::wstring official_build; |
507 GetValueFromVersionResource(data.get(), L"Official Build", | 499 GetValueFromVersionResource(data.get(), L"Official Build", |
508 &official_build); | 500 &official_build); |
509 if (official_build != L"1") | 501 if (official_build != L"1") |
510 version->append(L"-devel"); | 502 version->append(L"-devel"); |
511 GetValueFromVersionResource(data.get(), L"ProductShortName", | 503 GetValueFromVersionResource(data.get(), L"ProductShortName", |
512 product_name); | 504 product_name); |
513 GetValueFromVersionResource(data.get(), L"SpecialBuild", special_build); | 505 GetValueFromVersionResource(data.get(), L"SpecialBuild", special_build); |
514 } | 506 } |
515 } | 507 } |
516 *channel_name = GetChromeChannelName(true /* add_modifier */); | 508 *channel_name = GetChromeChannelName(false); |
517 } | 509 } |
518 | 510 |
511 // TODO(grt): Remove |add_modifier|. | |
519 std::wstring GetChromeChannelName(bool add_modifier) { | 512 std::wstring GetChromeChannelName(bool add_modifier) { |
520 const std::wstring& channel = InstallDetails::Get().channel(); | 513 return InstallDetails::Get().channel(); |
521 if (!add_modifier || !IsMultiInstall()) | |
522 return channel; | |
523 if (channel.empty()) | |
524 return L"m"; | |
525 return channel + L"-m"; | |
526 } | 514 } |
527 | 515 |
528 std::wstring GetBrowserCrashDumpAttemptsRegistryPath() { | 516 std::wstring GetBrowserCrashDumpAttemptsRegistryPath() { |
529 return GetChromeInstallRegistryPath().append(kBrowserCrashDumpMetricsSubKey); | 517 return GetChromeInstallRegistryPath().append(kBrowserCrashDumpMetricsSubKey); |
530 } | 518 } |
531 | 519 |
532 bool MatchPattern(const std::wstring& source, const std::wstring& pattern) { | 520 bool MatchPattern(const std::wstring& source, const std::wstring& pattern) { |
533 assert(pattern.find(L"**") == std::wstring::npos); | 521 assert(pattern.find(L"**") == std::wstring::npos); |
534 return MatchPatternImpl(source, pattern, 0, 0); | 522 return MatchPatternImpl(source, pattern, 0, 0); |
535 } | 523 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 Trace(L"Failed to create directory %ls, last error is %d\n", | 729 Trace(L"Failed to create directory %ls, last error is %d\n", |
742 full_path_str, error_code); | 730 full_path_str, error_code); |
743 return false; | 731 return false; |
744 } | 732 } |
745 } | 733 } |
746 return true; | 734 return true; |
747 } | 735 } |
748 | 736 |
749 // This function takes these inputs rather than accessing the module's | 737 // This function takes these inputs rather than accessing the module's |
750 // InstallDetails instance since it is used to bootstrap InstallDetails. | 738 // InstallDetails instance since it is used to bootstrap InstallDetails. |
751 std::wstring DetermineChannel(const InstallConstants& mode, | 739 std::wstring DetermineChannel(const InstallConstants& mode, bool system_level) { |
752 bool system_level, | |
753 bool multi_install) { | |
754 if (!kUseGoogleUpdateIntegration) | 740 if (!kUseGoogleUpdateIntegration) |
755 return std::wstring(); | 741 return std::wstring(); |
756 | 742 |
757 switch (mode.channel_strategy) { | 743 switch (mode.channel_strategy) { |
758 case ChannelStrategy::UNSUPPORTED: | 744 case ChannelStrategy::UNSUPPORTED: |
759 assert(false); | 745 assert(false); |
760 break; | 746 break; |
761 case ChannelStrategy::ADDITIONAL_PARAMETERS: | 747 case ChannelStrategy::ADDITIONAL_PARAMETERS: |
762 return ChannelFromAdditionalParameters(mode, system_level, multi_install); | 748 return ChannelFromAdditionalParameters(mode, system_level); |
763 case ChannelStrategy::FIXED: | 749 case ChannelStrategy::FIXED: |
764 return mode.default_channel_name; | 750 return mode.default_channel_name; |
765 } | 751 } |
766 | 752 |
767 return std::wstring(); | 753 return std::wstring(); |
768 } | 754 } |
769 | 755 |
770 } // namespace install_static | 756 } // namespace install_static |
OLD | NEW |