OLD | NEW |
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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/extensions/extension_service.h" | |
14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
16 #include "components/nacl/common/nacl_process_type.h" | 15 #include "components/nacl/common/nacl_process_type.h" |
17 #include "content/public/browser/browser_child_process_host_iterator.h" | 16 #include "content/public/browser/browser_child_process_host_iterator.h" |
18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/child_process_data.h" | 18 #include "content/public/browser/child_process_data.h" |
20 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
21 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
23 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
24 #include "content/public/browser/render_widget_host_iterator.h" | 23 #include "content/public/browser/render_widget_host_iterator.h" |
25 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
26 #include "content/public/common/bindings_policy.h" | 25 #include "content/public/common/bindings_policy.h" |
27 #include "extensions/browser/extension_system.h" | |
28 #include "extensions/browser/process_manager.h" | |
29 #include "extensions/browser/process_map.h" | |
30 #include "extensions/browser/view_type_utils.h" | |
31 #include "extensions/common/extension.h" | |
32 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
34 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
35 | 29 |
36 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 30 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
37 #include "content/public/browser/zygote_host_linux.h" | 31 #include "content/public/browser/zygote_host_linux.h" |
38 #endif | 32 #endif |
39 | 33 |
| 34 #if defined(ENABLE_EXTENSIONS) |
| 35 #include "chrome/browser/extensions/extension_service.h" |
| 36 #include "extensions/browser/extension_system.h" |
| 37 #include "extensions/browser/process_manager.h" |
| 38 #include "extensions/browser/process_map.h" |
| 39 #include "extensions/browser/view_type_utils.h" |
| 40 #include "extensions/common/extension.h" |
| 41 #endif |
| 42 |
40 using base::StringPrintf; | 43 using base::StringPrintf; |
41 using content::BrowserChildProcessHostIterator; | 44 using content::BrowserChildProcessHostIterator; |
42 using content::BrowserThread; | 45 using content::BrowserThread; |
43 using content::NavigationEntry; | 46 using content::NavigationEntry; |
44 using content::RenderViewHost; | 47 using content::RenderViewHost; |
45 using content::RenderWidgetHost; | 48 using content::RenderWidgetHost; |
46 using content::WebContents; | 49 using content::WebContents; |
| 50 #if defined(ENABLE_EXTENSIONS) |
47 using extensions::Extension; | 51 using extensions::Extension; |
| 52 #endif |
48 | 53 |
49 // static | 54 // static |
50 std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish( | 55 std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish( |
51 RendererProcessType type) { | 56 RendererProcessType type) { |
52 switch (type) { | 57 switch (type) { |
53 case RENDERER_NORMAL: | 58 case RENDERER_NORMAL: |
54 return "Tab"; | 59 return "Tab"; |
55 case RENDERER_CHROME: | 60 case RENDERER_CHROME: |
56 return "Tab (Chrome)"; | 61 return "Tab (Chrome)"; |
57 case RENDERER_EXTENSION: | 62 case RENDERER_EXTENSION: |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 RenderWidgetHost::GetRenderWidgetHosts()); | 266 RenderWidgetHost::GetRenderWidgetHosts()); |
262 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { | 267 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
263 content::RenderProcessHost* render_process_host = | 268 content::RenderProcessHost* render_process_host = |
264 widget->GetProcess(); | 269 widget->GetProcess(); |
265 DCHECK(render_process_host); | 270 DCHECK(render_process_host); |
266 // Ignore processes that don't have a connection, such as crashed tabs. | 271 // Ignore processes that don't have a connection, such as crashed tabs. |
267 if (!render_process_host->HasConnection() || | 272 if (!render_process_host->HasConnection() || |
268 process.pid != base::GetProcId(render_process_host->GetHandle())) { | 273 process.pid != base::GetProcId(render_process_host->GetHandle())) { |
269 continue; | 274 continue; |
270 } | 275 } |
271 process.process_type = content::PROCESS_TYPE_RENDERER; | |
272 content::BrowserContext* context = | |
273 render_process_host->GetBrowserContext(); | |
274 ExtensionService* extension_service = | |
275 extensions::ExtensionSystem::Get(context)->extension_service(); | |
276 extensions::ProcessMap* extension_process_map = NULL; | |
277 // No extensions on Android. So extension_service can be NULL. | |
278 if (extension_service) | |
279 extension_process_map = extensions::ProcessMap::Get(context); | |
280 | 276 |
281 // The RenderProcessHost may host multiple WebContentses. Any | 277 // The RenderProcessHost may host multiple WebContentses. Any |
282 // of them which contain diagnostics information make the whole | 278 // of them which contain diagnostics information make the whole |
283 // process be considered a diagnostics process. | 279 // process be considered a diagnostics process. |
284 if (!widget->IsRenderView()) | 280 if (!widget->IsRenderView()) |
285 continue; | 281 continue; |
286 | 282 |
| 283 process.process_type = content::PROCESS_TYPE_RENDERER; |
| 284 bool is_extension = false; |
287 RenderViewHost* host = RenderViewHost::From(widget); | 285 RenderViewHost* host = RenderViewHost::From(widget); |
| 286 #if defined(ENABLE_EXTENSIONS) |
| 287 content::BrowserContext* context = |
| 288 render_process_host->GetBrowserContext(); |
| 289 ExtensionService* extension_service = |
| 290 extensions::ExtensionSystem::Get(context)->extension_service(); |
| 291 extensions::ProcessMap* extension_process_map = |
| 292 extensions::ProcessMap::Get(context); |
| 293 is_extension = extension_process_map->Contains( |
| 294 host->GetProcess()->GetID()); |
| 295 #endif |
| 296 |
288 WebContents* contents = WebContents::FromRenderViewHost(host); | 297 WebContents* contents = WebContents::FromRenderViewHost(host); |
289 GURL url; | 298 GURL url; |
290 if (contents) { | 299 if (contents) { |
291 url = contents->GetURL(); | 300 url = contents->GetURL(); |
292 SiteData* site_data = | 301 SiteData* site_data = |
293 &chrome_browser->site_data[contents->GetBrowserContext()]; | 302 &chrome_browser->site_data[contents->GetBrowserContext()]; |
294 SiteDetails::CollectSiteInfo(contents, site_data); | 303 SiteDetails::CollectSiteInfo(contents, site_data); |
295 } | 304 } |
| 305 #if defined(ENABLE_EXTENSIONS) |
296 extensions::ViewType type = extensions::GetViewType(contents); | 306 extensions::ViewType type = extensions::GetViewType(contents); |
| 307 #endif |
297 if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) { | 308 if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) { |
298 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME; | 309 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME; |
299 } else if (extension_process_map && | 310 } else if (is_extension) { |
300 extension_process_map->Contains(host->GetProcess()->GetID())) { | 311 #if defined(ENABLE_EXTENSIONS) |
301 // For our purposes, don't count processes containing only hosted apps | 312 // For our purposes, don't count processes containing only hosted apps |
302 // as extension processes. See also: crbug.com/102533. | 313 // as extension processes. See also: crbug.com/102533. |
303 std::set<std::string> extension_ids = | 314 std::set<std::string> extension_ids = |
304 extension_process_map->GetExtensionsInProcess( | 315 extension_process_map->GetExtensionsInProcess( |
305 host->GetProcess()->GetID()); | 316 host->GetProcess()->GetID()); |
306 for (std::set<std::string>::iterator iter = extension_ids.begin(); | 317 for (std::set<std::string>::iterator iter = extension_ids.begin(); |
307 iter != extension_ids.end(); ++iter) { | 318 iter != extension_ids.end(); ++iter) { |
308 const Extension* extension = | 319 const Extension* extension = |
309 extension_service->GetExtensionById(*iter, false); | 320 extension_service->GetExtensionById(*iter, false); |
310 if (extension && !extension->is_hosted_app()) { | 321 if (extension && !extension->is_hosted_app()) { |
311 process.renderer_type = | 322 process.renderer_type = |
312 ProcessMemoryInformation::RENDERER_EXTENSION; | 323 ProcessMemoryInformation::RENDERER_EXTENSION; |
313 break; | 324 break; |
314 } | 325 } |
315 } | 326 } |
| 327 #endif |
316 } | 328 } |
317 if (extension_process_map && | 329 #if defined(ENABLE_EXTENSIONS) |
318 extension_process_map->Contains(host->GetProcess()->GetID())) { | 330 if (is_extension) { |
319 const Extension* extension = | 331 const Extension* extension = |
320 extension_service->extensions()->GetByID(url.host()); | 332 extension_service->extensions()->GetByID(url.host()); |
321 if (extension) { | 333 if (extension) { |
322 base::string16 title = base::UTF8ToUTF16(extension->name()); | 334 base::string16 title = base::UTF8ToUTF16(extension->name()); |
323 process.titles.push_back(title); | 335 process.titles.push_back(title); |
324 process.renderer_type = | 336 process.renderer_type = |
325 ProcessMemoryInformation::RENDERER_EXTENSION; | 337 ProcessMemoryInformation::RENDERER_EXTENSION; |
326 continue; | 338 continue; |
327 } | 339 } |
328 } | 340 } |
| 341 #endif |
329 | 342 |
330 if (!contents) { | 343 if (!contents) { |
331 process.renderer_type = | 344 process.renderer_type = |
332 ProcessMemoryInformation::RENDERER_INTERSTITIAL; | 345 ProcessMemoryInformation::RENDERER_INTERSTITIAL; |
333 continue; | 346 continue; |
334 } | 347 } |
335 | 348 |
| 349 #if defined(ENABLE_EXTENSIONS) |
336 if (type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { | 350 if (type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { |
337 process.titles.push_back(base::UTF8ToUTF16(url.spec())); | 351 process.titles.push_back(base::UTF8ToUTF16(url.spec())); |
338 process.renderer_type = | 352 process.renderer_type = |
339 ProcessMemoryInformation::RENDERER_BACKGROUND_APP; | 353 ProcessMemoryInformation::RENDERER_BACKGROUND_APP; |
340 continue; | 354 continue; |
341 } | 355 } |
| 356 #endif |
342 | 357 |
343 // Since we have a WebContents and and the renderer type hasn't been | 358 // Since we have a WebContents and and the renderer type hasn't been |
344 // set yet, it must be a normal tabbed renderer. | 359 // set yet, it must be a normal tabbed renderer. |
345 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN) | 360 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN) |
346 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL; | 361 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL; |
347 | 362 |
348 base::string16 title = contents->GetTitle(); | 363 base::string16 title = contents->GetTitle(); |
349 if (!title.length()) | 364 if (!title.length()) |
350 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); | 365 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
351 process.titles.push_back(title); | 366 process.titles.push_back(title); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 | 638 |
624 if (swap_info_.orig_data_size > 0 && swap_info_.compr_data_size > 0) { | 639 if (swap_info_.orig_data_size > 0 && swap_info_.compr_data_size > 0) { |
625 UMA_HISTOGRAM_CUSTOM_COUNTS( | 640 UMA_HISTOGRAM_CUSTOM_COUNTS( |
626 "Memory.Swap.CompressionRatio", | 641 "Memory.Swap.CompressionRatio", |
627 swap_info_.orig_data_size / swap_info_.compr_data_size, | 642 swap_info_.orig_data_size / swap_info_.compr_data_size, |
628 1, 20, 20); | 643 1, 20, 20); |
629 } | 644 } |
630 } | 645 } |
631 | 646 |
632 #endif | 647 #endif |
OLD | NEW |