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

Unified Diff: chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.cc

Issue 2736603002: mediaview: Support watchers in ArcFileSystemOperationRunner. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.cc
diff --git a/chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.cc b/chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.cc
index 8f6fd077378ce8561fa13b5e4e3c80949a2f4a54..4cbb0b54e59123dd771ab785bfc7bb8ee1c8235c 100644
--- a/chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.cc
+++ b/chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.cc
@@ -7,7 +7,6 @@
#include <utility>
#include <vector>
-#include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h"
#include "components/arc/arc_service_manager.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
@@ -34,8 +33,8 @@ void GetFileSizeOnUIThread(const GURL& url,
auto* runner =
ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
if (!runner) {
- LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
- << "File system operations are dropped.";
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
callback.Run(-1);
return;
}
@@ -48,8 +47,8 @@ void OpenFileToReadOnUIThread(const GURL& url,
auto* runner =
ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
if (!runner) {
- LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
- << "File system operations are dropped.";
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
callback.Run(mojo::ScopedHandle());
return;
}
@@ -63,8 +62,8 @@ void GetDocumentOnUIThread(const std::string& authority,
auto* runner =
ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
if (!runner) {
- LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
- << "File system operations are dropped.";
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
callback.Run(mojom::DocumentPtr());
return;
}
@@ -78,16 +77,95 @@ void GetChildDocumentsOnUIThread(const std::string& authority,
auto* runner =
ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
if (!runner) {
- LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
- << "File system operations are dropped.";
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
callback.Run(base::nullopt);
return;
}
runner->GetChildDocuments(authority, parent_document_id, callback);
}
+void AddWatcherOnUIThread(const std::string& authority,
+ const std::string& document_id,
+ const WatcherCallback& watcher_callback,
+ const AddWatcherCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ auto* runner =
+ ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
+ if (!runner) {
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
+ callback.Run(-1);
+ return;
+ }
+ runner->AddWatcher(authority, document_id, watcher_callback, callback);
+}
+
+void RemoveWatcherOnUIThread(int64_t watcher_id,
+ const RemoveWatcherCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ auto* runner =
+ ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
+ if (!runner) {
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
+ callback.Run(false);
+ return;
+ }
+ runner->RemoveWatcher(watcher_id, callback);
+}
+
+void AddObserverOnUIThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ auto* runner =
+ ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
+ if (!runner) {
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
+ return;
+ }
+ runner->AddObserver(observer.get());
+}
+
+void RemoveObserverOnUIThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ auto* runner =
+ ArcServiceManager::GetGlobalService<ArcFileSystemOperationRunner>();
+ if (!runner) {
+ DLOG(ERROR) << "ArcFileSystemOperationRunner unavailable. "
+ << "File system operations are dropped.";
+ return;
+ }
+ runner->RemoveObserver(observer.get());
+}
+
} // namespace
+ObserverIOThreadWrapper::ObserverIOThreadWrapper(
+ ArcFileSystemOperationRunner::Observer* underlying_observer)
+ : underlying_observer_(underlying_observer) {}
+
+ObserverIOThreadWrapper::~ObserverIOThreadWrapper() = default;
+
+void ObserverIOThreadWrapper::Disable() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ disabled_ = true;
+}
+
+void ObserverIOThreadWrapper::OnWatchersCleared() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ObserverIOThreadWrapper::OnWatchersClearedOnIOThread, this));
+}
+
+void ObserverIOThreadWrapper::OnWatchersClearedOnIOThread() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (disabled_)
+ return;
+ underlying_observer_->OnWatchersCleared();
+}
+
void GetFileSizeOnIOThread(const GURL& url,
const GetFileSizeCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -129,6 +207,44 @@ void GetChildDocumentsOnIOThread(const std::string& authority,
callback)));
}
+void AddWatcherOnIOThread(const std::string& authority,
+ const std::string& document_id,
+ const WatcherCallback& watcher_callback,
+ const AddWatcherCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &AddWatcherOnUIThread, authority, document_id,
+ base::Bind(&PostToIOThread<ArcFileSystemOperationRunner::ChangeType>,
+ watcher_callback),
+ base::Bind(&PostToIOThread<int64_t>, callback)));
+}
+
+void RemoveWatcherOnIOThread(int64_t watcher_id,
+ const RemoveWatcherCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&RemoveWatcherOnUIThread, watcher_id,
+ base::Bind(&PostToIOThread<bool>, callback)));
+}
+
+void AddObserverOnIOThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&AddObserverOnUIThread, observer));
+}
+
+void RemoveObserverOnIOThread(scoped_refptr<ObserverIOThreadWrapper> observer) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ // Disable the observer now to guarantee the underlying observer is never
+ // called after this function returns.
+ observer->Disable();
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&RemoveObserverOnUIThread, observer));
+}
+
} // namespace file_system_operation_runner_util
} // namespace arc
« no previous file with comments | « chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698