Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h

Issue 2574173002: mediaview: Implement ArcDocumentsProviderRoot. (Closed)
Patch Set: Revive unit tests & fixed build breakage. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.h"
hashimoto 2016/12/20 04:55:07 nit: Can't be replaced with callback_forward.h?
Shuhei Takahashi 2016/12/20 06:08:24 Done.
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 NameMapping = std::map<base::FilePath::StringType, ThinDocument>;
hashimoto 2016/12/20 04:55:07 nit: "NameMapping" sounds like a mapping from name
Shuhei Takahashi 2016/12/20 06:08:24 Done.
54
55 using ResolveToDocumentIdCallback =
56 base::Callback<void(const std::string& document_id)>;
57 using ReadDirectoryInternalCallback =
58 base::Callback<void(NameMapping mapping)>;
59
60 void GetFileInfoWithDocumentId(const GetFileInfoCallback& callback,
61 const std::string& document_id);
62 void GetFileInfoWithDocument(const GetFileInfoCallback& callback,
63 mojom::DocumentPtr document);
64
65 void ReadDirectoryWithDocumentId(const ReadDirectoryCallback& callback,
66 const std::string& document_id);
67 void ReadDirectoryWithNameMapping(const ReadDirectoryCallback& callback,
68 NameMapping mapping);
69
70 // Resolves |path| to a document ID. Failures are indicated by an empty
71 // document ID.
72 void ResolveToDocumentId(const base::FilePath& path,
73 const ResolveToDocumentIdCallback& callback);
74 void ResolveToDocumentIdRecursively(
75 const std::string& document_id,
76 const std::vector<base::FilePath::StringType>& components,
77 const ResolveToDocumentIdCallback& callback);
78 void ResolveToDocumentIdRecursivelyWithNameMapping(
79 const std::vector<base::FilePath::StringType>& components,
80 const ResolveToDocumentIdCallback& callback,
81 NameMapping mapping);
82
83 // Enumerates child documents of a directory specified by |document_id|.
84 // The result is returned as a NameMapping.
85 void ReadDirectoryInternal(const std::string& document_id,
86 const ReadDirectoryInternalCallback& callback);
87 void ReadDirectoryInternalWithChildDocuments(
88 const ReadDirectoryInternalCallback& callback,
89 base::Optional<std::vector<mojom::DocumentPtr>> maybe_children);
90
91 const std::string authority_;
92 const std::string root_document_id_;
93 base::WeakPtrFactory<ArcDocumentsProviderRoot> weak_ptr_factory_;
94
38 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot); 95 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderRoot);
39 }; 96 };
40 97
41 } // namespace arc 98 } // namespace arc
42 99
43 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_ 100 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_ROOT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698