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

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

Issue 2709613006: mediaview: Implement FakeFileSystemInstance. (Closed)
Patch Set: Addressed hidehiko's comments. 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
« no previous file with comments | « components/arc/test/fake_file_system_instance.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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())
134 return;
135 for (int64_t watcher_id : iter->second) {
136 host_->OnDocumentChanged(watcher_id, type);
137 }
138 }
139
118 void FakeFileSystemInstance::AddWatcher(const std::string& authority, 140 void FakeFileSystemInstance::AddWatcher(const std::string& authority,
119 const std::string& document_id, 141 const std::string& document_id,
120 const AddWatcherCallback& callback) { 142 const AddWatcherCallback& callback) {
121 DCHECK(thread_checker_.CalledOnValidThread()); 143 DCHECK(thread_checker_.CalledOnValidThread());
122 NOTIMPLEMENTED(); 144 DocumentKey key(authority, document_id);
145 auto iter = documents_.find(key);
146 if (iter == documents_.end()) {
147 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
148 base::Bind(callback, -1));
149 return;
150 }
151 int64_t watcher_id = next_watcher_id_++;
152 document_to_watchers_[key].insert(watcher_id);
153 watcher_to_document_.insert(std::make_pair(watcher_id, key));
154 base::ThreadTaskRunnerHandle::Get()->PostTask(
155 FROM_HERE, base::Bind(callback, watcher_id));
123 } 156 }
124 157
125 void FakeFileSystemInstance::GetFileSize(const std::string& url, 158 void FakeFileSystemInstance::GetFileSize(const std::string& url,
126 const GetFileSizeCallback& callback) { 159 const GetFileSizeCallback& callback) {
127 DCHECK(thread_checker_.CalledOnValidThread()); 160 DCHECK(thread_checker_.CalledOnValidThread());
128 auto iter = files_.find(url); 161 auto iter = files_.find(url);
129 if (iter == files_.end()) { 162 if (iter == files_.end()) {
130 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 163 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
131 base::Bind(callback, -1)); 164 base::Bind(callback, -1));
132 return; 165 return;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 children.emplace_back(MakeDocument(doc_iter->second)); 229 children.emplace_back(MakeDocument(doc_iter->second));
197 } 230 }
198 base::ThreadTaskRunnerHandle::Get()->PostTask( 231 base::ThreadTaskRunnerHandle::Get()->PostTask(
199 FROM_HERE, 232 FROM_HERE,
200 base::Bind(callback, 233 base::Bind(callback,
201 base::Passed(base::make_optional(std::move(children))))); 234 base::Passed(base::make_optional(std::move(children)))));
202 } 235 }
203 236
204 void FakeFileSystemInstance::Init(mojom::FileSystemHostPtr host) { 237 void FakeFileSystemInstance::Init(mojom::FileSystemHostPtr host) {
205 DCHECK(thread_checker_.CalledOnValidThread()); 238 DCHECK(thread_checker_.CalledOnValidThread());
206 NOTIMPLEMENTED(); 239 DCHECK(host);
240 DCHECK(!host_);
241 host_ = std::move(host);
207 } 242 }
208 243
209 void FakeFileSystemInstance::RemoveWatcher( 244 void FakeFileSystemInstance::RemoveWatcher(
210 int64_t watcher_id, 245 int64_t watcher_id,
211 const RemoveWatcherCallback& callback) { 246 const RemoveWatcherCallback& callback) {
212 DCHECK(thread_checker_.CalledOnValidThread()); 247 DCHECK(thread_checker_.CalledOnValidThread());
213 NOTIMPLEMENTED(); 248 auto iter = watcher_to_document_.find(watcher_id);
249 if (iter == watcher_to_document_.end()) {
250 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
251 base::Bind(callback, false));
252 return;
253 }
254 document_to_watchers_[iter->second].erase(watcher_id);
255 watcher_to_document_.erase(iter);
256 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
257 base::Bind(callback, true));
214 } 258 }
215 259
216 void FakeFileSystemInstance::RequestMediaScan( 260 void FakeFileSystemInstance::RequestMediaScan(
217 const std::vector<std::string>& paths) { 261 const std::vector<std::string>& paths) {
218 DCHECK(thread_checker_.CalledOnValidThread()); 262 DCHECK(thread_checker_.CalledOnValidThread());
219 // Do nothing and pretend we scaned them. 263 // Do nothing and pretend we scaned them.
220 } 264 }
221 265
222 } // namespace arc 266 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/test/fake_file_system_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698