| OLD | NEW | 
|    1 // Copyright 2016 The Chromium Authors. All rights reserved. |    1 // Copyright 2016 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 "mojo/edk/system/node_channel.h" |    5 #include "mojo/edk/system/node_channel.h" | 
|    6  |    6  | 
|    7 #include <cstring> |    7 #include <cstring> | 
|    8 #include <limits> |    8 #include <limits> | 
|    9 #include <sstream> |    9 #include <sstream> | 
|   10  |   10  | 
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  153   *out_data = reinterpret_cast<const DataType*>( |  153   *out_data = reinterpret_cast<const DataType*>( | 
|  154       static_cast<const char*>(bytes) + sizeof(Header)); |  154       static_cast<const char*>(bytes) + sizeof(Header)); | 
|  155   return true; |  155   return true; | 
|  156 } |  156 } | 
|  157  |  157  | 
|  158 }  // namespace |  158 }  // namespace | 
|  159  |  159  | 
|  160 // static |  160 // static | 
|  161 scoped_refptr<NodeChannel> NodeChannel::Create( |  161 scoped_refptr<NodeChannel> NodeChannel::Create( | 
|  162     Delegate* delegate, |  162     Delegate* delegate, | 
|  163     ScopedPlatformHandle platform_handle, |  163     ConnectionParam connection_param, | 
|  164     scoped_refptr<base::TaskRunner> io_task_runner, |  164     scoped_refptr<base::TaskRunner> io_task_runner, | 
|  165     const ProcessErrorCallback& process_error_callback) { |  165     const ProcessErrorCallback& process_error_callback) { | 
|  166 #if defined(OS_NACL_SFI) |  166 #if defined(OS_NACL_SFI) | 
|  167   LOG(FATAL) << "Multi-process not yet supported on NaCl-SFI"; |  167   LOG(FATAL) << "Multi-process not yet supported on NaCl-SFI"; | 
|  168   return nullptr; |  168   return nullptr; | 
|  169 #else |  169 #else | 
|  170   return new NodeChannel(delegate, std::move(platform_handle), io_task_runner, |  170   return new NodeChannel(delegate, std::move(connection_param), io_task_runner, | 
|  171                          process_error_callback); |  171                          process_error_callback); | 
|  172 #endif |  172 #endif | 
|  173 } |  173 } | 
|  174  |  174  | 
|  175 // static |  175 // static | 
|  176 Channel::MessagePtr NodeChannel::CreatePortsMessage(size_t payload_size, |  176 Channel::MessagePtr NodeChannel::CreatePortsMessage(size_t payload_size, | 
|  177                                                     void** payload, |  177                                                     void** payload, | 
|  178                                                     size_t num_handles) { |  178                                                     size_t num_handles) { | 
|  179   return CreateMessage(MessageType::PORTS_MESSAGE, payload_size, num_handles, |  179   return CreateMessage(MessageType::PORTS_MESSAGE, payload_size, num_handles, | 
|  180                        payload); |  180                        payload); | 
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  447       &data); |  447       &data); | 
|  448   data->source = source; |  448   data->source = source; | 
|  449   if (message->payload_size()) |  449   if (message->payload_size()) | 
|  450     memcpy(data + 1, message->payload(), message->payload_size()); |  450     memcpy(data + 1, message->payload(), message->payload_size()); | 
|  451   relayed_message->SetHandles(message->TakeHandles()); |  451   relayed_message->SetHandles(message->TakeHandles()); | 
|  452   WriteChannelMessage(std::move(relayed_message)); |  452   WriteChannelMessage(std::move(relayed_message)); | 
|  453 } |  453 } | 
|  454 #endif  // defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |  454 #endif  // defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) | 
|  455  |  455  | 
|  456 NodeChannel::NodeChannel(Delegate* delegate, |  456 NodeChannel::NodeChannel(Delegate* delegate, | 
|  457                          ScopedPlatformHandle platform_handle, |  457                          ConnectionParam connection_param, | 
|  458                          scoped_refptr<base::TaskRunner> io_task_runner, |  458                          scoped_refptr<base::TaskRunner> io_task_runner, | 
|  459                          const ProcessErrorCallback& process_error_callback) |  459                          const ProcessErrorCallback& process_error_callback) | 
|  460     : delegate_(delegate), |  460     : delegate_(delegate), | 
|  461       io_task_runner_(io_task_runner), |  461       io_task_runner_(io_task_runner), | 
|  462       process_error_callback_(process_error_callback) |  462       process_error_callback_(process_error_callback) | 
|  463 #if !defined(OS_NACL_SFI) |  463 #if !defined(OS_NACL_SFI) | 
|  464       , channel_( |  464       , | 
|  465           Channel::Create(this, std::move(platform_handle), io_task_runner_)) |  465       channel_( | 
 |  466           Channel::Create(this, std::move(connection_param), io_task_runner_)) | 
|  466 #endif |  467 #endif | 
|  467       { |  468 { | 
|  468 } |  469 } | 
|  469  |  470  | 
|  470 NodeChannel::~NodeChannel() { |  471 NodeChannel::~NodeChannel() { | 
|  471   ShutDown(); |  472   ShutDown(); | 
|  472 } |  473 } | 
|  473  |  474  | 
|  474 void NodeChannel::OnChannelMessage(const void* payload, |  475 void NodeChannel::OnChannelMessage(const void* payload, | 
|  475                                    size_t payload_size, |  476                                    size_t payload_size, | 
|  476                                    ScopedPlatformHandleVectorPtr handles) { |  477                                    ScopedPlatformHandleVectorPtr handles) { | 
|  477   DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |  478   DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  895  |  896  | 
|  896   base::AutoLock lock(channel_lock_); |  897   base::AutoLock lock(channel_lock_); | 
|  897   if (!channel_) |  898   if (!channel_) | 
|  898     DLOG(ERROR) << "Dropping message on closed channel."; |  899     DLOG(ERROR) << "Dropping message on closed channel."; | 
|  899   else |  900   else | 
|  900     channel_->Write(std::move(message)); |  901     channel_->Write(std::move(message)); | 
|  901 } |  902 } | 
|  902  |  903  | 
|  903 }  // namespace edk |  904 }  // namespace edk | 
|  904 }  // namespace mojo |  905 }  // namespace mojo | 
| OLD | NEW |