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 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/task_scheduler/post_task.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_keycode_map.h"
......@@ -166,34 +167,41 @@ void BrailleControllerImpl::StartConnecting() {
if (!libbrlapi_loader_.loaded()) {
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
// socket directory. This is necessary to avoid a race condition
// and because we don't retry to connect after errors that will
// persist until there's a change to the socket directory (i.e.
// ENOENT).
BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
base::BindOnce(&BrailleControllerImpl::StartWatchingSocketDirOnFileThread,
sequenced_task_runner_->PostTaskAndReply(
FROM_HERE,
base::BindOnce(&BrailleControllerImpl::StartWatchingSocketDirOnTaskThread,
base::Unretained(this)),
base::BindOnce(&BrailleControllerImpl::TryToConnect,
base::Unretained(this)));
ResetRetryConnectHorizon();
}
void BrailleControllerImpl::StartWatchingSocketDirOnFileThread() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
void BrailleControllerImpl::StartWatchingSocketDirOnTaskThread() {
base::ThreadRestrictions::AssertIOAllowed();
base::FilePath brlapi_dir(BRLAPI_SOCKETPATH);
if (!file_path_watcher_.Watch(
brlapi_dir, false, base::Bind(
&BrailleControllerImpl::OnSocketDirChangedOnFileThread,
base::Unretained(this)))) {
brlapi_dir, false,
base::Bind(&BrailleControllerImpl::OnSocketDirChangedOnTaskThread,
base::Unretained(this)))) {
LOG(WARNING) << "Couldn't watch brlapi directory " << BRLAPI_SOCKETPATH;
}
}
void BrailleControllerImpl::OnSocketDirChangedOnFileThread(
const base::FilePath& path, bool error) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
void BrailleControllerImpl::OnSocketDirChangedOnTaskThread(
const base::FilePath& path,
bool error) {
base::ThreadRestrictions::AssertIOAllowed();
if (error) {
LOG(ERROR) << "Error watching brlapi directory: " << path.value();
return;
......
......@@ -55,8 +55,8 @@ class BrailleControllerImpl : public BrailleController {
// Tries to connect and starts watching for new brlapi servers.
// No-op if already called.
void StartConnecting();
void StartWatchingSocketDirOnFileThread();
void OnSocketDirChangedOnFileThread(const base::FilePath& path, bool error);
void StartWatchingSocketDirOnTaskThread();
void OnSocketDirChangedOnTaskThread(const base::FilePath& path, bool error);
void OnSocketDirChangedOnIOThread();
void TryToConnect();
void ResetRetryConnectHorizon();
......@@ -75,11 +75,12 @@ class BrailleControllerImpl : public BrailleController {
bool started_connecting_;
bool connect_scheduled_;
base::Time retry_connect_horizon_;
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
// Manipulated on the UI thread.
base::ObserverList<BrailleObserver> observers_;
// Manipulated on the FILE thread.
// Manipulated by the SequencedTaskRunner.
base::FilePathWatcher file_path_watcher_;
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