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

Unified Diff: chrome/browser/extensions/api/messaging/native_message_process_host.cc

Issue 323683002: net: FileStream cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comments, fix init typo Created 6 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/messaging/native_message_process_host.cc
diff --git a/chrome/browser/extensions/api/messaging/native_message_process_host.cc b/chrome/browser/extensions/api/messaging/native_message_process_host.cc
index b4993dc5c8c770a607d03c9b9f529b9176e49ce8..15b02ec4489ebcbb5c93e59358973c2963f3f2d9 100644
--- a/chrome/browser/extensions/api/messaging/native_message_process_host.cc
+++ b/chrome/browser/extensions/api/messaging/native_message_process_host.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/logging.h"
-#include "base/platform_file.h"
#include "base/prefs/pref_service.h"
#include "base/process/kill.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -102,13 +101,11 @@ NativeMessageProcessHost::NativeMessageProcessHost(
native_host_name_(native_host_name),
destination_port_(destination_port),
launcher_(launcher.Pass()),
- closed_(false),
process_handle_(base::kNullProcessHandle),
-#if defined(OS_POSIX)
- read_file_(base::kInvalidPlatformFileValue),
-#endif
+ closed_(false),
read_pending_(false),
- write_pending_(false) {
+ write_pending_(false),
+ direct_read_for_test_(false) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// It's safe to use base::Unretained() here because NativeMessagePort always
@@ -188,10 +185,6 @@ void NativeMessageProcessHost::OnHostProcessLaunched(
}
process_handle_ = process_handle;
-#if defined(OS_POSIX)
- // This object is not the owner of the file so it should not keep an fd.
- read_file_ = read_file.GetPlatformFile();
-#endif
scoped_refptr<base::TaskRunner> task_runner(
content::BrowserThread::GetBlockingPool()->
@@ -230,19 +223,8 @@ void NativeMessageProcessHost::Send(const std::string& json) {
DoWrite();
}
-#if defined(OS_POSIX)
-void NativeMessageProcessHost::OnFileCanReadWithoutBlocking(int fd) {
- DCHECK_EQ(fd, read_file_);
- DoRead();
-}
-
-void NativeMessageProcessHost::OnFileCanWriteWithoutBlocking(int fd) {
- NOTREACHED();
-}
-#endif // !defined(OS_POSIX)
-
-void NativeMessageProcessHost::ReadNowForTesting() {
- DoRead();
+void NativeMessageProcessHost::DontWaitToReadForTesting() {
+ direct_read_for_test_ = true;
}
void NativeMessageProcessHost::WaitRead() {
@@ -250,18 +232,7 @@ void NativeMessageProcessHost::WaitRead() {
return;
DCHECK(!read_pending_);
-
- // On POSIX FileStream::Read() uses blocking thread pool, so it's better to
- // wait for the file to become readable before calling DoRead(). Otherwise it
- // would always be consuming one thread in the thread pool. On Windows
- // FileStream uses overlapped IO, so that optimization isn't necessary there.
-#if defined(OS_POSIX)
- base::MessageLoopForIO::current()->WatchFileDescriptor(
- read_file_, false /* persistent */,
- base::MessageLoopForIO::WATCH_READ, &read_watcher_, this);
-#else // defined(OS_POSIX)
DoRead();
-#endif // defined(!OS_POSIX)
}
void NativeMessageProcessHost::DoRead() {
@@ -269,10 +240,20 @@ void NativeMessageProcessHost::DoRead() {
while (!closed_ && !read_pending_) {
read_buffer_ = new net::IOBuffer(kReadBufferSize);
- int result = read_stream_->Read(
- read_buffer_.get(),
- kReadBufferSize,
- base::Bind(&NativeMessageProcessHost::OnRead, base::Unretained(this)));
+ int result;
+ if (direct_read_for_test_) {
+ result = read_stream_->Read(
+ read_buffer_.get(),
+ kReadBufferSize,
+ base::Bind(&NativeMessageProcessHost::OnRead,
+ base::Unretained(this)));
+ } else {
+ result = read_stream_->ReadNonBlocking(
+ read_buffer_.get(),
+ kReadBufferSize,
+ base::Bind(&NativeMessageProcessHost::OnRead,
+ base::Unretained(this)));
+ }
HandleReadResult(result);
}
}

Powered by Google App Engine
This is Rietveld 408576698