Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_ | 5 #ifndef COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_ |
| 6 #define COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_ | 6 #define COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 8 #include <string> | 11 #include <string> |
| 12 #include <utility> | |
| 9 #include <vector> | 13 #include <vector> |
| 10 | 14 |
| 15 #include "base/files/scoped_temp_dir.h" | |
| 11 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/threading/thread_checker.h" | |
| 12 #include "components/arc/common/file_system.mojom.h" | 18 #include "components/arc/common/file_system.mojom.h" |
| 13 | 19 |
| 14 namespace arc { | 20 namespace arc { |
| 15 | 21 |
| 16 // A fake implementation which returns errors for all requests or just ignores | 22 // Fake implementation to operate on documents in memory. |
| 17 // them. | 23 // |
| 24 // ArcFileSystemOperationRunner provides two types of methods: content URL | |
| 25 // based and documents provider based. According to backend type, you need | |
| 26 // to setup the fake with different functions. | |
| 27 // | |
| 28 // Content URL based functions are: | |
| 29 // - GetFileSize() | |
| 30 // - OpenFileToRead() | |
| 31 // Fake files for those functions can be set up by AddFile(). | |
| 32 // | |
| 33 // Documents provider based functions are: | |
| 34 // - GetDocument() | |
| 35 // - GetChildDocuments() | |
| 36 // Fake documents for those functions can be set up by AddDocument(). | |
| 37 // | |
| 38 // Notes: | |
| 39 // - GetChildDocuments() returns child documents in the same order as they were | |
| 40 // added with AddDocument(). | |
| 41 // - All member functions must be called on the same thread. | |
| 18 class FakeFileSystemInstance : public mojom::FileSystemInstance { | 42 class FakeFileSystemInstance : public mojom::FileSystemInstance { |
| 19 public: | 43 public: |
| 44 // Specification of a fake file available to content URL based methods. | |
| 45 struct File { | |
| 46 enum class Seekable { | |
| 47 YES, | |
|
hashimoto
2017/01/30 03:29:10
How about swapping the order (i.e. NO, YES) to mak
| |
| 48 NO, | |
| 49 }; | |
| 50 | |
| 51 // Content URL of a file. | |
| 52 std::string url; | |
| 53 | |
| 54 // The content of a file. | |
| 55 std::string content; | |
| 56 | |
| 57 // Whether this file is seekable or not. | |
| 58 Seekable seekable; | |
| 59 | |
| 60 File(const std::string& url, const std::string& content, Seekable seekable); | |
| 61 File(const File& rhs); | |
|
hashimoto
2017/01/30 03:29:10
"rhs" doesn't make sense in a ctor.
Shuhei Takahashi
2017/01/30 03:39:16
Pro tip: Just "does not make sense" in review comm
hidehiko
2017/01/30 05:21:57
FYI:
I'm fine with either "rhs" or "that" as it is
| |
| 62 ~File(); | |
| 63 }; | |
| 64 | |
| 65 // Specification of a fake document available to documents provider based | |
| 66 // methods. | |
| 67 struct Document { | |
| 68 // Authority. | |
| 69 std::string authority; | |
| 70 | |
| 71 // ID of this document. | |
| 72 std::string document_id; | |
| 73 | |
| 74 // ID of the parent document. Can be empty if this is a root. | |
| 75 std::string parent_document_id; | |
| 76 | |
| 77 // File name displayed to users. | |
| 78 std::string display_name; | |
| 79 | |
| 80 // MIME type. | |
| 81 std::string mime_type; | |
| 82 | |
| 83 // File size in bytes. Set to -1 if size is not available. | |
| 84 int64_t size; | |
| 85 | |
| 86 // Last modified time in milliseconds from the UNIX epoch. | |
| 87 // TODO(crbug.com/672737): Use base::Time once the corresponding field | |
| 88 // in file_system.mojom stops using uint64. | |
| 89 uint64_t last_modified; | |
| 90 | |
| 91 Document(const std::string& authority, | |
| 92 const std::string& document_id, | |
| 93 const std::string& parent_document_id, | |
| 94 const std::string& display_name, | |
| 95 const std::string& mime_type, | |
| 96 int64_t size, | |
| 97 uint64_t last_modified); | |
| 98 Document(const Document& rhs); | |
| 99 ~Document(); | |
| 100 }; | |
| 101 | |
| 20 FakeFileSystemInstance(); | 102 FakeFileSystemInstance(); |
| 103 ~FakeFileSystemInstance() override; | |
| 104 | |
| 105 // Adds a file accessible by content URL based methods. | |
| 106 void AddFile(const File& file); | |
| 107 | |
| 108 // Adds a document accessible by document provider based methods. | |
| 109 void AddDocument(const Document& document); | |
| 21 | 110 |
| 22 // mojom::FileSystemInstance: | 111 // mojom::FileSystemInstance: |
| 23 ~FakeFileSystemInstance() override; | |
| 24 | |
| 25 void GetChildDocuments(const std::string& authority, | 112 void GetChildDocuments(const std::string& authority, |
| 26 const std::string& document_id, | 113 const std::string& document_id, |
| 27 const GetChildDocumentsCallback& callback) override; | 114 const GetChildDocumentsCallback& callback) override; |
| 28 | |
| 29 void GetDocument(const std::string& authority, | 115 void GetDocument(const std::string& authority, |
| 30 const std::string& document_id, | 116 const std::string& document_id, |
| 31 const GetDocumentCallback& callback) override; | 117 const GetDocumentCallback& callback) override; |
| 32 | |
| 33 void GetFileSize(const std::string& url, | 118 void GetFileSize(const std::string& url, |
| 34 const GetFileSizeCallback& callback) override; | 119 const GetFileSizeCallback& callback) override; |
| 35 | |
| 36 void OpenFileToRead(const std::string& url, | 120 void OpenFileToRead(const std::string& url, |
| 37 const OpenFileToReadCallback& callback) override; | 121 const OpenFileToReadCallback& callback) override; |
| 38 | |
| 39 void RequestMediaScan(const std::vector<std::string>& paths) override; | 122 void RequestMediaScan(const std::vector<std::string>& paths) override; |
| 40 | 123 |
| 41 private: | 124 private: |
| 125 // A pair of an authority and a document ID which identifies the location | |
| 126 // of a document in documents providers. | |
| 127 using DocumentKey = std::pair<std::string, std::string>; | |
| 128 | |
| 129 base::ThreadChecker thread_checker_; | |
| 130 | |
| 131 base::ScopedTempDir temp_dir_; | |
| 132 | |
| 133 // Mapping from a content URL to a file. | |
| 134 std::map<std::string, File> files_; | |
| 135 | |
| 136 // Mapping from a document key to a document. | |
| 137 std::map<DocumentKey, Document> documents_; | |
| 138 | |
| 139 // Mapping from a document key to its child documents. | |
| 140 std::map<DocumentKey, std::vector<DocumentKey>> child_documents_; | |
| 141 | |
| 42 DISALLOW_COPY_AND_ASSIGN(FakeFileSystemInstance); | 142 DISALLOW_COPY_AND_ASSIGN(FakeFileSystemInstance); |
| 43 }; | 143 }; |
| 44 | 144 |
| 45 } // namespace arc | 145 } // namespace arc |
| 46 | 146 |
| 47 #endif // COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_ | 147 #endif // COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_ |
| OLD | NEW |