Index: chrome/browser/memory_details_linux.cc |
=================================================================== |
--- chrome/browser/memory_details_linux.cc (revision 0) |
+++ chrome/browser/memory_details_linux.cc (revision 0) |
@@ -0,0 +1,106 @@ |
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/memory_details.h" |
+ |
+#include "app/l10n_util.h" |
+#include "base/file_version_info.h" |
+#include "base/string_util.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chrome_thread.h" |
+#include "chrome/common/child_process_host.h" |
+#include "chrome/common/url_constants.h" |
+#include "grit/chromium_strings.h" |
+ |
+// Known browsers which we collect details for. |
+enum _BrowserProcess { |
+ CHROME_BROWSER = 0, |
+ FIREFOX_BROWSER, |
+ OPERA_BROWSER, |
+ KONQUEROR_BROWSER, |
+ MAX_BROWSERS |
+} BrowserProcess; |
+ |
+// Template of static data we use for finding browser process information. |
+// These entries must match the ordering for MemoryDetails::BrowserProcess. |
+static ProcessData g_process_template[MAX_BROWSERS]; |
+ |
+MemoryDetails::MemoryDetails() |
+ : ui_loop_(NULL) { |
+ static const std::wstring google_browser_name = |
+ l10n_util::GetString(IDS_PRODUCT_NAME); |
Evan Martin
2009/08/03 05:16:11
We avoid statics as a rule; is there a reason for
|
+ ProcessData g_process_template[MAX_BROWSERS] = { |
Evan Martin
2009/08/03 05:16:11
Does this shadow the other definition? I am confu
|
+ { google_browser_name.c_str(), L"chrome", }, |
+ { L"Firefox", L"firefox-bin", }, |
Joel Stanley (old)
2009/08/03 16:02:37
Some other browsers present on my Ubuntu Karmic sy
|
+ { L"Opera", L"opera", }, |
+ { L"Konqueror", L"konqueror", }, |
+ }; |
+ |
+ for (unsigned int index = 0; index < arraysize(g_process_template); ++index) { |
Evan Martin
2009/08/03 05:16:11
size_t
|
+ ProcessData process; |
+ process.name = g_process_template[index].name; |
+ process.process_name = g_process_template[index].process_name; |
+ process_data_.push_back(process); |
+ } |
+} |
+ |
+ProcessData* MemoryDetails::ChromeBrowser() { |
+ return &process_data_[CHROME_BROWSER]; |
+} |
+ |
+void MemoryDetails::CollectProcessData( |
+ std::vector<ProcessMemoryInformation> child_info) { |
+ DCHECK(MessageLoop::current() == |
+ ChromeThread::GetMessageLoop(ChromeThread::FILE)); |
+ |
+ for (unsigned int index = 0; index < arraysize(g_process_template); index++) { |
Evan Martin
2009/08/03 05:16:11
size_t
|
+ process_data_[index].processes.clear(); |
+ |
+ base::NamedProcessIterator process_iter(process_data_[index].process_name, |
+ NULL); |
+ |
+ const ProcessEntry* entry; |
+ while ((entry = process_iter.NextProcessEntry())) { |
+ ProcessMemoryInformation info; |
+ info.pid = entry->pid; |
+ |
+ if (info.pid == base::GetCurrentProcId()) |
+ info.type = ChildProcessInfo::BROWSER_PROCESS; |
+ else |
+ info.type = ChildProcessInfo::UNKNOWN_PROCESS; |
+ |
+ base::ProcessHandle handle; |
+ if (!base::OpenProcessHandle(entry->pid, &handle)) |
+ continue; |
+ scoped_ptr<base::ProcessMetrics> metrics; |
+ metrics.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); |
+ metrics->GetCommittedKBytes(&info.committed); |
+ metrics->GetWorkingSetKBytes(&info.working_set); |
+ |
+ // Get Version Information. |
+ if (index == CHROME_BROWSER) { |
+ scoped_ptr<FileVersionInfo> version_info( |
+ FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
+ if (version_info != NULL) |
+ info.version = version_info->file_version(); |
+ // Check if this is one of the child processes whose data we collected |
+ // on the IO thread, and if so copy over that data. |
+ for (size_t child = 0; child < child_info.size(); child++) { |
+ if (child_info[child].pid != info.pid) |
+ continue; |
+ info.titles = child_info[child].titles; |
+ info.type = child_info[child].type; |
+ break; |
+ } |
+ } |
+ |
+ // Add the process info to our list. |
+ process_data_[index].processes.push_back(info); |
+ } |
+ } |
+ |
+ // Finally return to the browser thread. |
+ ui_loop_->PostTask(FROM_HERE, |
+ NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnUIThread)); |
+} |