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