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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ |
6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/optional.h" | 16 #include "base/optional.h" |
17 #include "components/arc/common/file_system.mojom.h" | 17 #include "components/arc/common/file_system.mojom.h" |
18 #include "storage/browser/fileapi/async_file_util.h" | 18 #include "storage/browser/fileapi/async_file_util.h" |
19 | 19 |
| 20 class GURL; |
| 21 |
20 namespace arc { | 22 namespace arc { |
21 | 23 |
22 // Represents a file system root in Android Documents Provider. | 24 // Represents a file system root in Android Documents Provider. |
23 // | 25 // |
24 // All methods must be called on the IO thread. | 26 // All methods must be called on the IO thread. |
25 // If this object is deleted while there are in-flight operations, callbacks | 27 // If this object is deleted while there are in-flight operations, callbacks |
26 // for those operations will be never called. | 28 // for those operations will be never called. |
27 class ArcDocumentsProviderRoot { | 29 class ArcDocumentsProviderRoot { |
28 public: | 30 public: |
29 using GetFileInfoCallback = storage::AsyncFileUtil::GetFileInfoCallback; | 31 using GetFileInfoCallback = storage::AsyncFileUtil::GetFileInfoCallback; |
30 using ReadDirectoryCallback = storage::AsyncFileUtil::ReadDirectoryCallback; | 32 using ReadDirectoryCallback = storage::AsyncFileUtil::ReadDirectoryCallback; |
| 33 using ResolveToContentUrlCallback = |
| 34 base::Callback<void(const GURL& content_url)>; |
31 | 35 |
32 ArcDocumentsProviderRoot(const std::string& authority, | 36 ArcDocumentsProviderRoot(const std::string& authority, |
33 const std::string& root_document_id); | 37 const std::string& root_document_id); |
34 ~ArcDocumentsProviderRoot(); | 38 ~ArcDocumentsProviderRoot(); |
35 | 39 |
36 // Queries information of a file just like AsyncFileUtil.GetFileInfo(). | 40 // Queries information of a file just like AsyncFileUtil.GetFileInfo(). |
37 void GetFileInfo(const base::FilePath& path, | 41 void GetFileInfo(const base::FilePath& path, |
38 const GetFileInfoCallback& callback); | 42 const GetFileInfoCallback& callback); |
39 | 43 |
40 // Queries a list of files under a directory just like | 44 // Queries a list of files under a directory just like |
41 // AsyncFileUtil.ReadDirectory(). | 45 // AsyncFileUtil.ReadDirectory(). |
42 void ReadDirectory(const base::FilePath& path, | 46 void ReadDirectory(const base::FilePath& path, |
43 const ReadDirectoryCallback& callback); | 47 const ReadDirectoryCallback& callback); |
44 | 48 |
| 49 // Resolves a file path into a content:// URL pointing to the file |
| 50 // on DocumentsProvider. Returns URL that can be passed to |
| 51 // ArcContentFileSystemFileSystemReader to read the content. |
| 52 // On errors, an invalid GURL is returned. |
| 53 void ResolveToContentUrl(const base::FilePath& path, |
| 54 const ResolveToContentUrlCallback& callback); |
| 55 |
45 private: | 56 private: |
46 // Thin representation of a document in documents provider. | 57 // Thin representation of a document in documents provider. |
47 struct ThinDocument { | 58 struct ThinDocument { |
48 std::string document_id; | 59 std::string document_id; |
49 bool is_directory; | 60 bool is_directory; |
50 }; | 61 }; |
51 | 62 |
52 // Mapping from a file name to a ThinDocument. | 63 // Mapping from a file name to a ThinDocument. |
53 using NameMapping = std::map<base::FilePath::StringType, ThinDocument>; | 64 using NameMapping = std::map<base::FilePath::StringType, ThinDocument>; |
54 | 65 |
55 using ResolveToDocumentIdCallback = | 66 using ResolveToDocumentIdCallback = |
56 base::Callback<void(const std::string& document_id)>; | 67 base::Callback<void(const std::string& document_id)>; |
57 using ReadDirectoryInternalCallback = | 68 using ReadDirectoryInternalCallback = |
58 base::Callback<void(NameMapping mapping)>; | 69 base::Callback<void(NameMapping mapping)>; |
59 | 70 |
60 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback, | 71 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback, |
61 const std::string& document_id); | 72 const std::string& document_id); |
62 void GetFileInfoWithDocument(const GetFileInfoCallback& callback, | 73 void GetFileInfoWithDocument(const GetFileInfoCallback& callback, |
63 mojom::DocumentPtr document); | 74 mojom::DocumentPtr document); |
64 | 75 |
65 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback, | 76 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback, |
66 const std::string& document_id); | 77 const std::string& document_id); |
67 void ReadDirectoryWithNameMapping(const ReadDirectoryCallback& callback, | 78 void ReadDirectoryWithNameMapping(const ReadDirectoryCallback& callback, |
68 NameMapping mapping); | 79 NameMapping mapping); |
69 | 80 |
| 81 void ResolveToContentUrlWithDocumentId( |
| 82 const ResolveToContentUrlCallback& callback, |
| 83 const std::string& document_id); |
| 84 |
70 // Resolves |path| to a document ID. Failures are indicated by an empty | 85 // Resolves |path| to a document ID. Failures are indicated by an empty |
71 // document ID. | 86 // document ID. |
72 void ResolveToDocumentId(const base::FilePath& path, | 87 void ResolveToDocumentId(const base::FilePath& path, |
73 const ResolveToDocumentIdCallback& callback); | 88 const ResolveToDocumentIdCallback& callback); |
74 void ResolveToDocumentIdRecursively( | 89 void ResolveToDocumentIdRecursively( |
75 const std::string& document_id, | 90 const std::string& document_id, |
76 const std::vector<base::FilePath::StringType>& components, | 91 const std::vector<base::FilePath::StringType>& components, |
77 const ResolveToDocumentIdCallback& callback); | 92 const ResolveToDocumentIdCallback& callback); |
78 void ResolveToDocumentIdRecursivelyWithNameMapping( | 93 void ResolveToDocumentIdRecursivelyWithNameMapping( |
79 const std::vector<base::FilePath::StringType>& components, | 94 const std::vector<base::FilePath::StringType>& components, |
(...skipping 11 matching lines...) Expand all Loading... |
91 const std::string authority_; | 106 const std::string authority_; |
92 const std::string root_document_id_; | 107 const std::string root_document_id_; |
93 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_; | 108 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_; |
94 | 109 |
95 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); | 110 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); |
96 }; | 111 }; |
97 | 112 |
98 } // namespace arc | 113 } // namespace arc |
99 | 114 |
100 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ | 115 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ |
OLD | NEW |