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

Unified Diff: components/arc/test/fake_file_system_instance.cc

Issue 2709613006: mediaview: Implement FakeFileSystemInstance. (Closed)
Patch Set: Addressed hidehiko's comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/arc/test/fake_file_system_instance.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/arc/test/fake_file_system_instance.cc
diff --git a/components/arc/test/fake_file_system_instance.cc b/components/arc/test/fake_file_system_instance.cc
index 9e75360c753c7aaf78a6ffe1e5b8b28ac14ecb66..4a3dcc89b826e8c5f6722049b094f378c8af7b23 100644
--- a/components/arc/test/fake_file_system_instance.cc
+++ b/components/arc/test/fake_file_system_instance.cc
@@ -7,6 +7,8 @@
#include <string.h>
#include <unistd.h>
+#include <utility>
+
#include "base/bind.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
@@ -96,6 +98,10 @@ FakeFileSystemInstance::~FakeFileSystemInstance() {
DCHECK(thread_checker_.CalledOnValidThread());
}
+bool FakeFileSystemInstance::InitCalled() {
+ return host_;
+}
+
void FakeFileSystemInstance::AddFile(const File& file) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_EQ(0u, files_.count(std::string(file.url)));
@@ -115,11 +121,38 @@ void FakeFileSystemInstance::AddDocument(const Document& document) {
}
}
+void FakeFileSystemInstance::TriggerWatchers(const std::string& authority,
+ const std::string& document_id,
+ mojom::ChangeType type) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!host_) {
+ LOG(ERROR) << "FileSystemHost is not available.";
+ return;
+ }
+ auto iter = document_to_watchers_.find(DocumentKey(authority, document_id));
+ if (iter == document_to_watchers_.end())
+ return;
+ for (int64_t watcher_id : iter->second) {
+ host_->OnDocumentChanged(watcher_id, type);
+ }
+}
+
void FakeFileSystemInstance::AddWatcher(const std::string& authority,
const std::string& document_id,
const AddWatcherCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- NOTIMPLEMENTED();
+ DocumentKey key(authority, document_id);
+ auto iter = documents_.find(key);
+ if (iter == documents_.end()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback, -1));
+ return;
+ }
+ int64_t watcher_id = next_watcher_id_++;
+ document_to_watchers_[key].insert(watcher_id);
+ watcher_to_document_.insert(std::make_pair(watcher_id, key));
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, watcher_id));
}
void FakeFileSystemInstance::GetFileSize(const std::string& url,
@@ -203,14 +236,25 @@ void FakeFileSystemInstance::GetChildDocuments(
void FakeFileSystemInstance::Init(mojom::FileSystemHostPtr host) {
DCHECK(thread_checker_.CalledOnValidThread());
- NOTIMPLEMENTED();
+ DCHECK(host);
+ DCHECK(!host_);
+ host_ = std::move(host);
}
void FakeFileSystemInstance::RemoveWatcher(
int64_t watcher_id,
const RemoveWatcherCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- NOTIMPLEMENTED();
+ auto iter = watcher_to_document_.find(watcher_id);
+ if (iter == watcher_to_document_.end()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback, false));
+ return;
+ }
+ document_to_watchers_[iter->second].erase(watcher_id);
+ watcher_to_document_.erase(iter);
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback, true));
}
void FakeFileSystemInstance::RequestMediaScan(
« 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