OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/braille_display_private/braille_controll
er_brlapi.h" | 5 #include "chrome/browser/extensions/api/braille_display_private/braille_controll
er_brlapi.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cerrno> | 8 #include <cerrno> |
9 #include <cstring> | 9 #include <cstring> |
10 #include <vector> | 10 #include <vector> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 BrailleControllerImpl::~BrailleControllerImpl() { | 60 BrailleControllerImpl::~BrailleControllerImpl() { |
61 } | 61 } |
62 | 62 |
63 void BrailleControllerImpl::TryLoadLibBrlApi() { | 63 void BrailleControllerImpl::TryLoadLibBrlApi() { |
64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
65 if (libbrlapi_loader_.loaded()) | 65 if (libbrlapi_loader_.loaded()) |
66 return; | 66 return; |
67 // These versions of libbrlapi work the same for the functions we | 67 // These versions of libbrlapi work the same for the functions we |
68 // are using. (0.6.0 adds brlapi_writeWText). | 68 // are using. (0.6.0 adds brlapi_writeWText). |
69 static const char* kSupportedVersions[] = { | 69 static const char* const kSupportedVersions[] = { |
70 "libbrlapi.so.0.5", | 70 "libbrlapi.so.0.5", |
71 "libbrlapi.so.0.6" | 71 "libbrlapi.so.0.6" |
72 }; | 72 }; |
73 for (size_t i = 0; i < arraysize(kSupportedVersions); ++i) { | 73 for (size_t i = 0; i < arraysize(kSupportedVersions); ++i) { |
74 if (libbrlapi_loader_.Load(kSupportedVersions[i])) | 74 if (libbrlapi_loader_.Load(kSupportedVersions[i])) |
75 return; | 75 return; |
76 } | 76 } |
77 LOG(WARNING) << "Couldn't load libbrlapi: " << strerror(errno); | 77 LOG(WARNING) << "Couldn't load libbrlapi: " << strerror(errno); |
78 } | 78 } |
79 | 79 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 while (true) { | 270 while (true) { |
271 int result = connection_->ReadKey(&code); | 271 int result = connection_->ReadKey(&code); |
272 if (result < 0) { // Error. | 272 if (result < 0) { // Error. |
273 brlapi_error_t* err = connection_->BrlapiError(); | 273 brlapi_error_t* err = connection_->BrlapiError(); |
274 if (err->brlerrno == BRLAPI_ERROR_LIBCERR && err->libcerrno == EINTR) | 274 if (err->brlerrno == BRLAPI_ERROR_LIBCERR && err->libcerrno == EINTR) |
275 continue; | 275 continue; |
276 // Disconnect on other errors. | 276 // Disconnect on other errors. |
277 VLOG(1) << "BrlAPI error: " << connection_->BrlapiStrError(); | 277 VLOG(1) << "BrlAPI error: " << connection_->BrlapiStrError(); |
278 Disconnect(); | 278 Disconnect(); |
279 return; | 279 return; |
280 } else if (result == 0) { // No more data. | 280 } else if (result == 0) { // No more data. |
281 return; | 281 return; |
282 } | 282 } |
283 scoped_ptr<KeyEvent> event = BrlapiKeyCodeToEvent(code); | 283 scoped_ptr<KeyEvent> event = BrlapiKeyCodeToEvent(code); |
284 if (event) | 284 if (event) |
285 DispatchKeyEvent(event.Pass()); | 285 DispatchKeyEvent(event.Pass()); |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 void BrailleControllerImpl::DispatchKeyEvent(scoped_ptr<KeyEvent> event) { | 289 void BrailleControllerImpl::DispatchKeyEvent(scoped_ptr<KeyEvent> event) { |
290 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 290 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
(...skipping 20 matching lines...) Expand all Loading... |
311 } | 311 } |
312 return; | 312 return; |
313 } | 313 } |
314 FOR_EACH_OBSERVER(BrailleObserver, observers_, | 314 FOR_EACH_OBSERVER(BrailleObserver, observers_, |
315 OnBrailleDisplayStateChanged(*new_state)); | 315 OnBrailleDisplayStateChanged(*new_state)); |
316 } | 316 } |
317 | 317 |
318 } // namespace braille_display_private | 318 } // namespace braille_display_private |
319 } // namespace api | 319 } // namespace api |
320 } // namespace extensions | 320 } // namespace extensions |
OLD | NEW |