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 TaskRunner; |
30 }; | 30 }; |
31 | 31 |
32 namespace IPC { | 32 namespace IPC { |
33 | 33 |
34 class AttachmentBroker; | 34 class AttachmentBroker; |
35 class Endpoint; | 35 class Endpoint; |
36 | 36 |
37 // Classes that inherit from this abstract base class are capable of | 37 // Classes that inherit from this abstract base class are capable of |
38 // communicating with a broker to send and receive attachments to Chrome IPC | 38 // communicating with a broker to send and receive attachments to Chrome IPC |
39 // messages. | 39 // messages. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 // Returns whether the attachment was available. If the attachment was | 79 // Returns whether the attachment was available. If the attachment was |
80 // available, populates the output parameter |attachment|. | 80 // available, populates the output parameter |attachment|. |
81 bool GetAttachmentWithId(BrokerableAttachment::AttachmentId id, | 81 bool GetAttachmentWithId(BrokerableAttachment::AttachmentId id, |
82 scoped_refptr<BrokerableAttachment>* attachment); | 82 scoped_refptr<BrokerableAttachment>* attachment); |
83 | 83 |
84 // Any given observer should only ever add itself once to the observer list. | 84 // Any given observer should only ever add itself once to the observer list. |
85 // Notifications to |observer| will be posted to |runner|. | 85 // Notifications to |observer| will be posted to |runner|. |
86 // The |observer| is expected to call RemoveObserver() before being destroyed. | 86 // The |observer| is expected to call RemoveObserver() before being destroyed. |
87 void AddObserver(Observer* observer, | 87 void AddObserver(Observer* observer, |
88 const scoped_refptr<base::SequencedTaskRunner>& runner); | 88 const scoped_refptr<base::TaskRunner>& runner); |
89 void RemoveObserver(Observer* observer); | 89 void RemoveObserver(Observer* observer); |
90 | 90 |
91 // These two methods should only be called by the broker process. | 91 // These two methods should only be called by the broker process. |
92 // | 92 // |
93 // Each unprivileged process should have one IPC channel on which it | 93 // Each unprivileged process should have one IPC channel on which it |
94 // communicates attachment information with the broker process. In the broker | 94 // communicates attachment information with the broker process. In the broker |
95 // process, these channels must be registered and deregistered with the | 95 // process, these channels must be registered and deregistered with the |
96 // Attachment Broker as they are created and destroyed. | 96 // Attachment Broker as they are created and destroyed. |
97 virtual void RegisterCommunicationChannel(Endpoint* endpoint); | 97 virtual void RegisterCommunicationChannel(Endpoint* endpoint); |
98 virtual void DeregisterCommunicationChannel(Endpoint* endpoint); | 98 virtual void DeregisterCommunicationChannel(Endpoint* endpoint); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 AttachmentVector attachments_; | 133 AttachmentVector attachments_; |
134 | 134 |
135 struct ObserverInfo { | 135 struct ObserverInfo { |
136 ObserverInfo(); | 136 ObserverInfo(); |
137 ~ObserverInfo(); | 137 ~ObserverInfo(); |
138 | 138 |
139 Observer* observer; | 139 Observer* observer; |
140 int unique_id; | 140 int unique_id; |
141 | 141 |
142 // Notifications must be dispatched onto |runner|. | 142 // Notifications must be dispatched onto |runner|. |
143 scoped_refptr<base::SequencedTaskRunner> runner; | 143 scoped_refptr<base::TaskRunner> runner; |
144 }; | 144 }; |
145 std::vector<ObserverInfo> observers_; | 145 std::vector<ObserverInfo> observers_; |
146 | 146 |
147 // This member holds the last id given to an ObserverInfo. | 147 // This member holds the last id given to an ObserverInfo. |
148 int last_unique_id_; | 148 int last_unique_id_; |
149 | 149 |
150 // The AttachmentBroker can be accessed from any thread, so modifications to | 150 // The AttachmentBroker can be accessed from any thread, so modifications to |
151 // internal state must be guarded by a lock. | 151 // internal state must be guarded by a lock. |
152 base::Lock lock_; | 152 base::Lock lock_; |
153 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); | 153 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); |
154 }; | 154 }; |
155 | 155 |
156 } // namespace IPC | 156 } // namespace IPC |
157 | 157 |
158 #endif // IPC_ATTACHMENT_BROKER_H_ | 158 #endif // IPC_ATTACHMENT_BROKER_H_ |
OLD | NEW |