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