Index: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document.h |
diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document.h b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d1b1029d7d7cd1673703dc2ed16ca1728e9850b6 |
--- /dev/null |
+++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document.h |
@@ -0,0 +1,71 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_DOCUMENT_H_ |
+#define CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_DOCUMENT_H_ |
+ |
+#include <map> |
+#include <memory> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/files/file_path.h" |
+#include "base/logging.h" |
+#include "base/macros.h" |
+#include "base/threading/thread_checker.h" |
+#include "components/arc/common/file_system.mojom.h" |
+ |
+namespace arc { |
+ |
+// ArcDocumentsProviderDocument represents a document in DocumentsProvider. |
+// |
+// Since Android DocumentProvider is more permissive about display names |
+// (e.g. duplicated file names in the same directory are allowed), we need |
+// to expose some files to Chrome with rewritten file names. This object |
+// will remember the mapping from rewritten file names to its child documents. |
+// |
+// WARNING: This class is thread-unsafe. Must be accessed only from a single |
+// thread. |
+class ArcDocumentsProviderDocument { |
+ public: |
+ // A mapping from rewritten file names to documents. |
+ using ChildMap = std::map<base::FilePath::StringType, |
+ std::unique_ptr<ArcDocumentsProviderDocument>>; |
+ |
+ ArcDocumentsProviderDocument(const std::string& document_id, |
+ bool is_directory); |
+ ~ArcDocumentsProviderDocument(); |
+ |
+ const std::string& document_id() const { return document_id_; } |
+ bool is_directory() const { return is_directory_; } |
+ |
+ // Must not be called unless is_directory() == true. |
+ const ChildMap& children() const { |
+ DCHECK(is_directory_); |
+ return *children_; |
+ } |
+ |
+ // Recursively looks up a descendant document with a relative path. |
+ // If a document with the specific relative path is not found, nullptr is |
+ // returned. |
+ ArcDocumentsProviderDocument* Lookup(const base::FilePath& path); |
+ |
+ // Updates the child mapping with info retrieved from Android. |
+ void UpdateWithChildDocuments( |
+ const std::vector<mojom::DocumentPtr>& children); |
+ |
+ private: |
+ const std::string document_id_; |
+ 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.
|
+ // This will be non-null only when this entry is for a directory. |
+ const std::unique_ptr<ChildMap> children_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderDocument); |
+}; |
+ |
+} // namespace arc |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_DOCUMENT_H_ |