Commit 9fc69fb7 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[TaskScheduler]: Add ScopedBlockingCall in FilePathWatcher::Watch.

ScopedBlockingCall serves as a precise annotation of the scope that may/will
block for the scheduler. This CL moves ScopedBlockingCall from the call site
to the implementation of FilePathWatcher::Watch, which is more accurate.

Bug: 874080
Change-Id: I03cf5d28a2c4763c0c358699aff9f32d686b46b6
Reviewed-on: https://chromium-review.googlesource.com/1243366
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594782}
parent e81c896a
......@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/strings/stringprintf.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/sequenced_task_runner_handle.h"
namespace base {
......@@ -110,6 +111,7 @@ void FilePathWatcherFSEvents::Cancel() {
set_cancelled();
callback_.Reset();
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
// Switch to the dispatch queue to tear down the event stream. As the queue is
// owned by |this|, and this method is called from the destructor, execute the
// block synchronously.
......
......@@ -12,6 +12,7 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/sequenced_task_runner_handle.h"
// On some platforms these are not defined.
......@@ -79,6 +80,7 @@ int FilePathWatcherKQueue::EventsForPath(FilePath path, EventVector* events) {
}
uintptr_t FilePathWatcherKQueue::FileDescriptorForPath(const FilePath& path) {
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
int fd = HANDLE_EINTR(open(path.value().c_str(), O_EVTONLY));
if (fd == -1)
return kNoFileDescriptor;
......@@ -209,6 +211,7 @@ bool FilePathWatcherKQueue::UpdateWatches(bool* target_file_affected) {
}
EventVector updates(valid);
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
int count = HANDLE_EINTR(kevent(kqueue_, &events_[0], valid, &updates[0],
valid, NULL));
if (!AreKeventValuesValid(&updates[0], count)) {
......@@ -256,6 +259,7 @@ bool FilePathWatcherKQueue::Watch(const FilePath& path,
EventVector responses(last_entry);
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
int count = HANDLE_EINTR(kevent(kqueue_, &events_[0], last_entry,
&responses[0], last_entry, NULL));
if (!AreKeventValuesValid(&responses[0], count)) {
......
......@@ -35,6 +35,7 @@
#include "base/stl_util.h"
#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
......@@ -227,6 +228,8 @@ void InotifyReaderThreadDelegate::ThreadMain() {
FD_ZERO(&rfds);
FD_SET(inotify_fd_, &rfds);
ScopedBlockingCall scoped_blocking_call(BlockingType::WILL_BLOCK);
// Wait until some inotify events are available.
int select_result =
HANDLE_EINTR(select(inotify_fd_ + 1, &rfds, nullptr, nullptr, nullptr));
......@@ -291,6 +294,7 @@ InotifyReader::Watch InotifyReader::AddWatch(
AutoLock auto_lock(lock_);
ScopedBlockingCall scoped_blocking_call(BlockingType::WILL_BLOCK);
Watch watch = inotify_add_watch(inotify_fd_, path.value().c_str(),
IN_ATTRIB | IN_CREATE | IN_DELETE |
IN_CLOSE_WRITE | IN_MOVE |
......@@ -314,6 +318,8 @@ void InotifyReader::RemoveWatch(Watch watch, FilePathWatcherImpl* watcher) {
if (watchers_[watch].empty()) {
watchers_.erase(watch);
ScopedBlockingCall scoped_blocking_call(BlockingType::WILL_BLOCK);
inotify_rm_watch(inotify_fd_, watch);
}
}
......
......@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h"
#include "base/win/object_watcher.h"
......@@ -99,6 +100,7 @@ bool FilePathWatcherImpl::Watch(const FilePath& path,
recursive_watch_ = recursive;
File::Info file_info;
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
if (GetFileInfo(target_, &file_info)) {
last_modified_ = file_info.last_modified;
first_notification_ = Time::Now();
......@@ -143,7 +145,11 @@ void FilePathWatcherImpl::OnObjectSignaled(HANDLE object) {
// Check whether the event applies to |target_| and notify the callback.
File::Info file_info;
bool file_exists = GetFileInfo(target_, &file_info);
bool file_exists = false;
{
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
file_exists = GetFileInfo(target_, &file_info);
}
if (recursive_watch_) {
// Only the mtime of |target_| is tracked but in a recursive watch,
// some other file or directory may have changed so all notifications
......@@ -194,6 +200,7 @@ void FilePathWatcherImpl::OnObjectSignaled(HANDLE object) {
bool FilePathWatcherImpl::SetupWatchHandle(const FilePath& dir,
bool recursive,
HANDLE* handle) {
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
*handle = FindFirstChangeNotification(
dir.value().c_str(),
recursive,
......@@ -233,6 +240,8 @@ bool FilePathWatcherImpl::UpdateWatch() {
if (handle_ != INVALID_HANDLE_VALUE)
DestroyWatch();
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
// Start at the target and walk up the directory chain until we succesfully
// create a watch handle in |handle_|. |child_dirs| keeps a stack of child
// directories stripped from target, in reverse order.
......@@ -276,6 +285,8 @@ bool FilePathWatcherImpl::UpdateWatch() {
void FilePathWatcherImpl::DestroyWatch() {
watcher_.StopWatching();
ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
FindCloseChangeNotification(handle_);
handle_ = INVALID_HANDLE_VALUE;
}
......
......@@ -15,7 +15,6 @@
#include "base/stl_util.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/media_galleries/gallery_watch_manager_observer.h"
......@@ -118,7 +117,6 @@ void GalleryWatchManager::FileWatchManager::AddFileWatch(
const base::FilePath& path,
const base::Callback<void(bool)>& callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// This can occur if the GalleryWatchManager attempts to watch the same path
// again before recieving the callback. It's benign.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment