Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_ROUTER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/lib/connector.h" | 10 #include "mojo/public/cpp/bindings/lib/connector.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 void set_incoming_receiver(MessageReceiverWithResponder* receiver) { | 26 void set_incoming_receiver(MessageReceiverWithResponder* receiver) { |
| 27 incoming_receiver_ = receiver; | 27 incoming_receiver_ = receiver; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Sets the error handler to receive notifications when an error is | 30 // Sets the error handler to receive notifications when an error is |
| 31 // encountered while reading from the pipe or waiting to read from the pipe. | 31 // encountered while reading from the pipe or waiting to read from the pipe. |
| 32 void set_error_handler(ErrorHandler* error_handler) { | 32 void set_error_handler(ErrorHandler* error_handler) { |
| 33 connector_.set_error_handler(error_handler); | 33 connector_.set_error_handler(error_handler); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Errors from incoming receivers will force the router's connector into an | |
| 37 // error state, where no more messages will be processed. This method is used | |
| 38 // during testing to prevent that from happening. | |
| 39 void set_enforce_errors_from_incoming_receiver(bool enforce) { | |
| 40 connector_.set_enforce_errors_from_incoming_receiver(enforce); | |
| 41 } | |
| 42 | |
| 43 // Returns true if an error was encountered while reading from the pipe or | 36 // Returns true if an error was encountered while reading from the pipe or |
| 44 // waiting to read from the pipe. | 37 // waiting to read from the pipe. |
| 45 bool encountered_error() const { return connector_.encountered_error(); } | 38 bool encountered_error() const { return connector_.encountered_error(); } |
| 46 | 39 |
| 47 void CloseMessagePipe() { | 40 void CloseMessagePipe() { |
| 48 connector_.CloseMessagePipe(); | 41 connector_.CloseMessagePipe(); |
| 49 } | 42 } |
| 50 | 43 |
| 51 ScopedMessagePipeHandle PassMessagePipe() { | 44 ScopedMessagePipeHandle PassMessagePipe() { |
| 52 return connector_.PassMessagePipe(); | 45 return connector_.PassMessagePipe(); |
| 53 } | 46 } |
| 54 | 47 |
| 55 // MessageReceiver implementation: | 48 // MessageReceiver implementation: |
| 56 virtual bool Accept(Message* message) MOJO_OVERRIDE; | 49 virtual bool Accept(Message* message) MOJO_OVERRIDE; |
| 57 virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder) | 50 virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder) |
| 58 MOJO_OVERRIDE; | 51 MOJO_OVERRIDE; |
| 59 | 52 |
| 53 // Sets this object to testing mode. | |
| 54 // In testing mode: | |
| 55 // - the object is more tolerant of unrecognized response messages; | |
| 56 // - the connector continues working after seeing errors from its incoming | |
| 57 // receiver. | |
| 58 void EnableTestingMode(); | |
|
darin (slow to review)
2014/06/12 23:06:56
another idea is to call this permissive mode. that
yzshen1
2014/06/12 23:12:21
I think if it is currently only useful for testing
| |
| 59 | |
| 60 private: | 60 private: |
| 61 typedef std::map<uint64_t, MessageReceiver*> ResponderMap; | 61 typedef std::map<uint64_t, MessageReceiver*> ResponderMap; |
| 62 | 62 |
| 63 class HandleIncomingMessageThunk : public MessageReceiver { | 63 class HandleIncomingMessageThunk : public MessageReceiver { |
| 64 public: | 64 public: |
| 65 HandleIncomingMessageThunk(Router* router); | 65 HandleIncomingMessageThunk(Router* router); |
| 66 virtual ~HandleIncomingMessageThunk(); | 66 virtual ~HandleIncomingMessageThunk(); |
| 67 | 67 |
| 68 // MessageReceiver implementation: | 68 // MessageReceiver implementation: |
| 69 virtual bool Accept(Message* message) MOJO_OVERRIDE; | 69 virtual bool Accept(Message* message) MOJO_OVERRIDE; |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 Router* router_; | 72 Router* router_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 bool HandleIncomingMessage(Message* message); | 75 bool HandleIncomingMessage(Message* message); |
| 76 | 76 |
| 77 HandleIncomingMessageThunk thunk_; | 77 HandleIncomingMessageThunk thunk_; |
| 78 FilterChain filters_; | 78 FilterChain filters_; |
| 79 Connector connector_; | 79 Connector connector_; |
| 80 SharedData<Router*> weak_self_; | 80 SharedData<Router*> weak_self_; |
| 81 MessageReceiverWithResponder* incoming_receiver_; | 81 MessageReceiverWithResponder* incoming_receiver_; |
| 82 ResponderMap responders_; | 82 ResponderMap responders_; |
| 83 uint64_t next_request_id_; | 83 uint64_t next_request_id_; |
| 84 bool testing_mode_; | |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 } // namespace internal | 87 } // namespace internal |
| 87 } // namespace mojo | 88 } // namespace mojo |
| 88 | 89 |
| 89 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ | 90 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
| OLD | NEW |