| 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 <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/common/process_type.h" | 19 #include "content/public/common/process_type.h" |
| 20 #include "grt/chromium_strings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" |
| 20 | 22 |
| 21 using base::ProcessEntry; | 23 using base::ProcessEntry; |
| 22 using content::BrowserThread; | 24 using content::BrowserThread; |
| 23 | 25 |
| 24 // Known browsers which we collect details for. | 26 // Known browsers which we collect details for. |
| 25 enum BrowserType { | 27 enum BrowserType { |
| 26 CHROME = 0, | 28 CHROME = 0, |
| 27 FIREFOX, | 29 FIREFOX, |
| 28 ICEWEASEL, | 30 ICEWEASEL, |
| 29 OPERA, | 31 OPERA, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 42 "Opera", | 44 "Opera", |
| 43 "Konqueror", | 45 "Konqueror", |
| 44 "Epiphany", | 46 "Epiphany", |
| 45 "Midori", | 47 "Midori", |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 // A mapping from process name to the type of browser. | 50 // A mapping from process name to the type of browser. |
| 49 static const struct { | 51 static const struct { |
| 50 const char process_name[16]; | 52 const char process_name[16]; |
| 51 BrowserType browser; | 53 BrowserType browser; |
| 52 } kBrowserBinaryNames[] = { | 54 } kBrowserBinaryNames[] = { |
| 53 { "firefox", FIREFOX }, | 55 { "firefox", FIREFOX }, |
| 54 { "firefox-3.5", FIREFOX }, | 56 { "firefox-3.5", FIREFOX }, |
| 55 { "firefox-3.0", FIREFOX }, | 57 { "firefox-3.0", FIREFOX }, |
| 56 { "firefox-bin", FIREFOX }, | 58 { "firefox-bin", FIREFOX }, |
| 57 { "iceweasel", ICEWEASEL }, | 59 { "iceweasel", ICEWEASEL }, |
| 58 { "opera", OPERA }, | 60 { "opera", OPERA }, |
| 59 { "konqueror", KONQUEROR }, | 61 { "konqueror", KONQUEROR }, |
| 60 { "epiphany-browse", EPIPHANY }, | 62 { "epiphany-browse", EPIPHANY }, |
| 61 { "epiphany", EPIPHANY }, | 63 { "epiphany", EPIPHANY }, |
| 62 { "midori", MIDORI }, | 64 { "midori", MIDORI }, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (GetBrowserType(parent_iter->second.name) != type) { | 187 if (GetBrowserType(parent_iter->second.name) != type) { |
| 186 // We found a process whose type is diffent from its parent's type. | 188 // We found a process whose type is diffent from its parent's type. |
| 187 // That means it is the root process of the browser. | 189 // That means it is the root process of the browser. |
| 188 browsers_found.insert(current_process.pid); | 190 browsers_found.insert(current_process.pid); |
| 189 break; | 191 break; |
| 190 } | 192 } |
| 191 } | 193 } |
| 192 | 194 |
| 193 ProcessData current_browser = | 195 ProcessData current_browser = |
| 194 GetProcessDataMemoryInformation(GetAllChildren(process_map, getpid())); | 196 GetProcessDataMemoryInformation(GetAllChildren(process_map, getpid())); |
| 195 current_browser.name = WideToUTF16(chrome::kBrowserAppName); | 197 current_browser.name = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
| 196 current_browser.process_name = ASCIIToUTF16("chrome"); | 198 current_browser.process_name = ASCIIToUTF16("chrome"); |
| 197 | 199 |
| 198 for (std::vector<ProcessMemoryInformation>::iterator | 200 for (std::vector<ProcessMemoryInformation>::iterator |
| 199 i = current_browser.processes.begin(); | 201 i = current_browser.processes.begin(); |
| 200 i != current_browser.processes.end(); ++i) { | 202 i != current_browser.processes.end(); ++i) { |
| 201 // Check if this is one of the child processes whose data we collected | 203 // Check if this is one of the child processes whose data we collected |
| 202 // on the IO thread, and if so copy over that data. | 204 // on the IO thread, and if so copy over that data. |
| 203 for (size_t child = 0; child < child_info.size(); child++) { | 205 for (size_t child = 0; child < child_info.size(); child++) { |
| 204 if (child_info[child].pid != i->pid) | 206 if (child_info[child].pid != i->pid) |
| 205 continue; | 207 continue; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 226 if (type != MAX_BROWSERS) | 228 if (type != MAX_BROWSERS) |
| 227 browser.name = ASCIIToUTF16(kBrowserPrettyNames[type]); | 229 browser.name = ASCIIToUTF16(kBrowserPrettyNames[type]); |
| 228 process_data_.push_back(browser); | 230 process_data_.push_back(browser); |
| 229 } | 231 } |
| 230 | 232 |
| 231 // Finally return to the browser thread. | 233 // Finally return to the browser thread. |
| 232 BrowserThread::PostTask( | 234 BrowserThread::PostTask( |
| 233 BrowserThread::UI, FROM_HERE, | 235 BrowserThread::UI, FROM_HERE, |
| 234 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); | 236 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); |
| 235 } | 237 } |
| OLD | NEW |