diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-07 05:55:24 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-07 05:55:24 +0000 |
commit | 86993fd909ed30038f66c87fdee8b1d44e30012b (patch) | |
tree | c54d78fac1243408065cac47cbca96033f4167f7 /remoting/host/native_messaging | |
parent | 86f1b1b8c96acf72701d03898bb877db215aa653 (diff) | |
download | chromium_src-86993fd909ed30038f66c87fdee8b1d44e30012b.zip chromium_src-86993fd909ed30038f66c87fdee8b1d44e30012b.tar.gz chromium_src-86993fd909ed30038f66c87fdee8b1d44e30012b.tar.bz2 |
Stop using FileStream synchronously in remoting/host/native_messaging
FileStream will drop support of synchronous methods.
Use base::File instead.
BUG=351823
TEST=remoting_unittests
Review URL: https://codereview.chromium.org/225553003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/native_messaging')
4 files changed, 14 insertions, 40 deletions
diff --git a/remoting/host/native_messaging/native_messaging_reader.cc b/remoting/host/native_messaging/native_messaging_reader.cc index 031daf7..30f307b 100644 --- a/remoting/host/native_messaging/native_messaging_reader.cc +++ b/remoting/host/native_messaging/native_messaging_reader.cc @@ -7,6 +7,7 @@ #include <string> #include "base/bind.h" +#include "base/files/file.h" #include "base/json/json_reader.h" #include "base/location.h" #include "base/sequenced_task_runner.h" @@ -15,7 +16,6 @@ #include "base/thread_task_runner_handle.h" #include "base/threading/sequenced_worker_pool.h" #include "base/values.h" -#include "net/base/file_stream.h" namespace { @@ -49,7 +49,7 @@ class NativeMessagingReader::Core { // Notify the reader's EOF callback when an error occurs or EOF is reached. void NotifyEof(); - net::FileStream read_stream_; + base::File read_stream_; base::WeakPtr<NativeMessagingReader> reader_; @@ -67,7 +67,7 @@ NativeMessagingReader::Core::Core( scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, scoped_refptr<base::SequencedTaskRunner> read_task_runner, base::WeakPtr<NativeMessagingReader> reader) - : read_stream_(handle, base::PLATFORM_FILE_READ, NULL), + : read_stream_(handle), reader_(reader), caller_task_runner_(caller_task_runner), read_task_runner_(read_task_runner) { @@ -81,7 +81,7 @@ void NativeMessagingReader::Core::ReadMessage() { // Keep reading messages until the stream is closed or an error occurs. while (true) { MessageLengthType message_length; - int read_result = read_stream_.ReadUntilComplete( + int read_result = read_stream_.ReadAtCurrentPos( reinterpret_cast<char*>(&message_length), kMessageHeaderSize); if (read_result != kMessageHeaderSize) { // 0 means EOF which is normal and should not be logged as an error. @@ -100,8 +100,8 @@ void NativeMessagingReader::Core::ReadMessage() { } std::string message_json(message_length, '\0'); - read_result = read_stream_.ReadUntilComplete(string_as_array(&message_json), - message_length); + read_result = read_stream_.ReadAtCurrentPos(string_as_array(&message_json), + message_length); if (read_result != static_cast<int>(message_length)) { LOG(ERROR) << "Failed to read message body, read returned " << read_result; diff --git a/remoting/host/native_messaging/native_messaging_reader.h b/remoting/host/native_messaging/native_messaging_reader.h index 06eb4cc..a9e2047 100644 --- a/remoting/host/native_messaging/native_messaging_reader.h +++ b/remoting/host/native_messaging/native_messaging_reader.h @@ -17,10 +17,6 @@ class SequencedTaskRunner; class Value; } // namespace base -namespace net { -class FileStream; -} // namespace net - namespace remoting { // This class is used for reading messages from the Native Messaging client @@ -50,7 +46,7 @@ class NativeMessagingReader { void InvokeEofCallback(); // Holds the information that the read thread needs to access, such as the - // FileStream, and the TaskRunner used for posting notifications back to this + // File, and the TaskRunner used for posting notifications back to this // class. scoped_ptr<Core> core_; diff --git a/remoting/host/native_messaging/native_messaging_writer.cc b/remoting/host/native_messaging/native_messaging_writer.cc index 9788f21..fdfc25a 100644 --- a/remoting/host/native_messaging/native_messaging_writer.cc +++ b/remoting/host/native_messaging/native_messaging_writer.cc @@ -25,33 +25,12 @@ const int kMessageHeaderSize = sizeof(MessageLengthType); // result of std::string::length() without compiler warnings. const size_t kMaximumMessageSize = 1024 * 1024; -// Performs the same task as FileStream::WriteSync(), but ensures that exactly -// |buffer_length| bytes are written. Unlike WriteSync(), a partial write may -// only occur as a result of end-of-file or fatal error. Returns the number of -// bytes written (buffer_length) or an error-code <= 0. -// -// TODO(lambroslambrou): Add this method to net::FileStream, with unit-tests. -// See http://crbug.com/232202. -int WriteUntilComplete(net::FileStream* out, - const char* buffer, int buffer_length) { - int written = 0; - while (written < buffer_length) { - int result = out->WriteSync(buffer + written, buffer_length - written); - if (result <= 0) { - return result; - } - DCHECK_LE(result, buffer_length - written); - written += result; - } - return written; -} - } // namespace namespace remoting { NativeMessagingWriter::NativeMessagingWriter(base::PlatformFile handle) - : write_stream_(handle, base::PLATFORM_FILE_WRITE, NULL), + : write_stream_(handle), fail_(false) { } @@ -74,9 +53,8 @@ bool NativeMessagingWriter::WriteMessage(const base::Value& message) { MessageLengthType message_length = static_cast<MessageLengthType>(message_json.length()); - int result = WriteUntilComplete( - &write_stream_, reinterpret_cast<char*>(&message_length), - kMessageHeaderSize); + int result = write_stream_.WriteAtCurrentPos( + reinterpret_cast<char*>(&message_length), kMessageHeaderSize); if (result != kMessageHeaderSize) { LOG(ERROR) << "Failed to send message header, write returned " << result; fail_ = true; @@ -89,8 +67,8 @@ bool NativeMessagingWriter::WriteMessage(const base::Value& message) { // CHECK needed since data() is undefined on an empty std::string. CHECK(!message_json.empty()); - result = WriteUntilComplete(&write_stream_, message_json.data(), - message_length_as_int); + result = write_stream_.WriteAtCurrentPos(message_json.data(), + message_length_as_int); if (result != message_length_as_int) { LOG(ERROR) << "Failed to send message body, write returned " << result; fail_ = true; diff --git a/remoting/host/native_messaging/native_messaging_writer.h b/remoting/host/native_messaging/native_messaging_writer.h index 6208f91..560707a 100644 --- a/remoting/host/native_messaging/native_messaging_writer.h +++ b/remoting/host/native_messaging/native_messaging_writer.h @@ -5,8 +5,8 @@ #ifndef REMOTING_HOST_NATIVE_MESSAGING_NATIVE_MESSAGING_WRITER_H_ #define REMOTING_HOST_NATIVE_MESSAGING_NATIVE_MESSAGING_WRITER_H_ +#include "base/files/file.h" #include "base/platform_file.h" -#include "net/base/file_stream.h" namespace base { class Value; @@ -26,7 +26,7 @@ class NativeMessagingWriter { bool WriteMessage(const base::Value& message); private: - net::FileStream write_stream_; + base::File write_stream_; bool fail_; DISALLOW_COPY_AND_ASSIGN(NativeMessagingWriter); |