Index: mojo/edk/system/raw_channel_posix.cc |
diff --git a/mojo/edk/system/raw_channel_posix.cc b/mojo/edk/system/raw_channel_posix.cc |
index 096d0d78c439163b7ade76cec75989b45cfadc06..cec566b18db623cbce6995d0b1cdbc8fd32fda09 100644 |
--- a/mojo/edk/system/raw_channel_posix.cc |
+++ b/mojo/edk/system/raw_channel_posix.cc |
@@ -10,8 +10,10 @@ |
#include <algorithm> |
#include <deque> |
+#include <iterator> |
#include <memory> |
#include <utility> |
+#include <vector> |
#include "base/bind.h" |
#include "base/location.h" |
@@ -20,11 +22,13 @@ |
#include "base/message_loop/message_loop.h" |
#include "mojo/edk/embedder/platform_channel_utils.h" |
#include "mojo/edk/embedder/platform_handle.h" |
-#include "mojo/edk/embedder/platform_handle_vector.h" |
+#include "mojo/edk/embedder/scoped_platform_handle.h" |
#include "mojo/edk/system/transport_data.h" |
#include "mojo/edk/util/make_unique.h" |
#include "mojo/public/cpp/system/macros.h" |
+using mojo::embedder::ScopedPlatformHandle; |
+using mojo::util::MakeUnique; |
using mojo::util::MutexLocker; |
namespace mojo { |
@@ -52,7 +56,7 @@ class RawChannelPosix final : public RawChannel, |
const MessageInTransit::View& message_view) override; |
IOResult Read(size_t* bytes_read) override; |
IOResult ScheduleRead() override; |
- embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles( |
+ std::unique_ptr<std::vector<ScopedPlatformHandle>> GetReadPlatformHandles( |
size_t num_platform_handles, |
const void* platform_handle_table) override; |
IOResult WriteNoLock(size_t* platform_handles_written, |
@@ -80,7 +84,7 @@ class RawChannelPosix final : public RawChannel, |
bool pending_read_; |
- std::deque<embedder::PlatformHandle> read_platform_handles_; |
+ std::deque<embedder::ScopedPlatformHandle> read_platform_handles_; |
bool pending_write_ MOJO_GUARDED_BY(write_mutex()); |
@@ -112,8 +116,6 @@ RawChannelPosix::~RawChannelPosix() { |
// These must have been shut down/destroyed on the I/O thread. |
DCHECK(!read_watcher_); |
DCHECK(!write_watcher_); |
- |
- embedder::CloseAllPlatformHandles(&read_platform_handles_); |
} |
size_t RawChannelPosix::GetSerializedPlatformHandleSize() const { |
@@ -124,7 +126,7 @@ size_t RawChannelPosix::GetSerializedPlatformHandleSize() const { |
void RawChannelPosix::EnqueueMessageNoLock( |
std::unique_ptr<MessageInTransit> message) { |
if (message->transport_data()) { |
- embedder::PlatformHandleVector* const platform_handles = |
+ std::vector<ScopedPlatformHandle>* const platform_handles = |
message->transport_data()->platform_handles(); |
if (platform_handles && |
platform_handles->size() > embedder::kPlatformChannelMaxNumHandles) { |
@@ -139,11 +141,13 @@ void RawChannelPosix::EnqueueMessageNoLock( |
MessageInTransit::Type::RAW_CHANNEL, |
MessageInTransit::Subtype::RAW_CHANNEL_POSIX_EXTRA_PLATFORM_HANDLES, |
0, nullptr)); |
- embedder::ScopedPlatformHandleVectorPtr fds( |
- new embedder::PlatformHandleVector( |
- platform_handles->begin() + i, |
- platform_handles->begin() + i + |
- embedder::kPlatformChannelMaxNumHandles)); |
+ using IteratorType = std::vector<ScopedPlatformHandle>::iterator; |
+ std::unique_ptr<std::vector<ScopedPlatformHandle>> fds( |
+ MakeUnique<std::vector<ScopedPlatformHandle>>( |
+ std::move_iterator<IteratorType>(platform_handles->begin() + i), |
+ std::move_iterator<IteratorType>( |
+ platform_handles->begin() + i + |
+ embedder::kPlatformChannelMaxNumHandles))); |
fd_message->SetTransportData(util::MakeUnique<TransportData>( |
std::move(fds), GetSerializedPlatformHandleSize())); |
RawChannel::EnqueueMessageNoLock(std::move(fd_message)); |
@@ -193,21 +197,21 @@ RawChannel::IOResult RawChannelPosix::ScheduleRead() { |
return IO_PENDING; |
} |
-embedder::ScopedPlatformHandleVectorPtr RawChannelPosix::GetReadPlatformHandles( |
- size_t num_platform_handles, |
- const void* /*platform_handle_table*/) { |
+std::unique_ptr<std::vector<ScopedPlatformHandle>> |
+RawChannelPosix::GetReadPlatformHandles(size_t num_platform_handles, |
+ const void* /*platform_handle_table*/) { |
DCHECK_GT(num_platform_handles, 0u); |
if (read_platform_handles_.size() < num_platform_handles) { |
- embedder::CloseAllPlatformHandles(&read_platform_handles_); |
read_platform_handles_.clear(); |
- return embedder::ScopedPlatformHandleVectorPtr(); |
+ return nullptr; |
} |
- embedder::ScopedPlatformHandleVectorPtr rv( |
- new embedder::PlatformHandleVector(num_platform_handles)); |
- rv->assign(read_platform_handles_.begin(), |
- read_platform_handles_.begin() + num_platform_handles); |
+ auto rv = MakeUnique<std::vector<ScopedPlatformHandle>>(num_platform_handles); |
+ using IteratorType = std::deque<ScopedPlatformHandle>::iterator; |
+ rv->assign(std::move_iterator<IteratorType>(read_platform_handles_.begin()), |
+ std::move_iterator<IteratorType>(read_platform_handles_.begin() + |
+ num_platform_handles)); |
read_platform_handles_.erase( |
read_platform_handles_.begin(), |
read_platform_handles_.begin() + num_platform_handles); |
@@ -422,7 +426,6 @@ RawChannel::IOResult RawChannelPosix::ReadImpl(size_t* bytes_read) { |
(TransportData::GetMaxPlatformHandles() + |
embedder::kPlatformChannelMaxNumHandles)) { |
LOG(ERROR) << "Received too many platform handles"; |
- embedder::CloseAllPlatformHandles(&read_platform_handles_); |
read_platform_handles_.clear(); |
return IO_FAILED_UNKNOWN; |
} |