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

Side by Side Diff: chrome/browser/renderer_host/render_process_host.cc

Issue 42054: Stop using renderer specific host ids in ResourceDispatcher. This allows it ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 if (memory_tier >= arraysize(kMaxRenderersByRamTier)) 45 if (memory_tier >= arraysize(kMaxRenderersByRamTier))
46 max_count = chrome::kMaxRendererProcessCount; 46 max_count = chrome::kMaxRendererProcessCount;
47 else 47 else
48 max_count = kMaxRenderersByRamTier[memory_tier]; 48 max_count = kMaxRenderersByRamTier[memory_tier];
49 } 49 }
50 return max_count; 50 return max_count;
51 } 51 }
52 52
53 // Returns true if the given host is suitable for launching a new view 53 // Returns true if the given host is suitable for launching a new view
54 // associated with the given profile. 54 // associated with the given profile.
55 // TODO(jabdelmalek): do we want to avoid processes with hung renderers
56 // or with a large memory consumption?
57 static bool IsSuitableHost(Profile* profile, RenderProcessHost* host) { 55 static bool IsSuitableHost(Profile* profile, RenderProcessHost* host) {
58 return host->profile() == profile; 56 return host->profile() == profile;
59 } 57 }
60 58
61 // the global list of all renderer processes 59 // the global list of all renderer processes
62 IDMap<RenderProcessHost> all_hosts; 60 IDMap<RenderProcessHost> all_hosts;
63 61
64 } // namespace 62 } // namespace
65 63
66 bool RenderProcessHost::run_renderer_in_process_ = false; 64 bool RenderProcessHost::run_renderer_in_process_ = false;
67 65
68 RenderProcessHost::RenderProcessHost(Profile* profile) 66 RenderProcessHost::RenderProcessHost(Profile* profile)
69 : max_page_id_(-1), 67 : max_page_id_(-1),
70 notified_termination_(false), 68 notified_termination_(false),
69 pid_(-1),
71 profile_(profile) { 70 profile_(profile) {
72 host_id_ = all_hosts.Add(this);
73 } 71 }
74 72
75 RenderProcessHost::~RenderProcessHost() { 73 RenderProcessHost::~RenderProcessHost() {
76 } 74 }
77 75
78 void RenderProcessHost::Attach(IPC::Channel::Listener* listener, 76 void RenderProcessHost::Attach(IPC::Channel::Listener* listener,
79 int routing_id) { 77 int routing_id) {
80 listeners_.AddWithID(listener, routing_id); 78 listeners_.AddWithID(listener, routing_id);
81 } 79 }
82 80
83 void RenderProcessHost::Release(int listener_id) { 81 void RenderProcessHost::Release(int listener_id) {
84 DCHECK(listeners_.Lookup(listener_id) != NULL); 82 DCHECK(listeners_.Lookup(listener_id) != NULL);
85 listeners_.Remove(listener_id); 83 listeners_.Remove(listener_id);
86 84
87 // Make sure that all associated resource requests are stopped. 85 // Make sure that all associated resource requests are stopped.
88 CancelResourceRequests(listener_id); 86 CancelResourceRequests(listener_id);
89 87
90 // When no other owners of this object, we can delete ourselves 88 // When no other owners of this object, we can delete ourselves
91 if (listeners_.IsEmpty()) { 89 if (listeners_.IsEmpty()) {
92 if (!notified_termination_) { 90 if (!notified_termination_) {
93 bool close_expected = true; 91 bool close_expected = true;
94 NotificationService::current()->Notify( 92 NotificationService::current()->Notify(
95 NotificationType::RENDERER_PROCESS_TERMINATED, 93 NotificationType::RENDERER_PROCESS_TERMINATED,
96 Source<RenderProcessHost>(this), 94 Source<RenderProcessHost>(this),
97 Details<bool>(&close_expected)); 95 Details<bool>(&close_expected));
98 notified_termination_ = true; 96 notified_termination_ = true;
99 } 97 }
100 Unregister(); 98 if (pid_ >= 0) {
99 all_hosts.Remove(pid_);
100 pid_ = -1;
101 }
101 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 102 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
102 } 103 }
103 } 104 }
104 105
105 void RenderProcessHost::ReportExpectingClose(int32 listener_id) { 106 void RenderProcessHost::ReportExpectingClose(int32 listener_id) {
106 listeners_expecting_close_.insert(listener_id); 107 listeners_expecting_close_.insert(listener_id);
107 } 108 }
108 109
109 void RenderProcessHost::UpdateMaxPageID(int32 page_id) { 110 void RenderProcessHost::UpdateMaxPageID(int32 page_id) {
110 if (page_id > max_page_id_) 111 if (page_id > max_page_id_)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // Now pick a random suitable renderer, if we have any. 161 // Now pick a random suitable renderer, if we have any.
161 if (!suitable_renderers.empty()) { 162 if (!suitable_renderers.empty()) {
162 int suitable_count = static_cast<int>(suitable_renderers.size()); 163 int suitable_count = static_cast<int>(suitable_renderers.size());
163 int random_index = base::RandInt(0, suitable_count - 1); 164 int random_index = base::RandInt(0, suitable_count - 1);
164 return suitable_renderers[random_index]; 165 return suitable_renderers[random_index];
165 } 166 }
166 167
167 return NULL; 168 return NULL;
168 } 169 }
169 170
170 void RenderProcessHost::Unregister() { 171 void RenderProcessHost::SetProcessID(int pid) {
171 if (host_id_ >= 0) { 172 if (pid_ != -1) {
172 all_hosts.Remove(host_id_); 173 // This object is being reused after a renderer crash. Remove the old pid.
173 host_id_ = -1; 174 all_hosts.Remove(pid_);
174 } 175 }
176
177 pid_ = pid;
178 all_hosts.AddWithID(this, pid);
175 } 179 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_process_host.h ('k') | chrome/browser/renderer_host/render_view_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698