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/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 #include "base/synchronization/lock.h" |
11 #include "ipc/brokerable_attachment.h" | 12 #include "ipc/brokerable_attachment.h" |
12 #include "ipc/ipc_export.h" | 13 #include "ipc/ipc_export.h" |
13 #include "ipc/ipc_listener.h" | 14 #include "ipc/ipc_listener.h" |
14 | 15 |
15 // If the platform has no attachments that need brokering, then it shouldn't | 16 // If the platform has no attachments that need brokering, then it shouldn't |
16 // compile any code that calls member functions of AttachmentBroker. This | 17 // compile any code that calls member functions of AttachmentBroker. This |
17 // prevents symbols only used by AttachmentBroker and its subclasses from | 18 // prevents symbols only used by AttachmentBroker and its subclasses from |
18 // making it into the binary. | 19 // making it into the binary. |
19 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) | 20 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |
20 #define USE_ATTACHMENT_BROKER 1 | 21 #define USE_ATTACHMENT_BROKER 1 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Adds |attachment| to |attachments_|, and notifies the observers. | 93 // Adds |attachment| to |attachments_|, and notifies the observers. |
93 void HandleReceivedAttachment( | 94 void HandleReceivedAttachment( |
94 const scoped_refptr<BrokerableAttachment>& attachment); | 95 const scoped_refptr<BrokerableAttachment>& attachment); |
95 | 96 |
96 // Informs the observers that a new BrokerableAttachment has been received. | 97 // Informs the observers that a new BrokerableAttachment has been received. |
97 void NotifyObservers(const BrokerableAttachment::AttachmentId& id); | 98 void NotifyObservers(const BrokerableAttachment::AttachmentId& id); |
98 | 99 |
99 // This method is exposed for testing only. | 100 // This method is exposed for testing only. |
100 AttachmentVector* get_attachments() { return &attachments_; } | 101 AttachmentVector* get_attachments() { return &attachments_; } |
101 | 102 |
| 103 base::Lock* get_lock() { return &lock_; } |
| 104 |
102 private: | 105 private: |
103 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
104 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest, | 107 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest, |
105 ReceiveValidMessage); | 108 ReceiveValidMessage); |
106 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest, | 109 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest, |
107 ReceiveInvalidMessage); | 110 ReceiveInvalidMessage); |
108 #endif // defined(OS_WIN) | 111 #endif // defined(OS_WIN) |
109 | 112 |
110 // A vector of BrokerableAttachments that have been received, but not yet | 113 // A vector of BrokerableAttachments that have been received, but not yet |
111 // consumed. | 114 // consumed. |
112 // A std::vector is used instead of a std::map because this container is | 115 // A std::vector is used instead of a std::map because this container is |
113 // expected to have few elements, for which a std::vector is expected to have | 116 // expected to have few elements, for which a std::vector is expected to have |
114 // better performance. | 117 // better performance. |
115 AttachmentVector attachments_; | 118 AttachmentVector attachments_; |
116 | 119 |
117 std::vector<Observer*> observers_; | 120 std::vector<Observer*> observers_; |
| 121 |
| 122 // The AttachmentBroker can be accessed from any thread, so modifications to |
| 123 // internal state must be guarded by a lock. |
| 124 base::Lock lock_; |
118 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); | 125 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); |
119 }; | 126 }; |
120 | 127 |
121 } // namespace IPC | 128 } // namespace IPC |
122 | 129 |
123 #endif // IPC_ATTACHMENT_BROKER_H_ | 130 #endif // IPC_ATTACHMENT_BROKER_H_ |
OLD | NEW |