OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/system/monitor/tray_monitor.h" |
| 6 |
| 7 #include "ash/system/tray/tray_item_view.h" |
| 8 #include "ash/system/tray/tray_views.h" |
| 9 #include "base/process_util.h" |
| 10 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "ui/base/text/bytes_formatting.h" |
| 13 #include "ui/views/controls/label.h" |
| 14 #include "ui/views/border.h" |
| 15 |
| 16 namespace { |
| 17 const int kRefreshTimeoutMs = 1000; |
| 18 } |
| 19 |
| 20 namespace ash { |
| 21 namespace internal { |
| 22 |
| 23 TrayMonitor::TrayMonitor() : label_(NULL) { |
| 24 refresh_timer_.Start(FROM_HERE, |
| 25 base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs), |
| 26 this, &TrayMonitor::RefreshStats); |
| 27 } |
| 28 |
| 29 TrayMonitor::~TrayMonitor() { |
| 30 label_ = NULL; |
| 31 } |
| 32 |
| 33 views::View* TrayMonitor::CreateTrayView(user::LoginStatus status) { |
| 34 TrayItemView* view = new TrayItemView; |
| 35 view->CreateLabel(); |
| 36 label_ = view->label(); |
| 37 SetupLabelForTray(label_); |
| 38 return view; |
| 39 } |
| 40 |
| 41 void TrayMonitor::DestroyTrayView() { |
| 42 label_ = NULL; |
| 43 } |
| 44 |
| 45 void TrayMonitor::RefreshStats() { |
| 46 base::SystemMemoryInfoKB mem_info; |
| 47 base::GetSystemMemoryInfo(&mem_info); |
| 48 std::string output; |
| 49 string16 free_bytes = |
| 50 ui::FormatBytes(static_cast<int64>(mem_info.free) * 1024); |
| 51 output = StringPrintf("%s free", UTF16ToUTF8(free_bytes).c_str()); |
| 52 if (mem_info.gem_objects != -1 && mem_info.gem_size != -1) { |
| 53 string16 gem_size = ui::FormatBytes(mem_info.gem_size); |
| 54 output += StringPrintf(", %d gobjects alloced (%s)", |
| 55 mem_info.gem_objects, |
| 56 UTF16ToUTF8(gem_size).c_str()); |
| 57 } |
| 58 label_->SetText(UTF8ToUTF16(output)); |
| 59 } |
| 60 |
| 61 } // namespace internal |
| 62 } // namespace ash |
OLD | NEW |