Skip to content

Commit

Permalink
Remove PlatformFile from device/hid
Browse files Browse the repository at this point in the history
BUG=322664
R=rockot@chromium.org

Review URL: https://codereview.chromium.org/173003002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252479 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rvargas@chromium.org committed Feb 21, 2014
1 parent ea3ab1b commit 65f0d75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
41 changes: 17 additions & 24 deletions device/hid/hid_connection_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,26 @@ HidConnectionLinux::HidConnectionLinux(HidDeviceInfo device_info,
return;
}

base::PlatformFileError error;

int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_EXCLUSIVE_READ |
base::PLATFORM_FILE_EXCLUSIVE_WRITE;

base::PlatformFile device_file = base::CreatePlatformFile(
base::FilePath(dev_node),
flags,
NULL,
&error);
if (error || device_file <= 0) {
LOG(ERROR) << error;
if (device_file)
base::ClosePlatformFile(device_file);
int flags = base::File::FLAG_OPEN |
base::File::FLAG_READ |
base::File::FLAG_WRITE |
base::File::FLAG_EXCLUSIVE_READ |
base::File::FLAG_EXCLUSIVE_WRITE;

base::File device_file(base::FilePath(dev_node), flags);
if (!device_file.IsValid()) {
LOG(ERROR) << device_file.error_details();
return;
}
if (fcntl(device_file, F_SETFL, fcntl(device_file, F_GETFL) | O_NONBLOCK)) {
if (fcntl(device_file.GetPlatformFile(), F_SETFL,
fcntl(device_file.GetPlatformFile(), F_GETFL) | O_NONBLOCK)) {
PLOG(ERROR) << "Failed to set non-blocking flag to device file.";
return;
}
device_file_ = device_file;
device_file_ = device_file.Pass();

if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
device_file_,
device_file_.GetPlatformFile(),
true,
base::MessageLoopForIO::WATCH_READ_WRITE,
&device_file_watcher_,
Expand All @@ -82,11 +75,11 @@ HidConnectionLinux::~HidConnectionLinux() {

void HidConnectionLinux::OnFileCanReadWithoutBlocking(int fd) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_EQ(fd, device_file_);
DCHECK_EQ(fd, device_file_.GetPlatformFile());
DCHECK(initialized_);

uint8 buffer[1024] = {0};
int bytes = read(device_file_, buffer, 1024);
int bytes = read(device_file_.GetPlatformFile(), buffer, 1024);
if (bytes < 0) {
if (errno == EAGAIN) {
return;
Expand All @@ -110,7 +103,7 @@ void HidConnectionLinux::Disconnect() {

initialized_ = false;
device_file_watcher_.StopWatchingFileDescriptor();
close(device_file_);
device_file_.Close();
while (!read_queue_.empty()) {
PendingRequest callback = read_queue_.front();
read_queue_.pop();
Expand Down Expand Up @@ -145,7 +138,7 @@ void HidConnectionLinux::Write(scoped_refptr<net::IOBuffer> buffer,
callback.Run(false, 0);
return;
} else {
int bytes = write(device_file_, buffer->data(), size);
int bytes = write(device_file_.GetPlatformFile(), buffer->data(), size);
if (bytes < 0) {
Disconnect();
callback.Run(false, 0);
Expand Down
4 changes: 2 additions & 2 deletions device/hid/hid_connection_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef DEVICE_HID_HID_CONNECTION_LINUX_H_
#define DEVICE_HID_HID_CONNECTION_LINUX_H_

#include "base/files/file.h"
#include "base/memory/ref_counted.h"
#include "base/platform_file.h"
#include "base/tuple.h"
#include "device/hid/hid_connection.h"
#include "device/hid/hid_device_info.h"
Expand Down Expand Up @@ -49,7 +49,7 @@ class HidConnectionLinux : public HidConnection,
void ProcessReadQueue();
void Disconnect();

base::PlatformFile device_file_;
base::File device_file_;
base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_;

typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> PendingReport;
Expand Down

0 comments on commit 65f0d75

Please sign in to comment.