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

Side by Side Diff: ash/system/chromeos/network/tray_vpn.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix chromeos_unittests Created 7 years, 7 months 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/chromeos/network/tray_vpn.h" 5 #include "ash/system/chromeos/network/tray_vpn.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/chromeos/network/network_icon_animation.h" 8 #include "ash/system/chromeos/network/network_icon_animation.h"
9 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" 9 #include "ash/system/chromeos/network/network_state_list_detailed_view.h"
10 #include "ash/system/tray/system_tray.h" 10 #include "ash/system/tray/system_tray.h"
11 #include "ash/system/tray/system_tray_delegate.h" 11 #include "ash/system/tray/system_tray_delegate.h"
12 #include "ash/system/tray/system_tray_notifier.h" 12 #include "ash/system/tray/system_tray_notifier.h"
13 #include "ash/system/tray/tray_constants.h" 13 #include "ash/system/tray/tray_constants.h"
14 #include "ash/system/tray/tray_item_more.h" 14 #include "ash/system/tray/tray_item_more.h"
15 #include "ash/system/tray/tray_popup_label_button.h" 15 #include "ash/system/tray/tray_popup_label_button.h"
16 #include "chromeos/network/network_state.h" 16 #include "chromeos/network/network_state.h"
17 #include "chromeos/network/network_state_handler.h" 17 #include "chromeos/network/network_state_handler.h"
18 #include "grit/ash_strings.h" 18 #include "grit/ash_strings.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h" 19 #include "third_party/cros_system_api/dbus/service_constants.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 22
23 using chromeos::NetworkHandler;
23 using chromeos::NetworkState; 24 using chromeos::NetworkState;
24 using chromeos::NetworkStateHandler; 25 using chromeos::NetworkStateHandler;
25 26
26 namespace ash { 27 namespace ash {
27 namespace internal { 28 namespace internal {
28 29
29 namespace tray { 30 namespace tray {
30 31
31 class VpnDefaultView : public TrayItemMore, 32 class VpnDefaultView : public TrayItemMore,
32 public network_icon::AnimationObserver { 33 public network_icon::AnimationObserver {
33 public: 34 public:
34 VpnDefaultView(SystemTrayItem* owner, bool show_more) 35 VpnDefaultView(SystemTrayItem* owner, bool show_more)
35 : TrayItemMore(owner, show_more) { 36 : TrayItemMore(owner, show_more) {
36 Update(); 37 Update();
37 } 38 }
38 39
39 virtual ~VpnDefaultView() { 40 virtual ~VpnDefaultView() {
40 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 41 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
41 } 42 }
42 43
43 static bool ShouldShow() { 44 static bool ShouldShow() {
44 // Do not show VPN line in uber tray bubble if VPN is not configured. 45 // Do not show VPN line in uber tray bubble if VPN is not configured.
45 NetworkStateHandler* handler = NetworkStateHandler::Get(); 46 NetworkStateHandler* handler =
46 const NetworkState* vpn = handler->FirstNetworkByType( 47 NetworkHandler::Get()->network_state_handler();
47 flimflam::kTypeVPN); 48 const NetworkState* vpn = handler->FirstNetworkByType(flimflam::kTypeVPN);
48 return vpn != NULL; 49 return vpn != NULL;
49 } 50 }
50 51
51 void Update() { 52 void Update() {
52 gfx::ImageSkia image; 53 gfx::ImageSkia image;
53 base::string16 label; 54 base::string16 label;
54 bool animating = false; 55 bool animating = false;
55 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); 56 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating);
56 if (animating) 57 if (animating)
57 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 58 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
58 else 59 else
59 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 60 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
60 SetImage(&image); 61 SetImage(&image);
61 SetLabel(label); 62 SetLabel(label);
62 SetAccessibleName(label); 63 SetAccessibleName(label);
63 } 64 }
64 65
65 // network_icon::AnimationObserver 66 // network_icon::AnimationObserver
66 virtual void NetworkIconChanged() OVERRIDE { 67 virtual void NetworkIconChanged() OVERRIDE {
67 Update(); 68 Update();
68 } 69 }
69 70
70 private: 71 private:
71 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, 72 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image,
72 base::string16* label, 73 base::string16* label,
73 bool* animating) { 74 bool* animating) {
74 NetworkStateHandler* handler = NetworkStateHandler::Get(); 75 NetworkStateHandler* handler =
76 NetworkHandler::Get()->network_state_handler();
75 const NetworkState* vpn = handler->FirstNetworkByType( 77 const NetworkState* vpn = handler->FirstNetworkByType(
76 flimflam::kTypeVPN); 78 flimflam::kTypeVPN);
77 if (!vpn || (vpn->connection_state() == flimflam::kStateIdle)) { 79 if (!vpn || (vpn->connection_state() == flimflam::kStateIdle)) {
78 *image = network_icon::GetImageForDisconnectedNetwork( 80 *image = network_icon::GetImageForDisconnectedNetwork(
79 network_icon::ICON_TYPE_DEFAULT_VIEW, flimflam::kTypeVPN); 81 network_icon::ICON_TYPE_DEFAULT_VIEW, flimflam::kTypeVPN);
80 if (label) { 82 if (label) {
81 *label = l10n_util::GetStringUTF16( 83 *label = l10n_util::GetStringUTF16(
82 IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); 84 IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
83 } 85 }
84 *animating = false; 86 *animating = false;
(...skipping 22 matching lines...) Expand all
107 109
108 TrayVPN::~TrayVPN() { 110 TrayVPN::~TrayVPN() {
109 } 111 }
110 112
111 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { 113 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) {
112 return NULL; 114 return NULL;
113 } 115 }
114 116
115 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { 117 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) {
116 CHECK(default_ == NULL); 118 CHECK(default_ == NULL);
117 if (!chromeos::NetworkStateHandler::IsInitialized()) 119 if (!chromeos::NetworkHandler::IsInitialized())
118 return NULL; 120 return NULL;
119 if (status == user::LOGGED_IN_NONE) 121 if (status == user::LOGGED_IN_NONE)
120 return NULL; 122 return NULL;
121 if (!tray::VpnDefaultView::ShouldShow()) 123 if (!tray::VpnDefaultView::ShouldShow())
122 return NULL; 124 return NULL;
123 125
124 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); 126 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED);
125 return default_; 127 return default_;
126 } 128 }
127 129
128 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { 130 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) {
129 CHECK(detailed_ == NULL); 131 CHECK(detailed_ == NULL);
130 if (!chromeos::NetworkStateHandler::IsInitialized()) 132 if (!chromeos::NetworkHandler::IsInitialized())
131 return NULL; 133 return NULL;
132 134
133 detailed_ = new tray::NetworkStateListDetailedView( 135 detailed_ = new tray::NetworkStateListDetailedView(
134 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status); 136 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status);
135 detailed_->Init(); 137 detailed_->Init();
136 return detailed_; 138 return detailed_;
137 } 139 }
138 140
139 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) { 141 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) {
140 return NULL; 142 return NULL;
(...skipping 30 matching lines...) Expand all
171 } 173 }
172 } 174 }
173 175
174 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { 176 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) {
175 if (detailed_) 177 if (detailed_)
176 detailed_->NetworkServiceChanged(network); 178 detailed_->NetworkServiceChanged(network);
177 } 179 }
178 180
179 } // namespace internal 181 } // namespace internal
180 } // namespace ash 182 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_network_state_observer.cc ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698