OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_MACH_BROKER_MAC_H_ | 5 #ifndef CONTENT_BROWSER_MACH_BROKER_MAC_H_ |
6 #define CONTENT_BROWSER_MACH_BROKER_MAC_H_ | 6 #define CONTENT_BROWSER_MACH_BROKER_MAC_H_ |
7 | 7 |
| 8 #include <mach/mach.h> |
| 9 |
8 #include <map> | 10 #include <map> |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include <mach/mach.h> | |
12 | |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
15 #include "base/process/process_metrics.h" | 15 #include "base/process/process_metrics.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "content/public/browser/browser_child_process_observer.h" | 17 #include "content/public/browser/browser_child_process_observer.h" |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // Performs any necessary setup that cannot happen in the constructor. | 55 // Performs any necessary setup that cannot happen in the constructor. |
56 // Callers MUST acquire the lock given by GetLock() before calling this | 56 // Callers MUST acquire the lock given by GetLock() before calling this |
57 // method (and release the lock afterwards). | 57 // method (and release the lock afterwards). |
58 void EnsureRunning(); | 58 void EnsureRunning(); |
59 | 59 |
60 // Adds a placeholder to the map for the given pid with MACH_PORT_NULL. | 60 // Adds a placeholder to the map for the given pid with MACH_PORT_NULL. |
61 // Callers are expected to later update the port with FinalizePid(). Callers | 61 // Callers are expected to later update the port with FinalizePid(). Callers |
62 // MUST acquire the lock given by GetLock() before calling this method (and | 62 // MUST acquire the lock given by GetLock() before calling this method (and |
63 // release the lock afterwards). | 63 // release the lock afterwards). |
64 void AddPlaceholderForPid(base::ProcessHandle pid); | 64 void AddPlaceholderForPid(base::ProcessHandle pid, int child_process_id); |
65 | 65 |
66 // Implement |ProcessMetrics::PortProvider|. | 66 // Implement |ProcessMetrics::PortProvider|. |
67 mach_port_t TaskForPid(base::ProcessHandle process) const override; | 67 mach_port_t TaskForPid(base::ProcessHandle process) const override; |
68 | 68 |
69 // Implement |BrowserChildProcessObserver|. | 69 // Implement |BrowserChildProcessObserver|. |
70 void BrowserChildProcessHostDisconnected( | 70 void BrowserChildProcessHostDisconnected( |
71 const ChildProcessData& data) override; | 71 const ChildProcessData& data) override; |
72 void BrowserChildProcessCrashed(const ChildProcessData& data) override; | 72 void BrowserChildProcessCrashed(const ChildProcessData& data) override; |
73 | 73 |
74 // Implement |NotificationObserver|. | 74 // Implement |NotificationObserver|. |
(...skipping 10 matching lines...) Expand all Loading... |
85 ~MachBroker() override; | 85 ~MachBroker() override; |
86 | 86 |
87 // Updates the mapping for |pid| to include the given |mach_info|. Does | 87 // Updates the mapping for |pid| to include the given |mach_info|. Does |
88 // nothing if PlaceholderForPid() has not already been called for the given | 88 // nothing if PlaceholderForPid() has not already been called for the given |
89 // |pid|. Callers MUST acquire the lock given by GetLock() before calling | 89 // |pid|. Callers MUST acquire the lock given by GetLock() before calling |
90 // this method (and release the lock afterwards). | 90 // this method (and release the lock afterwards). |
91 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); | 91 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); |
92 | 92 |
93 // Removes all mappings belonging to |pid| from the broker. | 93 // Removes all mappings belonging to |pid| from the broker. |
94 void InvalidatePid(base::ProcessHandle pid); | 94 void InvalidatePid(base::ProcessHandle pid); |
| 95 // Removes all mappings belonging to |child_process_id| from the broker. |
| 96 void InvalidateChildProcessId(int child_process_id); |
95 | 97 |
96 // Returns the Mach port name to use when sending or receiving messages. | 98 // Returns the Mach port name to use when sending or receiving messages. |
97 // Does the Right Thing in the browser and in child processes. | 99 // Does the Right Thing in the browser and in child processes. |
98 static std::string GetMachPortName(); | 100 static std::string GetMachPortName(); |
99 // Callback used to register notifications on the UI thread. | 101 // Callback used to register notifications on the UI thread. |
100 void RegisterNotifications(); | 102 void RegisterNotifications(); |
101 | 103 |
102 // True if the listener thread has been started. | 104 // True if the listener thread has been started. |
103 bool listener_thread_started_; | 105 bool listener_thread_started_; |
104 | 106 |
105 // Used to register for notifications received by NotificationObserver. | 107 // Used to register for notifications received by NotificationObserver. |
106 // Accessed only on the UI thread. | 108 // Accessed only on the UI thread. |
107 NotificationRegistrar registrar_; | 109 NotificationRegistrar registrar_; |
108 | 110 |
109 // Stores mach info for every process in the broker. | 111 // Stores mach info for every process in the broker. |
110 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; | 112 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; |
111 MachMap mach_map_; | 113 MachMap mach_map_; |
112 | 114 |
| 115 // Stores the Child process unique id (RenderProcessHost ID) for every process |
| 116 typedef std::map<base::ProcessHandle, int> ChildProcessIdMap; |
| 117 ChildProcessIdMap child_process_id_map_; |
| 118 |
113 // Mutex that guards |mach_map_|. | 119 // Mutex that guards |mach_map_|. |
114 mutable base::Lock lock_; | 120 mutable base::Lock lock_; |
115 | 121 |
116 DISALLOW_COPY_AND_ASSIGN(MachBroker); | 122 DISALLOW_COPY_AND_ASSIGN(MachBroker); |
117 }; | 123 }; |
118 | 124 |
119 } // namespace content | 125 } // namespace content |
120 | 126 |
121 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ | 127 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ |
OLD | NEW |