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 <algorithm> | 9 #include <algorithm> |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; | 50 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; |
51 const wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; | 51 const wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; |
52 | 52 |
53 const wchar_t kAppGuidCanary[] = | 53 const wchar_t kAppGuidCanary[] = |
54 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; | 54 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; |
55 const wchar_t kAppGuidGoogleChrome[] = | 55 const wchar_t kAppGuidGoogleChrome[] = |
56 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 56 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
57 const wchar_t kAppGuidGoogleBinaries[] = | 57 const wchar_t kAppGuidGoogleBinaries[] = |
58 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | 58 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
59 | 59 |
| 60 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; |
| 61 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; |
| 62 const wchar_t kRestartInfo[] = L"CHROME_RESTART"; |
| 63 const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT"; |
| 64 |
| 65 const char kGpuProcess[] = "gpu-process"; |
| 66 const char kPpapiPluginProcess[] = "ppapi"; |
| 67 const char kRendererProcess[] = "renderer"; |
| 68 const char kUtilityProcess[] = "utility"; |
| 69 |
60 namespace { | 70 namespace { |
61 | 71 |
62 // TODO(ananta) | 72 // TODO(ananta) |
63 // http://crbug.com/604923 | 73 // http://crbug.com/604923 |
64 // These constants are defined in the chrome/installer directory as well. We | 74 // These constants are defined in the chrome/installer directory as well. We |
65 // need to unify them. | 75 // need to unify them. |
66 #if defined(GOOGLE_CHROME_BUILD) | 76 #if defined(GOOGLE_CHROME_BUILD) |
67 const wchar_t kSxSSuffix[] = L" SxS"; | 77 const wchar_t kSxSSuffix[] = L" SxS"; |
68 const wchar_t kGoogleChromeInstallSubDir1[] = L"Google"; | 78 const wchar_t kGoogleChromeInstallSubDir1[] = L"Google"; |
69 const wchar_t kGoogleChromeInstallSubDir2[] = L"Chrome"; | 79 const wchar_t kGoogleChromeInstallSubDir2[] = L"Chrome"; |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 if (pattern[pattern_index] == L'*') { | 392 if (pattern[pattern_index] == L'*') { |
383 return MatchPatternImpl(source, pattern, source_index + 1, | 393 return MatchPatternImpl(source, pattern, source_index + 1, |
384 pattern_index) || | 394 pattern_index) || |
385 MatchPatternImpl(source, pattern, source_index, pattern_index + 1); | 395 MatchPatternImpl(source, pattern, source_index, pattern_index + 1); |
386 } | 396 } |
387 return false; | 397 return false; |
388 } | 398 } |
389 | 399 |
390 // Defines the type of whitespace characters typically found in strings. | 400 // Defines the type of whitespace characters typically found in strings. |
391 constexpr char kWhiteSpaces[] = " \t\n\r\f\v"; | 401 constexpr char kWhiteSpaces[] = " \t\n\r\f\v"; |
| 402 constexpr base::char16 kWhiteSpaces16[] = L" \t\n\r\f\v"; |
| 403 |
| 404 // Define specializations for white spaces based on the type of the string. |
| 405 template<class StringType> StringType GetWhiteSpacesForType(); |
| 406 template<> |
| 407 base::string16 GetWhiteSpacesForType() { |
| 408 return kWhiteSpaces16; |
| 409 } |
| 410 template<> |
| 411 std::string GetWhiteSpacesForType() { |
| 412 return kWhiteSpaces; |
| 413 } |
392 | 414 |
393 // Trim whitespaces from left & right | 415 // Trim whitespaces from left & right |
394 void Trim(std::string* str) { | 416 template<class StringType> |
395 str->erase(str->find_last_not_of(kWhiteSpaces) + 1); | 417 void TrimT(StringType* str) { |
396 str->erase(0, str->find_first_not_of(kWhiteSpaces)); | 418 str->erase(str->find_last_not_of(GetWhiteSpacesForType<StringType>()) + 1); |
| 419 str->erase(0, str->find_first_not_of(GetWhiteSpacesForType<StringType>())); |
397 } | 420 } |
398 | 421 |
399 bool IsValidNumber(const std::string& str) { | 422 bool IsValidNumber(const std::string& str) { |
400 if (str.empty()) | 423 if (str.empty()) |
401 return false; | 424 return false; |
402 return std::all_of(str.begin(), str.end(), ::isdigit); | 425 return std::all_of(str.begin(), str.end(), ::isdigit); |
403 } | 426 } |
404 | 427 |
| 428 // Tokenizes a string based on a single character delimiter. |
| 429 template<class StringType> |
| 430 std::vector<StringType> TokenizeStringT( |
| 431 const StringType& str, |
| 432 typename StringType::value_type delimiter, |
| 433 bool trim_spaces) { |
| 434 std::vector<StringType> tokens; |
| 435 std::basic_istringstream<typename StringType::value_type> buffer(str); |
| 436 for (StringType token; std::getline(buffer, token, delimiter);) { |
| 437 if (trim_spaces) |
| 438 TrimT<StringType>(&token); |
| 439 tokens.push_back(token); |
| 440 } |
| 441 return tokens; |
| 442 } |
| 443 |
405 } // namespace | 444 } // namespace |
406 | 445 |
407 bool IsSxSChrome(const wchar_t* exe_path) { | 446 bool IsSxSChrome(const wchar_t* exe_path) { |
408 return wcsstr(exe_path, L"Chrome SxS\\Application") != nullptr; | 447 return wcsstr(exe_path, L"Chrome SxS\\Application") != nullptr; |
409 } | 448 } |
410 | 449 |
411 bool IsSystemInstall(const wchar_t* exe_path) { | 450 bool IsSystemInstall(const wchar_t* exe_path) { |
412 wchar_t program_dir[MAX_PATH] = {}; | 451 wchar_t program_dir[MAX_PATH] = {}; |
413 DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir, | 452 DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir, |
414 arraysize(program_dir)); | 453 arraysize(program_dir)); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // We have to make sure the user data dir exists on first run. See | 590 // We have to make sure the user data dir exists on first run. See |
552 // http://crbug.com/591504. | 591 // http://crbug.com/591504. |
553 if (!RecursiveDirectoryCreate(crash_dir->c_str())) | 592 if (!RecursiveDirectoryCreate(crash_dir->c_str())) |
554 return false; | 593 return false; |
555 crash_dir->append(L"\\Crashpad"); | 594 crash_dir->append(L"\\Crashpad"); |
556 return true; | 595 return true; |
557 } | 596 } |
558 | 597 |
559 | 598 |
560 std::string GetEnvironmentString(const std::string& variable_name) { | 599 std::string GetEnvironmentString(const std::string& variable_name) { |
| 600 return UTF16ToUTF8(GetEnvironmentString16(UTF8ToUTF16(variable_name))); |
| 601 } |
| 602 |
| 603 base::string16 GetEnvironmentString16(const base::string16& variable_name) { |
561 DWORD value_length = | 604 DWORD value_length = |
562 ::GetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), nullptr, 0); | 605 ::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0); |
563 if (value_length == 0) | 606 if (value_length == 0) |
564 return std::string(); | 607 return base::string16(); |
565 std::unique_ptr<wchar_t[]> value(new wchar_t[value_length]); | 608 std::unique_ptr<wchar_t[]> value(new wchar_t[value_length]); |
566 ::GetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), value.get(), | 609 ::GetEnvironmentVariable(variable_name.c_str(), value.get(), value_length); |
567 value_length); | 610 return value.get(); |
568 return UTF16ToUTF8(value.get()); | |
569 } | 611 } |
570 | 612 |
571 bool SetEnvironmentString(const std::string& variable_name, | 613 bool SetEnvironmentString(const std::string& variable_name, |
572 const std::string& new_value) { | 614 const std::string& new_value) { |
573 return !!SetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), | 615 return SetEnvironmentString16(UTF8ToUTF16(variable_name), |
574 UTF8ToUTF16(new_value).c_str()); | 616 UTF8ToUTF16(new_value)); |
| 617 } |
| 618 |
| 619 bool SetEnvironmentString16(const base::string16& variable_name, |
| 620 const base::string16& new_value) { |
| 621 return !!SetEnvironmentVariable(variable_name.c_str(), new_value.c_str()); |
575 } | 622 } |
576 | 623 |
577 bool HasEnvironmentVariable(const std::string& variable_name) { | 624 bool HasEnvironmentVariable(const std::string& variable_name) { |
578 return !!::GetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), nullptr, | 625 return HasEnvironmentVariable16(UTF8ToUTF16(variable_name)); |
579 0); | 626 } |
| 627 |
| 628 bool HasEnvironmentVariable16(const base::string16& variable_name) { |
| 629 return !!::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0); |
580 } | 630 } |
581 | 631 |
582 bool GetExecutableVersionDetails(const base::string16& exe_path, | 632 bool GetExecutableVersionDetails(const base::string16& exe_path, |
583 base::string16* product_name, | 633 base::string16* product_name, |
584 base::string16* version, | 634 base::string16* version, |
585 base::string16* special_build, | 635 base::string16* special_build, |
586 base::string16* channel_name) { | 636 base::string16* channel_name) { |
587 assert(product_name); | 637 assert(product_name); |
588 assert(version); | 638 assert(version); |
589 assert(special_build); | 639 assert(special_build); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 size) != size) { | 807 size) != size) { |
758 assert(false); | 808 assert(false); |
759 return base::string16(); | 809 return base::string16(); |
760 } | 810 } |
761 return result; | 811 return result; |
762 } | 812 } |
763 | 813 |
764 std::vector<std::string> TokenizeString(const std::string& str, | 814 std::vector<std::string> TokenizeString(const std::string& str, |
765 char delimiter, | 815 char delimiter, |
766 bool trim_spaces) { | 816 bool trim_spaces) { |
767 std::vector<std::string> tokens; | 817 return TokenizeStringT<std::string>(str, delimiter, trim_spaces); |
768 std::istringstream buffer(str); | 818 } |
769 for (std::string token; std::getline(buffer, token, delimiter);) { | 819 |
770 if (trim_spaces) | 820 std::vector<base::string16> TokenizeString16(const base::string16& str, |
771 Trim(&token); | 821 base::char16 delimiter, |
772 tokens.push_back(token); | 822 bool trim_spaces) { |
773 } | 823 return TokenizeStringT<base::string16>(str, delimiter, trim_spaces); |
774 return tokens; | |
775 } | 824 } |
776 | 825 |
777 bool CompareVersionStrings(const std::string& version1, | 826 bool CompareVersionStrings(const std::string& version1, |
778 const std::string& version2, | 827 const std::string& version2, |
779 int* result) { | 828 int* result) { |
780 if (version1.empty() || version2.empty()) | 829 if (version1.empty() || version2.empty()) |
781 return false; | 830 return false; |
782 | 831 |
783 // Tokenize both version strings with "." as the separator. If either of | 832 // Tokenize both version strings with "." as the separator. If either of |
784 // the returned token lists are empty then bail. | 833 // the returned token lists are empty then bail. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 return true; | 894 return true; |
846 } | 895 } |
847 } | 896 } |
848 } | 897 } |
849 // Here it means that both versions are equal. | 898 // Here it means that both versions are equal. |
850 *result = 0; | 899 *result = 0; |
851 return true; | 900 return true; |
852 } | 901 } |
853 | 902 |
854 } // namespace install_static | 903 } // namespace install_static |
OLD | NEW |