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

Unified Diff: services/service_manager/public/cpp/lib/shared_file_util.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Addressed dchen@'s comments. Created 3 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: services/service_manager/public/cpp/lib/shared_file_util.cc
diff --git a/services/service_manager/public/cpp/lib/shared_file_util.cc b/services/service_manager/public/cpp/lib/shared_file_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..334eafef7144a16d56a4aa5e749285621cd40c0b
--- /dev/null
+++ b/services/service_manager/public/cpp/lib/shared_file_util.cc
@@ -0,0 +1,49 @@
+// Copyright 2017 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 "services/service_manager/public/cpp/shared_file_util.h"
+
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+
+namespace service_manager {
+
+void SharedFileSwitchValueBuilder::AddEntry(const std::string& key_str,
+ int key_id) {
+ if (!switch_value_.empty()) {
+ switch_value_ += ",";
+ }
+ switch_value_ += key_str, switch_value_ += ":";
+ switch_value_ += base::IntToString(key_id);
+}
+
+base::Optional<std::map<int, std::string>> ParseSharedFileSwitchValue(
+ const std::string& value) {
+ std::map<int, std::string> values;
+ std::vector<std::string> string_pairs = base::SplitString(
+ value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ for (const auto& pair : string_pairs) {
+ size_t colon_position = pair.find(":");
+ if (colon_position == std::string::npos || colon_position == 0 ||
+ colon_position == pair.size() - 1) {
+ DLOG(ERROR) << "Found invalid entry parsing shared file string value:"
+ << pair;
+ return {};
dcheng 2017/02/15 22:01:03 I believe the Chromium guidelines would discourage
Jay Civelli 2017/02/15 23:08:06 Done.
+ }
+ std::string key = pair.substr(0, colon_position);
+ std::string number_string =
+ pair.substr(colon_position + 1, std::string::npos);
+ int key_int;
+ if (!base::StringToInt(number_string, &key_int)) {
+ DLOG(ERROR) << "Found invalid entry parsing shared file string value:"
+ << number_string << " (not an int).";
+ return {};
+ }
+
+ values[key_int] = key;
+ }
+ return {std::move(values)};
dcheng 2017/02/15 22:01:03 Ditto: I believe the spirit of the rules would ind
Jay Civelli 2017/02/15 23:08:06 Done.
+}
+
+} // namespace service_manager

Powered by Google App Engine
This is Rietveld 408576698