[email protected] | 35cfded | 2014-01-10 20:50:18 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "mojo/system/platform_channel_pair.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "mojo/system/platform_channel.h" |
| 9 | |
| 10 | namespace mojo { |
| 11 | namespace system { |
| 12 | |
| 13 | PlatformChannelPair::~PlatformChannelPair() { |
| 14 | server_handle_.CloseIfNecessary(); |
| 15 | client_handle_.CloseIfNecessary(); |
| 16 | } |
| 17 | |
| 18 | scoped_ptr<PlatformChannel> PlatformChannelPair::CreateServerChannel() { |
| 19 | if (!server_handle_.is_valid()) { |
| 20 | LOG(WARNING) << "Server handle invalid"; |
| 21 | return scoped_ptr<PlatformChannel>(); |
| 22 | } |
| 23 | |
| 24 | scoped_ptr<PlatformChannel> rv = |
| 25 | PlatformChannel::CreateFromHandle(server_handle_); |
| 26 | server_handle_ = PlatformChannelHandle(); |
| 27 | return rv.Pass(); |
| 28 | } |
| 29 | |
| 30 | scoped_ptr<PlatformChannel> PlatformChannelPair::CreateClientChannel() { |
| 31 | if (!client_handle_.is_valid()) { |
| 32 | LOG(WARNING) << "Client handle invalid"; |
| 33 | return scoped_ptr<PlatformChannel>(); |
| 34 | } |
| 35 | |
| 36 | scoped_ptr<PlatformChannel> rv = |
| 37 | PlatformChannel::CreateFromHandle(client_handle_); |
| 38 | client_handle_ = PlatformChannelHandle(); |
| 39 | return rv.Pass(); |
| 40 | } |
| 41 | |
| 42 | } // namespace system |
| 43 | } // namespace mojo |