Commit a4579977 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

Remove use of FILE thread from braille_controller_brlapi.cc

This is part of the TaskScheduler migration, see the linked
bug and various messages on chromium-dev for context.

Bug: 689520
Test: flashed to Chromebook, plugged in braille display.

Change-Id: Id7f196ba58d5e013c516e63266d47f9307e4d2d1
Reviewed-on: https://chromium-review.googlesource.com/589776
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491520}
parent 0ad8bf2f
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/task_scheduler/post_task.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/extensions/api/braille_display_private/brlapi_connection.h" #include "chrome/browser/extensions/api/braille_display_private/brlapi_connection.h"
#include "chrome/browser/extensions/api/braille_display_private/brlapi_keycode_map.h" #include "chrome/browser/extensions/api/braille_display_private/brlapi_keycode_map.h"
...@@ -166,34 +167,41 @@ void BrailleControllerImpl::StartConnecting() { ...@@ -166,34 +167,41 @@ void BrailleControllerImpl::StartConnecting() {
if (!libbrlapi_loader_.loaded()) { if (!libbrlapi_loader_.loaded()) {
return; return;
} }
if (!sequenced_task_runner_) {
sequenced_task_runner_ = base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE});
}
// Only try to connect after we've started to watch the // Only try to connect after we've started to watch the
// socket directory. This is necessary to avoid a race condition // socket directory. This is necessary to avoid a race condition
// and because we don't retry to connect after errors that will // and because we don't retry to connect after errors that will
// persist until there's a change to the socket directory (i.e. // persist until there's a change to the socket directory (i.e.
// ENOENT). // ENOENT).
BrowserThread::PostTaskAndReply( sequenced_task_runner_->PostTaskAndReply(
BrowserThread::FILE, FROM_HERE, FROM_HERE,
base::BindOnce(&BrailleControllerImpl::StartWatchingSocketDirOnFileThread, base::BindOnce(&BrailleControllerImpl::StartWatchingSocketDirOnTaskThread,
base::Unretained(this)), base::Unretained(this)),
base::BindOnce(&BrailleControllerImpl::TryToConnect, base::BindOnce(&BrailleControllerImpl::TryToConnect,
base::Unretained(this))); base::Unretained(this)));
ResetRetryConnectHorizon(); ResetRetryConnectHorizon();
} }
void BrailleControllerImpl::StartWatchingSocketDirOnFileThread() { void BrailleControllerImpl::StartWatchingSocketDirOnTaskThread() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE); base::ThreadRestrictions::AssertIOAllowed();
base::FilePath brlapi_dir(BRLAPI_SOCKETPATH); base::FilePath brlapi_dir(BRLAPI_SOCKETPATH);
if (!file_path_watcher_.Watch( if (!file_path_watcher_.Watch(
brlapi_dir, false, base::Bind( brlapi_dir, false,
&BrailleControllerImpl::OnSocketDirChangedOnFileThread, base::Bind(&BrailleControllerImpl::OnSocketDirChangedOnTaskThread,
base::Unretained(this)))) { base::Unretained(this)))) {
LOG(WARNING) << "Couldn't watch brlapi directory " << BRLAPI_SOCKETPATH; LOG(WARNING) << "Couldn't watch brlapi directory " << BRLAPI_SOCKETPATH;
} }
} }
void BrailleControllerImpl::OnSocketDirChangedOnFileThread( void BrailleControllerImpl::OnSocketDirChangedOnTaskThread(
const base::FilePath& path, bool error) { const base::FilePath& path,
DCHECK_CURRENTLY_ON(BrowserThread::FILE); bool error) {
base::ThreadRestrictions::AssertIOAllowed();
if (error) { if (error) {
LOG(ERROR) << "Error watching brlapi directory: " << path.value(); LOG(ERROR) << "Error watching brlapi directory: " << path.value();
return; return;
......
...@@ -55,8 +55,8 @@ class BrailleControllerImpl : public BrailleController { ...@@ -55,8 +55,8 @@ class BrailleControllerImpl : public BrailleController {
// Tries to connect and starts watching for new brlapi servers. // Tries to connect and starts watching for new brlapi servers.
// No-op if already called. // No-op if already called.
void StartConnecting(); void StartConnecting();
void StartWatchingSocketDirOnFileThread(); void StartWatchingSocketDirOnTaskThread();
void OnSocketDirChangedOnFileThread(const base::FilePath& path, bool error); void OnSocketDirChangedOnTaskThread(const base::FilePath& path, bool error);
void OnSocketDirChangedOnIOThread(); void OnSocketDirChangedOnIOThread();
void TryToConnect(); void TryToConnect();
void ResetRetryConnectHorizon(); void ResetRetryConnectHorizon();
...@@ -75,11 +75,12 @@ class BrailleControllerImpl : public BrailleController { ...@@ -75,11 +75,12 @@ class BrailleControllerImpl : public BrailleController {
bool started_connecting_; bool started_connecting_;
bool connect_scheduled_; bool connect_scheduled_;
base::Time retry_connect_horizon_; base::Time retry_connect_horizon_;
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
// Manipulated on the UI thread. // Manipulated on the UI thread.
base::ObserverList<BrailleObserver> observers_; base::ObserverList<BrailleObserver> observers_;
// Manipulated on the FILE thread. // Manipulated by the SequencedTaskRunner.
base::FilePathWatcher file_path_watcher_; base::FilePathWatcher file_path_watcher_;
friend struct base::DefaultSingletonTraits<BrailleControllerImpl>; friend struct base::DefaultSingletonTraits<BrailleControllerImpl>;
......
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