| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_connection.h" | 5 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return GetPortInfo(info); | 157 return GetPortInfo(info); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void SerialConnection::StartOpen() { | 160 void SerialConnection::StartOpen() { |
| 161 DCHECK(!open_complete_.is_null()); | 161 DCHECK(!open_complete_.is_null()); |
| 162 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 162 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 163 DCHECK(!file_.IsValid()); | 163 DCHECK(!file_.IsValid()); |
| 164 // It's the responsibility of the API wrapper around SerialConnection to | 164 // It's the responsibility of the API wrapper around SerialConnection to |
| 165 // validate the supplied path against the set of valid port names, and | 165 // validate the supplied path against the set of valid port names, and |
| 166 // it is a reasonable assumption that serial port names are ASCII. | 166 // it is a reasonable assumption that serial port names are ASCII. |
| 167 DCHECK(IsStringASCII(port_)); | 167 DCHECK(base::IsStringASCII(port_)); |
| 168 base::FilePath path( | 168 base::FilePath path( |
| 169 base::FilePath::FromUTF8Unsafe(MaybeFixUpPortName(port_))); | 169 base::FilePath::FromUTF8Unsafe(MaybeFixUpPortName(port_))); |
| 170 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | | 170 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 171 base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_WRITE | | 171 base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_WRITE | |
| 172 base::File::FLAG_EXCLUSIVE_WRITE | base::File::FLAG_ASYNC | | 172 base::File::FLAG_EXCLUSIVE_WRITE | base::File::FLAG_ASYNC | |
| 173 base::File::FLAG_TERMINAL_DEVICE; | 173 base::File::FLAG_TERMINAL_DEVICE; |
| 174 base::File file(path, flags); | 174 base::File file(path, flags); |
| 175 BrowserThread::PostTask( | 175 BrowserThread::PostTask( |
| 176 BrowserThread::IO, | 176 BrowserThread::IO, |
| 177 FROM_HERE, | 177 FROM_HERE, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 FROM_HERE, | 250 FROM_HERE, |
| 251 base::Bind(&TimeoutTask::Run, weak_factory_.GetWeakPtr()), | 251 base::Bind(&TimeoutTask::Run, weak_factory_.GetWeakPtr()), |
| 252 delay_); | 252 delay_); |
| 253 } | 253 } |
| 254 | 254 |
| 255 SerialConnection::TimeoutTask::~TimeoutTask() {} | 255 SerialConnection::TimeoutTask::~TimeoutTask() {} |
| 256 | 256 |
| 257 void SerialConnection::TimeoutTask::Run() const { closure_.Run(); } | 257 void SerialConnection::TimeoutTask::Run() const { closure_.Run(); } |
| 258 | 258 |
| 259 } // namespace extensions | 259 } // namespace extensions |
| OLD | NEW |