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_PRIVILEGED_H_ | 5 #ifndef IPC_ATTACHMENT_BROKER_PRIVILEGED_H_ |
6 #define IPC_ATTACHMENT_BROKER_PRIVILEGED_H_ | 6 #define IPC_ATTACHMENT_BROKER_PRIVILEGED_H_ |
7 | 7 |
| 8 #include <utility> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "ipc/attachment_broker.h" | 15 #include "ipc/attachment_broker.h" |
14 #include "ipc/ipc_export.h" | 16 #include "ipc/ipc_export.h" |
15 | 17 |
16 #if defined(OS_MACOSX) && !defined(OS_IOS) | 18 #if defined(OS_MACOSX) && !defined(OS_IOS) |
17 namespace base { | 19 namespace base { |
18 class PortProvider; | 20 class PortProvider; |
19 } // namespace base | 21 } // namespace base |
20 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 22 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
(...skipping 20 matching lines...) Expand all Loading... |
41 #else | 43 #else |
42 static void CreateBrokerIfNeeded(); | 44 static void CreateBrokerIfNeeded(); |
43 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 45 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
44 | 46 |
45 // Similar to CreateBrokerIfNeeded(), but useful for single process unit tests | 47 // Similar to CreateBrokerIfNeeded(), but useful for single process unit tests |
46 // that don't need real attachment brokering, and don't want to deal with | 48 // that don't need real attachment brokering, and don't want to deal with |
47 // setting up a fake PortProvider. | 49 // setting up a fake PortProvider. |
48 static void CreateBrokerForSingleProcessTests(); | 50 static void CreateBrokerForSingleProcessTests(); |
49 | 51 |
50 // AttachmentBroker overrides. | 52 // AttachmentBroker overrides. |
51 void RegisterCommunicationChannel(Endpoint* endpoint) override; | 53 void RegisterCommunicationChannel( |
| 54 Endpoint* endpoint, |
| 55 scoped_refptr<base::SingleThreadTaskRunner> runner) override; |
52 void DeregisterCommunicationChannel(Endpoint* endpoint) override; | 56 void DeregisterCommunicationChannel(Endpoint* endpoint) override; |
53 bool IsPrivilegedBroker() override; | 57 bool IsPrivilegedBroker() override; |
54 | 58 |
55 protected: | 59 protected: |
| 60 using EndpointRunnerPair = |
| 61 std::pair<Endpoint*, scoped_refptr<base::SingleThreadTaskRunner>>; |
| 62 |
56 // Returns the sender whose peer's process id is |id|. | 63 // Returns the sender whose peer's process id is |id|. |
57 // Returns nullptr if no sender is found. | 64 // Returns nullptr if no sender is found. |
58 // The lock returned by get_lock() must already be acquired before calling | 65 // The lock returned by get_lock() must already be acquired before calling |
59 // this method. The return value is only guaranteed to be valid while the lock | 66 // this method. The return value is only guaranteed to be valid while the lock |
60 // is held. | 67 // is held. |
61 Sender* GetSenderWithProcessId(base::ProcessId id); | 68 EndpointRunnerPair GetSenderWithProcessId(base::ProcessId id); |
| 69 |
| 70 // Sends a message to the endpoint, dispatching onto another thread if |
| 71 // necessary. |
| 72 void SendMessageToEndpoint(EndpointRunnerPair pair, Message* message); |
62 | 73 |
63 // Errors that can be reported by subclasses. | 74 // Errors that can be reported by subclasses. |
64 // These match tools/metrics/histograms.xml. | 75 // These match tools/metrics/histograms.xml. |
65 // This enum is append-only. | 76 // This enum is append-only. |
66 enum UMAError { | 77 enum UMAError { |
67 // The brokerable attachment had a valid destination. This is the success | 78 // The brokerable attachment had a valid destination. This is the success |
68 // case. | 79 // case. |
69 DESTINATION_FOUND = 0, | 80 DESTINATION_FOUND = 0, |
70 // The brokerable attachment had a destination, but the broker did not have | 81 // The brokerable attachment had a destination, but the broker did not have |
71 // a channel of communication with that process. | 82 // a channel of communication with that process. |
(...skipping 26 matching lines...) Expand all Loading... |
98 ERROR_COULD_NOT_OPEN_SOURCE_OR_DEST = 13, | 109 ERROR_COULD_NOT_OPEN_SOURCE_OR_DEST = 13, |
99 // The broker was asked to transfer a HANDLE with invalid permissions. | 110 // The broker was asked to transfer a HANDLE with invalid permissions. |
100 ERROR_INVALID_PERMISSIONS = 14, | 111 ERROR_INVALID_PERMISSIONS = 14, |
101 ERROR_MAX | 112 ERROR_MAX |
102 }; | 113 }; |
103 | 114 |
104 // Emits an UMA metric. | 115 // Emits an UMA metric. |
105 void LogError(UMAError error); | 116 void LogError(UMAError error); |
106 | 117 |
107 private: | 118 private: |
108 std::vector<Endpoint*> endpoints_; | 119 // A vector of Endpoints, and the SingleThreadTaskRunner that should be used |
| 120 // to invoke Send() on each Endpoint. |
| 121 std::vector<EndpointRunnerPair> endpoints_; |
109 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivileged); | 122 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivileged); |
110 }; | 123 }; |
111 | 124 |
112 } // namespace IPC | 125 } // namespace IPC |
113 | 126 |
114 #endif // IPC_ATTACHMENT_BROKER_PRIVILEGED_H_ | 127 #endif // IPC_ATTACHMENT_BROKER_PRIVILEGED_H_ |
OLD | NEW |