OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | |
9 | |
10 namespace mojo { | |
11 namespace internal { | |
12 | |
13 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle() | |
14 : id_(kInvalidInterfaceId), is_local_(true) {} | |
sky
2015/11/19 17:16:27
Use delegating constructors.
yzshen1
2015/11/19 22:00:41
Done.
| |
15 | |
16 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( | |
17 InterfaceId id, | |
18 bool is_local, | |
19 scoped_refptr<MultiplexRouter> router) | |
20 : id_(id), is_local_(is_local), router_(router.Pass()) { | |
21 DCHECK(!IsValidInterfaceId(id) || router_); | |
22 } | |
23 | |
24 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( | |
25 ScopedInterfaceEndpointHandle&& other) | |
26 : id_(other.id_), is_local_(other.is_local_) { | |
27 router_.swap(other.router_); | |
28 other.id_ = kInvalidInterfaceId; | |
29 } | |
30 | |
31 ScopedInterfaceEndpointHandle::~ScopedInterfaceEndpointHandle() { | |
32 reset(); | |
33 } | |
34 | |
35 ScopedInterfaceEndpointHandle& ScopedInterfaceEndpointHandle::operator=( | |
36 ScopedInterfaceEndpointHandle&& other) { | |
37 reset(); | |
sky
2015/11/19 17:16:27
Do you need to handle the case of other == this?
yzshen1
2015/11/19 22:00:41
Because this is a move assignment, I think it is u
| |
38 | |
39 id_ = other.id_; | |
40 is_local_ = other.is_local_; | |
41 router_.swap(other.router_); | |
42 | |
43 other.id_ = kInvalidInterfaceId; | |
44 | |
45 return *this; | |
46 } | |
47 | |
48 void ScopedInterfaceEndpointHandle::reset() { | |
49 if (!IsValidInterfaceId(id_)) | |
50 return; | |
51 | |
52 router_->CloseEndpointHandle(id_, is_local_); | |
53 | |
54 id_ = kInvalidInterfaceId; | |
55 router_ = nullptr; | |
56 } | |
57 | |
58 void ScopedInterfaceEndpointHandle::swap(ScopedInterfaceEndpointHandle& other) { | |
59 using std::swap; | |
60 swap(other.id_, id_); | |
61 swap(other.is_local_, is_local_); | |
62 swap(other.router_, router_); | |
63 } | |
64 | |
65 InterfaceId ScopedInterfaceEndpointHandle::release() { | |
66 InterfaceId result = id_; | |
67 | |
68 id_ = kInvalidInterfaceId; | |
69 router_ = nullptr; | |
70 | |
71 return result; | |
72 } | |
73 | |
74 } // namespace internal | |
75 } // namespace mojo | |
OLD | NEW |