OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 IPC_ATTACHMENT_BROKER_H_ | 5 #ifndef IPC_ATTACHMENT_BROKER_H_ |
6 #define IPC_ATTACHMENT_BROKER_H_ | 6 #define IPC_ATTACHMENT_BROKER_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "ipc/brokerable_attachment.h" | 14 #include "ipc/brokerable_attachment.h" |
15 #include "ipc/ipc_export.h" | 15 #include "ipc/ipc_export.h" |
16 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
17 | 17 |
18 // If the platform has no attachments that need brokering, then it shouldn't | 18 // If the platform has no attachments that need brokering, then it shouldn't |
19 // compile any code that calls member functions of AttachmentBroker. This | 19 // compile any code that calls member functions of AttachmentBroker. This |
20 // prevents symbols only used by AttachmentBroker and its subclasses from | 20 // prevents symbols only used by AttachmentBroker and its subclasses from |
21 // making it into the binary. | 21 // making it into the binary. |
22 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) | 22 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |
23 #define USE_ATTACHMENT_BROKER 1 | 23 #define USE_ATTACHMENT_BROKER 1 |
24 #else | 24 #else |
25 #define USE_ATTACHMENT_BROKER 0 | 25 #define USE_ATTACHMENT_BROKER 0 |
26 #endif // defined(OS_WIN) | 26 #endif // defined(OS_WIN) |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 class SequencedTaskRunner; | 29 class SequencedTaskRunner; |
| 30 class SingleThreadTaskRunner; |
30 }; | 31 }; |
31 | 32 |
32 namespace IPC { | 33 namespace IPC { |
33 | 34 |
34 class AttachmentBroker; | 35 class AttachmentBroker; |
35 class Endpoint; | 36 class Endpoint; |
36 | 37 |
37 // Classes that inherit from this abstract base class are capable of | 38 // Classes that inherit from this abstract base class are capable of |
38 // communicating with a broker to send and receive attachments to Chrome IPC | 39 // communicating with a broker to send and receive attachments to Chrome IPC |
39 // messages. | 40 // messages. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 void AddObserver(Observer* observer, | 88 void AddObserver(Observer* observer, |
88 const scoped_refptr<base::SequencedTaskRunner>& runner); | 89 const scoped_refptr<base::SequencedTaskRunner>& runner); |
89 void RemoveObserver(Observer* observer); | 90 void RemoveObserver(Observer* observer); |
90 | 91 |
91 // These two methods should only be called by the broker process. | 92 // These two methods should only be called by the broker process. |
92 // | 93 // |
93 // Each unprivileged process should have one IPC channel on which it | 94 // Each unprivileged process should have one IPC channel on which it |
94 // communicates attachment information with the broker process. In the broker | 95 // communicates attachment information with the broker process. In the broker |
95 // process, these channels must be registered and deregistered with the | 96 // process, these channels must be registered and deregistered with the |
96 // Attachment Broker as they are created and destroyed. | 97 // Attachment Broker as they are created and destroyed. |
97 virtual void RegisterCommunicationChannel(Endpoint* endpoint); | 98 // |
| 99 // Invocations of Send() on |endpoint| will occur on thread bound to |runner|. |
| 100 virtual void RegisterCommunicationChannel( |
| 101 Endpoint* endpoint, |
| 102 scoped_refptr<base::SingleThreadTaskRunner> runner); |
98 virtual void DeregisterCommunicationChannel(Endpoint* endpoint); | 103 virtual void DeregisterCommunicationChannel(Endpoint* endpoint); |
99 | 104 |
100 // In each unprivileged process, exactly one channel should be used to | 105 // In each unprivileged process, exactly one channel should be used to |
101 // communicate brokerable attachments with the broker process. | 106 // communicate brokerable attachments with the broker process. |
102 virtual void RegisterBrokerCommunicationChannel(Endpoint* endpoint); | 107 virtual void RegisterBrokerCommunicationChannel(Endpoint* endpoint); |
103 virtual void DeregisterBrokerCommunicationChannel(Endpoint* endpoint); | 108 virtual void DeregisterBrokerCommunicationChannel(Endpoint* endpoint); |
104 | 109 |
105 // True if and only if this broker is privileged. | 110 // True if and only if this broker is privileged. |
106 virtual bool IsPrivilegedBroker(); | 111 virtual bool IsPrivilegedBroker(); |
107 | 112 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 163 |
159 // The AttachmentBroker can be accessed from any thread, so modifications to | 164 // The AttachmentBroker can be accessed from any thread, so modifications to |
160 // internal state must be guarded by a lock. | 165 // internal state must be guarded by a lock. |
161 base::Lock lock_; | 166 base::Lock lock_; |
162 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); | 167 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); |
163 }; | 168 }; |
164 | 169 |
165 } // namespace IPC | 170 } // namespace IPC |
166 | 171 |
167 #endif // IPC_ATTACHMENT_BROKER_H_ | 172 #endif // IPC_ATTACHMENT_BROKER_H_ |
OLD | NEW |