Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <iostream> | 6 #include <iostream> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 for (const StringPair& pair : pairs) { | 98 for (const StringPair& pair : pairs) { |
| 99 const GURL from(pair.first); | 99 const GURL from(pair.first); |
| 100 const GURL to(pair.second); | 100 const GURL to(pair.second); |
| 101 if (!from.is_valid() || !to.is_valid()) | 101 if (!from.is_valid() || !to.is_valid()) |
| 102 return false; | 102 return false; |
| 103 resolver->AddCustomMapping(from, to); | 103 resolver->AddCustomMapping(from, to); |
| 104 } | 104 } |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool isArgsFor(const std::string& arg, std::string* value) { | |
| 109 const std::string kArgsForSwitches[] = { | |
| 110 "-" + std::string(switches::kArgsFor), | |
| 111 "--" + std::string(switches::kArgsFor), | |
| 112 }; | |
| 113 for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) { | |
| 114 std::string argsfor_switch(kArgsForSwitches[i]); | |
| 115 if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) { | |
| 116 *value = arg.substr(argsfor_switch.size() + 1, std::string::npos); | |
| 117 return true; | |
| 118 } | |
| 119 } | |
| 120 return false; | |
| 121 } | |
| 122 | |
| 108 } // namespace | 123 } // namespace |
| 109 | 124 |
| 110 int main(int argc, char** argv) { | 125 int main(int argc, char** argv) { |
| 111 base::AtExitManager at_exit; | 126 base::AtExitManager at_exit; |
| 112 base::CommandLine::Init(argc, argv); | 127 base::CommandLine::Init(argc, argv); |
| 113 | 128 |
| 114 const base::CommandLine& command_line = | 129 const base::CommandLine& command_line = |
| 115 *base::CommandLine::ForCurrentProcess(); | 130 *base::CommandLine::ForCurrentProcess(); |
| 116 if (command_line.HasSwitch(switches::kHelp) || | 131 if (command_line.HasSwitch(switches::kHelp) || |
| 117 command_line.GetArgs().empty()){ | 132 command_line.GetArgs().empty()){ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 } | 165 } |
| 151 | 166 |
| 152 if (command_line.HasSwitch(switches::kURLMappings) && | 167 if (command_line.HasSwitch(switches::kURLMappings) && |
| 153 !ConfigureURLMappings( | 168 !ConfigureURLMappings( |
| 154 command_line.GetSwitchValueASCII(switches::kURLMappings), | 169 command_line.GetSwitchValueASCII(switches::kURLMappings), |
| 155 shell_context.mojo_url_resolver())) { | 170 shell_context.mojo_url_resolver())) { |
| 156 Usage(); | 171 Usage(); |
| 157 return 0; | 172 return 0; |
| 158 } | 173 } |
| 159 | 174 |
| 160 for (const auto& kv : command_line.GetSwitches()) { | 175 // The mojo_shell --args-for command-line switch is handled specially |
| 161 if (kv.first == switches::kArgsFor) | 176 // because it can appear more than once. The base::CommandLine class |
| 162 GetAppURLAndSetArgs(kv.second, &shell_context); | 177 // collapses multiple occurrences of the same switch. |
| 178 for(int i = 1; i < argc; i++) { | |
|
DaveMoore
2014/10/29 15:31:16
Nit: space between r and (
| |
| 179 std::string argsForValue; | |
| 180 if (isArgsFor(argv[i], &argsForValue)) | |
| 181 GetAppURLAndSetArgs(argsForValue, &shell_context); | |
| 163 } | 182 } |
| 164 | 183 |
| 165 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); | 184 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); |
| 166 message_loop.Run(); | 185 message_loop.Run(); |
| 167 } | 186 } |
| 168 } | 187 } |
| 169 return 0; | 188 return 0; |
| 170 } | 189 } |
| OLD | NEW |