OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/strings/string_util.h" |
| 10 #include "storage/browser/fileapi/file_system_url.h" |
| 11 |
| 12 namespace arc { |
| 13 |
| 14 const char kDocumentsProviderMountPointName[] = "arc-documents-provider"; |
| 15 const base::FilePath::CharType kDocumentsProviderMountPointPath[] = |
| 16 "/special/arc-documents-provider"; |
| 17 |
| 18 bool ParseDocumentsProviderUrl(const storage::FileSystemURL& url, |
| 19 std::string* authority, |
| 20 std::string* root_document_id, |
| 21 base::FilePath* path) { |
| 22 if (url.type() != storage::kFileSystemTypeArcDocumentsProvider) |
| 23 return false; |
| 24 base::FilePath url_path_stripped = url.path().StripTrailingSeparators(); |
| 25 |
| 26 if (!base::FilePath(kDocumentsProviderMountPointPath) |
| 27 .IsParent(url_path_stripped)) { |
| 28 return false; |
| 29 } |
| 30 |
| 31 // Filesystem URL format for documents provider is: |
| 32 // /special/arc-documents-provider/<authority>/<root_doc_id>/<relative_path> |
| 33 std::vector<base::FilePath::StringType> components; |
| 34 url_path_stripped.GetComponents(&components); |
| 35 if (components.size() < 5) |
| 36 return false; |
| 37 |
| 38 *authority = components[3]; |
| 39 *root_document_id = components[4]; |
| 40 |
| 41 base::FilePath root_path = base::FilePath(kDocumentsProviderMountPointPath) |
| 42 .Append(*authority) |
| 43 .Append(*root_document_id); |
| 44 // Special case: AppendRelativePath() fails for identical paths. |
| 45 if (url_path_stripped == root_path) { |
| 46 path->clear(); |
| 47 } else { |
| 48 bool success = root_path.AppendRelativePath(url_path_stripped, path); |
| 49 DCHECK(success); |
| 50 } |
| 51 return true; |
| 52 } |
| 53 |
| 54 } // namespace arc |
OLD | NEW |