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

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

Issue 287003004: Revert 270867 "Mojo: Internalize ServiceConnector<>" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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>
26 class InterfaceImplState : public ErrorHandler { 18 class InterfaceImplState : public ErrorHandler {
27 public: 19 public:
28 typedef typename Interface::Client Client; 20 typedef typename Interface::Client Client;
29 21
30 explicit InterfaceImplState(InterfaceImplBase<Interface>* instance) 22 explicit InterfaceImplState(WithErrorHandler<Interface>* instance)
31 : router_(NULL), 23 : router_(NULL),
32 client_(NULL), 24 client_(NULL),
33 proxy_(NULL) { 25 proxy_(NULL) {
34 assert(instance); 26 assert(instance);
35 stub_.set_sink(instance); 27 stub_.set_sink(instance);
36 } 28 }
37 29
38 virtual ~InterfaceImplState() { 30 virtual ~InterfaceImplState() {
39 delete proxy_; 31 delete proxy_;
40 if (router_) { 32 if (router_) {
(...skipping 18 matching lines...) Expand all
59 filters.Append(new MessageHeaderValidator) 51 filters.Append(new MessageHeaderValidator)
60 .Append(new typename Interface::RequestValidator_) 52 .Append(new typename Interface::RequestValidator_)
61 .Append(new typename Interface::Client::ResponseValidator_); 53 .Append(new typename Interface::Client::ResponseValidator_);
62 54
63 router_ = new Router(handle.Pass(), filters.Pass(), waiter); 55 router_ = new Router(handle.Pass(), filters.Pass(), waiter);
64 router_->set_incoming_receiver(&stub_); 56 router_->set_incoming_receiver(&stub_);
65 router_->set_error_handler(this); 57 router_->set_error_handler(this);
66 58
67 proxy_ = new typename Client::Proxy_(router_); 59 proxy_ = new typename Client::Proxy_(router_);
68 60
69 instance()->SetClient(proxy_); 61 stub_.sink()->SetClient(proxy_);
70 instance()->OnConnectionEstablished();
71 } 62 }
72 63
73 Router* router() { return router_; } 64 Router* router() { return router_; }
74 65
75 void set_client(Client* client) { client_ = client; } 66 void set_client(Client* client) { client_ = client; }
76 Client* client() { return client_; } 67 Client* client() { return client_; }
77 68
78 private: 69 private:
79 InterfaceImplBase<Interface>* instance() {
80 return static_cast<InterfaceImplBase<Interface>*>(stub_.sink());
81 }
82
83 virtual void OnConnectionError() MOJO_OVERRIDE { 70 virtual void OnConnectionError() MOJO_OVERRIDE {
84 instance()->OnConnectionError(); 71 static_cast<WithErrorHandler<Interface>*>(stub_.sink())->
72 OnConnectionError();
85 } 73 }
86 74
87 Router* router_; 75 Router* router_;
88 Client* client_; 76 Client* client_;
89 typename Client::Proxy_* proxy_; 77 typename Client::Proxy_* proxy_;
90 typename Interface::Stub_ stub_; 78 typename Interface::Stub_ stub_;
91 79
92 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); 80 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
93 }; 81 };
94 82
95 } // namespace internal 83 } // namespace internal
96 } // namespace mojo 84 } // namespace mojo
97 85
98 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ 86 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698