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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 &read_watcher_, | 24 &read_watcher_, |
25 this); | 25 this); |
26 } | 26 } |
27 | 27 |
28 void NativeMessageProcessHost::OnFileCanReadWithoutBlocking(int fd) { | 28 void NativeMessageProcessHost::OnFileCanReadWithoutBlocking(int fd) { |
29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
30 | 30 |
31 // Make sure that the fd given to us is the same one we started with. | 31 // Make sure that the fd given to us is the same one we started with. |
32 CHECK_EQ(fd, read_file_); | 32 CHECK_EQ(fd, read_file_); |
33 | 33 |
34 // If this is a sendMessage request, stop trying to read after the first | |
35 // message. | |
36 if (is_send_message_) | |
37 read_watcher_.StopWatchingFileDescriptor(); | |
38 | |
39 MessageType type; | |
40 std::string message; | 34 std::string message; |
41 if (!ReadMessage(&type, &message)) { | 35 if (!ReadMessage(&message)) { |
42 // A read failed, is the process dead? | 36 // A read failed, is the process dead? |
43 if (base::GetTerminationStatus(native_process_handle_, NULL) != | 37 if (base::GetTerminationStatus(native_process_handle_, NULL) != |
44 base::TERMINATION_STATUS_STILL_RUNNING) { | 38 base::TERMINATION_STATUS_STILL_RUNNING) { |
45 read_watcher_.StopWatchingFileDescriptor(); | 39 read_watcher_.StopWatchingFileDescriptor(); |
46 // Notify the message service that the channel should close. | 40 // Notify the message service that the channel should close. |
47 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 41 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
48 base::Bind(&Client::CloseChannel, weak_client_ui_, | 42 base::Bind(&Client::CloseChannel, weak_client_ui_, |
49 destination_port_, true)); | 43 destination_port_, true)); |
50 } | 44 } |
51 return; | 45 return; |
(...skipping 10 matching lines...) Expand all Loading... |
62 return file_util::WriteFileDescriptor(file, data, bytes_to_write); | 56 return file_util::WriteFileDescriptor(file, data, bytes_to_write); |
63 } | 57 } |
64 | 58 |
65 bool NativeMessageProcessHost::ReadData(FileHandle file, | 59 bool NativeMessageProcessHost::ReadData(FileHandle file, |
66 char* data, | 60 char* data, |
67 size_t bytes_to_read) { | 61 size_t bytes_to_read) { |
68 return file_util::ReadFromFD(file, data, bytes_to_read); | 62 return file_util::ReadFromFD(file, data, bytes_to_read); |
69 } | 63 } |
70 | 64 |
71 } // namespace extensions | 65 } // namespace extensions |
OLD | NEW |