Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: chrome/browser/extensions/api/serial/serial_connection.cc

Issue 158063002: Use udev for serial device enumeration on Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: -___- Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 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"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "chrome/browser/extensions/api/api_resource_manager.h" 13 #include "chrome/browser/extensions/api/api_resource_manager.h"
14 #include "chrome/browser/extensions/api/serial/serial_port_enumerator.h"
15 #include "chrome/common/extensions/api/serial.h" 14 #include "chrome/common/extensions/api/serial.h"
16 15
17 namespace extensions { 16 namespace extensions {
18 17
19 namespace { 18 namespace {
20 19
21 const int kDefaultBufferSize = 4096; 20 const int kDefaultBufferSize = 4096;
22 21
23 } 22 }
24 23
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 info->buffer_size = buffer_size_; 158 info->buffer_size = buffer_size_;
160 info->receive_timeout = receive_timeout_; 159 info->receive_timeout = receive_timeout_;
161 info->send_timeout = send_timeout_; 160 info->send_timeout = send_timeout_;
162 return GetPortInfo(info); 161 return GetPortInfo(info);
163 } 162 }
164 163
165 void SerialConnection::StartOpen() { 164 void SerialConnection::StartOpen() {
166 DCHECK(!open_complete_.is_null()); 165 DCHECK(!open_complete_.is_null());
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
168 DCHECK_EQ(file_, base::kInvalidPlatformFileValue); 167 DCHECK_EQ(file_, base::kInvalidPlatformFileValue);
169 const SerialPortEnumerator::StringSet name_set(
170 SerialPortEnumerator::GenerateValidSerialPortNames());
171 base::PlatformFile file = base::kInvalidPlatformFileValue; 168 base::PlatformFile file = base::kInvalidPlatformFileValue;
172 if (SerialPortEnumerator::DoesPortExist(name_set, port_)) { 169 // It's the responsibility of the API wrapper around SerialConnection to
173 // It's the responsibility of the API wrapper around SerialConnection to 170 // validate the supplied path against the set of valid port names, and
174 // validate the supplied path against the set of valid port names, and 171 // it is a reasonable assumption that serial port names are ASCII.
175 // it is a reasonable assumption that serial port names are ASCII. 172 DCHECK(IsStringASCII(port_));
176 DCHECK(IsStringASCII(port_)); 173 base::FilePath path(
177 base::FilePath path( 174 base::FilePath::FromUTF8Unsafe(MaybeFixUpPortName(port_)));
178 base::FilePath::FromUTF8Unsafe(MaybeFixUpPortName(port_))); 175 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ |
179 int flags = base::PLATFORM_FILE_OPEN | 176 base::PLATFORM_FILE_EXCLUSIVE_READ | base::PLATFORM_FILE_WRITE |
180 base::PLATFORM_FILE_READ | 177 base::PLATFORM_FILE_EXCLUSIVE_WRITE | base::PLATFORM_FILE_ASYNC |
181 base::PLATFORM_FILE_EXCLUSIVE_READ | 178 base::PLATFORM_FILE_TERMINAL_DEVICE;
182 base::PLATFORM_FILE_WRITE | 179 file = base::CreatePlatformFile(path, flags, NULL, NULL);
183 base::PLATFORM_FILE_EXCLUSIVE_WRITE |
184 base::PLATFORM_FILE_ASYNC |
185 base::PLATFORM_FILE_TERMINAL_DEVICE;
186 file = base::CreatePlatformFile(path, flags, NULL, NULL);
187 }
188 BrowserThread::PostTask( 180 BrowserThread::PostTask(
189 BrowserThread::IO, FROM_HERE, 181 BrowserThread::IO, FROM_HERE,
190 base::Bind(&SerialConnection::FinishOpen, base::Unretained(this), file)); 182 base::Bind(&SerialConnection::FinishOpen, base::Unretained(this), file));
191 } 183 }
192 184
193 void SerialConnection::FinishOpen(base::PlatformFile file) { 185 void SerialConnection::FinishOpen(base::PlatformFile file) {
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
195 DCHECK(!open_complete_.is_null()); 187 DCHECK(!open_complete_.is_null());
196 DCHECK_EQ(file_, base::kInvalidPlatformFileValue); 188 DCHECK_EQ(file_, base::kInvalidPlatformFileValue);
197 OpenCompleteCallback callback = open_complete_; 189 OpenCompleteCallback callback = open_complete_;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 delay_); 257 delay_);
266 } 258 }
267 259
268 SerialConnection::TimeoutTask::~TimeoutTask() {} 260 SerialConnection::TimeoutTask::~TimeoutTask() {}
269 261
270 void SerialConnection::TimeoutTask::Run() const { 262 void SerialConnection::TimeoutTask::Run() const {
271 closure_.Run(); 263 closure_.Run();
272 } 264 }
273 265
274 } // namespace extensions 266 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698