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

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: Removed unused method in apk_assets 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..e9d6840e2ec8018bdfc25629f481cb2720fcd509
--- /dev/null
+++ b/services/service_manager/public/cpp/lib/shared_file_util.cc
@@ -0,0 +1,48 @@
+// 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);
+}
+
+bool ParseSharedFileSwitchValue(const std::string& value,
+ std::map<int, std::string>* values) {
dcheng 2017/02/15 08:05:28 Ditto: does it make sense to return a base::Option
Jay Civelli 2017/02/15 19:53:48 Yes, done.
+ 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) {
+ LOG(ERROR) << "Found invalid entry parsing shared file string value:"
+ << pair;
+ return false;
+ }
+ 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)) {
+ LOG(ERROR) << "Found invalid entry parsing shared file string value:"
+ << number_string << " (not an int).";
+ return false;
+ }
+
+ (*values)[key_int] = key;
+ }
+ return true;
+}
+
+} // namespace service_manager

Powered by Google App Engine
This is Rietveld 408576698