| 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 18 matching lines...) Expand all Loading... |
| 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 | 34 // If this is a sendMessage request, stop trying to read after the first |
| 35 // message. | 35 // message. |
| 36 if (is_send_message_) | 36 if (is_send_message_) |
| 37 read_watcher_.StopWatchingFileDescriptor(); | 37 read_watcher_.StopWatchingFileDescriptor(); |
| 38 | 38 |
| 39 MessageType type; | |
| 40 std::string message; | 39 std::string message; |
| 41 if (!ReadMessage(&type, &message)) { | 40 if (!ReadMessage(&message)) { |
| 42 // A read failed, is the process dead? | 41 // A read failed, is the process dead? |
| 43 if (base::GetTerminationStatus(native_process_handle_, NULL) != | 42 if (base::GetTerminationStatus(native_process_handle_, NULL) != |
| 44 base::TERMINATION_STATUS_STILL_RUNNING) { | 43 base::TERMINATION_STATUS_STILL_RUNNING) { |
| 45 read_watcher_.StopWatchingFileDescriptor(); | 44 read_watcher_.StopWatchingFileDescriptor(); |
| 46 // Notify the message service that the channel should close. | 45 // Notify the message service that the channel should close. |
| 47 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 46 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 48 base::Bind(&Client::CloseChannel, weak_client_ui_, | 47 base::Bind(&Client::CloseChannel, weak_client_ui_, |
| 49 destination_port_, true)); | 48 destination_port_, true)); |
| 50 } | 49 } |
| 51 return; | 50 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 62 return file_util::WriteFileDescriptor(file, data, bytes_to_write); | 61 return file_util::WriteFileDescriptor(file, data, bytes_to_write); |
| 63 } | 62 } |
| 64 | 63 |
| 65 bool NativeMessageProcessHost::ReadData(FileHandle file, | 64 bool NativeMessageProcessHost::ReadData(FileHandle file, |
| 66 char* data, | 65 char* data, |
| 67 size_t bytes_to_read) { | 66 size_t bytes_to_read) { |
| 68 return file_util::ReadFromFD(file, data, bytes_to_read); | 67 return file_util::ReadFromFD(file, data, bytes_to_read); |
| 69 } | 68 } |
| 70 | 69 |
| 71 } // namespace extensions | 70 } // namespace extensions |
| OLD | NEW |