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

Unified Diff: chromeos/dbus/dbus_command_line_helper.cc

Issue 181413006: Replace misc. network stub flags with more flexible ones (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move SetupDefaultEnvironment to FakeDBusThreadManager Created 6 years, 10 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
Index: chromeos/dbus/dbus_command_line_helper.cc
diff --git a/chromeos/dbus/dbus_command_line_helper.cc b/chromeos/dbus/dbus_command_line_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..018b7382f7d79685bd4d917d3a319c69729eaf7f
--- /dev/null
+++ b/chromeos/dbus/dbus_command_line_helper.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/dbus_command_line_helper.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
+
+namespace {
+
+bool GetOptionArgs(const std::string& option,
+ std::string* arg0,
+ std::string* arg1) {
+ std::vector<std::string> args;
+ base::SplitString(option, '=', &args);
+ if (args.size() < 1) {
+ LOG(WARNING) << " Invalid option: " << option;
+ arg0->clear();
pneubeck (no reviews) 2014/03/03 20:36:19 just always clear at the beginning of this functio
stevenjb 2014/03/05 01:03:50 Done.
+ arg1->clear();
+ return false;
+ }
+ *arg0 = args[0];
+ if (args.size() >= 2)
+ *arg1 = args[1];
+ else
+ arg1->clear();
+ VLOG(2) << " Option: " << *arg0 << " = " << *arg1;
+ return true;
+}
+
+} // namespace
+
+namespace dbus_command_line_helper {
+
+bool ParseOptions(const std::string& switch_name,
+ const ParseOptionCallback& callback) {
pneubeck (no reviews) 2014/03/03 20:36:19 please use some existing parsing mechanism, e.g. j
stevenjb 2014/03/05 01:03:50 This is almost the same format as we use for vmodu
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (!command_line->HasSwitch(switch_name))
+ return false;
+
+ std::string option_str = command_line->GetSwitchValueASCII(switch_name);
+ VLOG(1) << "ParseOption: " << option_str;
+ std::vector<std::string> tokens;
+ base::SplitString(option_str, ',', &tokens);
+ for (std::vector<std::string>::iterator iter = tokens.begin();
+ iter != tokens.end(); ++iter) {
+ std::string arg0, arg1;
+ if (!GetOptionArgs(*iter, &arg0, &arg1))
+ continue;
+ if (!callback.Run(arg0, arg1))
+ LOG(WARNING) << "Unrecognized option: " << *iter;
+ }
+ return true;
+}
+
+} // namespace dbus_command_line_helper

Powered by Google App Engine
This is Rietveld 408576698