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