Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/install_static/install_util.cc

Issue 2031833002: Remove FilePath usage from the CrashReporterClient interface on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build error Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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, class DelimiterType>
430 std::vector<StringType> TokenizeStringT(const StringType& str,
431 DelimiterType delimiter,
grt (UTC plus 2) 2016/06/02 22:57:44 Can you do away with this template arg and use typ
ananta 2016/06/02 23:10:30 Done.
432 bool trim_spaces) {
433 std::vector<StringType> tokens;
434 std::basic_istringstream<DelimiterType> buffer(str);
435 for (StringType token; std::getline(buffer, token, delimiter);) {
436 if (trim_spaces)
437 TrimT<StringType>(&token);
438 tokens.push_back(token);
439 }
440 return tokens;
441 }
442
405 } // namespace 443 } // namespace
406 444
407 bool IsSxSChrome(const wchar_t* exe_path) { 445 bool IsSxSChrome(const wchar_t* exe_path) {
408 return wcsstr(exe_path, L"Chrome SxS\\Application") != nullptr; 446 return wcsstr(exe_path, L"Chrome SxS\\Application") != nullptr;
409 } 447 }
410 448
411 bool IsSystemInstall(const wchar_t* exe_path) { 449 bool IsSystemInstall(const wchar_t* exe_path) {
412 wchar_t program_dir[MAX_PATH] = {}; 450 wchar_t program_dir[MAX_PATH] = {};
413 DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir, 451 DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir,
414 arraysize(program_dir)); 452 arraysize(program_dir));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // We have to make sure the user data dir exists on first run. See 589 // We have to make sure the user data dir exists on first run. See
552 // http://crbug.com/591504. 590 // http://crbug.com/591504.
553 if (!RecursiveDirectoryCreate(crash_dir->c_str())) 591 if (!RecursiveDirectoryCreate(crash_dir->c_str()))
554 return false; 592 return false;
555 crash_dir->append(L"\\Crashpad"); 593 crash_dir->append(L"\\Crashpad");
556 return true; 594 return true;
557 } 595 }
558 596
559 597
560 std::string GetEnvironmentString(const std::string& variable_name) { 598 std::string GetEnvironmentString(const std::string& variable_name) {
599 return UTF16ToUTF8(GetEnvironmentString16(UTF8ToUTF16(variable_name)));
600 }
601
602 base::string16 GetEnvironmentString16(const base::string16& variable_name) {
561 DWORD value_length = 603 DWORD value_length =
562 ::GetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), nullptr, 0); 604 ::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0);
563 if (value_length == 0) 605 if (value_length == 0)
564 return std::string(); 606 return base::string16();
565 std::unique_ptr<wchar_t[]> value(new wchar_t[value_length]); 607 std::unique_ptr<wchar_t[]> value(new wchar_t[value_length]);
566 ::GetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), value.get(), 608 ::GetEnvironmentVariable(variable_name.c_str(), value.get(), value_length);
567 value_length); 609 return value.get();
568 return UTF16ToUTF8(value.get());
569 } 610 }
570 611
571 bool SetEnvironmentString(const std::string& variable_name, 612 bool SetEnvironmentString(const std::string& variable_name,
572 const std::string& new_value) { 613 const std::string& new_value) {
573 return !!SetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), 614 return SetEnvironmentString16(UTF8ToUTF16(variable_name),
574 UTF8ToUTF16(new_value).c_str()); 615 UTF8ToUTF16(new_value));
616 }
617
618 bool SetEnvironmentString16(const base::string16& variable_name,
619 const base::string16& new_value) {
620 return !!SetEnvironmentVariable(variable_name.c_str(), new_value.c_str());
575 } 621 }
576 622
577 bool HasEnvironmentVariable(const std::string& variable_name) { 623 bool HasEnvironmentVariable(const std::string& variable_name) {
578 return !!::GetEnvironmentVariable(UTF8ToUTF16(variable_name).c_str(), nullptr, 624 return HasEnvironmentVariable16(UTF8ToUTF16(variable_name));
579 0); 625 }
626
627 bool HasEnvironmentVariable16(const base::string16& variable_name) {
628 return !!::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0);
580 } 629 }
581 630
582 bool GetExecutableVersionDetails(const base::string16& exe_path, 631 bool GetExecutableVersionDetails(const base::string16& exe_path,
583 base::string16* product_name, 632 base::string16* product_name,
584 base::string16* version, 633 base::string16* version,
585 base::string16* special_build, 634 base::string16* special_build,
586 base::string16* channel_name) { 635 base::string16* channel_name) {
587 assert(product_name); 636 assert(product_name);
588 assert(version); 637 assert(version);
589 assert(special_build); 638 assert(special_build);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 size) != size) { 806 size) != size) {
758 assert(false); 807 assert(false);
759 return base::string16(); 808 return base::string16();
760 } 809 }
761 return result; 810 return result;
762 } 811 }
763 812
764 std::vector<std::string> TokenizeString(const std::string& str, 813 std::vector<std::string> TokenizeString(const std::string& str,
765 char delimiter, 814 char delimiter,
766 bool trim_spaces) { 815 bool trim_spaces) {
767 std::vector<std::string> tokens; 816 return TokenizeStringT<std::string, char>(str, delimiter, trim_spaces);
768 std::istringstream buffer(str); 817 }
769 for (std::string token; std::getline(buffer, token, delimiter);) { 818
770 if (trim_spaces) 819 std::vector<base::string16> TokenizeString16(const base::string16& str,
771 Trim(&token); 820 base::char16 delimiter,
772 tokens.push_back(token); 821 bool trim_spaces) {
773 } 822 return TokenizeStringT<base::string16, base::char16>(
774 return tokens; 823 str, delimiter, trim_spaces);
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698