Chromium Code Reviews| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 59 |
| 60 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; | 60 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; |
| 61 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; | 61 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; |
| 62 const wchar_t kRestartInfo[] = L"CHROME_RESTART"; | 62 const wchar_t kRestartInfo[] = L"CHROME_RESTART"; |
| 63 const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT"; | 63 const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT"; |
| 64 | 64 |
| 65 const char kGpuProcess[] = "gpu-process"; | 65 const char kGpuProcess[] = "gpu-process"; |
| 66 const char kPpapiPluginProcess[] = "ppapi"; | 66 const char kPpapiPluginProcess[] = "ppapi"; |
| 67 const char kRendererProcess[] = "renderer"; | 67 const char kRendererProcess[] = "renderer"; |
| 68 const char kUtilityProcess[] = "utility"; | 68 const char kUtilityProcess[] = "utility"; |
| 69 const char kProcessType[] = "type"; | |
| 70 const char kCrashpadHandler[] = "crashpad-handler"; | |
| 69 | 71 |
| 70 namespace { | 72 namespace { |
| 71 | 73 |
| 72 // TODO(ananta) | 74 // TODO(ananta) |
| 73 // http://crbug.com/604923 | 75 // http://crbug.com/604923 |
| 74 // These constants are defined in the chrome/installer directory as well. We | 76 // These constants are defined in the chrome/installer directory as well. We |
| 75 // need to unify them. | 77 // need to unify them. |
| 76 #if defined(GOOGLE_CHROME_BUILD) | 78 #if defined(GOOGLE_CHROME_BUILD) |
| 77 const wchar_t kSxSSuffix[] = L" SxS"; | 79 const wchar_t kSxSSuffix[] = L" SxS"; |
| 78 const wchar_t kGoogleChromeInstallSubDir1[] = L"Google"; | 80 const wchar_t kGoogleChromeInstallSubDir1[] = L"Google"; |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 893 *result = -1; | 895 *result = -1; |
| 894 return true; | 896 return true; |
| 895 } | 897 } |
| 896 } | 898 } |
| 897 } | 899 } |
| 898 // Here it means that both versions are equal. | 900 // Here it means that both versions are equal. |
| 899 *result = 0; | 901 *result = 0; |
| 900 return true; | 902 return true; |
| 901 } | 903 } |
| 902 | 904 |
| 905 std::string GetSwitchValueFromCommandLine(const std::string& command_line, | |
| 906 const std::string& switch_name) { | |
| 907 assert(!command_line.empty()); | |
| 908 assert(!switch_name.empty()); | |
| 909 | |
| 910 std::string command_line_copy = command_line; | |
| 911 // Remove leading and trailing spaces. | |
| 912 TrimT<std::string>(&command_line_copy); | |
| 913 | |
| 914 // Find the switch in the command line. If we don't find the --type | |
| 915 // switch, return an empty string. | |
| 916 std::string switch_token = "--"; | |
| 917 switch_token += switch_name; | |
|
grt (UTC plus 2)
2016/06/14 02:20:49
wdyt of searching for "--switch=" here? if switch_
ananta
2016/06/14 03:24:05
Yeah. That makes it much simpler. Thanks. done
| |
| 918 size_t switch_offset = command_line_copy.find(switch_token); | |
| 919 if (switch_offset == std::string::npos) | |
| 920 return std::string(); | |
| 921 | |
| 922 // The format is --<switch name>=blah. Look for the = operator and then a | |
| 923 // trailing space. If we don't find a space assume that the switch value | |
| 924 // ends at the end of the command line. | |
| 925 size_t equal_to_operator_offset = | |
| 926 command_line_copy.find("=", switch_offset + switch_token.length()); | |
| 927 if (equal_to_operator_offset != std::string::npos) { | |
| 928 size_t switch_value_end_offset = command_line_copy.find_first_of( | |
| 929 GetWhiteSpacesForType<std::string>(), equal_to_operator_offset + 1); | |
| 930 if (switch_value_end_offset == std::string::npos) | |
| 931 switch_value_end_offset = command_line_copy.length() - 1; | |
| 932 | |
| 933 std::string switch_value = command_line_copy.substr( | |
| 934 equal_to_operator_offset + 1, | |
| 935 switch_value_end_offset - equal_to_operator_offset); | |
| 936 TrimT<std::string>(&switch_value); | |
| 937 return switch_value; | |
| 938 } | |
| 939 // We should never get here. This means that the command line is all wrong | |
| 940 // or our parsing failed. | |
| 941 assert(false); | |
| 942 return std::string(); | |
| 943 } | |
| 944 | |
| 903 } // namespace install_static | 945 } // namespace install_static |
| OLD | NEW |