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

Side by Side Diff: mojo/public/cpp/bindings/lib/router.cc

Issue 1455063004: Mojo C++ bindings: introduce MultiplexRouter and related classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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
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 #include "mojo/public/cpp/bindings/lib/router.h" 5 #include "mojo/public/cpp/bindings/lib/router.h"
6 6
7 #include "mojo/public/cpp/environment/logging.h" 7 #include "mojo/public/cpp/environment/logging.h"
8 8
9 namespace mojo { 9 namespace mojo {
10 namespace internal { 10 namespace internal {
11 11
12 // ---------------------------------------------------------------------------- 12 // ----------------------------------------------------------------------------
13 13
14 namespace {
15
14 class ResponderThunk : public MessageReceiverWithStatus { 16 class ResponderThunk : public MessageReceiverWithStatus {
15 public: 17 public:
16 explicit ResponderThunk(const SharedData<Router*>& router) 18 explicit ResponderThunk(const SharedData<Router*>& router)
17 : router_(router), accept_was_invoked_(false) {} 19 : router_(router), accept_was_invoked_(false) {}
18 ~ResponderThunk() override { 20 ~ResponderThunk() override {
19 if (!accept_was_invoked_) { 21 if (!accept_was_invoked_) {
20 // The Mojo application handled a message that was expecting a response 22 // The Mojo application handled a message that was expecting a response
21 // but did not send a response. 23 // but did not send a response.
22 Router* router = router_.value(); 24 Router* router = router_.value();
23 if (router) { 25 if (router) {
(...skipping 23 matching lines...) Expand all
47 bool IsValid() override { 49 bool IsValid() override {
48 Router* router = router_.value(); 50 Router* router = router_.value();
49 return router && !router->encountered_error() && router->is_valid(); 51 return router && !router->encountered_error() && router->is_valid();
50 } 52 }
51 53
52 private: 54 private:
53 SharedData<Router*> router_; 55 SharedData<Router*> router_;
54 bool accept_was_invoked_; 56 bool accept_was_invoked_;
55 }; 57 };
56 58
59 } // namespace
60
57 // ---------------------------------------------------------------------------- 61 // ----------------------------------------------------------------------------
58 62
59 Router::HandleIncomingMessageThunk::HandleIncomingMessageThunk(Router* router) 63 Router::HandleIncomingMessageThunk::HandleIncomingMessageThunk(Router* router)
60 : router_(router) { 64 : router_(router) {
61 } 65 }
62 66
63 Router::HandleIncomingMessageThunk::~HandleIncomingMessageThunk() { 67 Router::HandleIncomingMessageThunk::~HandleIncomingMessageThunk() {
64 } 68 }
65 69
66 bool Router::HandleIncomingMessageThunk::Accept(Message* message) { 70 bool Router::HandleIncomingMessageThunk::Accept(Message* message) {
67 return router_->HandleIncomingMessage(message); 71 return router_->HandleIncomingMessage(message);
68 } 72 }
69 73
70 // ---------------------------------------------------------------------------- 74 // ----------------------------------------------------------------------------
71 75
72 Router::Router(ScopedMessagePipeHandle message_pipe, 76 Router::Router(ScopedMessagePipeHandle message_pipe,
73 FilterChain filters, 77 FilterChain filters,
74 const MojoAsyncWaiter* waiter) 78 const MojoAsyncWaiter* waiter)
75 : thunk_(this), 79 : thunk_(this),
76 filters_(filters.Pass()), 80 filters_(filters.Pass()),
77 connector_(message_pipe.Pass(), waiter), 81 connector_(message_pipe.Pass(), Connector::SINGLE_THREADED_SEND, waiter),
78 weak_self_(this), 82 weak_self_(this),
79 incoming_receiver_(nullptr), 83 incoming_receiver_(nullptr),
80 next_request_id_(0), 84 next_request_id_(0),
81 testing_mode_(false) { 85 testing_mode_(false) {
82 filters_.SetSink(&thunk_); 86 filters_.SetSink(&thunk_);
83 connector_.set_incoming_receiver(filters_.GetHead()); 87 connector_.set_incoming_receiver(filters_.GetHead());
84 } 88 }
85 89
86 Router::~Router() { 90 Router::~Router() {
87 weak_self_.set_value(nullptr); 91 weak_self_.set_value(nullptr);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return false; 153 return false;
150 154
151 return incoming_receiver_->Accept(message); 155 return incoming_receiver_->Accept(message);
152 } 156 }
153 } 157 }
154 158
155 // ---------------------------------------------------------------------------- 159 // ----------------------------------------------------------------------------
156 160
157 } // namespace internal 161 } // namespace internal
158 } // namespace mojo 162 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/multiplex_router.cc ('k') | mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698