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

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

Issue 287143003: Mojo: Internalize ServiceConnector<> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing function 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/bindings/lib/filter_chain.h" 10 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
11 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" 11 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
12 #include "mojo/public/cpp/system/macros.h" 12 #include "mojo/public/cpp/system/macros.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace internal { 15 namespace internal {
16 16
17 template <typename Interface> 17 template <typename Interface>
18 class InterfaceImplBase : public Interface {
19 public:
20 virtual ~InterfaceImplBase() {}
21 virtual void OnConnectionEstablished() = 0;
22 virtual void OnConnectionError() = 0;
23 };
24
25 template <typename Interface>
18 class InterfaceImplState : public ErrorHandler { 26 class InterfaceImplState : public ErrorHandler {
19 public: 27 public:
20 typedef typename Interface::Client Client; 28 typedef typename Interface::Client Client;
21 29
22 explicit InterfaceImplState(WithErrorHandler<Interface>* instance) 30 explicit InterfaceImplState(InterfaceImplBase<Interface>* instance)
23 : router_(NULL), 31 : router_(NULL),
24 client_(NULL), 32 client_(NULL),
25 proxy_(NULL) { 33 proxy_(NULL) {
26 assert(instance); 34 assert(instance);
27 stub_.set_sink(instance); 35 stub_.set_sink(instance);
28 } 36 }
29 37
30 virtual ~InterfaceImplState() { 38 virtual ~InterfaceImplState() {
31 delete proxy_; 39 delete proxy_;
32 if (router_) { 40 if (router_) {
(...skipping 18 matching lines...) Expand all
51 filters.Append(new MessageHeaderValidator) 59 filters.Append(new MessageHeaderValidator)
52 .Append(new typename Interface::RequestValidator_) 60 .Append(new typename Interface::RequestValidator_)
53 .Append(new typename Interface::Client::ResponseValidator_); 61 .Append(new typename Interface::Client::ResponseValidator_);
54 62
55 router_ = new Router(handle.Pass(), filters.Pass(), waiter); 63 router_ = new Router(handle.Pass(), filters.Pass(), waiter);
56 router_->set_incoming_receiver(&stub_); 64 router_->set_incoming_receiver(&stub_);
57 router_->set_error_handler(this); 65 router_->set_error_handler(this);
58 66
59 proxy_ = new typename Client::Proxy_(router_); 67 proxy_ = new typename Client::Proxy_(router_);
60 68
61 stub_.sink()->SetClient(proxy_); 69 instance()->SetClient(proxy_);
70 instance()->OnConnectionEstablished();
62 } 71 }
63 72
64 Router* router() { return router_; } 73 Router* router() { return router_; }
65 74
66 void set_client(Client* client) { client_ = client; } 75 void set_client(Client* client) { client_ = client; }
67 Client* client() { return client_; } 76 Client* client() { return client_; }
68 77
69 private: 78 private:
79 InterfaceImplBase<Interface>* instance() {
80 return static_cast<InterfaceImplBase<Interface>*>(stub_.sink());
81 }
82
70 virtual void OnConnectionError() MOJO_OVERRIDE { 83 virtual void OnConnectionError() MOJO_OVERRIDE {
71 static_cast<WithErrorHandler<Interface>*>(stub_.sink())-> 84 instance()->OnConnectionError();
72 OnConnectionError();
73 } 85 }
74 86
75 Router* router_; 87 Router* router_;
76 Client* client_; 88 Client* client_;
77 typename Client::Proxy_* proxy_; 89 typename Client::Proxy_* proxy_;
78 typename Interface::Stub_ stub_; 90 typename Interface::Stub_ stub_;
79 91
80 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); 92 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
81 }; 93 };
82 94
83 } // namespace internal 95 } // namespace internal
84 } // namespace mojo 96 } // namespace mojo
85 97
86 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ 98 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_impl.h ('k') | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698