blob: cdf27a465426694349542cdb3f9787a65e90c543 [file] [log] [blame]
[email protected]35cfded2014-01-10 20:50:181// 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
10namespace mojo {
11namespace system {
12
13PlatformChannelPair::~PlatformChannelPair() {
14 server_handle_.CloseIfNecessary();
15 client_handle_.CloseIfNecessary();
16}
17
18scoped_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
30scoped_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