Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc

Issue 1455063004: Mojo C++ bindings: introduce MultiplexRouter and related classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 : ScopedInterfaceEndpointHandle(kInvalidInterfaceId, true, nullptr) {}
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();
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
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698