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

Side by Side Diff: chrome/browser/chromeos/status/network_menu_button.cc

Issue 4235005: Push for ers:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « chrome/browser/chromeos/status/network_menu_button.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/status/network_menu_button.h" 5 #include "chrome/browser/chromeos/status/network_menu_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 17 matching lines...) Expand all
28 // static 28 // static
29 const int NetworkMenuButton::kThrobDuration = 1000; 29 const int NetworkMenuButton::kThrobDuration = 1000;
30 30
31 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) 31 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
32 : StatusAreaButton(this), 32 : StatusAreaButton(this),
33 NetworkMenu(), 33 NetworkMenu(),
34 host_(host), 34 host_(host),
35 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { 35 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) {
36 animation_connecting_.SetThrobDuration(kThrobDuration); 36 animation_connecting_.SetThrobDuration(kThrobDuration);
37 animation_connecting_.SetTweenType(Tween::EASE_IN_OUT); 37 animation_connecting_.SetTweenType(Tween::EASE_IN_OUT);
38 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); 38 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary());
39 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); 39 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this);
40 CrosLibrary::Get()->GetNetworkLibrary()->AddCellularDataPlanObserver(this);
40 } 41 }
41 42
42 NetworkMenuButton::~NetworkMenuButton() { 43 NetworkMenuButton::~NetworkMenuButton() {
43 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); 44 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
45 netlib->RemoveNetworkManagerObserver(this);
46 netlib->RemoveObserverForAllNetworks(this);
47 netlib->RemoveCellularDataPlanObserver(this);
44 } 48 }
45 49
46 //////////////////////////////////////////////////////////////////////////////// 50 ////////////////////////////////////////////////////////////////////////////////
47 // NetworkMenuButton, AnimationDelegate implementation: 51 // NetworkMenuButton, AnimationDelegate implementation:
48 52
49 void NetworkMenuButton::AnimationProgressed(const Animation* animation) { 53 void NetworkMenuButton::AnimationProgressed(const Animation* animation) {
50 if (animation == &animation_connecting_) { 54 if (animation == &animation_connecting_) {
51 // Draw animation of bars icon fading in and out. 55 // Draw animation of bars icon fading in and out.
52 // We are fading between 0 bars and a third of the opacity of 4 bars. 56 // We are fading between 0 bars and a third of the opacity of 4 bars.
53 // Use the current value of the animation to calculate the alpha value 57 // Use the current value of the animation to calculate the alpha value
(...skipping 12 matching lines...) Expand all
66 70
67 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
68 // NetworkMenuButton, StatusAreaButton implementation: 72 // NetworkMenuButton, StatusAreaButton implementation:
69 73
70 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { 74 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
71 canvas->DrawBitmapInt(IconForDisplay(icon(), badge()), 75 canvas->DrawBitmapInt(IconForDisplay(icon(), badge()),
72 horizontal_padding(), 0); 76 horizontal_padding(), 0);
73 } 77 }
74 78
75 //////////////////////////////////////////////////////////////////////////////// 79 ////////////////////////////////////////////////////////////////////////////////
76 // NetworkMenuButton, NetworkLibrary::Observer implementation: 80 // NetworkMenuButton, NetworkLibrary::NetworkManagerObserver implementation:
77 81
78 void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { 82 void NetworkMenuButton::OnNetworkManagerChanged(NetworkLibrary* cros) {
79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 83 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
80 if (CrosLibrary::Get()->EnsureLoaded()) { 84 if (CrosLibrary::Get()->EnsureLoaded()) {
85 // Add an observer for the active network, if any
86 const Network* network = cros->active_network();
87 if (active_network_.empty() || network == NULL ||
88 active_network_ != network->service_path()) {
89 if (!active_network_.empty()) {
90 cros->RemoveNetworkObserver(active_network_, this);
91 }
92 if (network != NULL) {
93 cros->AddNetworkObserver(network->service_path(), this);
94 }
95 }
96 if (network)
97 active_network_ = network->service_path();
98 else
99 active_network_ = "";
100
81 if (cros->wifi_connecting() || cros->cellular_connecting()) { 101 if (cros->wifi_connecting() || cros->cellular_connecting()) {
82 // Start the connecting animation if not running. 102 // Start the connecting animation if not running.
83 if (!animation_connecting_.is_animating()) { 103 if (!animation_connecting_.is_animating()) {
84 animation_connecting_.Reset(); 104 animation_connecting_.Reset();
85 animation_connecting_.StartThrobbing(std::numeric_limits<int>::max()); 105 animation_connecting_.StartThrobbing(std::numeric_limits<int>::max());
86 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); 106 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
87 } 107 }
88 std::string network_name = cros->wifi_connecting() ? 108 std::string network_name = cros->wifi_connecting() ?
89 cros->wifi_network()->name() : cros->cellular_network()->name(); 109 cros->wifi_network()->name() : cros->cellular_network()->name();
90 bool configuring = cros->wifi_connecting() ? 110 bool configuring = cros->wifi_connecting() ?
91 cros->wifi_network()->configuring() : 111 cros->wifi_network()->configuring() :
92 cros->cellular_network()->configuring(); 112 cros->cellular_network()->configuring();
93 SetTooltipText( 113 SetTooltipText(
94 l10n_util::GetStringF(configuring ? 114 l10n_util::GetStringF(configuring ?
95 IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP : 115 IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP :
96 IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, 116 IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP,
97 UTF8ToWide(network_name))); 117 UTF8ToWide(network_name)));
98 } else { 118 } else {
99 // Stop connecting animation since we are not connecting. 119 // Stop connecting animation since we are not connecting.
100 animation_connecting_.Stop(); 120 animation_connecting_.Stop();
101 121 if (!cros->Connected()) {
102 // Always show the higher priority connection first. Ethernet then wifi.
103 if (cros->ethernet_connected()) {
104 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED));
105 SetTooltipText(
106 l10n_util::GetStringF(
107 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
108 l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)));
109 } else if (cros->wifi_connected()) {
110 SetIcon(IconForNetworkStrength(
111 cros->wifi_network()->strength(), false));
112 SetTooltipText(l10n_util::GetStringF(
113 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
114 UTF8ToWide(cros->wifi_network()->name())));
115 } else if (cros->cellular_connected()) {
116 const CellularNetwork* cellular = cros->cellular_network();
117 if (cellular->data_left() == CellularNetwork::DATA_NONE) {
118 // If no data, then we show 0 bars.
119 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
120 } else {
121 SetIcon(IconForNetworkStrength(cellular));
122 }
123 SetTooltipText(l10n_util::GetStringF(
124 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
125 UTF8ToWide(cellular->name())));
126 } else {
127 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); 122 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
128 SetTooltipText(l10n_util::GetString( 123 SetTooltipText(l10n_util::GetString(
129 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); 124 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP));
125 } else {
126 SetNetworkIcon(network);
130 } 127 }
131 } 128 }
132 129 SetNetworkBadge(cros, network);
133 // Figure out whether or not to show a badge.
134 int id = -1;
135 if (cros->Connecting()) {
136 if (cros->cellular_connecting()) {
137 id = IDR_STATUSBAR_NETWORK_3G;
138 }
139 } else if (cros->Connected()) {
140 if (!cros->ethernet_connected() && !cros->wifi_connected() &&
141 cros->cellular_connected()) {
142 switch (cros->cellular_network()->data_left()) {
143 case CellularNetwork::DATA_NONE:
144 case CellularNetwork::DATA_VERY_LOW:
145 id = IDR_STATUSBAR_NETWORK_3G_ERROR;
146 break;
147 case CellularNetwork::DATA_LOW:
148 id = IDR_STATUSBAR_NETWORK_3G_WARN;
149 break;
150 case CellularNetwork::DATA_NORMAL:
151 id = IDR_STATUSBAR_NETWORK_3G;
152 break;
153 }
154 }
155 } else {
156 id = IDR_STATUSBAR_NETWORK_DISCONNECTED;
157 }
158 if (id != -1) {
159 SetBadge(*rb.GetBitmapNamed(id));
160 } else {
161 SetBadge(SkBitmap());
162 }
163 } else { 130 } else {
164 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); 131 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
165 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); 132 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING));
133 SetTooltipText(l10n_util::GetString(
134 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP));
135 }
136
137 SchedulePaint();
138 UpdateMenu();
139 }
140
141 ////////////////////////////////////////////////////////////////////////////////
142 // NetworkMenuButton, NetworkLibrary::NetworkObserver implementation:
143 void NetworkMenuButton::OnNetworkChanged(NetworkLibrary* cros,
144 const Network* network) {
145 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
146 if (CrosLibrary::Get()->EnsureLoaded()) {
147 // Always show the active network connection, if any.
148 SetNetworkIcon(network);
149 SetNetworkBadge(cros, network);
150 } else {
151 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
152 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING));
166 SetTooltipText(l10n_util::GetString( 153 SetTooltipText(l10n_util::GetString(
167 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); 154 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP));
168 } 155 }
169 156
170 SchedulePaint(); 157 SchedulePaint();
171 UpdateMenu(); 158 UpdateMenu();
172 } 159 }
173 160
174 void NetworkMenuButton::CellularDataPlanChanged(NetworkLibrary* cros) { 161 void NetworkMenuButton::OnCellularDataPlanChanged(NetworkLibrary* cros) {
175 // Call NetworkChanged which will update the icon. 162 // Call OnNetworkManagerChanged which will update the icon.
176 NetworkChanged(cros); 163 OnNetworkManagerChanged(cros);
177 } 164 }
178 165
179 //////////////////////////////////////////////////////////////////////////////// 166 ////////////////////////////////////////////////////////////////////////////////
180 // NetworkMenuButton, NetworkMenu implementation: 167 // NetworkMenuButton, NetworkMenu implementation:
181 168
182 bool NetworkMenuButton::IsBrowserMode() const { 169 bool NetworkMenuButton::IsBrowserMode() const {
183 return host_->IsBrowserMode(); 170 return host_->IsBrowserMode();
184 } 171 }
185 172
186 gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const { 173 gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const {
187 return host_->GetNativeWindow(); 174 return host_->GetNativeWindow();
188 } 175 }
189 176
190 void NetworkMenuButton::OpenButtonOptions() const { 177 void NetworkMenuButton::OpenButtonOptions() const {
191 host_->OpenButtonOptions(this); 178 host_->OpenButtonOptions(this);
192 } 179 }
193 180
194 bool NetworkMenuButton::ShouldOpenButtonOptions() const { 181 bool NetworkMenuButton::ShouldOpenButtonOptions() const {
195 return host_->ShouldOpenButtonOptions(this); 182 return host_->ShouldOpenButtonOptions(this);
196 } 183 }
197 184
185 ////////////////////////////////////////////////////////////////////////////////
186 // NetworkMenuButton, private methods
187
188 void NetworkMenuButton::SetNetworkIcon(const Network* network) {
189 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
190 if (network && network->is_active()) {
191 if (network->type() == TYPE_ETHERNET) {
192 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED));
193 SetTooltipText(
194 l10n_util::GetStringF(
195 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
196 l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)));
197 } else if (network->type() == TYPE_WIFI) {
198 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network);
199 SetIcon(IconForNetworkStrength(wifi->strength(), false));
200 SetTooltipText(l10n_util::GetStringF(
201 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
202 UTF8ToWide(wifi->name())));
203 } else if (network->type() == TYPE_CELLULAR) {
204 const CellularNetwork* cellular =
205 static_cast<const CellularNetwork*>(network);
206 if (cellular->data_left() == CellularNetwork::DATA_NONE) {
207 // If no data, then we show 0 bars.
208 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
209 } else {
210 SetIcon(IconForNetworkStrength(cellular));
211 }
212 SetTooltipText(l10n_util::GetStringF(
213 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
214 UTF8ToWide(cellular->name())));
215 }
216 }
217 }
218
219 void NetworkMenuButton::SetNetworkBadge(NetworkLibrary* cros,
220 const Network* network) {
221 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
222 // Figure out whether or not to show a badge.
223 if (network && network->type() == TYPE_CELLULAR &&
224 (network->is_active() || network->connecting())) {
225 const CellularNetwork* cellular
226 = static_cast<const CellularNetwork*>(network);
227 SetBadge(BadgeForNetworkTechnology(cellular));
228 } else if (!cros->Connected() && !cros->Connecting()) {
229 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED));
230 } else {
231 SetBadge(SkBitmap());
232 }
233 }
234
198 } // namespace chromeos 235 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_menu_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698