Chromium Code Reviews| 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..dfb75bf204b02954d07219621201895a22851f8e 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" |
| @@ -86,8 +85,87 @@ void GetChildDocumentsOnUIThread(const std::string& authority, |
| 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) { |
| + LOG(ERROR) << "ArcFileSystemOperationRunner unavailable. " |
|
dcheng
2017/03/03 09:31:14
DLOG(ERROR) for all the other LOG(ERROR) introduce
Shuhei Takahashi
2017/03/03 10:11:58
Sure, done.
|
| + << "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) { |
| + LOG(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) { |
| + LOG(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) { |
| + LOG(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, |
|
dcheng
2017/03/03 09:31:14
Btw... does ObserverListThreadSafe help with this
Shuhei Takahashi
2017/03/03 10:11:58
I tried ObserverListThreadSafe actually, but I sti
|
| + 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 |