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

Unified Diff: chrome/browser/local_discovery/storage/path_util.cc

Issue 141703022: Support for file listing in privet local filesystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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: chrome/browser/local_discovery/storage/path_util.cc
diff --git a/chrome/browser/local_discovery/storage/path_util.cc b/chrome/browser/local_discovery/storage/path_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a5139a17e7f4e4c5a0dde07c57dbd07b5497b9bc
--- /dev/null
+++ b/chrome/browser/local_discovery/storage/path_util.cc
@@ -0,0 +1,71 @@
+// Copyright 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 "chrome/browser/local_discovery/storage/path_util.h"
+
+#include "base/logging.h"
+#include "base/strings/utf_string_conversions.h"
+
+namespace local_discovery {
+
+namespace {
+
+std::string UnescapeSlashes(const std::string& str) {
+ std::string output = "";
+ for (uint i = 0; i < str.length(); i++) {
+ if (str[i] == '$') {
+ i++;
+ switch (str[i]) {
+ case 's':
+ output += '/';
+ break;
+ case 'b':
+ output += '\\';
+ break;
+ case '$':
+ output += '$';
+ break;
+ default:
+ NOTREACHED();
+ }
+ } else {
+ output += str[i];
+ }
+ }
+
+ return output;
+}
+
+const int kNumComponentsInBasePrivetPath = 4;
+const int kIndexOfServiceNameInComponentList = 2;
+
+std::string PathStringToString(const base::FilePath::StringType& string) {
+#if defined(OS_WIN)
+ return base::UTF16ToUTF8(string);
+#else
+ return string;
+#endif
+}
+
+} // namespace
+
+ParsedPrivetPath::ParsedPrivetPath(const base::FilePath& file_path) {
+ std::vector<base::FilePath::StringType> components;
+ file_path.GetComponents(&components);
+ DCHECK(components.size() >= kNumComponentsInBasePrivetPath);
+ service_name = UnescapeSlashes(PathStringToString(
+ components[kIndexOfServiceNameInComponentList]));
+
+
+ for (uint i = kNumComponentsInBasePrivetPath; i < components.size(); i++) {
+ path += '/' + PathStringToString(components[i]);
+ }
+
+ if (path.empty()) path = "/";
+}
+
+ParsedPrivetPath::~ParsedPrivetPath() {
+}
+
+} // namespace local_discovery

Powered by Google App Engine
This is Rietveld 408576698