| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 12 #include "storage/browser/fileapi/file_system_url.h" | 12 #include "storage/browser/fileapi/file_system_url.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 namespace arc { | 15 namespace arc { |
| 16 | 16 |
| 17 const char kDocumentsProviderMountPointName[] = "arc-documents-provider"; | 17 const char kDocumentsProviderMountPointName[] = "arc-documents-provider"; |
| 18 const base::FilePath::CharType kDocumentsProviderMountPointPath[] = | 18 const base::FilePath::CharType kDocumentsProviderMountPointPath[] = |
| 19 "/special/arc-documents-provider"; | 19 "/special/arc-documents-provider"; |
| 20 const char kAndroidDirectoryMimeType[] = "vnd.android.document/directory"; | 20 const char kAndroidDirectoryMimeType[] = "vnd.android.document/directory"; |
| 21 | 21 |
| 22 base::FilePath GetDocumentsProviderMountPath( |
| 23 const std::string& authority, |
| 24 const std::string& root_document_id) { |
| 25 return base::FilePath(kDocumentsProviderMountPointPath) |
| 26 .Append(authority) |
| 27 .Append(root_document_id); |
| 28 } |
| 29 |
| 22 bool ParseDocumentsProviderUrl(const storage::FileSystemURL& url, | 30 bool ParseDocumentsProviderUrl(const storage::FileSystemURL& url, |
| 23 std::string* authority, | 31 std::string* authority, |
| 24 std::string* root_document_id, | 32 std::string* root_document_id, |
| 25 base::FilePath* path) { | 33 base::FilePath* path) { |
| 26 if (url.type() != storage::kFileSystemTypeArcDocumentsProvider) | 34 if (url.type() != storage::kFileSystemTypeArcDocumentsProvider) |
| 27 return false; | 35 return false; |
| 28 base::FilePath url_path_stripped = url.path().StripTrailingSeparators(); | 36 base::FilePath url_path_stripped = url.path().StripTrailingSeparators(); |
| 29 | 37 |
| 30 if (!base::FilePath(kDocumentsProviderMountPointPath) | 38 if (!base::FilePath(kDocumentsProviderMountPointPath) |
| 31 .IsParent(url_path_stripped)) { | 39 .IsParent(url_path_stripped)) { |
| 32 return false; | 40 return false; |
| 33 } | 41 } |
| 34 | 42 |
| 35 // Filesystem URL format for documents provider is: | 43 // Filesystem URL format for documents provider is: |
| 36 // /special/arc-documents-provider/<authority>/<root_doc_id>/<relative_path> | 44 // /special/arc-documents-provider/<authority>/<root_doc_id>/<relative_path> |
| 37 std::vector<base::FilePath::StringType> components; | 45 std::vector<base::FilePath::StringType> components; |
| 38 url_path_stripped.GetComponents(&components); | 46 url_path_stripped.GetComponents(&components); |
| 39 if (components.size() < 5) | 47 if (components.size() < 5) |
| 40 return false; | 48 return false; |
| 41 | 49 |
| 42 *authority = components[3]; | 50 *authority = components[3]; |
| 43 *root_document_id = components[4]; | 51 *root_document_id = components[4]; |
| 44 | 52 |
| 45 base::FilePath root_path = base::FilePath(kDocumentsProviderMountPointPath) | 53 base::FilePath root_path = |
| 46 .Append(*authority) | 54 GetDocumentsProviderMountPath(*authority, *root_document_id); |
| 47 .Append(*root_document_id); | |
| 48 // Special case: AppendRelativePath() fails for identical paths. | 55 // Special case: AppendRelativePath() fails for identical paths. |
| 49 if (url_path_stripped == root_path) { | 56 if (url_path_stripped == root_path) { |
| 50 path->clear(); | 57 path->clear(); |
| 51 } else { | 58 } else { |
| 52 bool success = root_path.AppendRelativePath(url_path_stripped, path); | 59 bool success = root_path.AppendRelativePath(url_path_stripped, path); |
| 53 DCHECK(success); | 60 DCHECK(success); |
| 54 } | 61 } |
| 55 return true; | 62 return true; |
| 56 } | 63 } |
| 57 | 64 |
| 58 GURL BuildDocumentUrl(const std::string& authority, | 65 GURL BuildDocumentUrl(const std::string& authority, |
| 59 const std::string& document_id) { | 66 const std::string& document_id) { |
| 60 return GURL(base::StringPrintf( | 67 return GURL(base::StringPrintf( |
| 61 "content://%s/document/%s", | 68 "content://%s/document/%s", |
| 62 net::EscapeQueryParamValue(authority, false /* use_plus */).c_str(), | 69 net::EscapeQueryParamValue(authority, false /* use_plus */).c_str(), |
| 63 net::EscapeQueryParamValue(document_id, false /* use_plus */).c_str())); | 70 net::EscapeQueryParamValue(document_id, false /* use_plus */).c_str())); |
| 64 } | 71 } |
| 65 | 72 |
| 66 } // namespace arc | 73 } // namespace arc |
| OLD | NEW |