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

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

Issue 10409088: Get rid of the RenderViewType concept in content, since it was only used by Chrome. Store the enum… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 8 years, 7 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"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/extensions/extension_process_manager.h" 14 #include "chrome/browser/extensions/extension_process_manager.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/chrome_view_type.h" 17 #include "chrome/browser/view_type_utils.h"
18 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/browser_child_process_host_iterator.h" 20 #include "content/public/browser/browser_child_process_host_iterator.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/child_process_data.h" 22 #include "content/public/browser/child_process_data.h"
23 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/render_view_host_delegate.h"
28 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/bindings_policy.h" 28 #include "content/public/common/bindings_policy.h"
30 #include "content/public/common/process_type.h" 29 #include "content/public/common/process_type.h"
31 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
32 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
33 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
34 33
35 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 34 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
36 #include "content/public/browser/zygote_host_linux.h" 35 #include "content/public/browser/zygote_host_linux.h"
37 #endif 36 #endif
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // of them which contain diagnostics information make the whole 234 // of them which contain diagnostics information make the whole
236 // process be considered a diagnostics process. 235 // process be considered a diagnostics process.
237 content::RenderProcessHost::RenderWidgetHostsIterator iter( 236 content::RenderProcessHost::RenderWidgetHostsIterator iter(
238 render_process_host->GetRenderWidgetHostsIterator()); 237 render_process_host->GetRenderWidgetHostsIterator());
239 for (; !iter.IsAtEnd(); iter.Advance()) { 238 for (; !iter.IsAtEnd(); iter.Advance()) {
240 const RenderWidgetHost* widget = iter.GetCurrentValue(); 239 const RenderWidgetHost* widget = iter.GetCurrentValue();
241 DCHECK(widget); 240 DCHECK(widget);
242 if (!widget || !widget->IsRenderView()) 241 if (!widget || !widget->IsRenderView())
243 continue; 242 continue;
244 243
245 const RenderViewHost* host = 244 RenderViewHost* host =
246 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); 245 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
247 content::RenderViewHostDelegate* host_delegate = host->GetDelegate(); 246 WebContents* contents = WebContents::FromRenderViewHost(host);
248 DCHECK(host_delegate); 247 GURL url;
249 GURL url = host_delegate->GetURL(); 248 if (contents)
250 content::ViewType type = host_delegate->GetRenderViewType(); 249 url = contents->GetURL();
250 chrome::ViewType type = chrome::GetViewType(contents);
251 if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) { 251 if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) {
252 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME; 252 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME;
253 } else if (extension_process_map->Contains( 253 } else if (extension_process_map->Contains(
254 host->GetProcess()->GetID())) { 254 host->GetProcess()->GetID())) {
255 // For our purposes, don't count processes containing only hosted apps 255 // For our purposes, don't count processes containing only hosted apps
256 // as extension processes. See also: crbug.com/102533. 256 // as extension processes. See also: crbug.com/102533.
257 std::set<std::string> extension_ids = 257 std::set<std::string> extension_ids =
258 extension_process_map->GetExtensionsInProcess( 258 extension_process_map->GetExtensionsInProcess(
259 host->GetProcess()->GetID()); 259 host->GetProcess()->GetID());
260 for (std::set<std::string>::iterator iter = extension_ids.begin(); 260 for (std::set<std::string>::iterator iter = extension_ids.begin();
261 iter != extension_ids.end(); ++iter) { 261 iter != extension_ids.end(); ++iter) {
262 const Extension* extension = 262 const Extension* extension =
263 extension_service->GetExtensionById(*iter, false); 263 extension_service->GetExtensionById(*iter, false);
264 if (extension && !extension->is_hosted_app()) { 264 if (extension && !extension->is_hosted_app()) {
265 process.renderer_type = 265 process.renderer_type =
266 ProcessMemoryInformation::RENDERER_EXTENSION; 266 ProcessMemoryInformation::RENDERER_EXTENSION;
267 break; 267 break;
268 } 268 }
269 } 269 }
270 } 270 }
271 WebContents* contents = host_delegate->GetAsWebContents(); 271 if (extension_process_map->Contains(host->GetProcess()->GetID())) {
272 if (!contents) { 272 const Extension* extension =
273 if (extension_process_map->Contains(host->GetProcess()->GetID())) { 273 extension_service->extensions()->GetByID(url.host());
274 const Extension* extension = 274 if (extension) {
275 extension_service->extensions()->GetByID(url.host()); 275 string16 title = UTF8ToUTF16(extension->name());
276 if (extension) { 276 process.titles.push_back(title);
277 string16 title = UTF8ToUTF16(extension->name());
278 process.titles.push_back(title);
279 }
280 } else if (process.renderer_type ==
281 ProcessMemoryInformation::RENDERER_UNKNOWN) {
282 process.titles.push_back(UTF8ToUTF16(url.spec()));
283 switch (type) {
284 case chrome::VIEW_TYPE_BACKGROUND_CONTENTS:
285 process.renderer_type =
286 ProcessMemoryInformation::RENDERER_BACKGROUND_APP;
287 break;
288 case content::VIEW_TYPE_INTERSTITIAL_PAGE:
289 process.renderer_type =
290 ProcessMemoryInformation::RENDERER_INTERSTITIAL;
291 break;
292 case chrome::VIEW_TYPE_NOTIFICATION:
293 process.renderer_type =
294 ProcessMemoryInformation::RENDERER_NOTIFICATION;
295 break;
296 default:
297 process.renderer_type =
298 ProcessMemoryInformation::RENDERER_UNKNOWN;
299 break;
300 }
301 } 277 }
302 continue; 278 continue;
303 } 279 }
304 280
305 // Since We have a WebContents and and the renderer type hasn't been 281 if (!contents) {
282 process.renderer_type =
283 ProcessMemoryInformation::RENDERER_INTERSTITIAL;
284 continue;
285 }
286
287 if (type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
288 process.titles.push_back(UTF8ToUTF16(url.spec()));
289 process.renderer_type =
290 ProcessMemoryInformation::RENDERER_BACKGROUND_APP;
291 continue;
292 }
293
294 if (type == chrome::VIEW_TYPE_NOTIFICATION) {
295 process.titles.push_back(UTF8ToUTF16(url.spec()));
296 process.renderer_type =
297 ProcessMemoryInformation::RENDERER_NOTIFICATION;
298 continue;
299 }
300
301 // Since we have a WebContents and and the renderer type hasn't been
306 // set yet, it must be a normal tabbed renderer. 302 // set yet, it must be a normal tabbed renderer.
307 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN) 303 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN)
308 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL; 304 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL;
309 305
310 string16 title = contents->GetTitle(); 306 string16 title = contents->GetTitle();
311 if (!title.length()) 307 if (!title.length())
312 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); 308 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
313 process.titles.push_back(title); 309 process.titles.push_back(title);
314 310
315 // We need to check the pending entry as well as the virtual_url to 311 // We need to check the pending entry as well as the virtual_url to
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount", 456 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount",
461 pepper_plugin_count); 457 pepper_plugin_count);
462 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); 458 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count);
463 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); 459 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count);
464 // TODO(viettrungluu): Do we want separate counts for the other 460 // TODO(viettrungluu): Do we want separate counts for the other
465 // (platform-specific) process types? 461 // (platform-specific) process types?
466 462
467 int total_sample = static_cast<int>(aggregate_memory / 1000); 463 int total_sample = static_cast<int>(aggregate_memory / 1000);
468 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); 464 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample);
469 } 465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698