| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | 5 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 if (closed_ || read_eof_) | 190 if (closed_ || read_eof_) |
| 191 return; | 191 return; |
| 192 | 192 |
| 193 DCHECK(!read_pending_); | 193 DCHECK(!read_pending_); |
| 194 | 194 |
| 195 // On POSIX FileStream::Read() uses blocking thread pool, so it's better to | 195 // On POSIX FileStream::Read() uses blocking thread pool, so it's better to |
| 196 // wait for the file to become readable before calling DoRead(). Otherwise it | 196 // wait for the file to become readable before calling DoRead(). Otherwise it |
| 197 // would always be consuming one thread in the thread pool. On Windows | 197 // would always be consuming one thread in the thread pool. On Windows |
| 198 // FileStream uses overlapped IO, so that optimization isn't necessary there. | 198 // FileStream uses overlapped IO, so that optimization isn't necessary there. |
| 199 #if defined(OS_POSIX) | 199 #if defined(OS_POSIX) |
| 200 MessageLoopForIO::current()->WatchFileDescriptor( | 200 base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 201 read_file_, false /* persistent */, MessageLoopForIO::WATCH_READ, | 201 read_file_, false /* persistent */, base::MessageLoopForIO::WATCH_READ, |
| 202 &read_watcher_, this); | 202 &read_watcher_, this); |
| 203 #else // defined(OS_POSIX) | 203 #else // defined(OS_POSIX) |
| 204 DoRead(); | 204 DoRead(); |
| 205 #endif // defined(!OS_POSIX) | 205 #endif // defined(!OS_POSIX) |
| 206 } | 206 } |
| 207 | 207 |
| 208 void NativeMessageProcessHost::DoRead() { | 208 void NativeMessageProcessHost::DoRead() { |
| 209 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 209 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 210 | 210 |
| 211 while (!closed_ && !read_eof_ && !read_pending_) { | 211 while (!closed_ && !read_eof_ && !read_pending_) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 closed_ = true; | 330 closed_ = true; |
| 331 read_stream_.reset(); | 331 read_stream_.reset(); |
| 332 write_stream_.reset(); | 332 write_stream_.reset(); |
| 333 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 333 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 334 base::Bind(&Client::CloseChannel, weak_client_ui_, | 334 base::Bind(&Client::CloseChannel, weak_client_ui_, |
| 335 destination_port_, error_message)); | 335 destination_port_, error_message)); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 } // namespace extensions | 339 } // namespace extensions |
| OLD | NEW |