summaryrefslogtreecommitdiffstats
path: root/remoting/host/native_messaging
diff options
context:
space:
mode:
authorrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 04:28:00 +0000
committerrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 04:28:00 +0000
commit0fa0bbf3cf20dd14dd8772b4e0f276ab464c8f03 (patch)
treed282e390ad38e00b8a3c13ce37f5f5f6ae6c226f /remoting/host/native_messaging
parent31e2cf6af44588f355e287fc53015a2ace7029ba (diff)
downloadchromium_src-0fa0bbf3cf20dd14dd8772b4e0f276ab464c8f03.zip
chromium_src-0fa0bbf3cf20dd14dd8772b4e0f276ab464c8f03.tar.gz
chromium_src-0fa0bbf3cf20dd14dd8772b4e0f276ab464c8f03.tar.bz2
Remove PlatformFile from remoting native messaging.
BUG=322664 Review URL: https://codereview.chromium.org/254863002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267737 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/native_messaging')
-rw-r--r--remoting/host/native_messaging/native_messaging_channel.cc23
-rw-r--r--remoting/host/native_messaging/native_messaging_channel.h4
-rw-r--r--remoting/host/native_messaging/native_messaging_reader.cc10
-rw-r--r--remoting/host/native_messaging/native_messaging_reader.h4
-rw-r--r--remoting/host/native_messaging/native_messaging_reader_unittest.cc19
-rw-r--r--remoting/host/native_messaging/native_messaging_writer.cc4
-rw-r--r--remoting/host/native_messaging/native_messaging_writer.h3
-rw-r--r--remoting/host/native_messaging/native_messaging_writer_unittest.cc37
8 files changed, 39 insertions, 65 deletions
diff --git a/remoting/host/native_messaging/native_messaging_channel.cc b/remoting/host/native_messaging/native_messaging_channel.cc
index 186b33b..007de56 100644
--- a/remoting/host/native_messaging/native_messaging_channel.cc
+++ b/remoting/host/native_messaging/native_messaging_channel.cc
@@ -17,24 +17,23 @@
namespace {
-base::PlatformFile DuplicatePlatformFile(base::PlatformFile handle) {
+base::File DuplicatePlatformFile(base::File file) {
base::PlatformFile result;
#if defined(OS_WIN)
if (!DuplicateHandle(GetCurrentProcess(),
- handle,
+ file.TakePlatformFile(),
GetCurrentProcess(),
&result,
0,
FALSE,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
- PLOG(ERROR) << "Failed to duplicate handle " << handle;
- return base::kInvalidPlatformFileValue;
+ PLOG(ERROR) << "Failed to duplicate handle " << file.GetPlatformFile();
+ return base::File();
}
- return result;
+ return base::File(result);
#elif defined(OS_POSIX)
- result = dup(handle);
- base::ClosePlatformFile(handle);
- return result;
+ result = dup(file.GetPlatformFile());
+ return base::File(result);
#else
#error Not implemented.
#endif
@@ -45,11 +44,11 @@ base::PlatformFile DuplicatePlatformFile(base::PlatformFile handle) {
namespace remoting {
NativeMessagingChannel::NativeMessagingChannel(
- base::PlatformFile input,
- base::PlatformFile output)
- : native_messaging_reader_(DuplicatePlatformFile(input)),
+ base::File input,
+ base::File output)
+ : native_messaging_reader_(DuplicatePlatformFile(input.Pass())),
native_messaging_writer_(new NativeMessagingWriter(
- DuplicatePlatformFile(output))),
+ DuplicatePlatformFile(output.Pass()))),
weak_factory_(this) {
weak_ptr_ = weak_factory_.GetWeakPtr();
}
diff --git a/remoting/host/native_messaging/native_messaging_channel.h b/remoting/host/native_messaging/native_messaging_channel.h
index 472cc06..926f547 100644
--- a/remoting/host/native_messaging/native_messaging_channel.h
+++ b/remoting/host/native_messaging/native_messaging_channel.h
@@ -6,10 +6,10 @@
#define REMOTING_HOST_NATIVE_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_
#include "base/callback.h"
+#include "base/files/file.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "base/platform_file.h"
#include "base/threading/non_thread_safe.h"
#include "remoting/host/native_messaging/native_messaging_reader.h"
#include "remoting/host/native_messaging/native_messaging_writer.h"
@@ -31,7 +31,7 @@ class NativeMessagingChannel : public base::NonThreadSafe {
// Constructs an object taking the ownership of |input| and |output|. Closes
// |input| and |output| to prevent the caller from using them.
- NativeMessagingChannel(base::PlatformFile input, base::PlatformFile output);
+ NativeMessagingChannel(base::File input, base::File output);
~NativeMessagingChannel();
// Starts reading and processing messages.
diff --git a/remoting/host/native_messaging/native_messaging_reader.cc b/remoting/host/native_messaging/native_messaging_reader.cc
index 30f307b..b2ff66d 100644
--- a/remoting/host/native_messaging/native_messaging_reader.cc
+++ b/remoting/host/native_messaging/native_messaging_reader.cc
@@ -35,7 +35,7 @@ namespace remoting {
class NativeMessagingReader::Core {
public:
- Core(base::PlatformFile handle,
+ Core(base::File file,
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SequencedTaskRunner> read_task_runner,
base::WeakPtr<NativeMessagingReader> reader_);
@@ -63,11 +63,11 @@ class NativeMessagingReader::Core {
};
NativeMessagingReader::Core::Core(
- base::PlatformFile handle,
+ base::File file,
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SequencedTaskRunner> read_task_runner,
base::WeakPtr<NativeMessagingReader> reader)
- : read_stream_(handle),
+ : read_stream_(file.Pass()),
reader_(reader),
caller_task_runner_(caller_task_runner),
read_task_runner_(read_task_runner) {
@@ -130,12 +130,12 @@ void NativeMessagingReader::Core::NotifyEof() {
base::Bind(&NativeMessagingReader::InvokeEofCallback, reader_));
}
-NativeMessagingReader::NativeMessagingReader(base::PlatformFile handle)
+NativeMessagingReader::NativeMessagingReader(base::File file)
: reader_thread_("Reader"),
weak_factory_(this) {
reader_thread_.Start();
read_task_runner_ = reader_thread_.message_loop_proxy();
- core_.reset(new Core(handle, base::ThreadTaskRunnerHandle::Get(),
+ core_.reset(new Core(file.Pass(), base::ThreadTaskRunnerHandle::Get(),
read_task_runner_, weak_factory_.GetWeakPtr()));
}
diff --git a/remoting/host/native_messaging/native_messaging_reader.h b/remoting/host/native_messaging/native_messaging_reader.h
index a9e2047..ed93e8d 100644
--- a/remoting/host/native_messaging/native_messaging_reader.h
+++ b/remoting/host/native_messaging/native_messaging_reader.h
@@ -7,9 +7,9 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/files/file.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "base/platform_file.h"
#include "base/threading/thread.h"
namespace base {
@@ -25,7 +25,7 @@ class NativeMessagingReader {
public:
typedef base::Callback<void(scoped_ptr<base::Value>)> MessageCallback;
- explicit NativeMessagingReader(base::PlatformFile handle);
+ explicit NativeMessagingReader(base::File file);
~NativeMessagingReader();
// Begin reading messages from the Native Messaging client webapp, calling
diff --git a/remoting/host/native_messaging/native_messaging_reader_unittest.cc b/remoting/host/native_messaging/native_messaging_reader_unittest.cc
index 35af8a2..964dffe 100644
--- a/remoting/host/native_messaging/native_messaging_reader_unittest.cc
+++ b/remoting/host/native_messaging/native_messaging_reader_unittest.cc
@@ -22,7 +22,6 @@ class NativeMessagingReaderTest : public testing::Test {
virtual ~NativeMessagingReaderTest();
virtual void SetUp() OVERRIDE;
- virtual void TearDown() OVERRIDE;
// Starts the reader and runs the MessageLoop to completion.
void Run();
@@ -39,8 +38,8 @@ class NativeMessagingReaderTest : public testing::Test {
protected:
scoped_ptr<NativeMessagingReader> reader_;
- base::PlatformFile read_handle_;
- base::PlatformFile write_handle_;
+ base::File read_file_;
+ base::File write_file_;
scoped_ptr<base::Value> message_;
private:
@@ -56,18 +55,13 @@ NativeMessagingReaderTest::NativeMessagingReaderTest() {
NativeMessagingReaderTest::~NativeMessagingReaderTest() {}
void NativeMessagingReaderTest::SetUp() {
- ASSERT_TRUE(MakePipe(&read_handle_, &write_handle_));
- reader_.reset(new NativeMessagingReader(read_handle_));
-}
-
-void NativeMessagingReaderTest::TearDown() {
- // |read_handle_| is owned by NativeMessagingReader's FileStream, so don't
- // try to close it here. Also, |write_handle_| gets closed by Run().
+ ASSERT_TRUE(MakePipe(&read_file_, &write_file_));
+ reader_.reset(new NativeMessagingReader(read_file_.Pass()));
}
void NativeMessagingReaderTest::Run() {
// Close the write-end, so the reader doesn't block waiting for more data.
- base::ClosePlatformFile(write_handle_);
+ write_file_.Close();
// base::Unretained is safe since no further tasks can run after
// RunLoop::Run() returns.
@@ -88,8 +82,7 @@ void NativeMessagingReaderTest::WriteMessage(std::string message) {
}
void NativeMessagingReaderTest::WriteData(const char* data, int length) {
- int written = base::WritePlatformFileAtCurrentPos(write_handle_, data,
- length);
+ int written = write_file_.WriteAtCurrentPos(data, length);
ASSERT_EQ(length, written);
}
diff --git a/remoting/host/native_messaging/native_messaging_writer.cc b/remoting/host/native_messaging/native_messaging_writer.cc
index fdfc25a..3266fdb7 100644
--- a/remoting/host/native_messaging/native_messaging_writer.cc
+++ b/remoting/host/native_messaging/native_messaging_writer.cc
@@ -29,8 +29,8 @@ const size_t kMaximumMessageSize = 1024 * 1024;
namespace remoting {
-NativeMessagingWriter::NativeMessagingWriter(base::PlatformFile handle)
- : write_stream_(handle),
+NativeMessagingWriter::NativeMessagingWriter(base::File file)
+ : write_stream_(file.Pass()),
fail_(false) {
}
diff --git a/remoting/host/native_messaging/native_messaging_writer.h b/remoting/host/native_messaging/native_messaging_writer.h
index 560707a..41f60bf 100644
--- a/remoting/host/native_messaging/native_messaging_writer.h
+++ b/remoting/host/native_messaging/native_messaging_writer.h
@@ -6,7 +6,6 @@
#define REMOTING_HOST_NATIVE_MESSAGING_NATIVE_MESSAGING_WRITER_H_
#include "base/files/file.h"
-#include "base/platform_file.h"
namespace base {
class Value;
@@ -18,7 +17,7 @@ namespace remoting {
// webapp.
class NativeMessagingWriter {
public:
- explicit NativeMessagingWriter(base::PlatformFile handle);
+ explicit NativeMessagingWriter(base::File file);
~NativeMessagingWriter();
// Sends a message to the Native Messaging client, returning true if
diff --git a/remoting/host/native_messaging/native_messaging_writer_unittest.cc b/remoting/host/native_messaging/native_messaging_writer_unittest.cc
index 52bdb1f..be7f2f0 100644
--- a/remoting/host/native_messaging/native_messaging_writer_unittest.cc
+++ b/remoting/host/native_messaging/native_messaging_writer_unittest.cc
@@ -21,13 +21,11 @@ class NativeMessagingWriterTest : public testing::Test {
virtual ~NativeMessagingWriterTest();
virtual void SetUp() OVERRIDE;
- virtual void TearDown() OVERRIDE;
protected:
scoped_ptr<NativeMessagingWriter> writer_;
- base::PlatformFile read_handle_;
- base::PlatformFile write_handle_;
- bool read_handle_open_;
+ base::File read_file_;
+ base::File write_file_;
};
NativeMessagingWriterTest::NativeMessagingWriterTest() {}
@@ -35,17 +33,8 @@ NativeMessagingWriterTest::NativeMessagingWriterTest() {}
NativeMessagingWriterTest::~NativeMessagingWriterTest() {}
void NativeMessagingWriterTest::SetUp() {
- ASSERT_TRUE(MakePipe(&read_handle_, &write_handle_));
- writer_.reset(new NativeMessagingWriter(write_handle_));
- read_handle_open_ = true;
-}
-
-void NativeMessagingWriterTest::TearDown() {
- // |write_handle_| is owned by NativeMessagingWriter's FileStream, so don't
- // try to close it here. And close |read_handle_| only if it hasn't
- // already been closed.
- if (read_handle_open_)
- base::ClosePlatformFile(read_handle_);
+ ASSERT_TRUE(MakePipe(&read_file_, &write_file_));
+ writer_.reset(new NativeMessagingWriter(write_file_.Pass()));
}
TEST_F(NativeMessagingWriterTest, GoodMessage) {
@@ -55,12 +44,10 @@ TEST_F(NativeMessagingWriterTest, GoodMessage) {
// Read from the pipe and verify the content.
uint32 length;
- int read = base::ReadPlatformFileAtCurrentPos(
- read_handle_, reinterpret_cast<char*>(&length), 4);
+ int read = read_file_.ReadAtCurrentPos(reinterpret_cast<char*>(&length), 4);
EXPECT_EQ(4, read);
std::string content(length, '\0');
- read = base::ReadPlatformFileAtCurrentPos(read_handle_,
- string_as_array(&content), length);
+ read = read_file_.ReadAtCurrentPos(string_as_array(&content), length);
EXPECT_EQ(static_cast<int>(length), read);
// |content| should now contain serialized |message|.
@@ -71,7 +58,7 @@ TEST_F(NativeMessagingWriterTest, GoodMessage) {
// and verify the read end immediately hits EOF.
writer_.reset(NULL);
char unused;
- read = base::ReadPlatformFileAtCurrentPos(read_handle_, &unused, 1);
+ read = read_file_.ReadAtCurrentPos(&unused, 1);
EXPECT_LE(read, 0);
}
@@ -88,13 +75,10 @@ TEST_F(NativeMessagingWriterTest, SecondMessage) {
int read;
std::string content;
for (int i = 0; i < 2; i++) {
- read = base::ReadPlatformFileAtCurrentPos(
- read_handle_, reinterpret_cast<char*>(&length), 4);
+ read = read_file_.ReadAtCurrentPos(reinterpret_cast<char*>(&length), 4);
EXPECT_EQ(4, read) << "i = " << i;
content.resize(length);
- read = base::ReadPlatformFileAtCurrentPos(read_handle_,
- string_as_array(&content),
- length);
+ read = read_file_.ReadAtCurrentPos(string_as_array(&content), length);
EXPECT_EQ(static_cast<int>(length), read) << "i = " << i;
}
@@ -105,8 +89,7 @@ TEST_F(NativeMessagingWriterTest, SecondMessage) {
TEST_F(NativeMessagingWriterTest, FailedWrite) {
// Close the read end so that writing fails immediately.
- base::ClosePlatformFile(read_handle_);
- read_handle_open_ = false;
+ read_file_.Close();
base::DictionaryValue message;
EXPECT_FALSE(writer_->WriteMessage(message));