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

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: Force InterfaceImpl subclasses to implement OnConnectionError 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 assert(instance);
21 stub_.set_sink(instance);
22 }
23
24 virtual ~InterfaceImplState() {
25 delete proxy_;
26 if (router_) {
27 router_->set_error_handler(NULL);
28 delete router_;
29 }
30 }
31
32 void BindProxy(
33 InterfacePtr<Interface>* ptr,
34 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
35 MessagePipe pipe;
36 ptr->Bind(pipe.handle0.Pass(), waiter);
37 Bind(pipe.handle1.Pass(), waiter);
38 }
39
40 void Bind(ScopedMessagePipeHandle handle,
41 MojoAsyncWaiter* waiter) {
42 assert(!router_);
43
44 router_ = new Router(handle.Pass(), waiter);
45 router_->set_incoming_receiver(&stub_);
46 router_->set_error_handler(this);
47
48 proxy_ = new typename Interface::Client_::Proxy_(router_);
49
50 stub_.sink()->SetClient(proxy_);
51 }
52
53 Router* router() { return router_; }
54
55 private:
56 virtual void OnConnectionError() MOJO_OVERRIDE {
57 static_cast<WithErrorHandler<Interface>*>(stub_.sink())->
58 OnConnectionError();
59 }
60
61 internal::Router* router_;
62 typename Interface::Client_::Proxy_* proxy_;
63 typename Interface::Stub_ stub_;
64
65 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
66 };
67
68 } // namespace internal
69 } // namespace mojo
70
71 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698