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

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

Issue 1535943002: Convert Pass()→std::move() in //mojo/public/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Regenerate correctly Created 4 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_INTERFACE_REQUEST_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
7 7
8 #include <utility>
9
8 #include "mojo/public/cpp/bindings/interface_ptr.h" 10 #include "mojo/public/cpp/bindings/interface_ptr.h"
9 11
10 namespace mojo { 12 namespace mojo {
11 13
12 // Represents a request from a remote client for an implementation of Interface 14 // Represents a request from a remote client for an implementation of Interface
13 // over a specified message pipe. The implementor of the interface should 15 // over a specified message pipe. The implementor of the interface should
14 // remove the message pipe by calling PassMessagePipe() and bind it to the 16 // remove the message pipe by calling PassMessagePipe() and bind it to the
15 // implementation. If this is not done, the InterfaceRequest will automatically 17 // implementation. If this is not done, the InterfaceRequest will automatically
16 // close the pipe on destruction. Can also represent the absence of a request 18 // close the pipe on destruction. Can also represent the absence of a request
17 // if the client did not provide a message pipe. 19 // if the client did not provide a message pipe.
18 template <typename Interface> 20 template <typename Interface>
19 class InterfaceRequest { 21 class InterfaceRequest {
20 MOJO_MOVE_ONLY_TYPE(InterfaceRequest) 22 MOJO_MOVE_ONLY_TYPE(InterfaceRequest)
21 public: 23 public:
22 // Constructs an empty InterfaceRequest, representing that the client is not 24 // Constructs an empty InterfaceRequest, representing that the client is not
23 // requesting an implementation of Interface. 25 // requesting an implementation of Interface.
24 InterfaceRequest() {} 26 InterfaceRequest() {}
25 InterfaceRequest(decltype(nullptr)) {} 27 InterfaceRequest(decltype(nullptr)) {}
26 28
27 // Takes the message pipe from another InterfaceRequest. 29 // Takes the message pipe from another InterfaceRequest.
28 InterfaceRequest(InterfaceRequest&& other) { handle_ = other.handle_.Pass(); } 30 InterfaceRequest(InterfaceRequest&& other) {
31 handle_ = std::move(other.handle_);
32 }
29 InterfaceRequest& operator=(InterfaceRequest&& other) { 33 InterfaceRequest& operator=(InterfaceRequest&& other) {
30 handle_ = other.handle_.Pass(); 34 handle_ = std::move(other.handle_);
31 return *this; 35 return *this;
32 } 36 }
33 37
34 // Assigning to nullptr resets the InterfaceRequest to an empty state, 38 // Assigning to nullptr resets the InterfaceRequest to an empty state,
35 // closing the message pipe currently bound to it (if any). 39 // closing the message pipe currently bound to it (if any).
36 InterfaceRequest& operator=(decltype(nullptr)) { 40 InterfaceRequest& operator=(decltype(nullptr)) {
37 handle_.reset(); 41 handle_.reset();
38 return *this; 42 return *this;
39 } 43 }
40 44
41 // Binds the request to a message pipe over which Interface is to be 45 // Binds the request to a message pipe over which Interface is to be
42 // requested. If the request is already bound to a message pipe, the current 46 // requested. If the request is already bound to a message pipe, the current
43 // message pipe will be closed. 47 // message pipe will be closed.
44 void Bind(ScopedMessagePipeHandle handle) { handle_ = handle.Pass(); } 48 void Bind(ScopedMessagePipeHandle handle) { handle_ = std::move(handle); }
45 49
46 // Indicates whether the request currently contains a valid message pipe. 50 // Indicates whether the request currently contains a valid message pipe.
47 bool is_pending() const { return handle_.is_valid(); } 51 bool is_pending() const { return handle_.is_valid(); }
48 52
49 // Removes the message pipe from the request and returns it. 53 // Removes the message pipe from the request and returns it.
50 ScopedMessagePipeHandle PassMessagePipe() { return handle_.Pass(); } 54 ScopedMessagePipeHandle PassMessagePipe() { return std::move(handle_); }
51 55
52 private: 56 private:
53 ScopedMessagePipeHandle handle_; 57 ScopedMessagePipeHandle handle_;
54 }; 58 };
55 59
56 // Makes an InterfaceRequest bound to the specified message pipe. If |handle| 60 // Makes an InterfaceRequest bound to the specified message pipe. If |handle|
57 // is empty or invalid, the resulting InterfaceRequest will represent the 61 // is empty or invalid, the resulting InterfaceRequest will represent the
58 // absence of a request. 62 // absence of a request.
59 template <typename Interface> 63 template <typename Interface>
60 InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) { 64 InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) {
61 InterfaceRequest<Interface> request; 65 InterfaceRequest<Interface> request;
62 request.Bind(handle.Pass()); 66 request.Bind(std::move(handle));
63 return request.Pass(); 67 return std::move(request);
64 } 68 }
65 69
66 // Creates a new message pipe over which Interface is to be served. Binds the 70 // Creates a new message pipe over which Interface is to be served. Binds the
67 // specified InterfacePtr to one end of the message pipe, and returns an 71 // specified InterfacePtr to one end of the message pipe, and returns an
68 // InterfaceRequest bound to the other. The InterfacePtr should be passed to 72 // InterfaceRequest bound to the other. The InterfacePtr should be passed to
69 // the client, and the InterfaceRequest should be passed to whatever will 73 // the client, and the InterfaceRequest should be passed to whatever will
70 // provide the implementation. The implementation should typically be bound to 74 // provide the implementation. The implementation should typically be bound to
71 // the InterfaceRequest using the Binding or StrongBinding classes. The client 75 // the InterfaceRequest using the Binding or StrongBinding classes. The client
72 // may begin to issue calls even before an implementation has been bound, since 76 // may begin to issue calls even before an implementation has been bound, since
73 // messages sent over the pipe will just queue up until they are consumed by 77 // messages sent over the pipe will just queue up until they are consumed by
(...skipping 30 matching lines...) Expand all
104 // SourcePtr source; 108 // SourcePtr source;
105 // InterfaceRequest<Source> source_request = GetProxy(&source); 109 // InterfaceRequest<Source> source_request = GetProxy(&source);
106 // collector->RegisterSource(source.Pass()); 110 // collector->RegisterSource(source.Pass());
107 // CreateSource(source_request.Pass()); // Create implementation locally. 111 // CreateSource(source_request.Pass()); // Create implementation locally.
108 // 112 //
109 template <typename Interface> 113 template <typename Interface>
110 InterfaceRequest<typename Interface::GenericInterface> 114 InterfaceRequest<typename Interface::GenericInterface>
111 GetProxy(InterfacePtr<Interface>* ptr) { 115 GetProxy(InterfacePtr<Interface>* ptr) {
112 MessagePipe pipe; 116 MessagePipe pipe;
113 ptr->Bind(InterfacePtrInfo<typename Interface::GenericInterface>( 117 ptr->Bind(InterfacePtrInfo<typename Interface::GenericInterface>(
114 pipe.handle0.Pass(), 0u)); 118 std::move(pipe.handle0), 0u));
115 return MakeRequest<typename Interface::GenericInterface>( 119 return MakeRequest<typename Interface::GenericInterface>(
116 pipe.handle1.Pass()); 120 std::move(pipe.handle1));
117 } 121 }
118 122
119 } // namespace mojo 123 } // namespace mojo
120 124
121 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ 125 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_ptr_info.h ('k') | mojo/public/cpp/bindings/lib/array_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698