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

Unified 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: Moved the kArgsForSwitches constant Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/desktop/mojo_main.cc
diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc
index 02be823e8ef4475412f11d99d1cf8c7a6c6e1591..34c7c00b19d82a2b21250605d8833127e6bf2495 100644
--- a/mojo/shell/desktop/mojo_main.cc
+++ b/mojo/shell/desktop/mojo_main.cc
@@ -105,6 +105,21 @@ bool ConfigureURLMappings(const std::string& mappings,
return true;
}
+bool isArgsFor(const std::string& arg, std::string* value) {
+ const std::string kArgsForSwitches[] = {
+ "-" + std::string(switches::kArgsFor),
+ "--" + std::string(switches::kArgsFor),
+ };
+ for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) {
+ std::string argsfor_switch(kArgsForSwitches[i]);
+ if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) {
+ *value = arg.substr(argsfor_switch.size() + 1, std::string::npos);
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
int main(int argc, char** argv) {
@@ -157,9 +172,13 @@ int main(int argc, char** argv) {
return 0;
}
- for (const auto& kv : command_line.GetSwitches()) {
- if (kv.first == switches::kArgsFor)
- GetAppURLAndSetArgs(kv.second, &shell_context);
+ // The mojo_shell --args-for command-line switch is handled specially
+ // because it can appear more than once. The base::CommandLine class
+ // collapses multiple occurrences of the same switch.
+ for(int i = 1; i < argc; i++) {
DaveMoore 2014/10/29 15:31:16 Nit: space between r and (
+ std::string argsForValue;
+ if (isArgsFor(argv[i], &argsForValue))
+ GetAppURLAndSetArgs(argsForValue, &shell_context);
}
message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context));
« 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