OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 SAFARI_BROWSER, | 44 SAFARI_BROWSER, |
45 FIREFOX_BROWSER, | 45 FIREFOX_BROWSER, |
46 CAMINO_BROWSER, | 46 CAMINO_BROWSER, |
47 OPERA_BROWSER, | 47 OPERA_BROWSER, |
48 OMNIWEB_BROWSER, | 48 OMNIWEB_BROWSER, |
49 MAX_BROWSERS | 49 MAX_BROWSERS |
50 } BrowserProcess; | 50 } BrowserProcess; |
51 | 51 |
52 | 52 |
53 MemoryDetails::MemoryDetails() { | 53 MemoryDetails::MemoryDetails() { |
54 static const std::wstring google_browser_name = | 54 static const std::string google_browser_name = |
55 l10n_util::GetString(IDS_PRODUCT_NAME); | 55 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); |
56 // (Human and process) names of browsers; should match the ordering for | 56 // (Human and process) names of browsers; should match the ordering for |
57 // |BrowserProcess| (i.e., |BrowserType|). | 57 // |BrowserProcess| (i.e., |BrowserType|). |
58 // TODO(viettrungluu): The current setup means that we can't detect both | 58 // TODO(viettrungluu): The current setup means that we can't detect both |
59 // Chrome and Chromium at the same time! | 59 // Chrome and Chromium at the same time! |
60 // TODO(viettrungluu): Get localized browser names for other browsers | 60 // TODO(viettrungluu): Get localized browser names for other browsers |
61 // (crbug.com/25779). | 61 // (crbug.com/25779). |
62 struct { | 62 struct { |
63 const wchar_t* name; | 63 const char* name; |
64 const wchar_t* process_name; | 64 const char* process_name; |
65 } process_template[MAX_BROWSERS] = { | 65 } process_template[MAX_BROWSERS] = { |
66 { google_browser_name.c_str(), chrome::kBrowserProcessExecutableName, }, | 66 { google_browser_name.c_str(), chrome::kBrowserProcessExecutableName, }, |
67 { L"Safari", L"Safari", }, | 67 { "Safari", "Safari", }, |
68 { L"Firefox", L"firefox-bin", }, | 68 { "Firefox", "firefox-bin", }, |
69 { L"Camino", L"Camino", }, | 69 { "Camino", "Camino", }, |
70 { L"Opera", L"Opera", }, | 70 { "Opera", "Opera", }, |
71 { L"OmniWeb", L"OmniWeb", }, | 71 { "OmniWeb", "OmniWeb", }, |
72 }; | 72 }; |
73 | 73 |
74 for (size_t index = 0; index < MAX_BROWSERS; ++index) { | 74 for (size_t index = 0; index < MAX_BROWSERS; ++index) { |
75 ProcessData process; | 75 ProcessData process; |
76 process.name = process_template[index].name; | 76 process.name = UTF8ToUTF16(process_template[index].name); |
77 process.process_name = process_template[index].process_name; | 77 process.process_name = UTF8ToUTF16(process_template[index].process_name); |
78 process_data_.push_back(process); | 78 process_data_.push_back(process); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 ProcessData* MemoryDetails::ChromeBrowser() { | 82 ProcessData* MemoryDetails::ChromeBrowser() { |
83 return &process_data_[CHROME_BROWSER]; | 83 return &process_data_[CHROME_BROWSER]; |
84 } | 84 } |
85 | 85 |
86 void MemoryDetails::CollectProcessData( | 86 void MemoryDetails::CollectProcessData( |
87 std::vector<ProcessMemoryInformation> child_info) { | 87 std::vector<ProcessMemoryInformation> child_info) { |
88 // This must be run on the file thread to avoid jank (|ProcessInfoSnapshot| | 88 // This must be run on the file thread to avoid jank (|ProcessInfoSnapshot| |
89 // runs /bin/ps, which isn't instantaneous). | 89 // runs /bin/ps, which isn't instantaneous). |
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
91 | 91 |
92 // Clear old data. | 92 // Clear old data. |
93 for (size_t index = 0; index < MAX_BROWSERS; index++) | 93 for (size_t index = 0; index < MAX_BROWSERS; index++) |
94 process_data_[index].processes.clear(); | 94 process_data_[index].processes.clear(); |
95 | 95 |
96 // First, we use |NamedProcessIterator| to get the PIDs of the processes we're | 96 // First, we use |NamedProcessIterator| to get the PIDs of the processes we're |
97 // interested in; we save our results to avoid extra calls to | 97 // interested in; we save our results to avoid extra calls to |
98 // |NamedProcessIterator| (for performance reasons) and to avoid additional | 98 // |NamedProcessIterator| (for performance reasons) and to avoid additional |
99 // inconsistencies caused by racing. Then we run |/bin/ps| *once* to get | 99 // inconsistencies caused by racing. Then we run |/bin/ps| *once* to get |
100 // information on those PIDs. Then we used our saved information to iterate | 100 // information on those PIDs. Then we used our saved information to iterate |
101 // over browsers, then over PIDs. | 101 // over browsers, then over PIDs. |
102 | 102 |
103 // Get PIDs of main browser processes. | 103 // Get PIDs of main browser processes. |
104 std::vector<base::ProcessId> pids_by_browser[MAX_BROWSERS]; | 104 std::vector<base::ProcessId> pids_by_browser[MAX_BROWSERS]; |
105 std::vector<base::ProcessId> all_pids; | 105 std::vector<base::ProcessId> all_pids; |
106 for (size_t index = CHROME_BROWSER; index < MAX_BROWSERS; index++) { | 106 for (size_t index = CHROME_BROWSER; index < MAX_BROWSERS; index++) { |
107 base::NamedProcessIterator process_it(process_data_[index].process_name, | 107 base::NamedProcessIterator process_it( |
108 NULL); | 108 UTF16ToUTF8(process_data_[index].process_name), NULL); |
109 | 109 |
110 while (const base::ProcessEntry* entry = process_it.NextProcessEntry()) { | 110 while (const base::ProcessEntry* entry = process_it.NextProcessEntry()) { |
111 pids_by_browser[index].push_back(entry->pid()); | 111 pids_by_browser[index].push_back(entry->pid()); |
112 all_pids.push_back(entry->pid()); | 112 all_pids.push_back(entry->pid()); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 // Get PIDs of helpers. | 116 // Get PIDs of helpers. |
117 std::vector<base::ProcessId> helper_pids; | 117 std::vector<base::ProcessId> helper_pids; |
118 { | 118 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 version_info.reset(FileVersionInfo::CreateFileVersionInfo( | 151 version_info.reset(FileVersionInfo::CreateFileVersionInfo( |
152 bundle_name)); | 152 bundle_name)); |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 if (version_info.get()) { | 156 if (version_info.get()) { |
157 info.product_name = version_info->product_name(); | 157 info.product_name = version_info->product_name(); |
158 info.version = version_info->product_version(); | 158 info.version = version_info->product_version(); |
159 } else { | 159 } else { |
160 info.product_name = process_data_[index].name; | 160 info.product_name = process_data_[index].name; |
161 info.version = L""; | 161 info.version = string16(); |
162 } | 162 } |
163 | 163 |
164 // Memory info. | 164 // Memory info. |
165 process_info.GetCommittedKBytesOfPID(info.pid, &info.committed); | 165 process_info.GetCommittedKBytesOfPID(info.pid, &info.committed); |
166 process_info.GetWorkingSetKBytesOfPID(info.pid, &info.working_set); | 166 process_info.GetWorkingSetKBytesOfPID(info.pid, &info.working_set); |
167 | 167 |
168 // Add the process info to our list. | 168 // Add the process info to our list. |
169 process_data_[index].processes.push_back(info); | 169 process_data_[index].processes.push_back(info); |
170 } | 170 } |
171 } | 171 } |
(...skipping 23 matching lines...) Expand all Loading... |
195 const ProcessInfoSnapshot& process_info) { | 195 const ProcessInfoSnapshot& process_info) { |
196 ProcessMemoryInformation info; | 196 ProcessMemoryInformation info; |
197 info.pid = pid; | 197 info.pid = pid; |
198 if (info.pid == base::GetCurrentProcId()) | 198 if (info.pid == base::GetCurrentProcId()) |
199 info.type = ChildProcessInfo::BROWSER_PROCESS; | 199 info.type = ChildProcessInfo::BROWSER_PROCESS; |
200 else | 200 else |
201 info.type = ChildProcessInfo::UNKNOWN_PROCESS; | 201 info.type = ChildProcessInfo::UNKNOWN_PROCESS; |
202 | 202 |
203 chrome::VersionInfo version_info; | 203 chrome::VersionInfo version_info; |
204 if (version_info.is_valid()) { | 204 if (version_info.is_valid()) { |
205 info.product_name = ASCIIToWide(version_info.Name()); | 205 info.product_name = ASCIIToUTF16(version_info.Name()); |
206 info.version = ASCIIToWide(version_info.Version()); | 206 info.version = ASCIIToUTF16(version_info.Version()); |
207 } else { | 207 } else { |
208 info.product_name = process_data_[CHROME_BROWSER].name; | 208 info.product_name = process_data_[CHROME_BROWSER].name; |
209 info.version = L""; | 209 info.version = string16(); |
210 } | 210 } |
211 | 211 |
212 // Check if this is one of the child processes whose data we collected | 212 // Check if this is one of the child processes whose data we collected |
213 // on the IO thread, and if so copy over that data. | 213 // on the IO thread, and if so copy over that data. |
214 for (size_t child = 0; child < child_info.size(); child++) { | 214 for (size_t child = 0; child < child_info.size(); child++) { |
215 if (child_info[child].pid == info.pid) { | 215 if (child_info[child].pid == info.pid) { |
216 info.titles = child_info[child].titles; | 216 info.titles = child_info[child].titles; |
217 info.type = child_info[child].type; | 217 info.type = child_info[child].type; |
218 break; | 218 break; |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 // Memory info. | 222 // Memory info. |
223 process_info.GetCommittedKBytesOfPID(info.pid, &info.committed); | 223 process_info.GetCommittedKBytesOfPID(info.pid, &info.committed); |
224 process_info.GetWorkingSetKBytesOfPID(info.pid, &info.working_set); | 224 process_info.GetWorkingSetKBytesOfPID(info.pid, &info.working_set); |
225 | 225 |
226 // Add the process info to our list. | 226 // Add the process info to our list. |
227 process_data_[CHROME_BROWSER].processes.push_back(info); | 227 process_data_[CHROME_BROWSER].processes.push_back(info); |
228 } | 228 } |
OLD | NEW |