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> | 8 #include <mach/mach.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 | 12 |
| 13 #include "base/mac/dispatch_source_mach.h" |
| 14 #include "base/mac/scoped_mach_port.h" |
| 15 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
14 #include "base/process/process_handle.h" | 17 #include "base/process/process_handle.h" |
15 #include "base/process/process_metrics.h" | 18 #include "base/process/process_metrics.h" |
16 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
17 #include "content/public/browser/browser_child_process_observer.h" | 20 #include "content/public/browser/browser_child_process_observer.h" |
18 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
20 | 23 |
21 namespace content { | 24 namespace content { |
22 | 25 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 void BrowserChildProcessCrashed(const ChildProcessData& data, | 75 void BrowserChildProcessCrashed(const ChildProcessData& data, |
73 int exit_code) override; | 76 int exit_code) override; |
74 | 77 |
75 // Implement |NotificationObserver|. | 78 // Implement |NotificationObserver|. |
76 void Observe(int type, | 79 void Observe(int type, |
77 const NotificationSource& source, | 80 const NotificationSource& source, |
78 const NotificationDetails& details) override; | 81 const NotificationDetails& details) override; |
79 | 82 |
80 private: | 83 private: |
81 friend class MachBrokerTest; | 84 friend class MachBrokerTest; |
82 friend class MachListenerThreadDelegate; | |
83 friend struct DefaultSingletonTraits<MachBroker>; | 85 friend struct DefaultSingletonTraits<MachBroker>; |
84 | 86 |
85 MachBroker(); | 87 MachBroker(); |
86 ~MachBroker() override; | 88 ~MachBroker() override; |
87 | 89 |
| 90 // Performs any initialization work. |
| 91 bool Init(); |
| 92 |
| 93 // Message handler that is invoked on |dispatch_source_| when an |
| 94 // incoming message needs to be received. |
| 95 void HandleRequest(); |
| 96 |
88 // Updates the mapping for |pid| to include the given |mach_info|. Does | 97 // Updates the mapping for |pid| to include the given |mach_info|. Does |
89 // nothing if PlaceholderForPid() has not already been called for the given | 98 // nothing if PlaceholderForPid() has not already been called for the given |
90 // |pid|. Callers MUST acquire the lock given by GetLock() before calling | 99 // |pid|. Callers MUST acquire the lock given by GetLock() before calling |
91 // this method (and release the lock afterwards). | 100 // this method (and release the lock afterwards). |
92 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); | 101 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); |
93 | 102 |
94 // Removes all mappings belonging to |child_process_id| from the broker. | 103 // Removes all mappings belonging to |child_process_id| from the broker. |
95 void InvalidateChildProcessId(int child_process_id); | 104 void InvalidateChildProcessId(int child_process_id); |
96 | 105 |
97 // Returns the Mach port name to use when sending or receiving messages. | 106 // Returns the Mach port name to use when sending or receiving messages. |
98 // Does the Right Thing in the browser and in child processes. | 107 // Does the Right Thing in the browser and in child processes. |
99 static std::string GetMachPortName(); | 108 static std::string GetMachPortName(); |
| 109 |
100 // Callback used to register notifications on the UI thread. | 110 // Callback used to register notifications on the UI thread. |
101 void RegisterNotifications(); | 111 void RegisterNotifications(); |
102 | 112 |
103 // True if the listener thread has been started. | 113 // Whether or not the class has been initialized. |
104 bool listener_thread_started_; | 114 bool initialized_; |
105 | 115 |
106 // Used to register for notifications received by NotificationObserver. | 116 // Used to register for notifications received by NotificationObserver. |
107 // Accessed only on the UI thread. | 117 // Accessed only on the UI thread. |
108 NotificationRegistrar registrar_; | 118 NotificationRegistrar registrar_; |
109 | 119 |
| 120 // The Mach port on which the server listens. |
| 121 base::mac::ScopedMachReceiveRight server_port_; |
| 122 |
| 123 // The dispatch source and queue on which Mach messages will be received. |
| 124 scoped_ptr<base::DispatchSourceMach> dispatch_source_; |
| 125 |
110 // Stores mach info for every process in the broker. | 126 // Stores mach info for every process in the broker. |
111 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; | 127 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; |
112 MachMap mach_map_; | 128 MachMap mach_map_; |
113 | 129 |
114 // Stores the Child process unique id (RenderProcessHost ID) for every | 130 // Stores the Child process unique id (RenderProcessHost ID) for every |
115 // process. | 131 // process. |
116 typedef std::map<int, base::ProcessHandle> ChildProcessIdMap; | 132 typedef std::map<int, base::ProcessHandle> ChildProcessIdMap; |
117 ChildProcessIdMap child_process_id_map_; | 133 ChildProcessIdMap child_process_id_map_; |
118 | 134 |
119 // Mutex that guards |mach_map_| and |child_process_id_map_|. | 135 // Mutex that guards |mach_map_| and |child_process_id_map_|. |
120 mutable base::Lock lock_; | 136 mutable base::Lock lock_; |
121 | 137 |
122 DISALLOW_COPY_AND_ASSIGN(MachBroker); | 138 DISALLOW_COPY_AND_ASSIGN(MachBroker); |
123 }; | 139 }; |
124 | 140 |
125 } // namespace content | 141 } // namespace content |
126 | 142 |
127 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ | 143 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ |
OLD | NEW |