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

Side by Side Diff: chrome/browser/memory_details.cc

Issue 16431010: Refactor RenderProcessHost to use IPC::Listener instead of RenderWidgetHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix cleanup crashes. Created 7 years, 6 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) 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 #include "chrome/browser/memory_details.h" 5 #include "chrome/browser/memory_details.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_version_info.h" 8 #include "base/file_version_info.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 ProcessData* const chrome_browser = ChromeBrowser(); 207 ProcessData* const chrome_browser = ChromeBrowser();
208 // Get more information about the process. 208 // Get more information about the process.
209 for (size_t index = 0; index < chrome_browser->processes.size(); 209 for (size_t index = 0; index < chrome_browser->processes.size();
210 index++) { 210 index++) {
211 // Check if it's a renderer, if so get the list of page titles in it and 211 // Check if it's a renderer, if so get the list of page titles in it and
212 // check if it's a diagnostics-related process. We skip about:memory pages. 212 // check if it's a diagnostics-related process. We skip about:memory pages.
213 // Iterate the RenderProcessHosts to find the tab contents. 213 // Iterate the RenderProcessHosts to find the tab contents.
214 ProcessMemoryInformation& process = 214 ProcessMemoryInformation& process =
215 chrome_browser->processes[index]; 215 chrome_browser->processes[index];
216 216
217 for (content::RenderProcessHost::iterator renderer_iter( 217 scoped_ptr<RenderWidgetHost::List> hosts =
218 content::RenderProcessHost::AllHostsIterator()); 218 RenderWidgetHost::GetRenderWidgetHosts();
219 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { 219 for (RenderWidgetHost::List::const_iterator it = hosts->begin();
220 content::RenderProcessHost* render_process_host = 220 it != hosts->end();
221 renderer_iter.GetCurrentValue(); 221 ++it) {
222 const RenderWidgetHost* widget = *it;
223 content::RenderProcessHost* render_process_host = widget->GetProcess();
222 DCHECK(render_process_host); 224 DCHECK(render_process_host);
223 // Ignore processes that don't have a connection, such as crashed tabs. 225 // Ignore processes that don't have a connection, such as crashed tabs.
224 if (!render_process_host->HasConnection() || 226 if (!render_process_host->HasConnection() ||
225 process.pid != base::GetProcId(render_process_host->GetHandle())) { 227 process.pid != base::GetProcId(render_process_host->GetHandle())) {
226 continue; 228 continue;
227 } 229 }
228 process.process_type = content::PROCESS_TYPE_RENDERER; 230 process.process_type = content::PROCESS_TYPE_RENDERER;
229 Profile* profile = 231 Profile* profile =
230 Profile::FromBrowserContext( 232 Profile::FromBrowserContext(
231 render_process_host->GetBrowserContext()); 233 render_process_host->GetBrowserContext());
232 ExtensionService* extension_service = profile->GetExtensionService(); 234 ExtensionService* extension_service = profile->GetExtensionService();
233 extensions::ProcessMap* extension_process_map = NULL; 235 extensions::ProcessMap* extension_process_map = NULL;
234 // No extensions on Android. So extension_service can be NULL. 236 // No extensions on Android. So extension_service can be NULL.
235 if (extension_service) 237 if (extension_service)
236 extension_process_map = extension_service->process_map(); 238 extension_process_map = extension_service->process_map();
237 239
238 // The RenderProcessHost may host multiple WebContentses. Any 240 // The RenderProcessHost may host multiple WebContentses. Any
239 // of them which contain diagnostics information make the whole 241 // of them which contain diagnostics information make the whole
240 // process be considered a diagnostics process. 242 // process be considered a diagnostics process.
241 content::RenderProcessHost::RenderWidgetHostsIterator iter( 243 if (!widget->IsRenderView())
242 render_process_host->GetRenderWidgetHostsIterator()); 244 continue;
243 for (; !iter.IsAtEnd(); iter.Advance()) {
244 const RenderWidgetHost* widget = iter.GetCurrentValue();
245 DCHECK(widget);
246 if (!widget || !widget->IsRenderView())
247 continue;
248 245
249 RenderViewHost* host = 246 RenderViewHost* host =
250 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); 247 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
251 WebContents* contents = WebContents::FromRenderViewHost(host); 248 WebContents* contents = WebContents::FromRenderViewHost(host);
252 GURL url; 249 GURL url;
253 if (contents) 250 if (contents)
254 url = contents->GetURL(); 251 url = contents->GetURL();
255 extensions::ViewType type = extensions::GetViewType(contents); 252 extensions::ViewType type = extensions::GetViewType(contents);
256 if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) { 253 if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) {
257 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME; 254 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME;
258 } else if (extension_process_map && 255 } else if (extension_process_map &&
259 extension_process_map->Contains(host->GetProcess()->GetID())) { 256 extension_process_map->Contains(host->GetProcess()->GetID())) {
260 // For our purposes, don't count processes containing only hosted apps 257 // For our purposes, don't count processes containing only hosted apps
261 // as extension processes. See also: crbug.com/102533. 258 // as extension processes. See also: crbug.com/102533.
262 std::set<std::string> extension_ids = 259 std::set<std::string> extension_ids =
263 extension_process_map->GetExtensionsInProcess( 260 extension_process_map->GetExtensionsInProcess(
264 host->GetProcess()->GetID()); 261 host->GetProcess()->GetID());
265 for (std::set<std::string>::iterator iter = extension_ids.begin(); 262 for (std::set<std::string>::iterator iter = extension_ids.begin();
266 iter != extension_ids.end(); ++iter) { 263 iter != extension_ids.end(); ++iter) {
267 const Extension* extension = 264 const Extension* extension =
268 extension_service->GetExtensionById(*iter, false); 265 extension_service->GetExtensionById(*iter, false);
269 if (extension && !extension->is_hosted_app()) { 266 if (extension && !extension->is_hosted_app()) {
270 process.renderer_type = 267 process.renderer_type =
271 ProcessMemoryInformation::RENDERER_EXTENSION; 268 ProcessMemoryInformation::RENDERER_EXTENSION;
272 break; 269 break;
273 }
274 } 270 }
275 } 271 }
276 if (extension_process_map && 272 }
277 extension_process_map->Contains(host->GetProcess()->GetID())) { 273 if (extension_process_map &&
278 const Extension* extension = 274 extension_process_map->Contains(host->GetProcess()->GetID())) {
279 extension_service->extensions()->GetByID(url.host()); 275 const Extension* extension =
280 if (extension) { 276 extension_service->extensions()->GetByID(url.host());
281 string16 title = UTF8ToUTF16(extension->name()); 277 if (extension) {
282 process.titles.push_back(title); 278 string16 title = UTF8ToUTF16(extension->name());
283 process.renderer_type = 279 process.titles.push_back(title);
284 ProcessMemoryInformation::RENDERER_EXTENSION;
285 continue;
286 }
287 }
288
289 if (!contents) {
290 process.renderer_type = 280 process.renderer_type =
291 ProcessMemoryInformation::RENDERER_INTERSTITIAL; 281 ProcessMemoryInformation::RENDERER_EXTENSION;
292 continue; 282 continue;
293 } 283 }
284 }
294 285
295 if (type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { 286 if (!contents) {
296 process.titles.push_back(UTF8ToUTF16(url.spec())); 287 process.renderer_type =
297 process.renderer_type = 288 ProcessMemoryInformation::RENDERER_INTERSTITIAL;
298 ProcessMemoryInformation::RENDERER_BACKGROUND_APP; 289 continue;
299 continue; 290 }
300 }
301 291
302 if (type == extensions::VIEW_TYPE_NOTIFICATION) { 292 if (type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
303 process.titles.push_back(UTF8ToUTF16(url.spec())); 293 process.titles.push_back(UTF8ToUTF16(url.spec()));
304 process.renderer_type = 294 process.renderer_type =
305 ProcessMemoryInformation::RENDERER_NOTIFICATION; 295 ProcessMemoryInformation::RENDERER_BACKGROUND_APP;
306 continue; 296 continue;
307 } 297 }
308 298
309 // Since we have a WebContents and and the renderer type hasn't been 299 if (type == extensions::VIEW_TYPE_NOTIFICATION) {
310 // set yet, it must be a normal tabbed renderer. 300 process.titles.push_back(UTF8ToUTF16(url.spec()));
311 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN) 301 process.renderer_type =
312 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL; 302 ProcessMemoryInformation::RENDERER_NOTIFICATION;
303 continue;
304 }
313 305
314 string16 title = contents->GetTitle(); 306 // Since we have a WebContents and and the renderer type hasn't been
315 if (!title.length()) 307 // set yet, it must be a normal tabbed renderer.
316 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); 308 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN)
317 process.titles.push_back(title); 309 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL;
318 310
319 // We need to check the pending entry as well as the virtual_url to 311 string16 title = contents->GetTitle();
320 // see if it's a chrome://memory URL (we don't want to count these in 312 if (!title.length())
321 // the total memory usage of the browser). 313 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
322 // 314 process.titles.push_back(title);
323 // When we reach here, chrome://memory will be the pending entry since 315
324 // we haven't responded with any data such that it would be committed. 316 // We need to check the pending entry as well as the virtual_url to
325 // If you have another chrome://memory tab open (which would be 317 // see if it's a chrome://memory URL (we don't want to count these in
326 // committed), we don't want to count it either, so we also check the 318 // the total memory usage of the browser).
327 // last committed entry. 319 //
328 // 320 // When we reach here, chrome://memory will be the pending entry since
329 // Either the pending or last committed entries can be NULL. 321 // we haven't responded with any data such that it would be committed.
330 const NavigationEntry* pending_entry = 322 // If you have another chrome://memory tab open (which would be
331 contents->GetController().GetPendingEntry(); 323 // committed), we don't want to count it either, so we also check the
332 const NavigationEntry* last_committed_entry = 324 // last committed entry.
333 contents->GetController().GetLastCommittedEntry(); 325 //
334 if ((last_committed_entry && 326 // Either the pending or last committed entries can be NULL.
335 LowerCaseEqualsASCII(last_committed_entry->GetVirtualURL().spec(), 327 const NavigationEntry* pending_entry =
336 chrome::kChromeUIMemoryURL)) || 328 contents->GetController().GetPendingEntry();
337 (pending_entry && 329 const NavigationEntry* last_committed_entry =
338 LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(), 330 contents->GetController().GetLastCommittedEntry();
339 chrome::kChromeUIMemoryURL))) 331 if ((last_committed_entry &&
340 process.is_diagnostics = true; 332 LowerCaseEqualsASCII(last_committed_entry->GetVirtualURL().spec(),
341 } 333 chrome::kChromeUIMemoryURL)) ||
334 (pending_entry &&
335 LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(),
336 chrome::kChromeUIMemoryURL)))
337 process.is_diagnostics = true;
338 //
342 } 339 }
343 340
344 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 341 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
345 if (process.pid == zygote_pid) { 342 if (process.pid == zygote_pid) {
346 process.process_type = content::PROCESS_TYPE_ZYGOTE; 343 process.process_type = content::PROCESS_TYPE_ZYGOTE;
347 } else if (process.pid == sandbox_helper_pid) { 344 } else if (process.pid == sandbox_helper_pid) {
348 process.process_type = content::PROCESS_TYPE_SANDBOX_HELPER; 345 process.process_type = content::PROCESS_TYPE_SANDBOX_HELPER;
349 } 346 }
350 #endif 347 #endif
351 } 348 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginBrokerProcessCount", 475 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginBrokerProcessCount",
479 pepper_plugin_broker_count); 476 pepper_plugin_broker_count);
480 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); 477 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count);
481 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); 478 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count);
482 // TODO(viettrungluu): Do we want separate counts for the other 479 // TODO(viettrungluu): Do we want separate counts for the other
483 // (platform-specific) process types? 480 // (platform-specific) process types?
484 481
485 int total_sample = static_cast<int>(aggregate_memory / 1000); 482 int total_sample = static_cast<int>(aggregate_memory / 1000);
486 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); 483 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample);
487 } 484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698