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_forward.h" | 12 #include "base/callback_forward.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 NameToThinDocumentMap = | 64 using NameToThinDocumentMap = |
54 std::map<base::FilePath::StringType, ThinDocument>; | 65 std::map<base::FilePath::StringType, ThinDocument>; |
55 | 66 |
56 using ResolveToDocumentIdCallback = | 67 using ResolveToDocumentIdCallback = |
57 base::Callback<void(const std::string& document_id)>; | 68 base::Callback<void(const std::string& document_id)>; |
58 using ReadDirectoryInternalCallback = | 69 using ReadDirectoryInternalCallback = |
59 base::Callback<void(base::File::Error error, | 70 base::Callback<void(base::File::Error error, |
60 NameToThinDocumentMap mapping)>; | 71 NameToThinDocumentMap mapping)>; |
61 | 72 |
62 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback, | 73 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback, |
63 const std::string& document_id); | 74 const std::string& document_id); |
64 void GetFileInfoWithDocument(const GetFileInfoCallback& callback, | 75 void GetFileInfoWithDocument(const GetFileInfoCallback& callback, |
65 mojom::DocumentPtr document); | 76 mojom::DocumentPtr document); |
66 | 77 |
67 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback, | 78 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback, |
68 const std::string& document_id); | 79 const std::string& document_id); |
69 void ReadDirectoryWithNameToThinDocumentMap( | 80 void ReadDirectoryWithNameToThinDocumentMap( |
70 const ReadDirectoryCallback& callback, | 81 const ReadDirectoryCallback& callback, |
71 base::File::Error error, | 82 base::File::Error error, |
72 NameToThinDocumentMap mapping); | 83 NameToThinDocumentMap mapping); |
73 | 84 |
| 85 void ResolveToContentUrlWithDocumentId( |
| 86 const ResolveToContentUrlCallback& callback, |
| 87 const std::string& document_id); |
| 88 |
74 // Resolves |path| to a document ID. Failures are indicated by an empty | 89 // Resolves |path| to a document ID. Failures are indicated by an empty |
75 // document ID. | 90 // document ID. |
76 void ResolveToDocumentId(const base::FilePath& path, | 91 void ResolveToDocumentId(const base::FilePath& path, |
77 const ResolveToDocumentIdCallback& callback); | 92 const ResolveToDocumentIdCallback& callback); |
78 void ResolveToDocumentIdRecursively( | 93 void ResolveToDocumentIdRecursively( |
79 const std::string& document_id, | 94 const std::string& document_id, |
80 const std::vector<base::FilePath::StringType>& components, | 95 const std::vector<base::FilePath::StringType>& components, |
81 const ResolveToDocumentIdCallback& callback); | 96 const ResolveToDocumentIdCallback& callback); |
82 void ResolveToDocumentIdRecursivelyWithNameToThinDocumentMap( | 97 void ResolveToDocumentIdRecursivelyWithNameToThinDocumentMap( |
83 const std::vector<base::FilePath::StringType>& components, | 98 const std::vector<base::FilePath::StringType>& components, |
(...skipping 12 matching lines...) Expand all Loading... |
96 const std::string authority_; | 111 const std::string authority_; |
97 const std::string root_document_id_; | 112 const std::string root_document_id_; |
98 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_; | 113 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_; |
99 | 114 |
100 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); | 115 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); |
101 }; | 116 }; |
102 | 117 |
103 } // namespace arc | 118 } // namespace arc |
104 | 119 |
105 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ | 120 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ |
OLD | NEW |