summaryrefslogtreecommitdiffstats
path: root/chromium/ash/system/monitor/tray_monitor.cc
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2014-03-18 13:16:26 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-03-20 15:55:39 +0100
commit3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch)
tree92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/ash/system/monitor/tray_monitor.cc
parente90d7c4b152c56919d963987e2503f9909a666d2 (diff)
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies needed on Windows. Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42 Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu> Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/ash/system/monitor/tray_monitor.cc')
-rw-r--r--chromium/ash/system/monitor/tray_monitor.cc100
1 files changed, 100 insertions, 0 deletions
diff --git a/chromium/ash/system/monitor/tray_monitor.cc b/chromium/ash/system/monitor/tray_monitor.cc
new file mode 100644
index 00000000000..bc3d532ea55
--- /dev/null
+++ b/chromium/ash/system/monitor/tray_monitor.cc
@@ -0,0 +1,100 @@
+// 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 "base/process/memory.h"
+#include "base/process/process_metrics.h"
+#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/public/browser/gpu_data_manager.h"
+#include "ui/base/text/bytes_formatting.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/label.h"
+
+namespace {
+const int kRefreshTimeoutMs = 1000;
+}
+
+namespace ash {
+namespace internal {
+
+TrayMonitor::TrayMonitor(SystemTray* system_tray)
+ : SystemTrayItem(system_tray),
+ label_(NULL) {
+ refresh_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs),
+ this, &TrayMonitor::OnTimer);
+}
+
+TrayMonitor::~TrayMonitor() {
+ label_ = NULL;
+}
+
+views::View* TrayMonitor::CreateTrayView(user::LoginStatus status) {
+ TrayItemView* view = new TrayItemView(this);
+ view->CreateLabel();
+ label_ = view->label();
+ label_->SetAutoColorReadabilityEnabled(false);
+ label_->SetEnabledColor(SK_ColorWHITE);
+ label_->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
+ label_->SetShadowColors(SkColorSetARGB(64, 0, 0, 0),
+ SkColorSetARGB(64, 0, 0, 0));
+ label_->SetShadowOffset(0, 1);
+ label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ label_->SetFont(label_->font().DeriveFont(-2));
+ return view;
+}
+
+void TrayMonitor::DestroyTrayView() {
+ label_ = NULL;
+}
+
+void TrayMonitor::OnTimer() {
+ content::GpuDataManager::GetGpuProcessHandlesCallback callback =
+ base::Bind(&TrayMonitor::OnGotHandles, base::Unretained(this));
+ refresh_timer_.Stop();
+ content::GpuDataManager::GetInstance()->GetGpuProcessHandles(callback);
+}
+
+void TrayMonitor::OnGotHandles(const std::list<base::ProcessHandle>& handles) {
+ base::SystemMemoryInfoKB mem_info;
+ base::GetSystemMemoryInfo(&mem_info);
+ std::string output;
+ base::string16 free_bytes =
+ ui::FormatBytes(static_cast<int64>(mem_info.free) * 1024);
+ output = base::StringPrintf("free: %s", UTF16ToUTF8(free_bytes).c_str());
+#if defined(OS_CHROMEOS)
+ if (mem_info.gem_size != -1) {
+ base::string16 gem_size = ui::FormatBytes(mem_info.gem_size);
+ output += base::StringPrintf(" gmem: %s", UTF16ToUTF8(gem_size).c_str());
+ if (mem_info.gem_objects != -1)
+ output += base::StringPrintf(" gobjects: %d", mem_info.gem_objects);
+ }
+#endif
+ size_t total_private_bytes = 0, total_shared_bytes = 0;
+ for (std::list<base::ProcessHandle>::const_iterator i = handles.begin();
+ i != handles.end(); ++i) {
+ base::ProcessMetrics* pm = base::ProcessMetrics::CreateProcessMetrics(*i);
+ size_t private_bytes, shared_bytes;
+ pm->GetMemoryBytes(&private_bytes, &shared_bytes);
+ total_private_bytes += private_bytes;
+ total_shared_bytes += shared_bytes;
+ delete pm;
+ }
+ base::string16 private_size = ui::FormatBytes(total_private_bytes);
+ base::string16 shared_size = ui::FormatBytes(total_shared_bytes);
+
+ output += base::StringPrintf("\nGPU private: %s shared: %s",
+ UTF16ToUTF8(private_size).c_str(),
+ UTF16ToUTF8(shared_size).c_str());
+ label_->SetText(UTF8ToUTF16(output));
+ refresh_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs),
+ this, &TrayMonitor::OnTimer);
+}
+
+} // namespace internal
+} // namespace ash