summaryrefslogtreecommitdiffstats
path: root/remoting/host
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
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')
-rw-r--r--remoting/host/it2me/it2me_native_messaging_host_main.cc11
-rw-r--r--remoting/host/it2me/it2me_native_messaging_host_unittest.cc40
-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
-rw-r--r--remoting/host/setup/me2me_native_messaging_host.cc3
-rw-r--r--remoting/host/setup/me2me_native_messaging_host_main.cc27
-rw-r--r--remoting/host/setup/me2me_native_messaging_host_unittest.cc45
-rw-r--r--remoting/host/setup/test_util.cc16
-rw-r--r--remoting/host/setup/test_util.h9
15 files changed, 118 insertions, 137 deletions
diff --git a/remoting/host/it2me/it2me_native_messaging_host_main.cc b/remoting/host/it2me/it2me_native_messaging_host_main.cc
index 77d91a2..1483e04 100644
--- a/remoting/host/it2me/it2me_native_messaging_host_main.cc
+++ b/remoting/host/it2me/it2me_native_messaging_host_main.cc
@@ -81,8 +81,8 @@ int StartIt2MeNativeMessagingHost() {
// the hosting executable specifies "Windows" subsystem. However the returned
// handles are invalid in that case unless standard input and output are
// redirected to a pipe or file.
- base::PlatformFile read_file = GetStdHandle(STD_INPUT_HANDLE);
- base::PlatformFile write_file = GetStdHandle(STD_OUTPUT_HANDLE);
+ base::File read_file(GetStdHandle(STD_INPUT_HANDLE));
+ base::File write_file(GetStdHandle(STD_OUTPUT_HANDLE));
// After the native messaging channel starts the native messaging reader
// will keep doing blocking read operations on the input named pipe.
@@ -95,8 +95,9 @@ int StartIt2MeNativeMessagingHost() {
SetStdHandle(STD_INPUT_HANDLE, NULL);
SetStdHandle(STD_OUTPUT_HANDLE, NULL);
#elif defined(OS_POSIX)
- base::PlatformFile read_file = STDIN_FILENO;
- base::PlatformFile write_file = STDOUT_FILENO;
+ // The files are automatically closed.
+ base::File read_file(STDIN_FILENO);
+ base::File write_file(STDOUT_FILENO);
#else
#error Not implemented.
#endif
@@ -112,7 +113,7 @@ int StartIt2MeNativeMessagingHost() {
// Set up the native messaging channel.
scoped_ptr<NativeMessagingChannel> channel(
- new NativeMessagingChannel(read_file, write_file));
+ new NativeMessagingChannel(read_file.Pass(), write_file.Pass()));
scoped_ptr<It2MeNativeMessagingHost> host(
new It2MeNativeMessagingHost(
diff --git a/remoting/host/it2me/it2me_native_messaging_host_unittest.cc b/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
index 76389d17..b438b96 100644
--- a/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
+++ b/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
@@ -192,13 +192,13 @@ class It2MeNativeMessagingHostTest : public testing::Test {
void ExitTest();
// Each test creates two unidirectional pipes: "input" and "output".
- // It2MeNativeMessagingHost reads from input_read_handle and writes to
- // output_write_handle. The unittest supplies data to input_write_handle, and
+ // It2MeNativeMessagingHost reads from input_read_file and writes to
+ // output_write_file. The unittest supplies data to input_write_handle, and
// verifies output from output_read_handle.
//
// unittest -> [input] -> It2MeNativeMessagingHost -> [output] -> unittest
- base::PlatformFile input_write_handle_;
- base::PlatformFile output_read_handle_;
+ base::File input_write_file_;
+ base::File output_read_file_;
// Message loop of the test thread.
scoped_ptr<base::MessageLoop> test_message_loop_;
@@ -239,7 +239,7 @@ void It2MeNativeMessagingHostTest::SetUp() {
void It2MeNativeMessagingHostTest::TearDown() {
// Closing the write-end of the input will send an EOF to the native
// messaging reader. This will trigger a host shutdown.
- base::ClosePlatformFile(input_write_handle_);
+ input_write_file_.Close();
// Start a new RunLoop and Wait until the host finishes shutting down.
test_run_loop_.reset(new base::RunLoop());
@@ -250,23 +250,23 @@ void It2MeNativeMessagingHostTest::TearDown() {
EXPECT_FALSE(response);
// The It2MeNativeMessagingHost dtor closes the handles that are passed to it.
- // So the only handle left to close is |output_read_handle_|.
- base::ClosePlatformFile(output_read_handle_);
+ // So the only handle left to close is |output_read_file_|.
+ output_read_file_.Close();
}
scoped_ptr<base::DictionaryValue>
It2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() {
uint32 length;
- int read_result = base::ReadPlatformFileAtCurrentPos(
- output_read_handle_, reinterpret_cast<char*>(&length), sizeof(length));
+ int read_result = output_read_file_.ReadAtCurrentPos(
+ reinterpret_cast<char*>(&length), sizeof(length));
if (read_result != sizeof(length)) {
// The output pipe has been closed, return an empty message.
return scoped_ptr<base::DictionaryValue>();
}
std::string message_json(length, '\0');
- read_result = base::ReadPlatformFileAtCurrentPos(
- output_read_handle_, string_as_array(&message_json), length);
+ read_result = output_read_file_.ReadAtCurrentPos(
+ string_as_array(&message_json), length);
if (read_result != static_cast<int>(length)) {
LOG(ERROR) << "Message size (" << read_result
<< ") doesn't match the header (" << length << ").";
@@ -289,10 +289,9 @@ void It2MeNativeMessagingHostTest::WriteMessageToInputPipe(
base::JSONWriter::Write(&message, &message_json);
uint32 length = message_json.length();
- base::WritePlatformFileAtCurrentPos(
- input_write_handle_, reinterpret_cast<char*>(&length), sizeof(length));
- base::WritePlatformFileAtCurrentPos(
- input_write_handle_, message_json.data(), length);
+ input_write_file_.WriteAtCurrentPos(reinterpret_cast<char*>(&length),
+ sizeof(length));
+ input_write_file_.WriteAtCurrentPos(message_json.data(), length);
}
void It2MeNativeMessagingHostTest::VerifyHelloResponse(int request_id) {
@@ -423,17 +422,18 @@ void It2MeNativeMessagingHostTest::TestBadRequest(const base::Value& message,
void It2MeNativeMessagingHostTest::StartHost() {
DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
- base::PlatformFile input_read_handle;
- base::PlatformFile output_write_handle;
+ base::File input_read_file;
+ base::File output_write_file;
- ASSERT_TRUE(MakePipe(&input_read_handle, &input_write_handle_));
- ASSERT_TRUE(MakePipe(&output_read_handle_, &output_write_handle));
+ ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_));
+ ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file));
// Creating a native messaging host with a mock It2MeHostFactory.
scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory());
scoped_ptr<NativeMessagingChannel> channel(
- new NativeMessagingChannel(input_read_handle, output_write_handle));
+ new NativeMessagingChannel(input_read_file.Pass(),
+ output_write_file.Pass()));
host_.reset(
new It2MeNativeMessagingHost(
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));
diff --git a/remoting/host/setup/me2me_native_messaging_host.cc b/remoting/host/setup/me2me_native_messaging_host.cc
index b7183b0..72076db 100644
--- a/remoting/host/setup/me2me_native_messaging_host.cc
+++ b/remoting/host/setup/me2me_native_messaging_host.cc
@@ -661,7 +661,8 @@ void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() {
// Set up the native messaging channel to talk to the elevated host.
// Note that input for the elevate channel is output forthe elevated host.
elevated_channel_.reset(new NativeMessagingChannel(
- delegate_read_handle.Take(), delegate_write_handle.Take()));
+ base::File(delegate_read_handle.Take()),
+ base::File(delegate_write_handle.Take())));
elevated_channel_->Start(
base::Bind(&Me2MeNativeMessagingHost::ProcessDelegateResponse, weak_ptr_),
diff --git a/remoting/host/setup/me2me_native_messaging_host_main.cc b/remoting/host/setup/me2me_native_messaging_host_main.cc
index 5e0e0e2..8cf6566 100644
--- a/remoting/host/setup/me2me_native_messaging_host_main.cc
+++ b/remoting/host/setup/me2me_native_messaging_host_main.cc
@@ -102,8 +102,8 @@ int StartMe2MeNativeMessagingHost() {
}
}
- base::PlatformFile read_file;
- base::PlatformFile write_file;
+ base::File read_file;
+ base::File write_file;
bool needs_elevation = false;
#if defined(OS_WIN)
@@ -126,19 +126,19 @@ int StartMe2MeNativeMessagingHost() {
command_line->GetSwitchValueNative(kOutputSwitchName);
// A NULL SECURITY_ATTRIBUTES signifies that the handle can't be inherited
- read_file = CreateFile(
+ read_file = base::File(CreateFile(
input_pipe_name.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
- if (read_file == INVALID_HANDLE_VALUE) {
+ FILE_ATTRIBUTE_NORMAL, NULL));
+ if (!read_file.IsValid()) {
LOG_GETLASTERROR(ERROR) <<
"CreateFile failed on '" << input_pipe_name << "'";
return kInitializationFailed;
}
- write_file = CreateFile(
+ write_file = base::File(CreateFile(
output_pipe_name.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
- if (write_file == INVALID_HANDLE_VALUE) {
+ FILE_ATTRIBUTE_NORMAL, NULL));
+ if (!write_file.IsValid()) {
LOG_GETLASTERROR(ERROR) <<
"CreateFile failed on '" << output_pipe_name << "'";
return kInitializationFailed;
@@ -148,8 +148,8 @@ int StartMe2MeNativeMessagingHost() {
// the hosting executable specifies "Windows" subsystem. However the
// returned handles are invalid in that case unless standard input and
// output are redirected to a pipe or file.
- read_file = GetStdHandle(STD_INPUT_HANDLE);
- write_file = GetStdHandle(STD_OUTPUT_HANDLE);
+ read_file = base::File(GetStdHandle(STD_INPUT_HANDLE));
+ write_file = base::File(GetStdHandle(STD_OUTPUT_HANDLE));
// After the native messaging channel starts the native messaging reader
// will keep doing blocking read operations on the input named pipe.
@@ -163,8 +163,9 @@ int StartMe2MeNativeMessagingHost() {
SetStdHandle(STD_OUTPUT_HANDLE, NULL);
}
#elif defined(OS_POSIX)
- read_file = STDIN_FILENO;
- write_file = STDOUT_FILENO;
+ // The files will be automatically closed.
+ read_file = base::File(STDIN_FILENO);
+ write_file = base::File(STDOUT_FILENO);
#else
#error Not implemented.
#endif
@@ -229,7 +230,7 @@ int StartMe2MeNativeMessagingHost() {
// Set up the native messaging channel.
scoped_ptr<NativeMessagingChannel> channel(
- new NativeMessagingChannel(read_file, write_file));
+ new NativeMessagingChannel(read_file.Pass(), write_file.Pass()));
// Create the native messaging host.
scoped_ptr<Me2MeNativeMessagingHost> host(
diff --git a/remoting/host/setup/me2me_native_messaging_host_unittest.cc b/remoting/host/setup/me2me_native_messaging_host_unittest.cc
index 0d0f2af..65ba402 100644
--- a/remoting/host/setup/me2me_native_messaging_host_unittest.cc
+++ b/remoting/host/setup/me2me_native_messaging_host_unittest.cc
@@ -251,12 +251,12 @@ class Me2MeNativeMessagingHostTest : public testing::Test {
// Each test creates two unidirectional pipes: "input" and "output".
// Me2MeNativeMessagingHost reads from input_read_handle and writes to
- // output_write_handle. The unittest supplies data to input_write_handle, and
+ // output_write_file. The unittest supplies data to input_write_handle, and
// verifies output from output_read_handle.
//
// unittest -> [input] -> Me2MeNativeMessagingHost -> [output] -> unittest
- base::PlatformFile input_write_handle_;
- base::PlatformFile output_read_handle_;
+ base::File input_write_file_;
+ base::File output_read_file_;
// Message loop of the test thread.
scoped_ptr<base::MessageLoop> test_message_loop_;
@@ -277,11 +277,11 @@ Me2MeNativeMessagingHostTest::Me2MeNativeMessagingHostTest() {}
Me2MeNativeMessagingHostTest::~Me2MeNativeMessagingHostTest() {}
void Me2MeNativeMessagingHostTest::SetUp() {
- base::PlatformFile input_read_handle;
- base::PlatformFile output_write_handle;
+ base::File input_read_file;
+ base::File output_write_file;
- ASSERT_TRUE(MakePipe(&input_read_handle, &input_write_handle_));
- ASSERT_TRUE(MakePipe(&output_read_handle_, &output_write_handle));
+ ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_));
+ ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file));
test_message_loop_.reset(new base::MessageLoop());
test_run_loop_.reset(new base::RunLoop());
@@ -308,11 +308,11 @@ void Me2MeNativeMessagingHostTest::SetUp() {
void Me2MeNativeMessagingHostTest::StartHost() {
DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
- base::PlatformFile input_read_handle;
- base::PlatformFile output_write_handle;
+ base::File input_read_file;
+ base::File output_write_file;
- ASSERT_TRUE(MakePipe(&input_read_handle, &input_write_handle_));
- ASSERT_TRUE(MakePipe(&output_read_handle_, &output_write_handle));
+ ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_));
+ ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file));
daemon_controller_delegate_ = new MockDaemonControllerDelegate();
scoped_refptr<DaemonController> daemon_controller(
@@ -324,7 +324,8 @@ void Me2MeNativeMessagingHostTest::StartHost() {
new MockPairingRegistryDelegate()));
scoped_ptr<NativeMessagingChannel> channel(
- new NativeMessagingChannel(input_read_handle, output_write_handle));
+ new NativeMessagingChannel(input_read_file.Pass(),
+ output_write_file.Pass()));
host_.reset(new Me2MeNativeMessagingHost(
false,
@@ -367,7 +368,7 @@ void Me2MeNativeMessagingHostTest::ExitTest() {
void Me2MeNativeMessagingHostTest::TearDown() {
// Closing the write-end of the input will send an EOF to the native
// messaging reader. This will trigger a host shutdown.
- base::ClosePlatformFile(input_write_handle_);
+ input_write_file_.Close();
// Start a new RunLoop and Wait until the host finishes shutting down.
test_run_loop_.reset(new base::RunLoop());
@@ -378,22 +379,22 @@ void Me2MeNativeMessagingHostTest::TearDown() {
EXPECT_FALSE(response);
// The It2MeMe2MeNativeMessagingHost dtor closes the handles that are passed
- // to it. So the only handle left to close is |output_read_handle_|.
- base::ClosePlatformFile(output_read_handle_);
+ // to it. So the only handle left to close is |output_read_file_|.
+ output_read_file_.Close();
}
scoped_ptr<base::DictionaryValue>
Me2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() {
uint32 length;
- int read_result = base::ReadPlatformFileAtCurrentPos(
- output_read_handle_, reinterpret_cast<char*>(&length), sizeof(length));
+ int read_result = output_read_file_.ReadAtCurrentPos(
+ reinterpret_cast<char*>(&length), sizeof(length));
if (read_result != sizeof(length)) {
return scoped_ptr<base::DictionaryValue>();
}
std::string message_json(length, '\0');
- read_result = base::ReadPlatformFileAtCurrentPos(
- output_read_handle_, string_as_array(&message_json), length);
+ read_result = output_read_file_.ReadAtCurrentPos(
+ string_as_array(&message_json), length);
if (read_result != static_cast<int>(length)) {
return scoped_ptr<base::DictionaryValue>();
}
@@ -413,11 +414,9 @@ void Me2MeNativeMessagingHostTest::WriteMessageToInputPipe(
base::JSONWriter::Write(&message, &message_json);
uint32 length = message_json.length();
- base::WritePlatformFileAtCurrentPos(input_write_handle_,
- reinterpret_cast<char*>(&length),
+ input_write_file_.WriteAtCurrentPos(reinterpret_cast<char*>(&length),
sizeof(length));
- base::WritePlatformFileAtCurrentPos(input_write_handle_, message_json.data(),
- length);
+ input_write_file_.WriteAtCurrentPos(message_json.data(), length);
}
void Me2MeNativeMessagingHostTest::TestBadRequest(const base::Value& message) {
diff --git a/remoting/host/setup/test_util.cc b/remoting/host/setup/test_util.cc
index 9266c74..51c610b 100644
--- a/remoting/host/setup/test_util.cc
+++ b/remoting/host/setup/test_util.cc
@@ -12,15 +12,21 @@
namespace remoting {
-bool MakePipe(base::PlatformFile* read_handle,
- base::PlatformFile* write_handle) {
+bool MakePipe(base::File* read_file,
+ base::File* write_file) {
#if defined(OS_WIN)
- return CreatePipe(read_handle, write_handle, NULL, 0) != FALSE;
+ base::PlatformFile read_handle;
+ base::PlatformFile write_handle;
+ if (!CreatePipe(&read_handle, &write_handle, NULL, 0))
+ return false;
+ *read_file = base::File(read_handle);
+ *write_file = base::File(write_handle);
+ return true;
#elif defined(OS_POSIX)
int fds[2];
if (pipe(fds) == 0) {
- *read_handle = fds[0];
- *write_handle = fds[1];
+ *read_file = base::File(fds[0]);
+ *write_file = base::File(fds[1]);
return true;
}
return false;
diff --git a/remoting/host/setup/test_util.h b/remoting/host/setup/test_util.h
index 77a46ab..8a40f5b 100644
--- a/remoting/host/setup/test_util.h
+++ b/remoting/host/setup/test_util.h
@@ -5,15 +5,14 @@
#ifndef REMOTING_HOST_SETUP_TEST_UTIL_H_
#define REMOTING_HOST_SETUP_TEST_UTIL_H_
-#include "base/platform_file.h"
+#include "base/files/file.h"
namespace remoting {
// Creates an anonymous, unidirectional pipe, returning true if successful. On
-// success, the caller is responsible for closing both ends using
-// base::ClosePlatformFile().
-bool MakePipe(base::PlatformFile* read_handle,
- base::PlatformFile* write_handle);
+// success, the receives ownership of both files.
+bool MakePipe(base::File* read_file,
+ base::File* write_file);
} // namespace remoting