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 <string> | 9 #include <string> |
| 10 #include <vector> |
9 | 11 |
| 12 #include "base/callback_forward.h" |
10 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
11 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/optional.h" |
| 17 #include "components/arc/common/file_system.mojom.h" |
12 #include "storage/browser/fileapi/async_file_util.h" | 18 #include "storage/browser/fileapi/async_file_util.h" |
13 | 19 |
14 namespace arc { | 20 namespace arc { |
15 | 21 |
16 // Represents a file system root in Android Documents Provider. | 22 // Represents a file system root in Android Documents Provider. |
17 // | 23 // |
18 // All methods must be called on the IO thread. | 24 // All methods must be called on the IO thread. |
| 25 // If this object is deleted while there are in-flight operations, callbacks |
| 26 // for those operations will be never called. |
19 class ArcDocumentsProviderRoot { | 27 class ArcDocumentsProviderRoot { |
20 public: | 28 public: |
21 using GetFileInfoCallback = storage::AsyncFileUtil::GetFileInfoCallback; | 29 using GetFileInfoCallback = storage::AsyncFileUtil::GetFileInfoCallback; |
22 using ReadDirectoryCallback = storage::AsyncFileUtil::ReadDirectoryCallback; | 30 using ReadDirectoryCallback = storage::AsyncFileUtil::ReadDirectoryCallback; |
23 | 31 |
24 ArcDocumentsProviderRoot(const std::string& authority, | 32 ArcDocumentsProviderRoot(const std::string& authority, |
25 const std::string& root_document_id); | 33 const std::string& root_document_id); |
26 ~ArcDocumentsProviderRoot(); | 34 ~ArcDocumentsProviderRoot(); |
27 | 35 |
28 // Queries information of a file just like AsyncFileUtil.GetFileInfo(). | 36 // Queries information of a file just like AsyncFileUtil.GetFileInfo(). |
29 void GetFileInfo(const base::FilePath& path, | 37 void GetFileInfo(const base::FilePath& path, |
30 const GetFileInfoCallback& callback); | 38 const GetFileInfoCallback& callback); |
31 | 39 |
32 // Queries a list of files under a directory just like | 40 // Queries a list of files under a directory just like |
33 // AsyncFileUtil.ReadDirectory(). | 41 // AsyncFileUtil.ReadDirectory(). |
34 void ReadDirectory(const base::FilePath& path, | 42 void ReadDirectory(const base::FilePath& path, |
35 const ReadDirectoryCallback& callback); | 43 const ReadDirectoryCallback& callback); |
36 | 44 |
37 private: | 45 private: |
| 46 // Thin representation of a document in documents provider. |
| 47 struct ThinDocument { |
| 48 std::string document_id; |
| 49 bool is_directory; |
| 50 }; |
| 51 |
| 52 // Mapping from a file name to a ThinDocument. |
| 53 using NameToThinDocumentMap = |
| 54 std::map<base::FilePath::StringType, ThinDocument>; |
| 55 |
| 56 using ResolveToDocumentIdCallback = |
| 57 base::Callback<void(const std::string& document_id)>; |
| 58 using ReadDirectoryInternalCallback = |
| 59 base::Callback<void(base::File::Error error, |
| 60 NameToThinDocumentMap mapping)>; |
| 61 |
| 62 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback, |
| 63 const std::string& document_id); |
| 64 void GetFileInfoWithDocument(const GetFileInfoCallback& callback, |
| 65 mojom::DocumentPtr document); |
| 66 |
| 67 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback, |
| 68 const std::string& document_id); |
| 69 void ReadDirectoryWithNameToThinDocumentMap( |
| 70 const ReadDirectoryCallback& callback, |
| 71 base::File::Error error, |
| 72 NameToThinDocumentMap mapping); |
| 73 |
| 74 // Resolves |path| to a document ID. Failures are indicated by an empty |
| 75 // document ID. |
| 76 void ResolveToDocumentId(const base::FilePath& path, |
| 77 const ResolveToDocumentIdCallback& callback); |
| 78 void ResolveToDocumentIdRecursively( |
| 79 const std::string& document_id, |
| 80 const std::vector<base::FilePath::StringType>& components, |
| 81 const ResolveToDocumentIdCallback& callback); |
| 82 void ResolveToDocumentIdRecursivelyWithNameToThinDocumentMap( |
| 83 const std::vector<base::FilePath::StringType>& components, |
| 84 const ResolveToDocumentIdCallback& callback, |
| 85 base::File::Error error, |
| 86 NameToThinDocumentMap mapping); |
| 87 |
| 88 // Enumerates child documents of a directory specified by |document_id|. |
| 89 // The result is returned as a NameToThinDocumentMap. |
| 90 void ReadDirectoryInternal(const std::string& document_id, |
| 91 const ReadDirectoryInternalCallback& callback); |
| 92 void ReadDirectoryInternalWithChildDocuments( |
| 93 const ReadDirectoryInternalCallback& callback, |
| 94 base::Optional<std::vector<mojom::DocumentPtr>> maybe_children); |
| 95 |
| 96 const std::string authority_; |
| 97 const std::string root_document_id_; |
| 98 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_; |
| 99 |
38 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); | 100 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); |
39 }; | 101 }; |
40 | 102 |
41 } // namespace arc | 103 } // namespace arc |
42 | 104 |
43 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ | 105 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ |
OLD | NEW |