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

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

Issue 11636050: Eliminate ApiResourceEventNotifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 (c) 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/file_path.h" 9 #include "base/file_path.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 11
12 namespace extensions { 12 namespace extensions {
13 13
14 const char kSerialConnectionNotFoundError[] = "Serial connection not found"; 14 const char kSerialConnectionNotFoundError[] = "Serial connection not found";
15 15
16 SerialConnection::SerialConnection(const std::string& port, 16 SerialConnection::SerialConnection(const std::string& port, int bitrate,
17 int bitrate,
18 const std::string& owner_extension_id) 17 const std::string& owner_extension_id)
19 : ApiResource(owner_extension_id, NULL), 18 : ApiResource(owner_extension_id), port_(port), bitrate_(bitrate),
20 port_(port),
21 bitrate_(bitrate),
22 file_(base::kInvalidPlatformFileValue) { 19 file_(base::kInvalidPlatformFileValue) {
23 CHECK(bitrate >= 0); 20 CHECK(bitrate >= 0);
24 } 21 }
25 22
26 SerialConnection::~SerialConnection() { 23 SerialConnection::~SerialConnection() {
27 Close(); 24 Close();
28 } 25 }
29 26
30 bool SerialConnection::Open() { 27 bool SerialConnection::Open() {
31 bool created = false; 28 bool created = false;
(...skipping 17 matching lines...) Expand all
49 46
50 void SerialConnection::Close() { 47 void SerialConnection::Close() {
51 if (file_ != base::kInvalidPlatformFileValue) { 48 if (file_ != base::kInvalidPlatformFileValue) {
52 base::ClosePlatformFile(file_); 49 base::ClosePlatformFile(file_);
53 file_ = base::kInvalidPlatformFileValue; 50 file_ = base::kInvalidPlatformFileValue;
54 } 51 }
55 } 52 }
56 53
57 int SerialConnection::Read(scoped_refptr<net::IOBufferWithSize> io_buffer) { 54 int SerialConnection::Read(scoped_refptr<net::IOBufferWithSize> io_buffer) {
58 DCHECK(io_buffer->data()); 55 DCHECK(io_buffer->data());
59 return base::ReadPlatformFileAtCurrentPos(file_, 56 return base::ReadPlatformFileAtCurrentPos(file_, io_buffer->data(),
60 io_buffer->data(),
61 io_buffer->size()); 57 io_buffer->size());
62 } 58 }
63 59
64 int SerialConnection::Write(scoped_refptr<net::IOBuffer> io_buffer, 60 int SerialConnection::Write(scoped_refptr<net::IOBuffer> io_buffer,
65 int byte_count) { 61 int byte_count) {
66 DCHECK(io_buffer->data()); 62 DCHECK(io_buffer->data());
67 DCHECK(byte_count >= 0); 63 DCHECK(byte_count >= 0);
68 return base::WritePlatformFileAtCurrentPos(file_, 64 return base::WritePlatformFileAtCurrentPos(file_, io_buffer->data(),
69 io_buffer->data(), byte_count); 65 byte_count);
70 } 66 }
71 67
72 void SerialConnection::Flush() { 68 void SerialConnection::Flush() {
73 base::FlushPlatformFile(file_); 69 base::FlushPlatformFile(file_);
74 } 70 }
75 71
76 } // namespace extensions 72 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/api_resource_manager_unittest.cc ('k') | chrome/browser/extensions/api/socket/socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698