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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/stl_util.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "chrome/browser/extensions/api/braille_display_private/brlapi_connectio
n.h" | 16 #include "chrome/browser/extensions/api/braille_display_private/brlapi_connectio
n.h" |
16 #include "chrome/browser/extensions/api/braille_display_private/brlapi_keycode_m
ap.h" | 17 #include "chrome/browser/extensions/api/braille_display_private/brlapi_keycode_m
ap.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 | 19 |
19 namespace extensions { | 20 namespace extensions { |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 using base::Time; | 22 using base::Time; |
22 using base::TimeDelta; | 23 using base::TimeDelta; |
23 namespace api { | 24 namespace api { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (!connection_->GetDisplaySize(&size)) { | 87 if (!connection_->GetDisplaySize(&size)) { |
87 Disconnect(); | 88 Disconnect(); |
88 } else if (size > 0) { // size == 0 means no display present. | 89 } else if (size > 0) { // size == 0 means no display present. |
89 display_state->available = true; | 90 display_state->available = true; |
90 display_state->text_cell_count.reset(new int(size)); | 91 display_state->text_cell_count.reset(new int(size)); |
91 } | 92 } |
92 } | 93 } |
93 return display_state.Pass(); | 94 return display_state.Pass(); |
94 } | 95 } |
95 | 96 |
96 void BrailleControllerImpl::WriteDots(const std::string& cells) { | 97 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) { |
97 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
98 if (connection_ && connection_->Connected()) { | 99 if (connection_ && connection_->Connected()) { |
99 size_t size; | 100 size_t size; |
100 if (!connection_->GetDisplaySize(&size)) { | 101 if (!connection_->GetDisplaySize(&size)) { |
101 Disconnect(); | 102 Disconnect(); |
102 } | 103 } |
103 std::vector<unsigned char> sizedCells(size); | 104 std::vector<unsigned char> sizedCells(size); |
104 std::memcpy(&sizedCells[0], cells.data(), std::min(cells.size(), size)); | 105 std::memcpy(&sizedCells[0], vector_as_array(&cells), |
| 106 std::min(cells.size(), size)); |
105 if (size > cells.size()) | 107 if (size > cells.size()) |
106 std::fill(sizedCells.begin() + cells.size(), sizedCells.end(), 0); | 108 std::fill(sizedCells.begin() + cells.size(), sizedCells.end(), 0); |
107 if (!connection_->WriteDots(&sizedCells[0])) | 109 if (!connection_->WriteDots(&sizedCells[0])) |
108 Disconnect(); | 110 Disconnect(); |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) { | 114 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) { |
113 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
114 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 116 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 313 } |
312 return; | 314 return; |
313 } | 315 } |
314 FOR_EACH_OBSERVER(BrailleObserver, observers_, | 316 FOR_EACH_OBSERVER(BrailleObserver, observers_, |
315 OnBrailleDisplayStateChanged(*new_state)); | 317 OnBrailleDisplayStateChanged(*new_state)); |
316 } | 318 } |
317 | 319 |
318 } // namespace braille_display_private | 320 } // namespace braille_display_private |
319 } // namespace api | 321 } // namespace api |
320 } // namespace extensions | 322 } // namespace extensions |
OLD | NEW |