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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | |
10 #include <algorithm> | 9 #include <algorithm> |
11 #include <cerrno> | 10 #include <cerrno> |
12 #include <cstring> | 11 #include <cstring> |
| 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "chrome/browser/extensions/api/braille_display_private/brlapi_connectio
n.h" | 19 #include "chrome/browser/extensions/api/braille_display_private/brlapi_connectio
n.h" |
20 #include "chrome/browser/extensions/api/braille_display_private/brlapi_keycode_m
ap.h" | 20 #include "chrome/browser/extensions/api/braille_display_private/brlapi_keycode_m
ap.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 | 22 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 scoped_ptr<DisplayState> display_state(new DisplayState); | 88 scoped_ptr<DisplayState> display_state(new DisplayState); |
89 if (connection_.get() && connection_->Connected()) { | 89 if (connection_.get() && connection_->Connected()) { |
90 size_t size; | 90 size_t size; |
91 if (!connection_->GetDisplaySize(&size)) { | 91 if (!connection_->GetDisplaySize(&size)) { |
92 Disconnect(); | 92 Disconnect(); |
93 } else if (size > 0) { // size == 0 means no display present. | 93 } else if (size > 0) { // size == 0 means no display present. |
94 display_state->available = true; | 94 display_state->available = true; |
95 display_state->text_cell_count.reset(new int(size)); | 95 display_state->text_cell_count.reset(new int(size)); |
96 } | 96 } |
97 } | 97 } |
98 return display_state.Pass(); | 98 return display_state; |
99 } | 99 } |
100 | 100 |
101 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) { | 101 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) { |
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
103 if (connection_ && connection_->Connected()) { | 103 if (connection_ && connection_->Connected()) { |
104 size_t size; | 104 size_t size; |
105 if (!connection_->GetDisplaySize(&size)) { | 105 if (!connection_->GetDisplaySize(&size)) { |
106 Disconnect(); | 106 Disconnect(); |
107 } | 107 } |
108 std::vector<unsigned char> sizedCells(size); | 108 std::vector<unsigned char> sizedCells(size); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 continue; | 280 continue; |
281 // Disconnect on other errors. | 281 // Disconnect on other errors. |
282 VLOG(1) << "BrlAPI error: " << connection_->BrlapiStrError(); | 282 VLOG(1) << "BrlAPI error: " << connection_->BrlapiStrError(); |
283 Disconnect(); | 283 Disconnect(); |
284 return; | 284 return; |
285 } else if (result == 0) { // No more data. | 285 } else if (result == 0) { // No more data. |
286 return; | 286 return; |
287 } | 287 } |
288 scoped_ptr<KeyEvent> event = BrlapiKeyCodeToEvent(code); | 288 scoped_ptr<KeyEvent> event = BrlapiKeyCodeToEvent(code); |
289 if (event) | 289 if (event) |
290 DispatchKeyEvent(event.Pass()); | 290 DispatchKeyEvent(std::move(event)); |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 void BrailleControllerImpl::DispatchKeyEvent(scoped_ptr<KeyEvent> event) { | 294 void BrailleControllerImpl::DispatchKeyEvent(scoped_ptr<KeyEvent> event) { |
295 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 295 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
296 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 296 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
297 base::Bind( | 297 base::Bind( |
298 &BrailleControllerImpl::DispatchKeyEvent, | 298 &BrailleControllerImpl::DispatchKeyEvent, |
299 base::Unretained(this), | 299 base::Unretained(this), |
300 base::Passed(&event))); | 300 base::Passed(&event))); |
(...skipping 15 matching lines...) Expand all Loading... |
316 } | 316 } |
317 return; | 317 return; |
318 } | 318 } |
319 FOR_EACH_OBSERVER(BrailleObserver, observers_, | 319 FOR_EACH_OBSERVER(BrailleObserver, observers_, |
320 OnBrailleDisplayStateChanged(*new_state)); | 320 OnBrailleDisplayStateChanged(*new_state)); |
321 } | 321 } |
322 | 322 |
323 } // namespace braille_display_private | 323 } // namespace braille_display_private |
324 } // namespace api | 324 } // namespace api |
325 } // namespace extensions | 325 } // namespace extensions |
OLD | NEW |