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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_DOCUMENT_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_DOCUMENT_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/files/file_path.h" | |
14 #include "base/logging.h" | |
15 #include "base/macros.h" | |
16 #include "base/threading/thread_checker.h" | |
17 #include "components/arc/common/file_system.mojom.h" | |
18 | |
19 namespace arc { | |
20 | |
21 // ArcDocumentsProviderDocument represents a document in DocumentsProvider. | |
22 // | |
23 // Since Android DocumentProvider is more permissive about display names | |
24 // (e.g. duplicated file names in the same directory are allowed), we need | |
25 // to expose some files to Chrome with rewritten file names. This object | |
26 // will remember the mapping from rewritten file names to its child documents. | |
27 // | |
28 // WARNING: This class is thread-unsafe. Must be accessed only from a single | |
29 // thread. | |
30 class ArcDocumentsProviderDocument { | |
31 public: | |
32 // A mapping from rewritten file names to documents. | |
33 using ChildMap = std::map<base::FilePath::StringType, | |
34 std::unique_ptr<ArcDocumentsProviderDocument>>; | |
35 | |
36 ArcDocumentsProviderDocument(const std::string& document_id, | |
37 bool is_directory); | |
38 ~ArcDocumentsProviderDocument(); | |
39 | |
40 const std::string& document_id() const { return document_id_; } | |
41 bool is_directory() const { return is_directory_; } | |
42 | |
43 // Must not be called unless is_directory() == true. | |
44 const ChildMap& children() const { | |
45 DCHECK(is_directory_); | |
46 return *children_; | |
47 } | |
48 | |
49 // Recursively looks up a descendant document with a relative path. | |
50 // If a document with the specific relative path is not found, nullptr is | |
51 // returned. | |
52 ArcDocumentsProviderDocument* Lookup(const base::FilePath& path); | |
53 | |
54 // Updates the child mapping with info retrieved from Android. | |
55 void UpdateWithChildDocuments( | |
56 const std::vector<mojom::DocumentPtr>& children); | |
57 | |
58 private: | |
59 const std::string document_id_; | |
60 const bool is_directory_; | |
hashimoto
2016/12/19 06:40:48
Why don't you just remember the mime type?
Shuhei Takahashi
2016/12/19 10:01:56
Because we only need is_directory, not mime type.
| |
61 // This will be non-null only when this entry is for a directory. | |
62 const std::unique_ptr<ChildMap> children_; | |
63 | |
64 base::ThreadChecker thread_checker_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderDocument); | |
67 }; | |
68 | |
69 } // namespace arc | |
70 | |
71 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_DOCUMENT_H _ | |
OLD | NEW |