| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/renderer_host/render_process_host.h" | 5 #include "chrome/browser/renderer_host/render_process_host.h" |
| 6 | 6 |
| 7 #include "base/rand_util.h" | 7 #include "base/rand_util.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "chrome/common/chrome_constants.h" | 9 #include "chrome/common/chrome_constants.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 // the global list of all renderer processes | 59 // the global list of all renderer processes |
| 60 IDMap<RenderProcessHost> all_hosts; | 60 IDMap<RenderProcessHost> all_hosts; |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 bool RenderProcessHost::run_renderer_in_process_ = false; | 64 bool RenderProcessHost::run_renderer_in_process_ = false; |
| 65 | 65 |
| 66 RenderProcessHost::RenderProcessHost(Profile* profile) | 66 RenderProcessHost::RenderProcessHost(Profile* profile) |
| 67 : max_page_id_(-1), | 67 : max_page_id_(-1), |
| 68 notified_termination_(false), | |
| 69 pid_(-1), | 68 pid_(-1), |
| 70 profile_(profile) { | 69 profile_(profile) { |
| 71 } | 70 } |
| 72 | 71 |
| 73 RenderProcessHost::~RenderProcessHost() { | 72 RenderProcessHost::~RenderProcessHost() { |
| 74 } | 73 } |
| 75 | 74 |
| 76 void RenderProcessHost::Attach(IPC::Channel::Listener* listener, | 75 void RenderProcessHost::Attach(IPC::Channel::Listener* listener, |
| 77 int routing_id) { | 76 int routing_id) { |
| 78 listeners_.AddWithID(listener, routing_id); | 77 listeners_.AddWithID(listener, routing_id); |
| 79 } | 78 } |
| 80 | 79 |
| 81 void RenderProcessHost::Release(int listener_id) { | 80 void RenderProcessHost::Release(int listener_id) { |
| 82 DCHECK(listeners_.Lookup(listener_id) != NULL); | 81 DCHECK(listeners_.Lookup(listener_id) != NULL); |
| 83 listeners_.Remove(listener_id); | 82 listeners_.Remove(listener_id); |
| 84 | 83 |
| 85 // Make sure that all associated resource requests are stopped. | 84 // Make sure that all associated resource requests are stopped. |
| 86 CancelResourceRequests(listener_id); | 85 CancelResourceRequests(listener_id); |
| 87 | 86 |
| 88 // When no other owners of this object, we can delete ourselves | 87 // When no other owners of this object, we can delete ourselves |
| 89 if (listeners_.IsEmpty()) { | 88 if (listeners_.IsEmpty()) { |
| 90 if (!notified_termination_) { | 89 NotificationService::current()->Notify( |
| 91 bool close_expected = true; | 90 NotificationType::RENDERER_PROCESS_TERMINATED, |
| 92 NotificationService::current()->Notify( | 91 Source<RenderProcessHost>(this), NotificationService::NoDetails()); |
| 93 NotificationType::RENDERER_PROCESS_TERMINATED, | |
| 94 Source<RenderProcessHost>(this), | |
| 95 Details<bool>(&close_expected)); | |
| 96 notified_termination_ = true; | |
| 97 } | |
| 98 if (pid_ >= 0) { | 92 if (pid_ >= 0) { |
| 99 all_hosts.Remove(pid_); | 93 all_hosts.Remove(pid_); |
| 100 pid_ = -1; | 94 pid_ = -1; |
| 101 } | 95 } |
| 102 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 96 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 103 } | 97 } |
| 104 } | 98 } |
| 105 | 99 |
| 106 void RenderProcessHost::ReportExpectingClose(int32 listener_id) { | 100 void RenderProcessHost::ReportExpectingClose(int32 listener_id) { |
| 107 listeners_expecting_close_.insert(listener_id); | 101 listeners_expecting_close_.insert(listener_id); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 164 |
| 171 void RenderProcessHost::SetProcessID(int pid) { | 165 void RenderProcessHost::SetProcessID(int pid) { |
| 172 if (pid_ != -1) { | 166 if (pid_ != -1) { |
| 173 // This object is being reused after a renderer crash. Remove the old pid. | 167 // This object is being reused after a renderer crash. Remove the old pid. |
| 174 all_hosts.Remove(pid_); | 168 all_hosts.Remove(pid_); |
| 175 } | 169 } |
| 176 | 170 |
| 177 pid_ = pid; | 171 pid_ = pid; |
| 178 all_hosts.AddWithID(this, pid); | 172 all_hosts.AddWithID(this, pid); |
| 179 } | 173 } |
| OLD | NEW |