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 namespace { | |
15 | |
16 constexpr base::FilePath::CharType kSpecialDirectory[] = | |
17 FILE_PATH_LITERAL("special"); | |
18 | |
19 } // namespace | |
20 | |
21 const char kDocumentsProviderMountPointName[] = "arc-documents-provider"; | |
22 const base::FilePath::CharType kDocumentsProviderMountPointPath[] = | |
23 "/special/arc-documents-provider"; | |
24 | |
25 bool ParseDocumentsProviderUrl(const storage::FileSystemURL& url, | |
26 std::string* authority, | |
27 std::string* root_document_id, | |
28 base::FilePath* path) { | |
29 if (url.type() != storage::kFileSystemTypeArcDocumentsProvider) | |
30 return false; | |
31 | |
32 // Filesystem URL format for documents provider is: | |
33 // /special/arc-documents-provider/<authority>/<root_doc_id>/<relative_path> | |
34 std::vector<base::FilePath::StringType> components; | |
35 url.path().GetComponents(&components); | |
36 if (components.size() < 5 || components[0] != FILE_PATH_LITERAL("/") || | |
37 components[1] != kSpecialDirectory || | |
38 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!
| |
39 return false; | |
40 } | |
41 | |
42 *authority = components[3]; | |
43 *root_document_id = components[4]; | |
44 | |
45 base::FilePath url_path_stripped = url.path().StripTrailingSeparators(); | |
46 base::FilePath root_path = base::FilePath(kDocumentsProviderMountPointPath) | |
47 .Append(*authority) | |
48 .Append(*root_document_id); | |
49 // Special case: AppendRelativePath() fails for identical paths. | |
50 if (url_path_stripped == root_path) { | |
51 path->clear(); | |
52 } else { | |
53 bool success = root_path.AppendRelativePath(url_path_stripped, path); | |
54 DCHECK(success); | |
55 } | |
56 return true; | |
57 } | |
58 | |
59 } // namespace arc | |
OLD | NEW |