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

Unified Diff: ash/system/monitor/tray_monitor.cc

Issue 11345017: Create ash memory monitor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make tray linux specific Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/monitor/tray_monitor.h ('k') | ash/system/tray/system_tray.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/monitor/tray_monitor.cc
diff --git a/ash/system/monitor/tray_monitor.cc b/ash/system/monitor/tray_monitor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4e4336d61591dcc825ad61080d6bd3ce44aa7fac
--- /dev/null
+++ b/ash/system/monitor/tray_monitor.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2012 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 "ash/system/monitor/tray_monitor.h"
+
+#include "ash/system/tray/tray_item_view.h"
+#include "ash/system/tray/tray_views.h"
+#include "base/process_util.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "ui/base/text/bytes_formatting.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/border.h"
+
+namespace {
+const int kRefreshTimeoutMs = 1000;
+}
+
+namespace ash {
+namespace internal {
+
+TrayMonitor::TrayMonitor() : label_(NULL) {
+ refresh_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs),
+ this, &TrayMonitor::RefreshStats);
+}
+
+TrayMonitor::~TrayMonitor() {
+ label_ = NULL;
+}
+
+views::View* TrayMonitor::CreateTrayView(user::LoginStatus status) {
+ TrayItemView* view = new TrayItemView;
+ view->CreateLabel();
+ label_ = view->label();
+ SetupLabelForTray(label_);
+ return view;
+}
+
+void TrayMonitor::DestroyTrayView() {
+ label_ = NULL;
+}
+
+void TrayMonitor::RefreshStats() {
+ base::SystemMemoryInfoKB mem_info;
+ base::GetSystemMemoryInfo(&mem_info);
+ std::string output;
+ string16 free_bytes =
+ ui::FormatBytes(static_cast<int64>(mem_info.free) * 1024);
+ output = StringPrintf("%s free", UTF16ToUTF8(free_bytes).c_str());
+ if (mem_info.gem_objects != -1 && mem_info.gem_size != -1) {
+ string16 gem_size = ui::FormatBytes(mem_info.gem_size);
+ output += StringPrintf(", %d gobjects alloced (%s)",
+ mem_info.gem_objects,
+ UTF16ToUTF8(gem_size).c_str());
+ }
+ label_->SetText(UTF8ToUTF16(output));
+}
+
+} // namespace internal
+} // namespace ash
« no previous file with comments | « ash/system/monitor/tray_monitor.h ('k') | ash/system/tray/system_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698