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

Side by Side Diff: mojo/public/bindings/lib/remote_ptr.h

Issue 109103003: Mojo: abstract interface implementation from generated Stub classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_BINDINGS_LIB_REMOTE_PTR_H_ 5 #ifndef MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_
6 #define MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_ 6 #define MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 9
10 #include "mojo/public/bindings/lib/connector.h" 10 #include "mojo/public/bindings/lib/connector.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // private: 47 // private:
48 // mojo::RemotePtr<FooClient> client_; 48 // mojo::RemotePtr<FooClient> client_;
49 // }; 49 // };
50 // 50 //
51 template <typename S> 51 template <typename S>
52 class RemotePtr { 52 class RemotePtr {
53 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(RemotePtr, RValue); 53 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(RemotePtr, RValue);
54 54
55 public: 55 public:
56 RemotePtr() : state_(NULL) {} 56 RemotePtr() : state_(NULL) {}
57 explicit RemotePtr(ScopedMessagePipeHandle message_pipe) 57 RemotePtr(ScopedMessagePipeHandle message_pipe, typename S::_Peer* peer)
58 : state_(new State(message_pipe.Pass())) { 58 : state_(new State(message_pipe.Pass(), peer)) {
59 } 59 }
60 60
61 // Move-only constructor and operator=. 61 // Move-only constructor and operator=.
62 RemotePtr(RValue other) : state_(other.object->release()) {} 62 RemotePtr(RValue other) : state_(other.object->release()) {}
63 RemotePtr& operator=(RValue other) { 63 RemotePtr& operator=(RValue other) {
64 state_ = other.object->release(); 64 state_ = other.object->release();
65 return *this; 65 return *this;
66 } 66 }
67 67
68 ~RemotePtr() { 68 ~RemotePtr() {
(...skipping 11 matching lines...) Expand all
80 80
81 S* operator->() { 81 S* operator->() {
82 return get(); 82 return get();
83 } 83 }
84 84
85 void reset() { 85 void reset() {
86 delete state_; 86 delete state_;
87 state_ = NULL; 87 state_ = NULL;
88 } 88 }
89 89
90 void reset(ScopedMessagePipeHandle message_pipe) { 90 void reset(ScopedMessagePipeHandle message_pipe, typename S::_Peer* peer) {
91 delete state_; 91 delete state_;
92 state_ = new State(message_pipe.Pass()); 92 state_ = new State(message_pipe.Pass(), peer);
93 } 93 }
94 94
95 bool encountered_error() const { 95 bool encountered_error() const {
96 assert(state_); 96 assert(state_);
97 return state_->connector.encountered_error(); 97 return state_->connector.encountered_error();
98 } 98 }
99 99
100 void SetPeer(typename S::_Peer::_Stub* peer) {
101 assert(state_);
102 state_->connector.SetIncomingReceiver(peer);
103 }
104
105 private: 100 private:
106 struct State { 101 struct State {
107 State(ScopedMessagePipeHandle message_pipe) 102 State(ScopedMessagePipeHandle message_pipe, typename S::_Peer* peer)
108 : connector(message_pipe.Pass()), 103 : connector(message_pipe.Pass()),
109 proxy(&connector) { 104 proxy(&connector),
105 stub(peer) {
106 connector.SetIncomingReceiver(&stub);
110 } 107 }
111 internal::Connector connector; 108 internal::Connector connector;
112 typename S::_Proxy proxy; 109 typename S::_Proxy proxy;
110 typename S::_Peer::_Stub stub;
113 }; 111 };
114 112
115 State* release() { 113 State* release() {
116 State* state = state_; 114 State* state = state_;
117 state_ = NULL; 115 state_ = NULL;
118 return state; 116 return state;
119 } 117 }
120 118
121 State* state_; 119 State* state_;
122 }; 120 };
123 121
124 } // namespace mojo 122 } // namespace mojo
125 123
126 #endif // MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_ 124 #endif // MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698