summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/status/memory_menu_button.cc130
-rw-r--r--chrome/browser/chromeos/status/memory_menu_button.h69
-rw-r--r--chrome/browser/chromeos/status/status_area_view.cc11
-rw-r--r--chrome/browser/chromeos/status/status_area_view.h2
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
7 files changed, 218 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/status/memory_menu_button.cc b/chrome/browser/chromeos/status/memory_menu_button.cc
new file mode 100644
index 0000000..4bdf9a1
--- /dev/null
+++ b/chrome/browser/chromeos/status/memory_menu_button.cc
@@ -0,0 +1,130 @@
+// Copyright (c) 2011 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/chromeos/status/memory_menu_button.h"
+
+#include "base/process_util.h" // GetSystemMemoryInfo
+#include "base/stringprintf.h"
+#include "chrome/browser/chromeos/status/status_area_host.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "views/widget/widget.h"
+
+namespace {
+
+// views::MenuItemView item ids
+enum {
+ MEM_TOTAL_ITEM,
+ MEM_FREE_ITEM,
+ MEM_BUFFERS_ITEM,
+ MEM_CACHE_ITEM,
+ SHMEM_ITEM,
+};
+
+} // namespace
+
+namespace chromeos {
+
+// Delay between updates, in seconds.
+const int kUpdateIntervalSeconds = 5;
+
+MemoryMenuButton::MemoryMenuButton(StatusAreaHost* host)
+ : StatusAreaButton(host, this),
+ mem_total_(0),
+ shmem_(0),
+ mem_free_(0),
+ mem_buffers_(0),
+ mem_cache_(0) {
+ UpdateTextAndSetNextTimer();
+}
+
+MemoryMenuButton::~MemoryMenuButton() {
+}
+
+void MemoryMenuButton::UpdateTextAndSetNextTimer() {
+ UpdateText();
+
+ timer_.Start(base::TimeDelta::FromSeconds(kUpdateIntervalSeconds), this,
+ &MemoryMenuButton::UpdateTextAndSetNextTimer);
+}
+
+void MemoryMenuButton::UpdateText() {
+ base::GetSystemMemoryInfo(&mem_total_, &mem_free_, &mem_buffers_, &mem_cache_,
+ &shmem_);
+ std::wstring label = base::StringPrintf(L"%d MB", mem_free_ / 1024);
+ SetText(label);
+ std::wstring tooltip = base::StringPrintf(
+ L"%d MB total\n%d MB free\n%d MB buffers\n%d MB cache\n%d MB shmem",
+ mem_total_ / 1024,
+ mem_free_ / 1024,
+ mem_buffers_ / 1024,
+ mem_cache_ / 1024,
+ shmem_ / 1024);
+ SetTooltipText(tooltip);
+ SchedulePaint();
+}
+
+// MemoryMenuButton, views::MenuDelegate implementation:
+std::wstring MemoryMenuButton::GetLabel(int id) const {
+ switch (id) {
+ case MEM_TOTAL_ITEM:
+ return StringPrintf(L"%d MB total", mem_total_ / 1024);
+ case MEM_FREE_ITEM:
+ return StringPrintf(L"%d MB free", mem_free_ / 1024);
+ case MEM_BUFFERS_ITEM:
+ return StringPrintf(L"%d MB buffers", mem_buffers_ / 1024);
+ case MEM_CACHE_ITEM:
+ return StringPrintf(L"%d MB cache", mem_cache_ / 1024);
+ case SHMEM_ITEM:
+ return StringPrintf(L"%d MB shmem", shmem_ / 1024);
+ default:
+ return std::wstring();
+ }
+}
+
+bool MemoryMenuButton::IsCommandEnabled(int id) const {
+ return false;
+}
+
+void MemoryMenuButton::ExecuteCommand(int id) {
+}
+
+int MemoryMenuButton::horizontal_padding() {
+ return 3;
+}
+
+// MemoryMenuButton, views::ViewMenuDelegate implementation:
+
+void MemoryMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
+ // View passed in must be a views::MenuButton, i.e. the MemoryMenuButton.
+ DCHECK_EQ(source, this);
+
+ EnsureMenu();
+
+ gfx::Point screen_location;
+ views::View::ConvertPointToScreen(source, &screen_location);
+ gfx::Rect bounds(screen_location, source->size());
+ menu_->RunMenuAt(
+ source->GetWidget()->GetTopLevelWidget(),
+ this,
+ bounds,
+ views::MenuItemView::TOPRIGHT,
+ true);
+}
+
+// MemoryMenuButton, views::View implementation:
+
+void MemoryMenuButton::EnsureMenu() {
+ // Just rebuild the menu each time to ensure the labels are up-to-date.
+ menu_.reset(new views::MenuItemView(this));
+ // Text for these items will be set by GetLabel().
+ menu_->AppendDelegateMenuItem(MEM_TOTAL_ITEM);
+ menu_->AppendDelegateMenuItem(MEM_FREE_ITEM);
+ menu_->AppendDelegateMenuItem(MEM_BUFFERS_ITEM);
+ menu_->AppendDelegateMenuItem(MEM_CACHE_ITEM);
+ menu_->AppendDelegateMenuItem(SHMEM_ITEM);
+ // TODO(jamescook): Add items to run memory_purger, dump heap profiles.
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/status/memory_menu_button.h b/chrome/browser/chromeos/status/memory_menu_button.h
new file mode 100644
index 0000000..c399df7
--- /dev/null
+++ b/chrome/browser/chromeos/status/memory_menu_button.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_STATUS_MEMORY_MENU_BUTTON_H_
+#define CHROME_BROWSER_CHROMEOS_STATUS_MEMORY_MENU_BUTTON_H_
+#pragma once
+
+#include "base/memory/scoped_ptr.h"
+#include "base/timer.h"
+#include "chrome/browser/chromeos/status/status_area_button.h"
+#include "views/controls/menu/menu_delegate.h"
+#include "views/controls/menu/view_menu_delegate.h"
+
+namespace views {
+class MenuItemView;
+}
+
+namespace chromeos {
+
+class StatusAreaHost;
+
+// Memory debugging display that lives in the status area.
+class MemoryMenuButton : public StatusAreaButton,
+ public views::MenuDelegate,
+ public views::ViewMenuDelegate {
+ public:
+ explicit MemoryMenuButton(StatusAreaHost* host);
+ virtual ~MemoryMenuButton();
+
+ // views::MenuDelegate implementation
+ virtual std::wstring GetLabel(int id) const OVERRIDE;
+ virtual bool IsCommandEnabled(int id) const OVERRIDE;
+ virtual void ExecuteCommand(int id) OVERRIDE;
+
+ // Updates the text on the menu button.
+ void UpdateText();
+
+ protected:
+ virtual int horizontal_padding();
+
+ private:
+ // views::ViewMenuDelegate implementation.
+ virtual void RunMenu(views::View* source, const gfx::Point& pt);
+
+ // Create and initialize menu if not already present.
+ void EnsureMenu();
+
+ // Updates text and schedules the timer to fire at the next minute interval.
+ void UpdateTextAndSetNextTimer();
+
+ base::OneShotTimer<MemoryMenuButton> timer_;
+
+ // NOTE: we use a scoped_ptr here as menu calls into 'this' from the
+ // constructor.
+ scoped_ptr<views::MenuItemView> menu_;
+
+ int mem_total_;
+ int shmem_; // video driver memory, hidden from OS
+ int mem_free_;
+ int mem_buffers_;
+ int mem_cache_;
+
+ DISALLOW_COPY_AND_ASSIGN(MemoryMenuButton);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_STATUS_MEMORY_MENU_BUTTON_H_
diff --git a/chrome/browser/chromeos/status/status_area_view.cc b/chrome/browser/chromeos/status/status_area_view.cc
index 161edfb..b87ca3c 100644
--- a/chrome/browser/chromeos/status/status_area_view.cc
+++ b/chrome/browser/chromeos/status/status_area_view.cc
@@ -6,12 +6,15 @@
#include <algorithm>
+#include "base/command_line.h"
#include "chrome/browser/chromeos/status/caps_lock_menu_button.h"
#include "chrome/browser/chromeos/status/clock_menu_button.h"
#include "chrome/browser/chromeos/status/input_method_menu_button.h"
+#include "chrome/browser/chromeos/status/memory_menu_button.h"
#include "chrome/browser/chromeos/status/network_menu_button.h"
#include "chrome/browser/chromeos/status/power_menu_button.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
+#include "chrome/common/chrome_switches.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
@@ -32,11 +35,17 @@ StatusAreaView::StatusAreaView(StatusAreaHost* host)
caps_lock_view_(NULL),
clock_view_(NULL),
input_method_view_(NULL),
+ memory_view_(NULL),
network_view_(NULL),
power_view_(NULL) {
}
void StatusAreaView::Init() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryWidget)) {
+ memory_view_ = new MemoryMenuButton(host_);
+ AddChildView(memory_view_);
+ }
+
caps_lock_view_ = new CapsLockMenuButton(host_);
caps_lock_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0));
AddChildView(caps_lock_view_);
@@ -102,6 +111,8 @@ void StatusAreaView::ChildPreferredSizeChanged(View* child) {
}
void StatusAreaView::MakeButtonsActive(bool active) {
+ if (memory_view_)
+ memory_view_->set_active(active);
clock_view()->set_active(active);
input_method_view()->set_active(active);
network_view()->set_active(active);
diff --git a/chrome/browser/chromeos/status/status_area_view.h b/chrome/browser/chromeos/status/status_area_view.h
index dc8c801..ec43087 100644
--- a/chrome/browser/chromeos/status/status_area_view.h
+++ b/chrome/browser/chromeos/status/status_area_view.h
@@ -15,6 +15,7 @@ namespace chromeos {
class CapsLockMenuButton;
class ClockMenuButton;
class InputMethodMenuButton;
+class MemoryMenuButton;
class NetworkMenuButton;
class PowerMenuButton;
class StatusAreaHost;
@@ -47,6 +48,7 @@ class StatusAreaView : public AccessiblePaneView {
CapsLockMenuButton* caps_lock_view_;
ClockMenuButton* clock_view_;
InputMethodMenuButton* input_method_view_;
+ MemoryMenuButton* memory_view_;
NetworkMenuButton* network_view_;
PowerMenuButton* power_view_;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 5e8e08e..e711143 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -710,6 +710,8 @@
'browser/chromeos/status/input_method_menu.h',
'browser/chromeos/status/input_method_menu_button.cc',
'browser/chromeos/status/input_method_menu_button.h',
+ 'browser/chromeos/status/memory_menu_button.cc',
+ 'browser/chromeos/status/memory_menu_button.h',
'browser/chromeos/status/network_dropdown_button.cc',
'browser/chromeos/status/network_dropdown_button.h',
'browser/chromeos/status/network_menu.cc',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 6f61f46..4629dbc 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -1057,6 +1057,9 @@ const char kLoginScreen[] = "login-screen";
// Allows control over the initial login screen size. Pass width,height.
const char kLoginScreenSize[] = "login-screen-size";
+// Shows a memory consumption status area widget for OOM debugging.
+const char kMemoryWidget[] = "memory-widget";
+
// Attempts to load libcros and validate it, then exits. A nonzero return code
// means the library could not be loaded correctly.
const char kTestLoadLibcros[] = "test-load-libcros";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index b363b9e..f9d4f4f 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -291,6 +291,7 @@ extern const char kLoginManager[];
// purposes.
extern const char kLoginScreen[];
extern const char kLoginScreenSize[];
+extern const char kMemoryWidget[];
extern const char kTestLoadLibcros[];
extern const char kLoginProfile[];
extern const char kLoginUser[];