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

Unified Diff: chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc

Issue 24325002: Fix threading bug in the brlapi braille controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 7 years, 3 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/extensions/api/braille_display_private/braille_controller_brlapi.cc
diff --git a/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc b/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc
index 4ab1194194a5e59fc6eb6abf19ae435f4b03e226..0fe8566b496a3f10c53632a83ef697023ad710af 100644
--- a/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc
+++ b/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc
@@ -134,7 +134,7 @@ void BrailleControllerImpl::SetCreateBrlapiConnectionForTesting(
}
void BrailleControllerImpl::PokeSocketDirForTesting() {
- OnSocketDirChanged(base::FilePath(), false /*error*/);
+ OnSocketDirChangedOnIOThread();
}
void BrailleControllerImpl::StartConnecting() {
@@ -146,26 +146,44 @@ void BrailleControllerImpl::StartConnecting() {
if (!libbrlapi_loader_.loaded()) {
return;
}
+ // One could argue that there is a race condition between starting to
+ // watch the socket asynchonously and trying to connect. While this is true,
+ // we are actually retrying to connect for a while, so this doesn't matter
+ // in practice.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE, base::Bind(
+ &BrailleControllerImpl::StartWatchingSocketDirOnFileThread,
+ base::Unretained(this)));
+ ResetRetryConnectHorizon();
+ TryToConnect();
+}
+
+void BrailleControllerImpl::StartWatchingSocketDirOnFileThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
base::FilePath brlapi_dir(BRLAPI_SOCKETPATH);
if (!file_path_watcher_.Watch(
brlapi_dir, false, base::Bind(
- &BrailleControllerImpl::OnSocketDirChanged,
+ &BrailleControllerImpl::OnSocketDirChangedOnFileThread,
base::Unretained(this)))) {
LOG(WARNING) << "Couldn't watch brlapi directory " << BRLAPI_SOCKETPATH;
- return;
}
- ResetRetryConnectHorizon();
- TryToConnect();
}
-void BrailleControllerImpl::OnSocketDirChanged(const base::FilePath& path,
- bool error) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(libbrlapi_loader_.loaded());
+void BrailleControllerImpl::OnSocketDirChangedOnFileThread(
+ const base::FilePath& path, bool error) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
if (error) {
LOG(ERROR) << "Error watching brlapi directory: " << path.value();
return;
}
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE, base::Bind(
+ &BrailleControllerImpl::OnSocketDirChangedOnIOThread,
+ base::Unretained(this)));
+}
+
+void BrailleControllerImpl::OnSocketDirChangedOnIOThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
LOG(INFO) << "BrlAPI directory changed";
// Every directory change resets the max retry time to the appropriate delay
// into the future.

Powered by Google App Engine
This is Rietveld 408576698