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

Side by Side Diff: mojo/public/cpp/bindings/lib/interface_impl_internal.h

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
7
8 #include "mojo/public/cpp/bindings/error_handler.h"
9 #include "mojo/public/cpp/bindings/interface_ptr.h"
10 #include "mojo/public/cpp/system/macros.h"
11
12 namespace mojo {
13 namespace internal {
14
15 template <typename Interface>
16 class InterfaceImplState : public ErrorHandler {
17 public:
18 explicit InterfaceImplState(WithErrorHandler<Interface>* instance)
19 : router_(NULL),
20 proxy_(NULL) {
21 assert(instance);
22 stub_.set_sink(instance);
23 }
24
25 virtual ~InterfaceImplState() {
26 delete proxy_;
27 if (router_) {
28 router_->set_error_handler(NULL);
29 delete router_;
30 }
31 }
32
33 void BindProxy(
34 InterfacePtr<Interface>* ptr,
35 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
36 MessagePipe pipe;
37 ptr->Bind(pipe.handle0.Pass(), waiter);
38 Bind(pipe.handle1.Pass(), waiter);
39 }
40
41 void Bind(ScopedMessagePipeHandle handle,
42 MojoAsyncWaiter* waiter) {
43 assert(!router_);
44
45 router_ = new Router(handle.Pass(), waiter);
46 router_->set_incoming_receiver(&stub_);
47 router_->set_error_handler(this);
48
49 proxy_ = new typename Interface::Client_::Proxy_(router_);
50
51 stub_.sink()->SetClient(proxy_);
52 }
53
54 Router* router() { return router_; }
55
56 private:
57 virtual void OnConnectionError() MOJO_OVERRIDE {
58 static_cast<WithErrorHandler<Interface>*>(stub_.sink())->
59 OnConnectionError();
60 }
61
62 internal::Router* router_;
63 typename Interface::Client_::Proxy_* proxy_;
64 typename Interface::Stub_ stub_;
65
66 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
67 };
68
69 } // namespace internal
70 } // namespace mojo
71
72 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698