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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/url_constants.h" | |
19 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
20 #include "components/nacl/common/nacl_process_type.h" | 19 #include "components/nacl/common/nacl_process_type.h" |
21 #include "components/strings/grit/components_strings.h" | 20 #include "components/strings/grit/components_strings.h" |
22 #include "content/public/browser/browser_child_process_host_iterator.h" | 21 #include "content/public/browser/browser_child_process_host_iterator.h" |
23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/child_process_data.h" | 23 #include "content/public/browser/child_process_data.h" |
25 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
26 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
27 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 int process_type, | 83 int process_type, |
85 RendererProcessType rtype) { | 84 RendererProcessType rtype) { |
86 if (process_type == content::PROCESS_TYPE_RENDERER) | 85 if (process_type == content::PROCESS_TYPE_RENDERER) |
87 return GetRendererTypeNameInEnglish(rtype); | 86 return GetRendererTypeNameInEnglish(rtype); |
88 return content::GetProcessTypeNameInEnglish(process_type); | 87 return content::GetProcessTypeNameInEnglish(process_type); |
89 } | 88 } |
90 | 89 |
91 ProcessMemoryInformation::ProcessMemoryInformation() | 90 ProcessMemoryInformation::ProcessMemoryInformation() |
92 : pid(0), | 91 : pid(0), |
93 num_processes(0), | 92 num_processes(0), |
94 is_diagnostics(false), | |
95 process_type(content::PROCESS_TYPE_UNKNOWN), | 93 process_type(content::PROCESS_TYPE_UNKNOWN), |
96 renderer_type(RENDERER_UNKNOWN) { | 94 renderer_type(RENDERER_UNKNOWN) { |
97 } | 95 } |
98 | 96 |
99 ProcessMemoryInformation::ProcessMemoryInformation( | 97 ProcessMemoryInformation::ProcessMemoryInformation( |
100 const ProcessMemoryInformation& other) = default; | 98 const ProcessMemoryInformation& other) = default; |
101 | 99 |
102 ProcessMemoryInformation::~ProcessMemoryInformation() {} | 100 ProcessMemoryInformation::~ProcessMemoryInformation() {} |
103 | 101 |
104 bool ProcessMemoryInformation::operator<( | 102 bool ProcessMemoryInformation::operator<( |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 process.renderer_type = | 325 process.renderer_type = |
328 ProcessMemoryInformation::RENDERER_BACKGROUND_APP; | 326 ProcessMemoryInformation::RENDERER_BACKGROUND_APP; |
329 continue; | 327 continue; |
330 } | 328 } |
331 #endif | 329 #endif |
332 | 330 |
333 base::string16 title = contents->GetTitle(); | 331 base::string16 title = contents->GetTitle(); |
334 if (!title.length()) | 332 if (!title.length()) |
335 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); | 333 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
336 process.titles.push_back(title); | 334 process.titles.push_back(title); |
337 | |
338 // The presence of a single WebContents with a diagnostics page will make | |
339 // the whole process be considered a diagnostics process. | |
340 // | |
341 // We need to check the pending entry as well as the virtual_url to | |
342 // see if it's a chrome://memory URL (we don't want to count these in | |
343 // the total memory usage of the browser). | |
344 // | |
345 // When we reach here, chrome://memory will be the pending entry since | |
346 // we haven't responded with any data such that it would be committed. | |
347 // If you have another chrome://memory tab open (which would be | |
348 // committed), we don't want to count it either, so we also check the | |
349 // last committed entry. | |
350 // | |
351 // Either the pending or last committed entries can be NULL. | |
352 const NavigationEntry* pending_entry = | |
353 contents->GetController().GetPendingEntry(); | |
354 const NavigationEntry* last_committed_entry = | |
355 contents->GetController().GetLastCommittedEntry(); | |
356 if ((last_committed_entry && | |
357 base::LowerCaseEqualsASCII( | |
358 last_committed_entry->GetVirtualURL().spec(), | |
359 chrome::kChromeUIMemoryURL)) || | |
360 (pending_entry && | |
361 base::LowerCaseEqualsASCII( | |
362 pending_entry->GetVirtualURL().spec(), | |
363 chrome::kChromeUIMemoryURL))) { | |
364 process.is_diagnostics = true; | |
365 } | |
366 } | 335 } |
367 | 336 |
368 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 337 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
369 if (content::ZygoteHost::GetInstance()->IsZygotePid(process.pid)) { | 338 if (content::ZygoteHost::GetInstance()->IsZygotePid(process.pid)) { |
370 process.process_type = content::PROCESS_TYPE_ZYGOTE; | 339 process.process_type = content::PROCESS_TYPE_ZYGOTE; |
371 } | 340 } |
372 #endif | 341 #endif |
373 } | 342 } |
374 | 343 |
375 // Get rid of other Chrome processes that are from a different profile. | 344 // Get rid of other Chrome processes that are from a different profile. |
376 auto is_unknown = [](ProcessMemoryInformation& process) { | 345 auto is_unknown = [](ProcessMemoryInformation& process) { |
377 return process.process_type == content::PROCESS_TYPE_UNKNOWN; | 346 return process.process_type == content::PROCESS_TYPE_UNKNOWN; |
378 }; | 347 }; |
379 auto& vector = chrome_browser->processes; | 348 auto& vector = chrome_browser->processes; |
380 vector.erase(std::remove_if(vector.begin(), vector.end(), is_unknown), | 349 vector.erase(std::remove_if(vector.begin(), vector.end(), is_unknown), |
381 vector.end()); | 350 vector.end()); |
382 | 351 |
383 OnDetailsAvailable(); | 352 OnDetailsAvailable(); |
384 } | 353 } |
OLD | NEW |