Chromium Code Reviews| 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 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cerrno> | 10 #include <cerrno> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 LOG(WARNING) << "Couldn't load libbrlapi: " << strerror(errno); | 82 LOG(WARNING) << "Couldn't load libbrlapi: " << strerror(errno); |
| 83 } | 83 } |
| 84 | 84 |
| 85 std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() { | 85 std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() { |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 87 StartConnecting(); | 87 StartConnecting(); |
| 88 std::unique_ptr<DisplayState> display_state(new DisplayState); | 88 std::unique_ptr<DisplayState> display_state(new DisplayState); |
| 89 if (connection_.get() && connection_->Connected()) { | 89 if (connection_.get() && connection_->Connected()) { |
| 90 size_t size; | 90 unsigned int columns, rows; |
| 91 if (!connection_->GetDisplaySize(&size)) { | 91 if (!connection_->GetDisplaySize(&columns, &rows)) { |
| 92 Disconnect(); | 92 Disconnect(); |
| 93 } else if (size > 0) { // size == 0 means no display present. | 93 } else if (rows * columns > 0) { |
| 94 // rows * columns == 0 means no display present. | |
| 94 display_state->available = true; | 95 display_state->available = true; |
| 95 display_state->text_cell_count.reset(new int(size)); | 96 display_state->text_column_count.reset(new int(columns)); |
| 97 display_state->text_row_count.reset(new int(rows)); | |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 return display_state; | 100 return display_state; |
| 99 } | 101 } |
| 100 | 102 |
| 101 void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) { | 103 void BrailleControllerImpl::WriteDots(const std::vector<std::vector<char>>& |
|
dmazzoni
2016/10/11 17:15:39
I'd probably indent it like this:
void BrailleCon
ultimatedbz
2016/10/16 01:12:38
Cool! didn't know about git cl format!
ultimatedbz
2016/10/16 01:12:38
Done.
| |
| 104 cells) { | |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 105 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 103 if (connection_ && connection_->Connected()) { | 106 if (connection_ && connection_->Connected()) { |
| 104 size_t size; | 107 unsigned int rows, columns; |
| 105 if (!connection_->GetDisplaySize(&size)) { | 108 if (!connection_->GetDisplaySize(&rows, &columns)) { |
| 106 Disconnect(); | 109 Disconnect(); |
| 107 } | 110 } |
| 108 std::vector<unsigned char> sizedCells(size); | 111 std::vector<std::vector<unsigned char>> sizedCells(rows, |
|
dmazzoni
2016/10/11 17:15:39
sizedCells -> sized_cells
ultimatedbz
2016/10/16 01:12:38
Done.
| |
| 109 std::memcpy(&sizedCells[0], cells.data(), std::min(cells.size(), size)); | 112 std::vector<unsigned char>(columns)); |
| 110 if (size > cells.size()) | 113 for (unsigned int i = 0; i < rows; i++) { |
|
dmazzoni
2016/10/11 17:15:39
I think you need to handle the case where cells.si
ultimatedbz
2016/10/16 01:12:38
Done.
| |
| 111 std::fill(sizedCells.begin() + cells.size(), sizedCells.end(), 0); | 114 std::memcpy(&sizedCells[i][0], cells[i].data(), std::min(cells[i].size(), |
| 112 if (!connection_->WriteDots(&sizedCells[0])) | 115 (unsigned long)columns)); |
|
dmazzoni
2016/10/11 17:15:39
Use a C++-style cast, and I think size_t is the co
ultimatedbz
2016/10/16 01:12:38
Done.
| |
| 116 if (columns > cells[i].size()) | |
|
dmazzoni
2016/10/11 17:15:39
For readability, you need braces {} if there's mor
ultimatedbz
2016/10/16 01:12:38
Done.
| |
| 117 std::fill(sizedCells[i].begin() + cells[i].size(), sizedCells[i].end(), | |
| 118 0); | |
| 119 } | |
| 120 // For now we are sending the whole 2D vector over. | |
| 121 if (!connection_->WriteDots(sizedCells)) | |
| 113 Disconnect(); | 122 Disconnect(); |
| 114 } | 123 } |
| 115 } | 124 } |
| 116 | 125 |
| 117 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) { | 126 void BrailleControllerImpl::AddObserver(BrailleObserver* observer) { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 128 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 120 base::Bind( | 129 base::Bind( |
| 121 &BrailleControllerImpl::StartConnecting, | 130 &BrailleControllerImpl::StartConnecting, |
| 122 base::Unretained(this)))) { | 131 base::Unretained(this)))) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 } | 327 } |
| 319 return; | 328 return; |
| 320 } | 329 } |
| 321 FOR_EACH_OBSERVER(BrailleObserver, observers_, | 330 FOR_EACH_OBSERVER(BrailleObserver, observers_, |
| 322 OnBrailleDisplayStateChanged(*new_state)); | 331 OnBrailleDisplayStateChanged(*new_state)); |
| 323 } | 332 } |
| 324 | 333 |
| 325 } // namespace braille_display_private | 334 } // namespace braille_display_private |
| 326 } // namespace api | 335 } // namespace api |
| 327 } // namespace extensions | 336 } // namespace extensions |
| OLD | NEW |