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

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

Issue 405653003: mojo: Make InterfacePtr<> testable in if() statements without .get(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to is_bound() Created 6 years, 5 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 | Annotate | Revision Log
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_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 State state; 97 State state;
98 internal_state_.Swap(&state); 98 internal_state_.Swap(&state);
99 return state.PassMessagePipe(); 99 return state.PassMessagePipe();
100 } 100 }
101 101
102 // DO NOT USE. Exposed only for internal use and for testing. 102 // DO NOT USE. Exposed only for internal use and for testing.
103 internal::InterfacePtrState<Interface>* internal_state() { 103 internal::InterfacePtrState<Interface>* internal_state() {
104 return &internal_state_; 104 return &internal_state_;
105 } 105 }
106 106
107 // Allow InterfacePtr<> to be used in boolean expressions, but not
108 // implicitly convertible to a real bool (which is dangerous).
109 private:
110 typedef internal::InterfacePtrState<Interface> InterfacePtr::*Testable;
111
112 public:
113 operator Testable() const {
114 return internal_state_.is_bound() ? &InterfacePtr::internal_state_ : NULL;
115 }
116
107 private: 117 private:
108 typedef internal::InterfacePtrState<Interface> State; 118 typedef internal::InterfacePtrState<Interface> State;
109 mutable State internal_state_; 119 mutable State internal_state_;
110 }; 120 };
111 121
112 // Takes a handle to the proxy end-point of a pipe. On the other end is 122 // Takes a handle to the proxy end-point of a pipe. On the other end is
113 // presumed to be an interface implementation of type |Interface|. Returns a 123 // presumed to be an interface implementation of type |Interface|. Returns a
114 // generated proxy to that interface, which may be used on the current thread. 124 // generated proxy to that interface, which may be used on the current thread.
115 // It is valid to call set_client on the returned InterfacePtr<..> to set an 125 // It is valid to call set_client on the returned InterfacePtr<..> to set an
116 // instance of Interface::Client. 126 // instance of Interface::Client.
117 template <typename Interface> 127 template <typename Interface>
118 InterfacePtr<Interface> MakeProxy( 128 InterfacePtr<Interface> MakeProxy(
119 ScopedMessagePipeHandle handle, 129 ScopedMessagePipeHandle handle,
120 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { 130 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
121 InterfacePtr<Interface> ptr; 131 InterfacePtr<Interface> ptr;
122 if (handle.is_valid()) 132 if (handle.is_valid())
123 ptr.Bind(handle.Pass(), waiter); 133 ptr.Bind(handle.Pass(), waiter);
124 return ptr.Pass(); 134 return ptr.Pass();
125 } 135 }
126 136
127 } // namespace mojo 137 } // namespace mojo
128 138
129 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ 139 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
OLDNEW
« no previous file with comments | « mojo/gles2/command_buffer_client_impl.cc ('k') | mojo/public/cpp/bindings/lib/interface_ptr_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698