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. |