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/serial/serial_io_handler.h" | 5 #include "chrome/browser/extensions/api/serial/serial_io_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 | 9 |
10 namespace { | |
11 #if defined(OS_WIN) | |
12 const base::PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE; | |
13 #elif defined(OS_POSIX) | |
14 const base::PlatformFile kInvalidPlatformFileValue = -1; | |
15 #endif | |
16 } // namespace | |
17 | |
10 namespace extensions { | 18 namespace extensions { |
11 | 19 |
12 SerialIoHandler::SerialIoHandler() | 20 SerialIoHandler::SerialIoHandler() |
13 : file_(base::kInvalidPlatformFileValue), | 21 : file_(kInvalidPlatformFileValue), |
rvargas (doing something else)
2014/06/06 19:18:06
There is already a bug filed about removing the ra
| |
14 pending_read_buffer_len_(0), | 22 pending_read_buffer_len_(0), |
15 pending_write_buffer_len_(0) { | 23 pending_write_buffer_len_(0) { |
16 } | 24 } |
17 | 25 |
18 SerialIoHandler::~SerialIoHandler() { | 26 SerialIoHandler::~SerialIoHandler() { |
19 DCHECK(CalledOnValidThread()); | 27 DCHECK(CalledOnValidThread()); |
20 } | 28 } |
21 | 29 |
22 void SerialIoHandler::Initialize(base::PlatformFile file, | 30 void SerialIoHandler::Initialize(base::PlatformFile file, |
23 const ReadCompleteCallback& read_callback, | 31 const ReadCompleteCallback& read_callback, |
24 const WriteCompleteCallback& write_callback) { | 32 const WriteCompleteCallback& write_callback) { |
25 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
26 DCHECK_EQ(file_, base::kInvalidPlatformFileValue); | 34 DCHECK_EQ(file_, kInvalidPlatformFileValue); |
27 | 35 |
28 file_ = file; | 36 file_ = file; |
29 read_complete_ = read_callback; | 37 read_complete_ = read_callback; |
30 write_complete_ = write_callback; | 38 write_complete_ = write_callback; |
31 | 39 |
32 InitializeImpl(); | 40 InitializeImpl(); |
33 } | 41 } |
34 | 42 |
35 void SerialIoHandler::Read(int max_bytes) { | 43 void SerialIoHandler::Read(int max_bytes) { |
36 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 | 119 |
112 void SerialIoHandler::QueueWriteCompleted(int bytes_written, | 120 void SerialIoHandler::QueueWriteCompleted(int bytes_written, |
113 api::serial::SendError error) { | 121 api::serial::SendError error) { |
114 base::MessageLoop::current()->PostTask( | 122 base::MessageLoop::current()->PostTask( |
115 FROM_HERE, base::Bind(&SerialIoHandler::WriteCompleted, this, | 123 FROM_HERE, base::Bind(&SerialIoHandler::WriteCompleted, this, |
116 bytes_written, error)); | 124 bytes_written, error)); |
117 } | 125 } |
118 | 126 |
119 } // namespace extensions | 127 } // namespace extensions |
120 | 128 |
OLD | NEW |