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

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

Issue 275363002: Internalize ServiceConnector<> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add OnConnectionEstablished() 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
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_LIB_INTERFACE_IMPL_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
7 7
8 #include "mojo/public/cpp/bindings/error_handler.h" 8 #include "mojo/public/cpp/bindings/error_handler.h"
9 #include "mojo/public/cpp/bindings/interface_ptr.h" 9 #include "mojo/public/cpp/bindings/interface_ptr.h"
10 #include "mojo/public/cpp/system/macros.h" 10 #include "mojo/public/cpp/system/macros.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace internal { 13 namespace internal {
14 14
15 class InterfaceImplBase : public ErrorHandler {
darin (slow to review) 2014/05/15 18:06:20 I don't think this interface is needed. InterfaceI
16 public:
17 virtual ~InterfaceImplBase() {}
18 virtual void OnConnectionEstablished() = 0;
19 virtual void OnConnectionError() = 0;
20 };
21
22 template <typename Base>
23 class WithInterfaceImplBase : public Base {
darin (slow to review) 2014/05/15 18:06:20 This class should just be renamed InterfaceImplBas
24 public:
25 virtual ~WithInterfaceImplBase() {}
26 virtual void OnConnectionEstablished() = 0;
27 virtual void OnConnectionError() = 0;
28 };
29
15 template <typename Interface> 30 template <typename Interface>
16 class InterfaceImplState : public ErrorHandler { 31 class InterfaceImplState : public InterfaceImplBase {
17 public: 32 public:
18 typedef typename Interface::Client Client; 33 typedef typename Interface::Client Client;
19 34
20 explicit InterfaceImplState(WithErrorHandler<Interface>* instance) 35 explicit InterfaceImplState(WithInterfaceImplBase<Interface>* instance)
21 : router_(NULL), 36 : router_(NULL),
22 client_(NULL), 37 client_(NULL),
23 proxy_(NULL) { 38 proxy_(NULL) {
24 assert(instance); 39 assert(instance);
25 stub_.set_sink(instance); 40 stub_.set_sink(instance);
26 } 41 }
27 42
28 virtual ~InterfaceImplState() { 43 virtual ~InterfaceImplState() {
29 delete proxy_; 44 delete proxy_;
30 if (router_) { 45 if (router_) {
(...skipping 14 matching lines...) Expand all
45 MojoAsyncWaiter* waiter) { 60 MojoAsyncWaiter* waiter) {
46 assert(!router_); 61 assert(!router_);
47 62
48 router_ = new Router(handle.Pass(), waiter); 63 router_ = new Router(handle.Pass(), waiter);
49 router_->set_incoming_receiver(&stub_); 64 router_->set_incoming_receiver(&stub_);
50 router_->set_error_handler(this); 65 router_->set_error_handler(this);
51 66
52 proxy_ = new typename Client::Proxy_(router_); 67 proxy_ = new typename Client::Proxy_(router_);
53 68
54 stub_.sink()->SetClient(proxy_); 69 stub_.sink()->SetClient(proxy_);
70 OnConnectionEstablished();
darin (slow to review) 2014/05/15 18:06:20 no need for the virtual function call here. this c
55 } 71 }
56 72
57 Router* router() { return router_; } 73 Router* router() { return router_; }
58 74
59 void set_client(Client* client) { client_ = client; } 75 void set_client(Client* client) { client_ = client; }
60 Client* client() { return client_; } 76 Client* client() { return client_; }
61 77
62 private: 78 private:
79 virtual void OnConnectionEstablished() MOJO_OVERRIDE {
80 static_cast<WithInterfaceImplBase<Interface>*>(stub_.sink())->
81 OnConnectionEstablished();
82 }
83
63 virtual void OnConnectionError() MOJO_OVERRIDE { 84 virtual void OnConnectionError() MOJO_OVERRIDE {
64 static_cast<WithErrorHandler<Interface>*>(stub_.sink())-> 85 static_cast<WithInterfaceImplBase<Interface>*>(stub_.sink())->
65 OnConnectionError(); 86 OnConnectionError();
66 } 87 }
67 88
68 internal::Router* router_; 89 internal::Router* router_;
69 Client* client_; 90 Client* client_;
70 typename Client::Proxy_* proxy_; 91 typename Client::Proxy_* proxy_;
71 typename Interface::Stub_ stub_; 92 typename Interface::Stub_ stub_;
72 93
73 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); 94 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
74 }; 95 };
75 96
76 } // namespace internal 97 } // namespace internal
77 } // namespace mojo 98 } // namespace mojo
78 99
79 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ 100 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698