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

Side by Side Diff: mojo/shell/desktop/mojo_main.cc

Issue 681363002: Corrected mojo_shell --args-for switch handling (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 const std::string kArgsForSwitches[] = {
109 "-" + std::string(switches::kArgsFor),
110 "--" + std::string(switches::kArgsFor),
111 };
abarth-chromium 2014/10/28 16:26:11 This looks like a static initializer. Presumably
hansmuller 2014/10/28 16:42:04 The kArgsForSwitches constant is stack allocated n
112
113 bool isArgsFor(const std::string& arg, std::string* value) {
114 for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) {
115 std::string argsfor_switch(kArgsForSwitches[i]);
116 if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) {
117 *value = arg.substr(argsfor_switch.size() + 1, std::string::npos);
118 return true;
119 }
120 }
121 return false;
122 }
123
108 } // namespace 124 } // namespace
109 125
110 int main(int argc, char** argv) { 126 int main(int argc, char** argv) {
111 base::AtExitManager at_exit; 127 base::AtExitManager at_exit;
112 base::CommandLine::Init(argc, argv); 128 base::CommandLine::Init(argc, argv);
113 129
114 const base::CommandLine& command_line = 130 const base::CommandLine& command_line =
115 *base::CommandLine::ForCurrentProcess(); 131 *base::CommandLine::ForCurrentProcess();
116 if (command_line.HasSwitch(switches::kHelp) || 132 if (command_line.HasSwitch(switches::kHelp) ||
117 command_line.GetArgs().empty()){ 133 command_line.GetArgs().empty()){
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 166 }
151 167
152 if (command_line.HasSwitch(switches::kURLMappings) && 168 if (command_line.HasSwitch(switches::kURLMappings) &&
153 !ConfigureURLMappings( 169 !ConfigureURLMappings(
154 command_line.GetSwitchValueASCII(switches::kURLMappings), 170 command_line.GetSwitchValueASCII(switches::kURLMappings),
155 shell_context.mojo_url_resolver())) { 171 shell_context.mojo_url_resolver())) {
156 Usage(); 172 Usage();
157 return 0; 173 return 0;
158 } 174 }
159 175
160 for (const auto& kv : command_line.GetSwitches()) { 176 // The mojo_shell --args-for command-line switch is handled specially
161 if (kv.first == switches::kArgsFor) 177 // because it can appear more than once. The base::CommandLine class
162 GetAppURLAndSetArgs(kv.second, &shell_context); 178 // collapses multiple occurrences of the same switch.
179 for(int i = 1; i < argc; i++) {
180 std::string argsForValue;
181 if (isArgsFor(argv[i], &argsForValue))
182 GetAppURLAndSetArgs(argsForValue, &shell_context);
163 } 183 }
164 184
165 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); 185 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context));
166 message_loop.Run(); 186 message_loop.Run();
167 } 187 }
168 } 188 }
169 return 0; 189 return 0;
170 } 190 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698