OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/system/platform_channel.h" | 5 #include "mojo/system/platform_channel.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 namespace system { | 10 namespace system { |
11 | 11 |
12 PlatformChannel::~PlatformChannel() { | 12 PlatformChannel::~PlatformChannel() { |
13 handle_.CloseIfNecessary(); | 13 handle_.CloseIfNecessary(); |
14 } | 14 } |
15 | 15 |
| 16 // static |
| 17 scoped_ptr<PlatformChannel> PlatformChannel::CreateFromHandle( |
| 18 const PlatformChannelHandle& handle) { |
| 19 DCHECK(handle.is_valid()); |
| 20 scoped_ptr<PlatformChannel> rv(new PlatformChannel()); |
| 21 *rv->mutable_handle() = handle; |
| 22 return rv.Pass(); |
| 23 } |
| 24 |
16 PlatformChannelHandle PlatformChannel::PassHandle() { | 25 PlatformChannelHandle PlatformChannel::PassHandle() { |
17 DCHECK(is_valid()); | 26 DCHECK(is_valid()); |
18 PlatformChannelHandle rv = handle_; | 27 PlatformChannelHandle rv = handle_; |
19 handle_ = PlatformChannelHandle(); | 28 handle_ = PlatformChannelHandle(); |
20 return rv; | 29 return rv; |
21 } | 30 } |
22 | 31 |
23 PlatformChannel::PlatformChannel() { | 32 PlatformChannel::PlatformChannel() { |
24 } | 33 } |
25 | 34 |
26 PlatformServerChannel::PlatformServerChannel(const std::string& name) | 35 // ----------------------------------------------------------------------------- |
27 : name_(name) { | 36 |
28 DCHECK(!name_.empty()); | 37 PlatformChannelPair::~PlatformChannelPair() { |
| 38 server_handle_.CloseIfNecessary(); |
| 39 client_handle_.CloseIfNecessary(); |
29 } | 40 } |
30 | 41 |
31 // Static factory method. | 42 scoped_ptr<PlatformChannel> PlatformChannelPair::CreateServerChannel() { |
32 // static | 43 if (!server_handle_.is_valid()) { |
33 scoped_ptr<PlatformClientChannel> PlatformClientChannel::CreateFromHandle( | 44 LOG(WARNING) << "Server handle invalid"; |
34 const PlatformChannelHandle& handle) { | 45 return scoped_ptr<PlatformChannel>(); |
35 DCHECK(handle.is_valid()); | 46 } |
36 scoped_ptr<PlatformClientChannel> rv(new PlatformClientChannel()); | 47 |
37 *rv->mutable_handle() = handle; | 48 scoped_ptr<PlatformChannel> rv = |
| 49 PlatformChannel::CreateFromHandle(server_handle_); |
| 50 server_handle_ = PlatformChannelHandle(); |
38 return rv.Pass(); | 51 return rv.Pass(); |
39 } | 52 } |
40 | 53 |
| 54 scoped_ptr<PlatformChannel> PlatformChannelPair::CreateClientChannel() { |
| 55 if (!client_handle_.is_valid()) { |
| 56 LOG(WARNING) << "Client handle invalid"; |
| 57 return scoped_ptr<PlatformChannel>(); |
| 58 } |
| 59 |
| 60 scoped_ptr<PlatformChannel> rv = |
| 61 PlatformChannel::CreateFromHandle(client_handle_); |
| 62 client_handle_ = PlatformChannelHandle(); |
| 63 return rv.Pass(); |
| 64 } |
| 65 |
41 } // namespace system | 66 } // namespace system |
42 } // namespace mojo | 67 } // namespace mojo |
OLD | NEW |