Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: ipc/attachment_broker.h

Issue 1414603003: ipc: Move AttachmentBrokerPrivileged singleton logic into ipc/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor formatting. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/child_process_host_impl.cc ('k') | ipc/attachment_broker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ipc/brokerable_attachment.h" 11 #include "ipc/brokerable_attachment.h"
12 #include "ipc/ipc_export.h" 12 #include "ipc/ipc_export.h"
13 #include "ipc/ipc_listener.h" 13 #include "ipc/ipc_listener.h"
14 14
15 // If the platform has no attachments that need brokering, then it shouldn't 15 // If the platform has no attachments that need brokering, then it shouldn't
16 // compile any code that calls member functions of AttachmentBroker. This 16 // compile any code that calls member functions of AttachmentBroker. This
17 // prevents symbols only used by AttachmentBroker and its subclasses from 17 // prevents symbols only used by AttachmentBroker and its subclasses from
18 // making it into the binary. 18 // making it into the binary.
19 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) 19 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
20 #define USE_ATTACHMENT_BROKER 1 20 #define USE_ATTACHMENT_BROKER 1
21 #else 21 #else
22 #define USE_ATTACHMENT_BROKER 0 22 #define USE_ATTACHMENT_BROKER 0
23 #endif // defined(OS_WIN) 23 #endif // defined(OS_WIN)
24 24
25 #if defined(OS_MACOSX) && !defined(OS_IOS)
26 namespace base {
27 class PortProvider;
28 } // namespace base
29 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
30
31 namespace IPC { 25 namespace IPC {
32 26
33 class AttachmentBroker; 27 class AttachmentBroker;
34 class Endpoint; 28 class Endpoint;
35 29
36 // Classes that inherit from this abstract base class are capable of 30 // Classes that inherit from this abstract base class are capable of
37 // communicating with a broker to send and receive attachments to Chrome IPC 31 // communicating with a broker to send and receive attachments to Chrome IPC
38 // messages. 32 // messages.
39 class IPC_EXPORT SupportsAttachmentBrokering { 33 class IPC_EXPORT SupportsAttachmentBrokering {
40 public: 34 public:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 79
86 // These two methods should only be called by the broker process. 80 // These two methods should only be called by the broker process.
87 // 81 //
88 // Each unprivileged process should have one IPC channel on which it 82 // Each unprivileged process should have one IPC channel on which it
89 // communicates attachment information with the broker process. In the broker 83 // communicates attachment information with the broker process. In the broker
90 // process, these channels must be registered and deregistered with the 84 // process, these channels must be registered and deregistered with the
91 // Attachment Broker as they are created and destroyed. 85 // Attachment Broker as they are created and destroyed.
92 virtual void RegisterCommunicationChannel(Endpoint* endpoint); 86 virtual void RegisterCommunicationChannel(Endpoint* endpoint);
93 virtual void DeregisterCommunicationChannel(Endpoint* endpoint); 87 virtual void DeregisterCommunicationChannel(Endpoint* endpoint);
94 88
95 #if defined(OS_MACOSX) && !defined(OS_IOS)
96 // This method should only be called by the broker process.
97 //
98 // The port provider must live as long as the AttachmentBroker. A port
99 // provider must be set before any attachment brokering occurs.
100 void set_port_provider(base::PortProvider* port_provider) {
101 DCHECK(!port_provider_);
102 port_provider_ = port_provider;
103 }
104 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
105
106 protected: 89 protected:
107 using AttachmentVector = std::vector<scoped_refptr<BrokerableAttachment>>; 90 using AttachmentVector = std::vector<scoped_refptr<BrokerableAttachment>>;
108 91
109 // Adds |attachment| to |attachments_|, and notifies the observers. 92 // Adds |attachment| to |attachments_|, and notifies the observers.
110 void HandleReceivedAttachment( 93 void HandleReceivedAttachment(
111 const scoped_refptr<BrokerableAttachment>& attachment); 94 const scoped_refptr<BrokerableAttachment>& attachment);
112 95
113 // Informs the observers that a new BrokerableAttachment has been received. 96 // Informs the observers that a new BrokerableAttachment has been received.
114 void NotifyObservers(const BrokerableAttachment::AttachmentId& id); 97 void NotifyObservers(const BrokerableAttachment::AttachmentId& id);
115 98
116 // This method is exposed for testing only. 99 // This method is exposed for testing only.
117 AttachmentVector* get_attachments() { return &attachments_; } 100 AttachmentVector* get_attachments() { return &attachments_; }
118 101
119 #if defined(OS_MACOSX) && !defined(OS_IOS)
120 base::PortProvider* port_provider() const { return port_provider_; }
121 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
122
123 private: 102 private:
124 #if defined(OS_WIN) 103 #if defined(OS_WIN)
125 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest, 104 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest,
126 ReceiveValidMessage); 105 ReceiveValidMessage);
127 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest, 106 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerUnprivilegedWinTest,
128 ReceiveInvalidMessage); 107 ReceiveInvalidMessage);
129 #endif // defined(OS_WIN) 108 #endif // defined(OS_WIN)
130 109
131 #if defined(OS_MACOSX) && !defined(OS_IOS)
132 base::PortProvider* port_provider_;
133 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
134
135 // A vector of BrokerableAttachments that have been received, but not yet 110 // A vector of BrokerableAttachments that have been received, but not yet
136 // consumed. 111 // consumed.
137 // A std::vector is used instead of a std::map because this container is 112 // A std::vector is used instead of a std::map because this container is
138 // expected to have few elements, for which a std::vector is expected to have 113 // expected to have few elements, for which a std::vector is expected to have
139 // better performance. 114 // better performance.
140 AttachmentVector attachments_; 115 AttachmentVector attachments_;
141 116
142 std::vector<Observer*> observers_; 117 std::vector<Observer*> observers_;
143 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); 118 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker);
144 }; 119 };
145 120
146 } // namespace IPC 121 } // namespace IPC
147 122
148 #endif // IPC_ATTACHMENT_BROKER_H_ 123 #endif // IPC_ATTACHMENT_BROKER_H_
OLDNEW
« no previous file with comments | « content/common/child_process_host_impl.cc ('k') | ipc/attachment_broker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698