| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_ |
| 6 #define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "mojo/edk/system/system_impl_export.h" |
| 12 |
| 13 namespace mojo { |
| 14 namespace system { |
| 15 |
| 16 class MessageInTransit; |
| 17 |
| 18 // Interface for receivers of messages from |ChannelEndpoint| (hence from |
| 19 // |Channel|). |port| is simply the value passed to |ChannelEndpoint| on |
| 20 // construction, and provides a lightweight way for an object to be the client |
| 21 // of multiple |ChannelEndpoint|s. (|MessagePipe| implements this interface, in |
| 22 // which case |port| is the port number for the |ProxyMessagePipeEndpoint| |
| 23 // corresdponding to the |ChannelEndpoint|.) |
| 24 // |
| 25 // Implementations of this class should be thread-safe. |ChannelEndpointClient| |
| 26 // *precedes* |ChannelEndpoint| in the lock order, so |ChannelEndpoint| should |
| 27 // never call into this class with its lock held. (Instead, it should take a |
| 28 // reference under its lock, release its lock, and make any needed call(s).) |
| 29 // |
| 30 // Note: As a consequence of this, all the client methods may be called even |
| 31 // after |ChannelEndpoint::DetachFromClient()| has been called (so the |
| 32 // |ChannelEndpoint| has apparently relinquished its pointer to the |
| 33 // |ChannelEndpointClient|). |
| 34 class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpointClient |
| 35 : public base::RefCountedThreadSafe<ChannelEndpointClient> { |
| 36 public: |
| 37 // Called by |ChannelEndpoint| in response to its |OnReadMessage()|, which is |
| 38 // called by |Channel| when it receives a message for the |ChannelEndpoint|. |
| 39 // (|port| is the value passed to |ChannelEndpoint|'s constructor as |
| 40 // |client_port|.) |
| 41 virtual bool OnReadMessage(unsigned port, |
| 42 scoped_ptr<MessageInTransit> message) = 0; |
| 43 |
| 44 // Called by |ChannelEndpoint| when the |Channel| is relinquishing its pointer |
| 45 // to the |ChannelEndpoint| (and vice versa). After this is called, |
| 46 // |OnReadMessage()| will no longer be called. |
| 47 virtual void OnDetachFromChannel(unsigned port) = 0; |
| 48 |
| 49 protected: |
| 50 ChannelEndpointClient() {} |
| 51 |
| 52 virtual ~ChannelEndpointClient() {} |
| 53 friend class base::RefCountedThreadSafe<ChannelEndpointClient>; |
| 54 |
| 55 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(ChannelEndpointClient); |
| 57 }; |
| 58 |
| 59 } // namespace system |
| 60 } // namespace mojo |
| 61 |
| 62 #endif // MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_ |
| OLD | NEW |