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

Side by Side Diff: mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h

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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_
7 7
8 #include <string>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/optional.h"
10 #include "mojo/public/cpp/bindings/bindings_export.h" 13 #include "mojo/public/cpp/bindings/bindings_export.h"
14 #include "mojo/public/cpp/bindings/disconnect_reason.h"
11 #include "mojo/public/cpp/bindings/interface_id.h" 15 #include "mojo/public/cpp/bindings/interface_id.h"
12 16
13 namespace mojo { 17 namespace mojo {
14 18
15 class AssociatedGroupController; 19 class AssociatedGroupController;
16 20
17 // ScopedInterfaceEndpointHandle refers to one end of an interface, either the 21 // ScopedInterfaceEndpointHandle refers to one end of an interface, either the
18 // implementation side or the client side. 22 // implementation side or the client side.
19 class MOJO_CPP_BINDINGS_EXPORT ScopedInterfaceEndpointHandle { 23 class MOJO_CPP_BINDINGS_EXPORT ScopedInterfaceEndpointHandle {
20 public: 24 public:
21 // Creates an invalid endpoint handle. 25 // Creates an invalid endpoint handle.
22 ScopedInterfaceEndpointHandle(); 26 ScopedInterfaceEndpointHandle();
23 27
24 ScopedInterfaceEndpointHandle(ScopedInterfaceEndpointHandle&& other); 28 ScopedInterfaceEndpointHandle(ScopedInterfaceEndpointHandle&& other);
25 29
26 ~ScopedInterfaceEndpointHandle(); 30 ~ScopedInterfaceEndpointHandle();
27 31
28 ScopedInterfaceEndpointHandle& operator=( 32 ScopedInterfaceEndpointHandle& operator=(
29 ScopedInterfaceEndpointHandle&& other); 33 ScopedInterfaceEndpointHandle&& other);
30 34
31 bool is_valid() const { return IsValidInterfaceId(id_); } 35 bool is_valid() const { return IsValidInterfaceId(id_); }
32 36
33 bool is_local() const { return is_local_; } 37 bool is_local() const { return is_local_; }
34 38
35 void reset(); 39 void reset();
40 void ResetWithReason(uint32_t custom_reason, const std::string& description);
41
36 void swap(ScopedInterfaceEndpointHandle& other); 42 void swap(ScopedInterfaceEndpointHandle& other);
37 43
38 // DO NOT USE METHODS BELOW THIS LINE. These are for internal use and testing. 44 // DO NOT USE METHODS BELOW THIS LINE. These are for internal use and testing.
39 45
40 InterfaceId id() const { return id_; } 46 InterfaceId id() const { return id_; }
41 47
42 AssociatedGroupController* group_controller() const { 48 AssociatedGroupController* group_controller() const {
43 return group_controller_.get(); 49 return group_controller_.get();
44 } 50 }
45 51
46 // Releases the handle without closing it. 52 // Releases the handle without closing it.
47 InterfaceId release(); 53 InterfaceId release();
48 54
49 private: 55 private:
50 friend class AssociatedGroupController; 56 friend class AssociatedGroupController;
51 57
52 // This is supposed to be used by AssociatedGroupController only. 58 // This is supposed to be used by AssociatedGroupController only.
53 // |id| is the corresponding interface ID. 59 // |id| is the corresponding interface ID.
54 // If |is_local| is false, this handle is meant to be passed over a message 60 // If |is_local| is false, this handle is meant to be passed over a message
55 // pipe the remote side of the associated group. 61 // pipe the remote side of the associated group.
56 ScopedInterfaceEndpointHandle( 62 ScopedInterfaceEndpointHandle(
57 InterfaceId id, 63 InterfaceId id,
58 bool is_local, 64 bool is_local,
59 scoped_refptr<AssociatedGroupController> group_controller); 65 scoped_refptr<AssociatedGroupController> group_controller);
60 66
67 void ResetInternal(const base::Optional<DisconnectReason>& reason);
68
61 InterfaceId id_; 69 InterfaceId id_;
62 bool is_local_; 70 bool is_local_;
63 scoped_refptr<AssociatedGroupController> group_controller_; 71 scoped_refptr<AssociatedGroupController> group_controller_;
64 72
65 DISALLOW_COPY_AND_ASSIGN(ScopedInterfaceEndpointHandle); 73 DISALLOW_COPY_AND_ASSIGN(ScopedInterfaceEndpointHandle);
66 }; 74 };
67 75
68 } // namespace mojo 76 } // namespace mojo
69 77
70 #endif // MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_ 78 #endif // MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698