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

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

Issue 2709613006: mediaview: Implement FakeFileSystemInstance. (Closed)
Patch Set: Review ready. Created 3 years, 9 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 #include "components/arc/test/fake_file_system_instance.h" 5 #include "components/arc/test/fake_file_system_instance.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include <utility>
11
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/files/file.h" 13 #include "base/files/file.h"
12 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
14 #include "base/files/scoped_file.h" 16 #include "base/files/scoped_file.h"
15 #include "base/location.h" 17 #include "base/location.h"
16 #include "base/logging.h" 18 #include "base/logging.h"
17 #include "base/optional.h" 19 #include "base/optional.h"
18 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
19 #include "mojo/edk/embedder/embedder.h" 21 #include "mojo/edk/embedder/embedder.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 91
90 FakeFileSystemInstance::FakeFileSystemInstance() { 92 FakeFileSystemInstance::FakeFileSystemInstance() {
91 bool temp_dir_created = temp_dir_.CreateUniqueTempDir(); 93 bool temp_dir_created = temp_dir_.CreateUniqueTempDir();
92 DCHECK(temp_dir_created); 94 DCHECK(temp_dir_created);
93 } 95 }
94 96
95 FakeFileSystemInstance::~FakeFileSystemInstance() { 97 FakeFileSystemInstance::~FakeFileSystemInstance() {
96 DCHECK(thread_checker_.CalledOnValidThread()); 98 DCHECK(thread_checker_.CalledOnValidThread());
97 } 99 }
98 100
101 bool FakeFileSystemInstance::InitCalled() {
102 return host_;
103 }
104
99 void FakeFileSystemInstance::AddFile(const File& file) { 105 void FakeFileSystemInstance::AddFile(const File& file) {
100 DCHECK(thread_checker_.CalledOnValidThread()); 106 DCHECK(thread_checker_.CalledOnValidThread());
101 DCHECK_EQ(0u, files_.count(std::string(file.url))); 107 DCHECK_EQ(0u, files_.count(std::string(file.url)));
102 files_.insert(std::make_pair(std::string(file.url), file)); 108 files_.insert(std::make_pair(std::string(file.url), file));
103 } 109 }
104 110
105 void FakeFileSystemInstance::AddDocument(const Document& document) { 111 void FakeFileSystemInstance::AddDocument(const Document& document) {
106 DCHECK(thread_checker_.CalledOnValidThread()); 112 DCHECK(thread_checker_.CalledOnValidThread());
107 DocumentKey key(document.authority, document.document_id); 113 DocumentKey key(document.authority, document.document_id);
108 DCHECK_EQ(0u, documents_.count(key)); 114 DCHECK_EQ(0u, documents_.count(key));
109 documents_.insert(std::make_pair(key, document)); 115 documents_.insert(std::make_pair(key, document));
110 child_documents_[key]; // Allocate a vector. 116 child_documents_[key]; // Allocate a vector.
111 if (!document.parent_document_id.empty()) { 117 if (!document.parent_document_id.empty()) {
112 DocumentKey parent_key(document.authority, document.parent_document_id); 118 DocumentKey parent_key(document.authority, document.parent_document_id);
113 DCHECK_EQ(1u, documents_.count(parent_key)); 119 DCHECK_EQ(1u, documents_.count(parent_key));
114 child_documents_[parent_key].push_back(key); 120 child_documents_[parent_key].push_back(key);
115 } 121 }
116 } 122 }
117 123
124 void FakeFileSystemInstance::TriggerWatchers(const std::string& authority,
125 const std::string& document_id,
126 mojom::ChangeType type) {
127 DCHECK(thread_checker_.CalledOnValidThread());
128 if (!host_) {
129 LOG(ERROR) << "FileSystemHost is not available.";
130 return;
131 }
132 auto iter = document_to_watchers_.find(DocumentKey(authority, document_id));
133 if (iter == document_to_watchers_.end()) {
hidehiko 2017/02/23 11:30:45 Could you elide the brace for one line if stmt?
Shuhei Takahashi 2017/02/24 06:08:58 Done.
134 return;
135 }
136 for (int64_t watcher_id : iter->second) {
137 host_->OnDocumentChanged(watcher_id, type);
138 }
139 }
140
118 void FakeFileSystemInstance::AddWatcher(const std::string& authority, 141 void FakeFileSystemInstance::AddWatcher(const std::string& authority,
119 const std::string& document_id, 142 const std::string& document_id,
120 const AddWatcherCallback& callback) { 143 const AddWatcherCallback& callback) {
121 DCHECK(thread_checker_.CalledOnValidThread()); 144 DCHECK(thread_checker_.CalledOnValidThread());
122 NOTIMPLEMENTED(); 145 DocumentKey key(authority, document_id);
146 auto iter = documents_.find(key);
147 if (iter == documents_.end()) {
148 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
149 base::Bind(callback, -1));
150 return;
151 }
152 int64_t watcher_id = next_watcher_id_++;
153 document_to_watchers_[key].insert(watcher_id);
154 watcher_to_document_.insert(std::make_pair(watcher_id, key));
155 base::ThreadTaskRunnerHandle::Get()->PostTask(
156 FROM_HERE, base::Bind(callback, watcher_id));
123 } 157 }
124 158
125 void FakeFileSystemInstance::GetFileSize(const std::string& url, 159 void FakeFileSystemInstance::GetFileSize(const std::string& url,
126 const GetFileSizeCallback& callback) { 160 const GetFileSizeCallback& callback) {
127 DCHECK(thread_checker_.CalledOnValidThread()); 161 DCHECK(thread_checker_.CalledOnValidThread());
128 auto iter = files_.find(url); 162 auto iter = files_.find(url);
129 if (iter == files_.end()) { 163 if (iter == files_.end()) {
130 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 164 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
131 base::Bind(callback, -1)); 165 base::Bind(callback, -1));
132 return; 166 return;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 children.emplace_back(MakeDocument(doc_iter->second)); 230 children.emplace_back(MakeDocument(doc_iter->second));
197 } 231 }
198 base::ThreadTaskRunnerHandle::Get()->PostTask( 232 base::ThreadTaskRunnerHandle::Get()->PostTask(
199 FROM_HERE, 233 FROM_HERE,
200 base::Bind(callback, 234 base::Bind(callback,
201 base::Passed(base::make_optional(std::move(children))))); 235 base::Passed(base::make_optional(std::move(children)))));
202 } 236 }
203 237
204 void FakeFileSystemInstance::Init(mojom::FileSystemHostPtr host) { 238 void FakeFileSystemInstance::Init(mojom::FileSystemHostPtr host) {
205 DCHECK(thread_checker_.CalledOnValidThread()); 239 DCHECK(thread_checker_.CalledOnValidThread());
206 NOTIMPLEMENTED(); 240 DCHECK(host);
241 DCHECK(!host_);
242 host_ = std::move(host);
207 } 243 }
208 244
209 void FakeFileSystemInstance::RemoveWatcher( 245 void FakeFileSystemInstance::RemoveWatcher(
210 int64_t watcher_id, 246 int64_t watcher_id,
211 const RemoveWatcherCallback& callback) { 247 const RemoveWatcherCallback& callback) {
212 DCHECK(thread_checker_.CalledOnValidThread()); 248 DCHECK(thread_checker_.CalledOnValidThread());
213 NOTIMPLEMENTED(); 249 auto iter = watcher_to_document_.find(watcher_id);
250 if (iter == watcher_to_document_.end()) {
251 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
252 base::Bind(callback, false));
253 return;
254 }
255 DocumentKey key = iter->second;
256 watcher_to_document_.erase(watcher_id);
257 document_to_watchers_[key].erase(watcher_id);
hidehiko 2017/02/23 11:30:45 Optional: you can document_to_watchers_[iter->seco
Shuhei Takahashi 2017/02/24 06:08:58 OK, done. (I also changed the argument of watcher_
258 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
259 base::Bind(callback, true));
214 } 260 }
215 261
216 void FakeFileSystemInstance::RequestMediaScan( 262 void FakeFileSystemInstance::RequestMediaScan(
217 const std::vector<std::string>& paths) { 263 const std::vector<std::string>& paths) {
218 DCHECK(thread_checker_.CalledOnValidThread()); 264 DCHECK(thread_checker_.CalledOnValidThread());
219 // Do nothing and pretend we scaned them. 265 // Do nothing and pretend we scaned them.
220 } 266 }
221 267
222 } // namespace arc 268 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698