Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1856)

Unified Diff: chrome/browser/mach_broker_mac.cc

Issue 549002: Mac: Other approach for IPCing child task_ts. (Closed)
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/mach_broker_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/mach_broker_mac.cc
diff --git a/chrome/browser/mach_broker_mac.cc b/chrome/browser/mach_broker_mac.cc
index 59f77282234969846948cac52df23c0b7a8b449b..977a83367a0f56bc11dca36ec897afdd966be61d 100644
--- a/chrome/browser/mach_broker_mac.cc
+++ b/chrome/browser/mach_broker_mac.cc
@@ -5,6 +5,44 @@
#include "chrome/browser/mach_broker_mac.h"
#include "base/logging.h"
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/common/child_process_info.h"
+#include "chrome/common/notification_service.h"
+
+// Required because notifications happen on the UI thread.
+class RegisterNotificationTask : public Task {
+ public:
+ RegisterNotificationTask(
+ MachBroker* broker)
+ : broker_(broker) { }
+
+ virtual void Run() {
+ broker_->registrar_.Add(broker_,
+ NotificationType::RENDERER_PROCESS_CLOSED,
+ NotificationService::AllSources());
+ broker_->registrar_.Add(broker_,
+ NotificationType::RENDERER_PROCESS_TERMINATED,
+ NotificationService::AllSources());
+ broker_->registrar_.Add(broker_,
+ NotificationType::CHILD_PROCESS_CRASHED,
+ NotificationService::AllSources());
+ broker_->registrar_.Add(broker_,
+ NotificationType::CHILD_PROCESS_HOST_DISCONNECTED,
+ NotificationService::AllSources());
+ broker_->registrar_.Add(broker_,
+ NotificationType::EXTENSION_PROCESS_TERMINATED,
+ NotificationService::AllSources());
+ }
+
+ private:
+ MachBroker* broker_;
+};
+
+MachBroker::MachBroker() {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE, new RegisterNotificationTask(this));
+}
// Returns the global MachBroker.
MachBroker* MachBroker::instance() {
@@ -22,7 +60,16 @@ void MachBroker::RegisterPid(
// Removes all mappings belonging to |pid| from the broker.
void MachBroker::Invalidate(base::ProcessHandle pid) {
AutoLock lock(lock_);
- mach_map_.erase(pid);
+ MachBroker::MachMap::iterator it = mach_map_.find(pid);
+ if (it == mach_map_.end())
+ return;
+
+ kern_return_t kr = mach_port_deallocate(mach_task_self(),
+ it->second.mach_task_);
+ LOG_IF(WARNING, kr != KERN_SUCCESS)
+ << "Failed to deallocate mach task " << it->second.mach_task_
+ << ", error " << kr;
+ mach_map_.erase(it);
}
// Returns the mach task belonging to |pid|.
@@ -33,3 +80,27 @@ mach_port_t MachBroker::TaskForPid(base::ProcessHandle pid) const {
return MACH_PORT_NULL;
return it->second.mach_task_;
}
+
+void MachBroker::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ base::ProcessHandle handle = 0;
+ switch (type.value) {
+ case NotificationType::RENDERER_PROCESS_CLOSED:
+ case NotificationType::RENDERER_PROCESS_TERMINATED:
+ handle = Source<RenderProcessHost>(source)->GetHandle();
+ break;
+ case NotificationType::EXTENSION_PROCESS_TERMINATED:
+ handle =
+ Details<ExtensionHost>(details)->render_process_host()->GetHandle();
+ break;
+ case NotificationType::CHILD_PROCESS_CRASHED:
+ case NotificationType::CHILD_PROCESS_HOST_DISCONNECTED:
+ handle = Details<ChildProcessInfo>(details)->handle();
+ break;
+ default:
+ NOTREACHED() << "Unexpected notification";
+ break;
+ }
+ Invalidate(handle);
+}
« no previous file with comments | « chrome/browser/mach_broker_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698