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

Unified Diff: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc

Issue 2572683004: mediaview: Introduce ArcDocumentsProviderRoot. (Closed)
Patch Set: Addressed lhchavez's comments. Created 4 years 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/chromeos/arc/fileapi/arc_documents_provider_util.cc
diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fc354022cd7a4e3581e51978d211436ca00710b4
--- /dev/null
+++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc
@@ -0,0 +1,59 @@
+// Copyright 2016 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/chromeos/arc/fileapi/arc_documents_provider_util.h"
+
+#include <vector>
+
+#include "base/strings/string_util.h"
+#include "storage/browser/fileapi/file_system_url.h"
+
+namespace arc {
+
+namespace {
+
+constexpr base::FilePath::CharType kSpecialDirectory[] =
+ FILE_PATH_LITERAL("special");
+
+} // namespace
+
+const char kDocumentsProviderMountPointName[] = "arc-documents-provider";
+const base::FilePath::CharType kDocumentsProviderMountPointPath[] =
+ "/special/arc-documents-provider";
+
+bool ParseDocumentsProviderUrl(const storage::FileSystemURL& url,
+ std::string* authority,
+ std::string* root_document_id,
+ base::FilePath* path) {
+ if (url.type() != storage::kFileSystemTypeArcDocumentsProvider)
+ return false;
+
+ // Filesystem URL format for documents provider is:
+ // /special/arc-documents-provider/<authority>/<root_doc_id>/<relative_path>
+ std::vector<base::FilePath::StringType> components;
+ url.path().GetComponents(&components);
+ if (components.size() < 5 || components[0] != FILE_PATH_LITERAL("/") ||
+ components[1] != kSpecialDirectory ||
+ components[2] != kDocumentsProviderMountPointName) {
hashimoto 2016/12/16 09:03:52 How about using base::FilePath::IsParent() instead
Shuhei Takahashi 2016/12/16 09:42:13 That sounds better!
+ return false;
+ }
+
+ *authority = components[3];
+ *root_document_id = components[4];
+
+ base::FilePath url_path_stripped = url.path().StripTrailingSeparators();
+ base::FilePath root_path = base::FilePath(kDocumentsProviderMountPointPath)
+ .Append(*authority)
+ .Append(*root_document_id);
+ // Special case: AppendRelativePath() fails for identical paths.
+ if (url_path_stripped == root_path) {
+ path->clear();
+ } else {
+ bool success = root_path.AppendRelativePath(url_path_stripped, path);
+ DCHECK(success);
+ }
+ return true;
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698