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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc

Issue 2712613002: Call WatcherManager functions on the IO thread. (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
Index: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
index 79aae0ff155491c7b23ada8b55bc64af0203ff97..717de13708e3e523b8495007c28c700ab8d78069 100644
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
@@ -7,13 +7,10 @@
#include <sys/statvfs.h>
#include <algorithm>
-#include <set>
#include <utility>
-#include <vector>
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
-#include "base/memory/weak_ptr.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
@@ -307,6 +304,26 @@ ExtensionFunction::ResponseAction FileManagerPrivateGrantAccessFunction::Run() {
return RespondNow(NoArguments());
}
+namespace {
+
+void PostResponseCallbackTaskToUIThread(
+ const FileWatchFunctionBase::ResponseCallback& callback,
+ bool success) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, success));
+}
+
+void PostNotificationCallbackTaskToUIThread(
+ const storage::WatcherManager::NotificationCallback& callback,
+ storage::WatcherManager::ChangeType type) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, type));
+}
+
+} // namespace
+
void FileWatchFunctionBase::Respond(bool success) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -336,63 +353,95 @@ bool FileWatchFunctionBase::RunAsync() {
return true;
}
- PerformFileWatchOperation(file_system_context, file_system_url,
- extension_id());
+ file_manager::EventRouter* const event_router =
+ file_manager::EventRouterFactory::GetForProfile(GetProfile());
+
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&FileWatchFunctionBase::RunAsyncOnIOThread,
+ this, file_system_context, file_system_url,
+ event_router->GetWeakPtr()));
return true;
}
-void FileManagerPrivateInternalAddFileWatchFunction::PerformFileWatchOperation(
+void FileWatchFunctionBase::RunAsyncOnIOThread(
scoped_refptr<storage::FileSystemContext> file_system_context,
const storage::FileSystemURL& file_system_url,
- const std::string& extension_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
- file_manager::EventRouter* const event_router =
- file_manager::EventRouterFactory::GetForProfile(GetProfile());
+ base::WeakPtr<file_manager::EventRouter> event_router) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
storage::WatcherManager* const watcher_manager =
file_system_context->GetWatcherManager(file_system_url.type());
- if (watcher_manager) {
- watcher_manager->AddWatcher(
- file_system_url, false /* recursive */,
+
+ if (!watcher_manager) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
base::Bind(
- &StatusCallbackToResponseCallback,
- base::Bind(&FileManagerPrivateInternalAddFileWatchFunction::Respond,
- this)),
- base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification,
- event_router->GetWeakPtr(), file_system_url, extension_id));
+ &FileWatchFunctionBase::PerformFallbackFileWatchOperationOnUIThread,
+ this, file_system_url, event_router));
return;
}
+ PerformFileWatchOperationOnIOThread(file_system_context, watcher_manager,
+ file_system_url, event_router);
+}
+
+void FileManagerPrivateInternalAddFileWatchFunction::
+ PerformFileWatchOperationOnIOThread(
+ scoped_refptr<storage::FileSystemContext> file_system_context,
+ storage::WatcherManager* watcher_manager,
+ const storage::FileSystemURL& file_system_url,
+ base::WeakPtr<file_manager::EventRouter> event_router) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ watcher_manager->AddWatcher(
+ file_system_url, false /* recursive */,
+ base::Bind(&StatusCallbackToResponseCallback,
+ base::Bind(&PostResponseCallbackTaskToUIThread,
+ base::Bind(&FileWatchFunctionBase::Respond, this))),
+ base::Bind(
+ &PostNotificationCallbackTaskToUIThread,
+ base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification,
+ event_router, file_system_url, extension_id())));
+}
+
+void FileManagerPrivateInternalAddFileWatchFunction::
+ PerformFallbackFileWatchOperationOnUIThread(
+ const storage::FileSystemURL& file_system_url,
+ base::WeakPtr<file_manager::EventRouter> event_router) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(event_router);
+
// Obsolete. Fallback code if storage::WatcherManager is not implemented.
- event_router->AddFileWatch(
- file_system_url.path(), file_system_url.virtual_path(), extension_id,
- base::Bind(&FileManagerPrivateInternalAddFileWatchFunction::Respond,
- this));
+ event_router->AddFileWatch(file_system_url.path(),
+ file_system_url.virtual_path(), extension_id(),
+ base::Bind(&FileWatchFunctionBase::Respond, this));
}
void FileManagerPrivateInternalRemoveFileWatchFunction::
- PerformFileWatchOperation(
+ PerformFileWatchOperationOnIOThread(
scoped_refptr<storage::FileSystemContext> file_system_context,
+ storage::WatcherManager* watcher_manager,
const storage::FileSystemURL& file_system_url,
- const std::string& extension_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ base::WeakPtr<file_manager::EventRouter> event_router) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
- file_manager::EventRouter* const event_router =
- file_manager::EventRouterFactory::GetForProfile(GetProfile());
+ watcher_manager->RemoveWatcher(
+ file_system_url, false /* recursive */,
+ base::Bind(
+ &StatusCallbackToResponseCallback,
+ base::Bind(&PostResponseCallbackTaskToUIThread,
+ base::Bind(&FileWatchFunctionBase::Respond, this))));
+}
- storage::WatcherManager* const watcher_manager =
- file_system_context->GetWatcherManager(file_system_url.type());
- if (watcher_manager) {
- watcher_manager->RemoveWatcher(
- file_system_url, false /* recursive */,
- base::Bind(&StatusCallbackToResponseCallback,
- base::Bind(&FileWatchFunctionBase::Respond, this)));
- return;
- }
+void FileManagerPrivateInternalRemoveFileWatchFunction::
+ PerformFallbackFileWatchOperationOnUIThread(
+ const storage::FileSystemURL& file_system_url,
+ base::WeakPtr<file_manager::EventRouter> event_router) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(event_router);
// Obsolete. Fallback code if storage::WatcherManager is not implemented.
- event_router->RemoveFileWatch(file_system_url.path(), extension_id);
+ event_router->RemoveFileWatch(file_system_url.path(), extension_id());
Respond(true);
}

Powered by Google App Engine
This is Rietveld 408576698