[email protected] | b0b67cf | 2012-01-18 21:59:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/browser/memory_details.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
asvitkine | 89406d1f | 2015-01-17 06:57:10 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | #include <set> |
| 9 | |
[email protected] | 24d6969 | 2011-10-21 18:26:51 | [diff] [blame] | 10 | #include "base/bind.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | #include "base/file_version_info.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 12 | #include "base/metrics/histogram.h" |
[email protected] | f9b29436 | 2013-06-10 20:22:31 | [diff] [blame] | 13 | #include "base/strings/string_util.h" |
| 14 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 15 | #include "base/strings/utf_string_conversions.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile.h" |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 18 | #include "chrome/common/url_constants.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 19 | #include "chrome/grit/generated_resources.h" |
[email protected] | d5d38325 | 2013-07-04 14:44:32 | [diff] [blame] | 20 | #include "components/nacl/common/nacl_process_type.h" |
sdefresne | 957f4a7 | 2016-02-18 12:44:29 | [diff] [blame] | 21 | #include "components/strings/grit/components_strings.h" |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 22 | #include "content/public/browser/browser_child_process_host_iterator.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 23 | #include "content/public/browser/browser_thread.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 24 | #include "content/public/browser/child_process_data.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 25 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 26 | #include "content/public/browser/navigation_entry.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 27 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 28 | #include "content/public/browser/render_view_host.h" |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 29 | #include "content/public/browser/render_widget_host.h" |
[email protected] | a801cb3 | 2013-09-11 18:02:27 | [diff] [blame] | 30 | #include "content/public/browser/render_widget_host_iterator.h" |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 31 | #include "content/public/browser/web_contents.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 32 | #include "content/public/common/bindings_policy.h" |
thestig | 5ef7dc8 | 2014-11-06 05:36:26 | [diff] [blame] | 33 | #include "content/public/common/content_constants.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 34 | #include "ui/base/l10n/l10n_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 35 | |
[email protected] | a423c9e | 2012-03-06 18:02:31 | [diff] [blame] | 36 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | c2c68b1f | 2012-02-25 00:29:15 | [diff] [blame] | 37 | #include "content/public/browser/zygote_host_linux.h" |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 38 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 40 | #if defined(ENABLE_EXTENSIONS) |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 41 | #include "extensions/browser/extension_registry.h" |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 42 | #include "extensions/browser/process_manager.h" |
| 43 | #include "extensions/browser/process_map.h" |
| 44 | #include "extensions/browser/view_type_utils.h" |
| 45 | #include "extensions/common/extension.h" |
| 46 | #endif |
| 47 | |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 48 | using base::StringPrintf; |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 49 | using content::BrowserChildProcessHostIterator; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 50 | using content::BrowserThread; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 51 | using content::NavigationEntry; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 52 | using content::RenderViewHost; |
| 53 | using content::RenderWidgetHost; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 54 | using content::WebContents; |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 55 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 56 | using extensions::Extension; |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 57 | #endif |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 58 | |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 59 | // static |
| 60 | std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish( |
| 61 | RendererProcessType type) { |
| 62 | switch (type) { |
| 63 | case RENDERER_NORMAL: |
| 64 | return "Tab"; |
| 65 | case RENDERER_CHROME: |
| 66 | return "Tab (Chrome)"; |
| 67 | case RENDERER_EXTENSION: |
| 68 | return "Extension"; |
| 69 | case RENDERER_DEVTOOLS: |
| 70 | return "Devtools"; |
| 71 | case RENDERER_INTERSTITIAL: |
| 72 | return "Interstitial"; |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 73 | case RENDERER_BACKGROUND_APP: |
| 74 | return "Background App"; |
| 75 | case RENDERER_UNKNOWN: |
| 76 | default: |
| 77 | NOTREACHED() << "Unknown renderer process type!"; |
| 78 | return "Unknown"; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // static |
| 83 | std::string ProcessMemoryInformation::GetFullTypeNameInEnglish( |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 84 | int process_type, |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 85 | RendererProcessType rtype) { |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 86 | if (process_type == content::PROCESS_TYPE_RENDERER) |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 87 | return GetRendererTypeNameInEnglish(rtype); |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 88 | return content::GetProcessTypeNameInEnglish(process_type); |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 91 | ProcessMemoryInformation::ProcessMemoryInformation() |
| 92 | : pid(0), |
| 93 | num_processes(0), |
| 94 | is_diagnostics(false), |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 95 | process_type(content::PROCESS_TYPE_UNKNOWN), |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 96 | renderer_type(RENDERER_UNKNOWN) { |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 97 | } |
| 98 | |
vmpstr | b8aacbe | 2016-02-26 02:00:48 | [diff] [blame^] | 99 | ProcessMemoryInformation::ProcessMemoryInformation( |
| 100 | const ProcessMemoryInformation& other) = default; |
| 101 | |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 102 | ProcessMemoryInformation::~ProcessMemoryInformation() {} |
| 103 | |
[email protected] | 8e23c88 | 2012-05-05 01:14:11 | [diff] [blame] | 104 | bool ProcessMemoryInformation::operator<( |
| 105 | const ProcessMemoryInformation& rhs) const { |
| 106 | return working_set.priv < rhs.working_set.priv; |
| 107 | } |
| 108 | |
[email protected] | 93aa89c7 | 2010-10-20 21:32:04 | [diff] [blame] | 109 | ProcessData::ProcessData() {} |
| 110 | |
| 111 | ProcessData::ProcessData(const ProcessData& rhs) |
| 112 | : name(rhs.name), |
| 113 | process_name(rhs.process_name), |
| 114 | processes(rhs.processes) { |
| 115 | } |
| 116 | |
| 117 | ProcessData::~ProcessData() {} |
| 118 | |
| 119 | ProcessData& ProcessData::operator=(const ProcessData& rhs) { |
| 120 | name = rhs.name; |
| 121 | process_name = rhs.process_name; |
| 122 | processes = rhs.processes; |
| 123 | return *this; |
| 124 | } |
| 125 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | // About threading: |
| 127 | // |
| 128 | // This operation will hit no fewer than 3 threads. |
| 129 | // |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 130 | // The BrowserChildProcessHostIterator can only be accessed from the IO thread. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | // |
| 132 | // The RenderProcessHostIterator can only be accessed from the UI thread. |
| 133 | // |
| 134 | // This operation can take 30-100ms to complete. We never want to have |
| 135 | // one task run for that long on the UI or IO threads. So, we run the |
hashimoto | a8ea28d | 2015-04-11 02:50:48 | [diff] [blame] | 136 | // expensive parts of this operation over on the blocking pool. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 137 | // |
asvitkine | 6f5f359 | 2015-01-21 20:50:37 | [diff] [blame] | 138 | void MemoryDetails::StartFetch(CollectionMode mode) { |
[email protected] | 9bb480ee | 2011-08-03 21:41:16 | [diff] [blame] | 139 | // This might get called from the UI or FILE threads, but should not be |
| 140 | // getting called from the IO thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 141 | DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 142 | |
| 143 | // In order to process this request, we need to use the plugin information. |
| 144 | // However, plugin process information is only available from the IO thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 145 | BrowserThread::PostTask( |
| 146 | BrowserThread::IO, FROM_HERE, |
asvitkine | 6f5f359 | 2015-01-21 20:50:37 | [diff] [blame] | 147 | base::Bind(&MemoryDetails::CollectChildInfoOnIOThread, this, mode)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 150 | MemoryDetails::~MemoryDetails() {} |
| 151 | |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 152 | std::string MemoryDetails::ToLogString() { |
| 153 | std::string log; |
| 154 | log.reserve(4096); |
[email protected] | 8e23c88 | 2012-05-05 01:14:11 | [diff] [blame] | 155 | ProcessMemoryInformationList processes = ChromeBrowser()->processes; |
| 156 | // Sort by memory consumption, low to high. |
| 157 | std::sort(processes.begin(), processes.end()); |
| 158 | // Print from high to low. |
| 159 | for (ProcessMemoryInformationList::reverse_iterator iter1 = |
| 160 | processes.rbegin(); |
| 161 | iter1 != processes.rend(); |
| 162 | ++iter1) { |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 163 | log += ProcessMemoryInformation::GetFullTypeNameInEnglish( |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 164 | iter1->process_type, iter1->renderer_type); |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 165 | if (!iter1->titles.empty()) { |
| 166 | log += " ["; |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 167 | for (std::vector<base::string16>::const_iterator iter2 = |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 168 | iter1->titles.begin(); |
| 169 | iter2 != iter1->titles.end(); ++iter2) { |
| 170 | if (iter2 != iter1->titles.begin()) |
| 171 | log += "|"; |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 172 | log += base::UTF16ToUTF8(*iter2); |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 173 | } |
| 174 | log += "]"; |
| 175 | } |
[email protected] | aa1255b | 2013-07-31 22:03:09 | [diff] [blame] | 176 | log += StringPrintf(" %d MB private, %d MB shared", |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 177 | static_cast<int>(iter1->working_set.priv) / 1024, |
| 178 | static_cast<int>(iter1->working_set.shared) / 1024); |
[email protected] | aa1255b | 2013-07-31 22:03:09 | [diff] [blame] | 179 | #if defined(OS_CHROMEOS) |
| 180 | log += StringPrintf(", %d MB swapped", |
| 181 | static_cast<int>(iter1->working_set.swapped) / 1024); |
| 182 | #endif |
| 183 | log += "\n"; |
[email protected] | 4306df7 | 2012-04-20 18:58:57 | [diff] [blame] | 184 | } |
| 185 | return log; |
| 186 | } |
| 187 | |
asvitkine | 6f5f359 | 2015-01-21 20:50:37 | [diff] [blame] | 188 | void MemoryDetails::CollectChildInfoOnIOThread(CollectionMode mode) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 189 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 190 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 191 | std::vector<ProcessMemoryInformation> child_info; |
| 192 | |
[email protected] | 82a14c1 | 2012-11-13 18:40:55 | [diff] [blame] | 193 | // Collect the list of child processes. A 0 |handle| means that |
| 194 | // the process is being launched, so we skip it. |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 195 | for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 196 | ProcessMemoryInformation info; |
[email protected] | 82a14c1 | 2012-11-13 18:40:55 | [diff] [blame] | 197 | if (!iter.GetData().handle) |
| 198 | continue; |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 199 | info.pid = base::GetProcId(iter.GetData().handle); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 200 | if (!info.pid) |
| 201 | continue; |
| 202 | |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 203 | info.process_type = iter.GetData().process_type; |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 204 | info.renderer_type = ProcessMemoryInformation::RENDERER_UNKNOWN; |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 205 | info.titles.push_back(iter.GetData().name); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 206 | child_info.push_back(info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 207 | } |
| 208 | |
hashimoto | a8ea28d | 2015-04-11 02:50:48 | [diff] [blame] | 209 | // Now go do expensive memory lookups on the blocking pool. |
| 210 | BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( |
| 211 | FROM_HERE, |
| 212 | base::Bind(&MemoryDetails::CollectProcessData, this, mode, child_info), |
| 213 | base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 214 | } |
| 215 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 216 | void MemoryDetails::CollectChildInfoOnUIThread() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 217 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 218 | ProcessData* const chrome_browser = ChromeBrowser(); |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 219 | |
| 220 | // First pass, collate the widgets by process ID. |
| 221 | std::map<base::ProcessId, std::vector<RenderWidgetHost*>> widgets_by_pid; |
| 222 | scoped_ptr<content::RenderWidgetHostIterator> widget_it( |
| 223 | RenderWidgetHost::GetRenderWidgetHosts()); |
| 224 | while (content::RenderWidgetHost* widget = widget_it->GetNextHost()) { |
| 225 | // Ignore processes that don't have a connection, such as crashed tabs. |
| 226 | if (!widget->GetProcess()->HasConnection()) |
| 227 | continue; |
| 228 | base::ProcessId pid = base::GetProcId(widget->GetProcess()->GetHandle()); |
| 229 | widgets_by_pid[pid].push_back(widget); |
| 230 | } |
| 231 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 232 | // Get more information about the process. |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 233 | for (ProcessMemoryInformation& process : chrome_browser->processes) { |
| 234 | // If there's at least one widget in the process, it is some kind of |
| 235 | // renderer process belonging to this browser. All these widgets will share |
| 236 | // a RenderProcessHost. |
| 237 | content::RenderProcessHost* render_process_host = nullptr; |
| 238 | if (!widgets_by_pid[process.pid].empty()) { |
| 239 | // Mark it as a normal renderer process, if we don't refine it to some |
| 240 | // other |renderer_type| later. |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 241 | process.process_type = content::PROCESS_TYPE_RENDERER; |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 242 | process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL; |
| 243 | render_process_host = widgets_by_pid[process.pid].front()->GetProcess(); |
| 244 | } |
| 245 | |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 246 | #if defined(ENABLE_EXTENSIONS) |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 247 | // Determine if this is an extension process. |
| 248 | bool process_is_for_extensions = false; |
| 249 | if (render_process_host) { |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 250 | content::BrowserContext* context = |
| 251 | render_process_host->GetBrowserContext(); |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 252 | extensions::ExtensionRegistry* extension_registry = |
| 253 | extensions::ExtensionRegistry::Get(context); |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 254 | extensions::ProcessMap* process_map = |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 255 | extensions::ProcessMap::Get(context); |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 256 | int rph_id = render_process_host->GetID(); |
| 257 | process_is_for_extensions = process_map->Contains(rph_id); |
| 258 | |
| 259 | // For our purposes, don't count processes containing only hosted apps |
| 260 | // as extension processes. See also: crbug.com/102533. |
| 261 | for (auto& extension_id : process_map->GetExtensionsInProcess(rph_id)) { |
| 262 | const Extension* extension = |
| 263 | extension_registry->enabled_extensions().GetByID(extension_id); |
| 264 | if (extension && !extension->is_hosted_app()) { |
| 265 | process.renderer_type = ProcessMemoryInformation::RENDERER_EXTENSION; |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | } |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 270 | #endif |
| 271 | |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 272 | // Use the list of widgets to iterate over the WebContents instances whose |
| 273 | // main RenderFrameHosts are in |process|. Refine our determination of the |
| 274 | // |process.renderer_type|, and record the page titles. |
| 275 | for (content::RenderWidgetHost* widget : widgets_by_pid[process.pid]) { |
| 276 | DCHECK_EQ(render_process_host, widget->GetProcess()); |
| 277 | |
| 278 | RenderViewHost* rvh = RenderViewHost::From(widget); |
| 279 | if (!rvh) |
| 280 | continue; |
| 281 | |
| 282 | WebContents* contents = WebContents::FromRenderViewHost(rvh); |
| 283 | |
| 284 | // Assume that an RVH without a web contents is an interstitial. |
| 285 | if (!contents) { |
| 286 | process.renderer_type = ProcessMemoryInformation::RENDERER_INTERSTITIAL; |
| 287 | continue; |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 288 | } |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 289 | |
| 290 | // If this is a RVH for a subframe; skip it to avoid double-counting the |
| 291 | // WebContents. |
| 292 | if (rvh != contents->GetRenderViewHost()) |
| 293 | continue; |
| 294 | |
| 295 | // The rest of this block will happen only once per WebContents. |
| 296 | GURL page_url = contents->GetLastCommittedURL(); |
| 297 | SiteData& site_data = |
| 298 | chrome_browser->site_data[contents->GetBrowserContext()]; |
| 299 | SiteDetails::CollectSiteInfo(contents, &site_data); |
| 300 | |
| 301 | bool is_webui = |
| 302 | rvh->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI; |
| 303 | |
| 304 | if (is_webui) { |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 305 | process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME; |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 306 | } |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 307 | |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 308 | #if defined(ENABLE_EXTENSIONS) |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 309 | if (!is_webui && process_is_for_extensions) { |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 310 | const Extension* extension = |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 311 | extensions::ExtensionRegistry::Get( |
| 312 | render_process_host->GetBrowserContext()) |
| 313 | ->enabled_extensions() |
| 314 | .GetByID(page_url.host()); |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 315 | if (extension) { |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 316 | base::string16 title = base::UTF8ToUTF16(extension->name()); |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 317 | process.titles.push_back(title); |
[email protected] | 299d7f1 | 2012-05-23 05:31:15 | [diff] [blame] | 318 | process.renderer_type = |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 319 | ProcessMemoryInformation::RENDERER_EXTENSION; |
[email protected] | 299d7f1 | 2012-05-23 05:31:15 | [diff] [blame] | 320 | continue; |
| 321 | } |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 322 | } |
[email protected] | 299d7f1 | 2012-05-23 05:31:15 | [diff] [blame] | 323 | |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 324 | extensions::ViewType type = extensions::GetViewType(contents); |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 325 | if (type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 326 | process.titles.push_back(base::UTF8ToUTF16(page_url.spec())); |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 327 | process.renderer_type = |
| 328 | ProcessMemoryInformation::RENDERER_BACKGROUND_APP; |
| 329 | continue; |
| 330 | } |
[email protected] | ddef62e | 2014-07-12 06:18:57 | [diff] [blame] | 331 | #endif |
[email protected] | 299d7f1 | 2012-05-23 05:31:15 | [diff] [blame] | 332 | |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 333 | base::string16 title = contents->GetTitle(); |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 334 | if (!title.length()) |
| 335 | title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
| 336 | process.titles.push_back(title); |
| 337 | |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 338 | // The presence of a single WebContents with a diagnostics page will make |
| 339 | // the whole process be considered a diagnostics process. |
| 340 | // |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 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 && |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 357 | base::LowerCaseEqualsASCII( |
| 358 | last_committed_entry->GetVirtualURL().spec(), |
| 359 | chrome::kChromeUIMemoryURL)) || |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 360 | (pending_entry && |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 361 | base::LowerCaseEqualsASCII( |
| 362 | pending_entry->GetVirtualURL().spec(), |
| 363 | chrome::kChromeUIMemoryURL))) { |
[email protected] | 039b84a4 | 2013-06-21 20:23:37 | [diff] [blame] | 364 | process.is_diagnostics = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | } |
| 366 | } |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 367 | |
[email protected] | a423c9e | 2012-03-06 18:02:31 | [diff] [blame] | 368 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
kerrnel | afd49a83b | 2016-01-22 21:16:15 | [diff] [blame] | 369 | if (content::ZygoteHost::GetInstance()->IsZygotePid(process.pid)) { |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 370 | process.process_type = content::PROCESS_TYPE_ZYGOTE; |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 371 | } |
| 372 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 373 | } |
| 374 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 375 | // Get rid of other Chrome processes that are from a different profile. |
nick | b2545f7 | 2015-10-30 20:05:15 | [diff] [blame] | 376 | auto is_unknown = [](ProcessMemoryInformation& process) { |
| 377 | return process.process_type == content::PROCESS_TYPE_UNKNOWN; |
| 378 | }; |
| 379 | auto& vector = chrome_browser->processes; |
| 380 | vector.erase(std::remove_if(vector.begin(), vector.end(), is_unknown), |
| 381 | vector.end()); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 382 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 383 | OnDetailsAvailable(); |
| 384 | } |