| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 class CONTENT_EXPORT MachBroker : public base::ProcessMetrics::PortProvider, | 37 class CONTENT_EXPORT MachBroker : public base::ProcessMetrics::PortProvider, |
| 38 public BrowserChildProcessObserver, | 38 public BrowserChildProcessObserver, |
| 39 public NotificationObserver { | 39 public NotificationObserver { |
| 40 public: | 40 public: |
| 41 // For use in child processes. This will send the task port of the current | 41 // For use in child processes. This will send the task port of the current |
| 42 // process over Mach IPC to the port registered by name (via this class) in | 42 // process over Mach IPC to the port registered by name (via this class) in |
| 43 // the parent process. Returns true if the message was sent successfully | 43 // the parent process. Returns true if the message was sent successfully |
| 44 // and false if otherwise. | 44 // and false if otherwise. |
| 45 static bool ChildSendTaskPortToParent(); | 45 static bool ChildSendTaskPortToParent(); |
| 46 | 46 |
| 47 // Returns the Mach port name to use when sending or receiving messages. | |
| 48 // Does the Right Thing in the browser and in child processes. | |
| 49 static std::string GetMachPortName(); | |
| 50 | |
| 51 // Returns the global MachBroker. | 47 // Returns the global MachBroker. |
| 52 static MachBroker* GetInstance(); | 48 static MachBroker* GetInstance(); |
| 53 | 49 |
| 54 // The lock that protects this MachBroker object. Clients MUST acquire and | 50 // The lock that protects this MachBroker object. Clients MUST acquire and |
| 55 // release this lock around calls to EnsureRunning(), PlaceholderForPid(), | 51 // release this lock around calls to EnsureRunning(), PlaceholderForPid(), |
| 56 // and FinalizePid(). | 52 // and FinalizePid(). |
| 57 base::Lock& GetLock(); | 53 base::Lock& GetLock(); |
| 58 | 54 |
| 59 // Performs any necessary setup that cannot happen in the constructor. | 55 // Performs any necessary setup that cannot happen in the constructor. |
| 60 // Callers MUST acquire the lock given by GetLock() before calling this | 56 // Callers MUST acquire the lock given by GetLock() before calling this |
| (...skipping 29 matching lines...) Expand all Loading... |
| 90 | 86 |
| 91 // 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 |
| 92 // nothing if PlaceholderForPid() has not already been called for the given | 88 // nothing if PlaceholderForPid() has not already been called for the given |
| 93 // |pid|. Callers MUST acquire the lock given by GetLock() before calling | 89 // |pid|. Callers MUST acquire the lock given by GetLock() before calling |
| 94 // this method (and release the lock afterwards). | 90 // this method (and release the lock afterwards). |
| 95 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); | 91 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); |
| 96 | 92 |
| 97 // Removes all mappings belonging to |pid| from the broker. | 93 // Removes all mappings belonging to |pid| from the broker. |
| 98 void InvalidatePid(base::ProcessHandle pid); | 94 void InvalidatePid(base::ProcessHandle pid); |
| 99 | 95 |
| 96 // Returns the Mach port name to use when sending or receiving messages. |
| 97 // Does the Right Thing in the browser and in child processes. |
| 98 static std::string GetMachPortName(); |
| 100 // Callback used to register notifications on the UI thread. | 99 // Callback used to register notifications on the UI thread. |
| 101 void RegisterNotifications(); | 100 void RegisterNotifications(); |
| 102 | 101 |
| 103 // True if the listener thread has been started. | 102 // True if the listener thread has been started. |
| 104 bool listener_thread_started_; | 103 bool listener_thread_started_; |
| 105 | 104 |
| 106 // Used to register for notifications received by NotificationObserver. | 105 // Used to register for notifications received by NotificationObserver. |
| 107 // Accessed only on the UI thread. | 106 // Accessed only on the UI thread. |
| 108 NotificationRegistrar registrar_; | 107 NotificationRegistrar registrar_; |
| 109 | 108 |
| 110 // Stores mach info for every process in the broker. | 109 // Stores mach info for every process in the broker. |
| 111 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; | 110 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; |
| 112 MachMap mach_map_; | 111 MachMap mach_map_; |
| 113 | 112 |
| 114 // Mutex that guards |mach_map_|. | 113 // Mutex that guards |mach_map_|. |
| 115 mutable base::Lock lock_; | 114 mutable base::Lock lock_; |
| 116 | 115 |
| 117 DISALLOW_COPY_AND_ASSIGN(MachBroker); | 116 DISALLOW_COPY_AND_ASSIGN(MachBroker); |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 } // namespace content | 119 } // namespace content |
| 121 | 120 |
| 122 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ | 121 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ |
| OLD | NEW |