| 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 <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 void NativeMessageProcessHost::ReadNowForTesting() { | 15 void NativeMessageProcessHost::ReadNowForTesting() { |
| 16 OnFileCanReadWithoutBlocking(read_file_); | 16 OnFileCanReadWithoutBlocking(read_file_); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void NativeMessageProcessHost::InitIO() { | 19 void NativeMessageProcessHost::InitIO() { |
| 20 // Always watch the read end. | 20 // Always watch the read end. |
| 21 MessageLoopForIO::current()->WatchFileDescriptor(read_file_, | 21 MessageLoopForIO::current()->WatchFileDescriptor(read_file_, |
| 22 true, /* persistent */ | 22 true, /* persistent */ |
| 23 MessageLoopForIO::WATCH_READ, | 23 MessageLoopForIO::WATCH_READ, |
| 24 &read_watcher_, | 24 &read_watcher_, |
| 25 this); | 25 this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void NativeMessageProcessHost::StopIO() { |
| 29 } |
| 30 |
| 28 void NativeMessageProcessHost::OnFileCanReadWithoutBlocking(int fd) { | 31 void NativeMessageProcessHost::OnFileCanReadWithoutBlocking(int fd) { |
| 29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 30 | 33 |
| 31 // Make sure that the fd given to us is the same one we started with. | 34 // Make sure that the fd given to us is the same one we started with. |
| 32 CHECK_EQ(fd, read_file_); | 35 CHECK_EQ(fd, read_file_); |
| 33 | 36 |
| 34 // If this is a sendMessage request, stop trying to read after the first | 37 // If this is a sendMessage request, stop trying to read after the first |
| 35 // message. | 38 // message. |
| 36 if (is_send_message_) | 39 if (is_send_message_) |
| 37 read_watcher_.StopWatchingFileDescriptor(); | 40 read_watcher_.StopWatchingFileDescriptor(); |
| 38 | 41 |
| 39 MessageType type; | 42 MessageType type; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 62 return file_util::WriteFileDescriptor(file, data, bytes_to_write); | 65 return file_util::WriteFileDescriptor(file, data, bytes_to_write); |
| 63 } | 66 } |
| 64 | 67 |
| 65 bool NativeMessageProcessHost::ReadData(FileHandle file, | 68 bool NativeMessageProcessHost::ReadData(FileHandle file, |
| 66 char* data, | 69 char* data, |
| 67 size_t bytes_to_read) { | 70 size_t bytes_to_read) { |
| 68 return file_util::ReadFromFD(file, data, bytes_to_read); | 71 return file_util::ReadFromFD(file, data, bytes_to_read); |
| 69 } | 72 } |
| 70 | 73 |
| 71 } // namespace extensions | 74 } // namespace extensions |
| OLD | NEW |