Chromium Code Reviews| 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..a9b4f7e16e89748b35be125fc90b6c177db52386 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document.h |
| @@ -0,0 +1,78 @@ |
| +// 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(); |
| + |
| + static ArcDocumentsProviderDocument* CreateFromDocument( |
| + const mojom::Document& document); |
| + |
| + 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: |
| + // Computes a file name for a document. |
| + 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
|
| + const mojom::DocumentPtr& document); |
| + |
| + const std::string document_id_; |
| + const bool is_directory_; |
| + // 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_ |