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

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

Issue 2649573004: Mojo bindings: merge the control messages of sending disconnect reason and notifying endpoint close… (Closed)
Patch Set: Created 3 years, 11 months 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/public/cpp/bindings/scoped_interface_endpoint_handle.h" 5 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/public/cpp/bindings/associated_group_controller.h" 8 #include "mojo/public/cpp/bindings/associated_group_controller.h"
9 9
10 namespace mojo { 10 namespace mojo {
(...skipping 14 matching lines...) Expand all
25 25
26 ScopedInterfaceEndpointHandle& ScopedInterfaceEndpointHandle::operator=( 26 ScopedInterfaceEndpointHandle& ScopedInterfaceEndpointHandle::operator=(
27 ScopedInterfaceEndpointHandle&& other) { 27 ScopedInterfaceEndpointHandle&& other) {
28 reset(); 28 reset();
29 swap(other); 29 swap(other);
30 30
31 return *this; 31 return *this;
32 } 32 }
33 33
34 void ScopedInterfaceEndpointHandle::reset() { 34 void ScopedInterfaceEndpointHandle::reset() {
35 if (!IsValidInterfaceId(id_)) 35 ResetInternal(base::nullopt);
36 return; 36 }
37 37
38 group_controller_->CloseEndpointHandle(id_, is_local_); 38 void ScopedInterfaceEndpointHandle::ResetWithReason(
39 39 uint32_t custom_reason,
40 id_ = kInvalidInterfaceId; 40 const std::string& description) {
41 is_local_ = true; 41 base::Optional<DisconnectReason> reason;
42 group_controller_ = nullptr; 42 reason.emplace(custom_reason, description);
43 ResetInternal(reason);
dcheng 2017/01/23 23:20:22 FWIW, here and a couple other places ResetInterna
yzshen1 2017/01/23 23:30:09 I think the original code doesn't copy either. Hav
dcheng 2017/01/24 03:39:21 Ah, you're right: my comment is only true if |reas
43 } 44 }
44 45
45 void ScopedInterfaceEndpointHandle::swap(ScopedInterfaceEndpointHandle& other) { 46 void ScopedInterfaceEndpointHandle::swap(ScopedInterfaceEndpointHandle& other) {
46 using std::swap; 47 using std::swap;
47 swap(other.id_, id_); 48 swap(other.id_, id_);
48 swap(other.is_local_, is_local_); 49 swap(other.is_local_, is_local_);
49 swap(other.group_controller_, group_controller_); 50 swap(other.group_controller_, group_controller_);
50 } 51 }
51 52
52 InterfaceId ScopedInterfaceEndpointHandle::release() { 53 InterfaceId ScopedInterfaceEndpointHandle::release() {
53 InterfaceId result = id_; 54 InterfaceId result = id_;
54 55
55 id_ = kInvalidInterfaceId; 56 id_ = kInvalidInterfaceId;
56 is_local_ = true; 57 is_local_ = true;
57 group_controller_ = nullptr; 58 group_controller_ = nullptr;
58 59
59 return result; 60 return result;
60 } 61 }
61 62
62 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( 63 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle(
63 InterfaceId id, 64 InterfaceId id,
64 bool is_local, 65 bool is_local,
65 scoped_refptr<AssociatedGroupController> group_controller) 66 scoped_refptr<AssociatedGroupController> group_controller)
66 : id_(id), 67 : id_(id),
67 is_local_(is_local), 68 is_local_(is_local),
68 group_controller_(std::move(group_controller)) { 69 group_controller_(std::move(group_controller)) {
69 DCHECK(!IsValidInterfaceId(id) || group_controller_); 70 DCHECK(!IsValidInterfaceId(id) || group_controller_);
70 } 71 }
71 72
73 void ScopedInterfaceEndpointHandle::ResetInternal(
74 const base::Optional<DisconnectReason>& reason) {
75 if (!IsValidInterfaceId(id_))
76 return;
77
78 group_controller_->CloseEndpointHandle(id_, is_local_, reason);
79
80 id_ = kInvalidInterfaceId;
81 is_local_ = true;
82 group_controller_ = nullptr;
83 }
84
72 } // namespace mojo 85 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/pipe_control_message_proxy.cc ('k') | mojo/public/cpp/bindings/pipe_control_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698