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

Side by Side Diff: ash/system/monitor/tray_monitor.cc

Issue 11415014: Stop using shell::GetInstance()->system_tray() in system tray items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified CL to provide TrayItems and Tray*Views with parent pointers instead. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/system_tray.h"
7 #include "ash/system/tray/tray_item_view.h" 8 #include "ash/system/tray/tray_item_view.h"
8 #include "ash/system/tray/tray_views.h" 9 #include "ash/system/tray/tray_views.h"
9 #include "base/process_util.h" 10 #include "base/process_util.h"
10 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "ui/base/text/bytes_formatting.h" 13 #include "ui/base/text/bytes_formatting.h"
13 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
14 #include "ui/views/border.h" 15 #include "ui/views/border.h"
15 16
16 namespace { 17 namespace {
17 const int kRefreshTimeoutMs = 1000; 18 const int kRefreshTimeoutMs = 1000;
18 } 19 }
19 20
20 namespace ash { 21 namespace ash {
21 namespace internal { 22 namespace internal {
22 23
23 TrayMonitor::TrayMonitor() : label_(NULL) { 24 TrayMonitor::TrayMonitor(SystemTray* system_tray)
25 : SystemTrayItem(system_tray),
26 label_(NULL) {
24 refresh_timer_.Start(FROM_HERE, 27 refresh_timer_.Start(FROM_HERE,
25 base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs), 28 base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs),
26 this, &TrayMonitor::RefreshStats); 29 this, &TrayMonitor::RefreshStats);
27 } 30 }
28 31
29 TrayMonitor::~TrayMonitor() { 32 TrayMonitor::~TrayMonitor() {
30 label_ = NULL; 33 label_ = NULL;
31 } 34 }
32 35
33 views::View* TrayMonitor::CreateTrayView(user::LoginStatus status) { 36 views::View* TrayMonitor::CreateTrayView(user::LoginStatus status) {
34 TrayItemView* view = new TrayItemView; 37 TrayItemView* view = new TrayItemView(this);
35 view->CreateLabel(); 38 view->CreateLabel();
36 label_ = view->label(); 39 label_ = view->label();
37 SetupLabelForTray(label_); 40 SetupLabelForTray(label_);
38 return view; 41 return view;
39 } 42 }
40 43
41 void TrayMonitor::DestroyTrayView() { 44 void TrayMonitor::DestroyTrayView() {
42 label_ = NULL; 45 label_ = NULL;
43 } 46 }
44 47
45 void TrayMonitor::RefreshStats() { 48 void TrayMonitor::RefreshStats() {
46 base::SystemMemoryInfoKB mem_info; 49 base::SystemMemoryInfoKB mem_info;
47 base::GetSystemMemoryInfo(&mem_info); 50 base::GetSystemMemoryInfo(&mem_info);
48 std::string output; 51 std::string output;
49 string16 free_bytes = 52 string16 free_bytes =
50 ui::FormatBytes(static_cast<int64>(mem_info.free) * 1024); 53 ui::FormatBytes(static_cast<int64>(mem_info.free) * 1024);
51 output = StringPrintf("%s free", UTF16ToUTF8(free_bytes).c_str()); 54 output = StringPrintf("%s free", UTF16ToUTF8(free_bytes).c_str());
52 if (mem_info.gem_objects != -1 && mem_info.gem_size != -1) { 55 if (mem_info.gem_objects != -1 && mem_info.gem_size != -1) {
53 string16 gem_size = ui::FormatBytes(mem_info.gem_size); 56 string16 gem_size = ui::FormatBytes(mem_info.gem_size);
54 output += StringPrintf(", %d gobjects alloced (%s)", 57 output += StringPrintf(", %d gobjects alloced (%s)",
55 mem_info.gem_objects, 58 mem_info.gem_objects,
56 UTF16ToUTF8(gem_size).c_str()); 59 UTF16ToUTF8(gem_size).c_str());
57 } 60 }
58 label_->SetText(UTF8ToUTF16(output)); 61 label_->SetText(UTF8ToUTF16(output));
59 } 62 }
60 63
61 } // namespace internal 64 } // namespace internal
62 } // namespace ash 65 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698