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_UNPRIVILEGED_H_ | 5 #ifndef IPC_ATTACHMENT_BROKER_UNPRIVILEGED_H_ |
6 #define IPC_ATTACHMENT_BROKER_UNPRIVILEGED_H_ | 6 #define IPC_ATTACHMENT_BROKER_UNPRIVILEGED_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "ipc/attachment_broker.h" | 10 #include "ipc/attachment_broker.h" |
11 #include "ipc/ipc_export.h" | 11 #include "ipc/ipc_export.h" |
12 | 12 |
13 namespace IPC { | 13 namespace IPC { |
14 | 14 |
15 class Endpoint; | 15 class Endpoint; |
16 class Sender; | 16 class Sender; |
17 | 17 |
18 // This abstract subclass of AttachmentBroker is intended for use in | 18 // This abstract subclass of AttachmentBroker is intended for use in |
19 // non-privileged processes. | 19 // non-privileged processes. |
20 class IPC_EXPORT AttachmentBrokerUnprivileged : public IPC::AttachmentBroker { | 20 class IPC_EXPORT AttachmentBrokerUnprivileged : public IPC::AttachmentBroker { |
21 public: | 21 public: |
22 AttachmentBrokerUnprivileged(); | 22 AttachmentBrokerUnprivileged(); |
23 ~AttachmentBrokerUnprivileged() override; | 23 ~AttachmentBrokerUnprivileged() override; |
24 | 24 |
25 // On platforms that support attachment brokering, returns a new instance of | 25 // If there is no global attachment broker, makes a new |
26 // a platform-specific attachment broker. Otherwise returns |nullptr|. | 26 // AttachmentBrokerUnprivileged and sets it as the global attachment broker. |
27 // The caller takes ownership of the newly created instance, and is | 27 // This method is thread safe. |
28 // responsible for ensuring that the attachment broker lives longer than | 28 static void CreateBrokerIfNeeded(); |
29 // every IPC::Channel. The new instance automatically registers itself as the | |
30 // global attachment broker. | |
31 static scoped_ptr<AttachmentBrokerUnprivileged> CreateBroker(); | |
32 | 29 |
33 // In each unprivileged process, exactly one channel should be used to | 30 // AttachmentBroker: |
34 // communicate brokerable attachments with the broker process. | 31 void RegisterBrokerCommunicationChannel(Endpoint* endpoint) override; |
35 void DesignateBrokerCommunicationChannel(Endpoint* endpoint); | 32 void DeregisterBrokerCommunicationChannel(Endpoint* endpoint) override; |
| 33 bool IsPrivilegedBroker() override; |
36 | 34 |
37 protected: | 35 protected: |
38 IPC::Sender* get_sender() { return sender_; } | 36 IPC::Sender* get_sender() { return sender_; } |
39 | 37 |
40 // Errors that can be reported by subclasses. | 38 // Errors that can be reported by subclasses. |
41 // These match tools/metrics/histograms/histograms.xml. | 39 // These match tools/metrics/histograms/histograms.xml. |
42 // This enum is append-only. | 40 // This enum is append-only. |
43 enum UMAError { | 41 enum UMAError { |
44 // The brokerable attachment was successfully processed. | 42 // The brokerable attachment was successfully processed. |
45 SUCCESS = 0, | 43 SUCCESS = 0, |
(...skipping 11 matching lines...) Expand all Loading... |
57 private: | 55 private: |
58 // |sender_| is used to send Messages to the privileged broker process. | 56 // |sender_| is used to send Messages to the privileged broker process. |
59 // |sender_| must live at least as long as this instance. | 57 // |sender_| must live at least as long as this instance. |
60 IPC::Sender* sender_; | 58 IPC::Sender* sender_; |
61 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerUnprivileged); | 59 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerUnprivileged); |
62 }; | 60 }; |
63 | 61 |
64 } // namespace IPC | 62 } // namespace IPC |
65 | 63 |
66 #endif // IPC_ATTACHMENT_BROKER_UNPRIVILEGED_H_ | 64 #endif // IPC_ATTACHMENT_BROKER_UNPRIVILEGED_H_ |
OLD | NEW |