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

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

Issue 6610029: Create a "GetWOW64Status()" utility function and make the rest of the codebas... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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) 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 <psapi.h> 7 #include <psapi.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_version_info.h" 10 #include "base/file_version_info.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/win/scoped_handle.h" 13 #include "base/win/scoped_handle.h"
14 #include "base/win/windows_version.h"
14 #include "chrome/common/chrome_version_info.h" 15 #include "chrome/common/chrome_version_info.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "content/browser/browser_child_process_host.h" 17 #include "content/browser/browser_child_process_host.h"
17 #include "content/browser/browser_thread.h" 18 #include "content/browser/browser_thread.h"
18 #include "content/browser/renderer_host/backing_store_manager.h" 19 #include "content/browser/renderer_host/backing_store_manager.h"
19 #include "content/browser/renderer_host/render_process_host.h" 20 #include "content/browser/renderer_host/render_process_host.h"
20 #include "content/browser/tab_contents/navigation_entry.h" 21 #include "content/browser/tab_contents/navigation_entry.h"
21 #include "grit/chromium_strings.h" 22 #include "grit/chromium_strings.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 if (!snapshot.Get()) { 83 if (!snapshot.Get()) {
83 LOG(ERROR) << "CreateToolhelp32Snaphot failed: " << GetLastError(); 84 LOG(ERROR) << "CreateToolhelp32Snaphot failed: " << GetLastError();
84 return; 85 return;
85 } 86 }
86 if (!::Process32First(snapshot, &process_entry)) { 87 if (!::Process32First(snapshot, &process_entry)) {
87 LOG(ERROR) << "Process32First failed: " << GetLastError(); 88 LOG(ERROR) << "Process32First failed: " << GetLastError();
88 return; 89 return;
89 } 90 }
90 do { 91 do {
91 base::ProcessId pid = process_entry.th32ProcessID; 92 base::ProcessId pid = process_entry.th32ProcessID;
92 base::win::ScopedHandle handle(::OpenProcess( 93 base::win::ScopedHandle process_handle(::OpenProcess(
93 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); 94 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid));
94 if (!handle.Get()) 95 if (!process_handle.Get())
95 continue; 96 continue;
96 bool is_64bit_process = false; 97 bool is_64bit_process = is_64bit_os &&
97 // IsWow64Process() returns FALSE for a 32bit process on a 32bit OS. 98 (base::win::GetWOW64StatusForProcess(process_handle) ==
98 // We need to check if the real OS is 64bit. 99 base::win::WOW64_DISABLED);
99 if (is_64bit_os) {
100 BOOL is_wow64 = FALSE;
101 // IsWow64Process() is supported by Windows XP SP2 or later.
102 IsWow64Process(handle, &is_wow64);
103 is_64bit_process = !is_wow64;
104 }
105 for (unsigned int index2 = 0; index2 < process_data_.size(); index2++) { 100 for (unsigned int index2 = 0; index2 < process_data_.size(); index2++) {
106 if (_wcsicmp(process_data_[index2].process_name.c_str(), 101 if (_wcsicmp(process_data_[index2].process_name.c_str(),
107 process_entry.szExeFile) != 0) 102 process_entry.szExeFile) != 0)
108 continue; 103 continue;
109 if (index2 == IE_BROWSER && is_64bit_process) 104 if (index2 == IE_BROWSER && is_64bit_process)
110 continue; // Should use IE_64BIT_BROWSER 105 continue; // Should use IE_64BIT_BROWSER
111 // Get Memory Information. 106 // Get Memory Information.
112 ProcessMemoryInformation info; 107 ProcessMemoryInformation info;
113 info.pid = pid; 108 info.pid = pid;
114 if (info.pid == GetCurrentProcessId()) 109 if (info.pid == GetCurrentProcessId())
115 info.type = ChildProcessInfo::BROWSER_PROCESS; 110 info.type = ChildProcessInfo::BROWSER_PROCESS;
116 else 111 else
117 info.type = ChildProcessInfo::UNKNOWN_PROCESS; 112 info.type = ChildProcessInfo::UNKNOWN_PROCESS;
118 113
119 scoped_ptr<base::ProcessMetrics> metrics; 114 scoped_ptr<base::ProcessMetrics> metrics;
120 metrics.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); 115 metrics.reset(base::ProcessMetrics::CreateProcessMetrics(process_handle));
121 metrics->GetCommittedKBytes(&info.committed); 116 metrics->GetCommittedKBytes(&info.committed);
122 metrics->GetWorkingSetKBytes(&info.working_set); 117 metrics->GetWorkingSetKBytes(&info.working_set);
123 118
124 // Get Version Information. 119 // Get Version Information.
125 TCHAR name[MAX_PATH]; 120 TCHAR name[MAX_PATH];
126 if (index2 == CHROME_BROWSER || index2 == CHROME_NACL_PROCESS) { 121 if (index2 == CHROME_BROWSER || index2 == CHROME_NACL_PROCESS) {
127 chrome::VersionInfo version_info; 122 chrome::VersionInfo version_info;
128 if (version_info.is_valid()) 123 if (version_info.is_valid())
129 info.version = ASCIIToWide(version_info.Version()); 124 info.version = ASCIIToWide(version_info.Version());
130 // Check if this is one of the child processes whose data we collected 125 // Check if this is one of the child processes whose data we collected
131 // on the IO thread, and if so copy over that data. 126 // on the IO thread, and if so copy over that data.
132 for (size_t child = 0; child < child_info.size(); child++) { 127 for (size_t child = 0; child < child_info.size(); child++) {
133 if (child_info[child].pid != info.pid) 128 if (child_info[child].pid != info.pid)
134 continue; 129 continue;
135 info.titles = child_info[child].titles; 130 info.titles = child_info[child].titles;
136 info.type = child_info[child].type; 131 info.type = child_info[child].type;
137 break; 132 break;
138 } 133 }
139 } else if (GetModuleFileNameEx(handle, NULL, name, MAX_PATH - 1)) { 134 } else if (GetModuleFileNameEx(process_handle, NULL, name,
135 MAX_PATH - 1)) {
140 std::wstring str_name(name); 136 std::wstring str_name(name);
141 scoped_ptr<FileVersionInfo> version_info( 137 scoped_ptr<FileVersionInfo> version_info(
142 FileVersionInfo::CreateFileVersionInfo(FilePath(str_name))); 138 FileVersionInfo::CreateFileVersionInfo(FilePath(str_name)));
143 if (version_info != NULL) { 139 if (version_info != NULL) {
144 info.version = version_info->product_version(); 140 info.version = version_info->product_version();
145 info.product_name = version_info->product_name(); 141 info.product_name = version_info->product_name();
146 } 142 }
147 } 143 }
148 144
149 // Add the process info to our list. 145 // Add the process info to our list.
150 if (index2 == CHROME_NACL_PROCESS) { 146 if (index2 == CHROME_NACL_PROCESS) {
151 // Add NaCl processes to Chrome's list 147 // Add NaCl processes to Chrome's list
152 process_data_[CHROME_BROWSER].processes.push_back(info); 148 process_data_[CHROME_BROWSER].processes.push_back(info);
153 } else { 149 } else {
154 process_data_[index2].processes.push_back(info); 150 process_data_[index2].processes.push_back(info);
155 } 151 }
156 break; 152 break;
157 } 153 }
158 } while (::Process32Next(snapshot, &process_entry)); 154 } while (::Process32Next(snapshot, &process_entry));
159 155
160 // Finally return to the browser thread. 156 // Finally return to the browser thread.
161 BrowserThread::PostTask( 157 BrowserThread::PostTask(
162 BrowserThread::UI, FROM_HERE, 158 BrowserThread::UI, FROM_HERE,
163 NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnUIThread)); 159 NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnUIThread));
164 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698