| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_version_info.h" | 13 #include "base/file_version_info.h" |
| 14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/process_info_snapshot.h" | 19 #include "chrome/browser/process_info_snapshot.h" |
| 20 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_version_info.h" | 21 #include "chrome/common/chrome_version_info.h" |
| 22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 23 #include "content/browser/browser_child_process_host.h" | 23 #include "content/browser/browser_child_process_host.h" |
| 24 #include "content/browser/renderer_host/backing_store_manager.h" | 24 #include "content/browser/renderer_host/backing_store_manager.h" |
| 25 #include "content/browser/tab_contents/navigation_entry.h" | 25 #include "content/browser/tab_contents/navigation_entry.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/common/process_type.h" |
| 27 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 29 | 30 |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| 31 | 32 |
| 32 // TODO(viettrungluu): Many of the TODOs below are subsumed by a general need to | 33 // TODO(viettrungluu): Many of the TODOs below are subsumed by a general need to |
| 33 // refactor the about:memory code (not just on Mac, but probably on other | 34 // refactor the about:memory code (not just on Mac, but probably on other |
| 34 // platforms as well). I've filed crbug.com/25456. | 35 // platforms as well). I've filed crbug.com/25456. |
| 35 | 36 |
| 36 class RenderViewHostDelegate; | 37 class RenderViewHostDelegate; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 ProcessInfoSnapshot process_info; | 144 ProcessInfoSnapshot process_info; |
| 144 process_info.Sample(all_pids); | 145 process_info.Sample(all_pids); |
| 145 | 146 |
| 146 // Handle the other processes first. | 147 // Handle the other processes first. |
| 147 for (size_t index = CHROME_BROWSER + 1; index < MAX_BROWSERS; index++) { | 148 for (size_t index = CHROME_BROWSER + 1; index < MAX_BROWSERS; index++) { |
| 148 for (std::vector<base::ProcessId>::const_iterator it = | 149 for (std::vector<base::ProcessId>::const_iterator it = |
| 149 pids_by_browser[index].begin(); | 150 pids_by_browser[index].begin(); |
| 150 it != pids_by_browser[index].end(); ++it) { | 151 it != pids_by_browser[index].end(); ++it) { |
| 151 ProcessMemoryInformation info; | 152 ProcessMemoryInformation info; |
| 152 info.pid = *it; | 153 info.pid = *it; |
| 153 info.type = ChildProcessInfo::UNKNOWN_PROCESS; | 154 info.type = content::PROCESS_TYPE_UNKNOWN; |
| 154 | 155 |
| 155 // Try to get version information. To do this, we need first to get the | 156 // Try to get version information. To do this, we need first to get the |
| 156 // executable's name (we can only believe |proc_info.command| if it looks | 157 // executable's name (we can only believe |proc_info.command| if it looks |
| 157 // like an absolute path). Then we need strip the executable's name back | 158 // like an absolute path). Then we need strip the executable's name back |
| 158 // to the bundle's name. And only then can we try to get the version. | 159 // to the bundle's name. And only then can we try to get the version. |
| 159 scoped_ptr<FileVersionInfo> version_info; | 160 scoped_ptr<FileVersionInfo> version_info; |
| 160 ProcessInfoSnapshot::ProcInfoEntry proc_info; | 161 ProcessInfoSnapshot::ProcInfoEntry proc_info; |
| 161 if (process_info.GetProcInfo(info.pid, &proc_info)) { | 162 if (process_info.GetProcInfo(info.pid, &proc_info)) { |
| 162 if (proc_info.command.length() > 1 && proc_info.command[0] == '/') { | 163 if (proc_info.command.length() > 1 && proc_info.command[0] == '/') { |
| 163 FilePath bundle_name = | 164 FilePath bundle_name = |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); | 205 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void MemoryDetails::CollectProcessDataChrome( | 208 void MemoryDetails::CollectProcessDataChrome( |
| 208 const std::vector<ProcessMemoryInformation>& child_info, | 209 const std::vector<ProcessMemoryInformation>& child_info, |
| 209 base::ProcessId pid, | 210 base::ProcessId pid, |
| 210 const ProcessInfoSnapshot& process_info) { | 211 const ProcessInfoSnapshot& process_info) { |
| 211 ProcessMemoryInformation info; | 212 ProcessMemoryInformation info; |
| 212 info.pid = pid; | 213 info.pid = pid; |
| 213 if (info.pid == base::GetCurrentProcId()) | 214 if (info.pid == base::GetCurrentProcId()) |
| 214 info.type = ChildProcessInfo::BROWSER_PROCESS; | 215 info.type = content::PROCESS_TYPE_BROWSER; |
| 215 else | 216 else |
| 216 info.type = ChildProcessInfo::UNKNOWN_PROCESS; | 217 info.type = content::PROCESS_TYPE_UNKNOWN; |
| 217 | 218 |
| 218 chrome::VersionInfo version_info; | 219 chrome::VersionInfo version_info; |
| 219 if (version_info.is_valid()) { | 220 if (version_info.is_valid()) { |
| 220 info.product_name = ASCIIToUTF16(version_info.Name()); | 221 info.product_name = ASCIIToUTF16(version_info.Name()); |
| 221 info.version = ASCIIToUTF16(version_info.Version()); | 222 info.version = ASCIIToUTF16(version_info.Version()); |
| 222 } else { | 223 } else { |
| 223 info.product_name = process_data_[CHROME_BROWSER].name; | 224 info.product_name = process_data_[CHROME_BROWSER].name; |
| 224 info.version = string16(); | 225 info.version = string16(); |
| 225 } | 226 } |
| 226 | 227 |
| 227 // Check if this is one of the child processes whose data we collected | 228 // Check if this is one of the child processes whose data we collected |
| 228 // on the IO thread, and if so copy over that data. | 229 // on the IO thread, and if so copy over that data. |
| 229 for (size_t child = 0; child < child_info.size(); child++) { | 230 for (size_t child = 0; child < child_info.size(); child++) { |
| 230 if (child_info[child].pid == info.pid) { | 231 if (child_info[child].pid == info.pid) { |
| 231 info.titles = child_info[child].titles; | 232 info.titles = child_info[child].titles; |
| 232 info.type = child_info[child].type; | 233 info.type = child_info[child].type; |
| 233 break; | 234 break; |
| 234 } | 235 } |
| 235 } | 236 } |
| 236 | 237 |
| 237 // Memory info. | 238 // Memory info. |
| 238 process_info.GetCommittedKBytesOfPID(info.pid, &info.committed); | 239 process_info.GetCommittedKBytesOfPID(info.pid, &info.committed); |
| 239 process_info.GetWorkingSetKBytesOfPID(info.pid, &info.working_set); | 240 process_info.GetWorkingSetKBytesOfPID(info.pid, &info.working_set); |
| 240 | 241 |
| 241 // Add the process info to our list. | 242 // Add the process info to our list. |
| 242 process_data_[CHROME_BROWSER].processes.push_back(info); | 243 process_data_[CHROME_BROWSER].processes.push_back(info); |
| 243 } | 244 } |
| OLD | NEW |