Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: components/arc/test/fake_file_system_instance.h

Issue 2709613006: mediaview: Implement FakeFileSystemInstance. (Closed)
Patch Set: Review ready. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set>
11 #include <string> 12 #include <string>
12 #include <utility> 13 #include <utility>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/threading/thread_checker.h" 18 #include "base/threading/thread_checker.h"
18 #include "components/arc/common/file_system.mojom.h" 19 #include "components/arc/common/file_system.mojom.h"
19 20
20 namespace arc { 21 namespace arc {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 const std::string& mime_type, 96 const std::string& mime_type,
96 int64_t size, 97 int64_t size,
97 uint64_t last_modified); 98 uint64_t last_modified);
98 Document(const Document& that); 99 Document(const Document& that);
99 ~Document(); 100 ~Document();
100 }; 101 };
101 102
102 FakeFileSystemInstance(); 103 FakeFileSystemInstance();
103 ~FakeFileSystemInstance() override; 104 ~FakeFileSystemInstance() override;
104 105
106 // Returns true if Init() has been called.
107 bool InitCalled();
108
105 // Adds a file accessible by content URL based methods. 109 // Adds a file accessible by content URL based methods.
106 void AddFile(const File& file); 110 void AddFile(const File& file);
107 111
108 // Adds a document accessible by document provider based methods. 112 // Adds a document accessible by document provider based methods.
109 void AddDocument(const Document& document); 113 void AddDocument(const Document& document);
110 114
115 // Triggers watchers installed to a document.
116 void TriggerWatchers(const std::string& authority,
117 const std::string& document_id,
118 mojom::ChangeType type);
119
111 // mojom::FileSystemInstance: 120 // mojom::FileSystemInstance:
112 void AddWatcher(const std::string& authority, 121 void AddWatcher(const std::string& authority,
113 const std::string& document_id, 122 const std::string& document_id,
114 const AddWatcherCallback& callback) override; 123 const AddWatcherCallback& callback) override;
115 void GetChildDocuments(const std::string& authority, 124 void GetChildDocuments(const std::string& authority,
116 const std::string& document_id, 125 const std::string& document_id,
117 const GetChildDocumentsCallback& callback) override; 126 const GetChildDocumentsCallback& callback) override;
118 void GetDocument(const std::string& authority, 127 void GetDocument(const std::string& authority,
119 const std::string& document_id, 128 const std::string& document_id,
120 const GetDocumentCallback& callback) override; 129 const GetDocumentCallback& callback) override;
121 void GetFileSize(const std::string& url, 130 void GetFileSize(const std::string& url,
122 const GetFileSizeCallback& callback) override; 131 const GetFileSizeCallback& callback) override;
123 void Init(mojom::FileSystemHostPtr host) override; 132 void Init(mojom::FileSystemHostPtr host) override;
124 void OpenFileToRead(const std::string& url, 133 void OpenFileToRead(const std::string& url,
125 const OpenFileToReadCallback& callback) override; 134 const OpenFileToReadCallback& callback) override;
126 void RemoveWatcher(int64_t watcher_id, 135 void RemoveWatcher(int64_t watcher_id,
127 const RemoveWatcherCallback& callback) override; 136 const RemoveWatcherCallback& callback) override;
128 void RequestMediaScan(const std::vector<std::string>& paths) override; 137 void RequestMediaScan(const std::vector<std::string>& paths) override;
129 138
130 private: 139 private:
131 // A pair of an authority and a document ID which identifies the location 140 // A pair of an authority and a document ID which identifies the location
132 // of a document in documents providers. 141 // of a document in documents providers.
133 using DocumentKey = std::pair<std::string, std::string>; 142 using DocumentKey = std::pair<std::string, std::string>;
134 143
135 base::ThreadChecker thread_checker_; 144 base::ThreadChecker thread_checker_;
136 145
137 base::ScopedTempDir temp_dir_; 146 base::ScopedTempDir temp_dir_;
138 147
148 mojom::FileSystemHostPtr host_;
149
139 // Mapping from a content URL to a file. 150 // Mapping from a content URL to a file.
140 std::map<std::string, File> files_; 151 std::map<std::string, File> files_;
141 152
142 // Mapping from a document key to a document. 153 // Mapping from a document key to a document.
143 std::map<DocumentKey, Document> documents_; 154 std::map<DocumentKey, Document> documents_;
144 155
145 // Mapping from a document key to its child documents. 156 // Mapping from a document key to its child documents.
146 std::map<DocumentKey, std::vector<DocumentKey>> child_documents_; 157 std::map<DocumentKey, std::vector<DocumentKey>> child_documents_;
147 158
159 // Mapping from a document key to its watchers.
160 std::map<DocumentKey, std::set<int64_t>> document_to_watchers_;
161
162 // Mapping from a watcher ID to a document key.
163 std::map<int64_t, DocumentKey> watcher_to_document_;
164
165 int64_t next_watcher_id_ = 1;
hidehiko 2017/02/23 11:30:45 Just curious: any reasons this id starts from 1 ra
Shuhei Takahashi 2017/02/24 06:08:58 Because 0 is not obvious to me if it indicates fai
166
148 DISALLOW_COPY_AND_ASSIGN(FakeFileSystemInstance); 167 DISALLOW_COPY_AND_ASSIGN(FakeFileSystemInstance);
149 }; 168 };
150 169
151 } // namespace arc 170 } // namespace arc
152 171
153 #endif // COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_ 172 #endif // COMPONENTS_ARC_TEST_FAKE_FILE_SYSTEM_INSTANCE_H_
OLDNEW
« no previous file with comments | « no previous file | components/arc/test/fake_file_system_instance.cc » ('j') | components/arc/test/fake_file_system_instance.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698