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 static ArcDocumentsProviderDocument* CreateFromDocument( | |
41 const mojom::Document& document); | |
42 | |
43 const std::string& document_id() const { return document_id_; } | |
44 bool is_directory() const { return is_directory_; } | |
45 | |
46 // Must not be called unless is_directory() == true. | |
47 const ChildMap& children() const { | |
48 DCHECK(is_directory_); | |
49 return *children_; | |
50 } | |
51 | |
52 // Recursively looks up a descendant document with a relative path. | |
53 // If a document with the specific relative path is not found, nullptr is | |
54 // returned. | |
55 ArcDocumentsProviderDocument* Lookup(const base::FilePath& path); | |
56 | |
57 // Updates the child mapping with info retrieved from Android. | |
58 void UpdateWithChildDocuments( | |
59 const std::vector<mojom::DocumentPtr>& children); | |
60 | |
61 private: | |
62 // Computes a file name for a document. | |
63 static base::FilePath::StringType GetFileNameForDocument( | |
Luis Héctor Chávez
2016/12/15 23:54:26
nit: can this be in the anonymous namespace?
Shuhei Takahashi
2016/12/16 05:47:14
Ah yes, I first put this function here for unit te
| |
64 const mojom::DocumentPtr& document); | |
65 | |
66 const std::string document_id_; | |
67 const bool is_directory_; | |
68 // This will be non-null only when this entry is for a directory. | |
69 const std::unique_ptr<ChildMap> children_; | |
70 | |
71 base::ThreadChecker thread_checker_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderDocument); | |
74 }; | |
75 | |
76 } // namespace arc | |
77 | |
78 #endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_DOCUMENT_H _ | |
OLD | NEW |