OLD | NEW |
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/network_message_observer.h" | 5 #include "chrome/browser/chromeos/network_message_observer.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 notification_connection_error_.Show(l10n_util::GetStringFUTF16( | 136 notification_connection_error_.Show(l10n_util::GetStringFUTF16( |
137 IDS_NETWORK_CONNECTION_ERROR_MESSAGE, | 137 IDS_NETWORK_CONNECTION_ERROR_MESSAGE, |
138 ASCIIToUTF16(new_failed_network)), false, false); | 138 ASCIIToUTF16(new_failed_network)), false, false); |
139 } | 139 } |
140 | 140 |
141 // Show login box if necessary. | 141 // Show login box if necessary. |
142 if (view && initialized_) | 142 if (view && initialized_) |
143 CreateModalPopup(view); | 143 CreateModalPopup(view); |
144 } | 144 } |
145 | 145 |
146 void NetworkMessageObserver::CellularDataPlanChanged(NetworkLibrary* obj) { | 146 void NetworkMessageObserver::CellularDataPlanChanged( |
147 const CellularNetwork& cellular = obj->cellular_network(); | 147 const std::string& service_path, const CellularDataPlanList& plans) { |
148 // Active plan is the first one in the list. Use empty one if none found. | 148 // Active plan is the first one in the list. Use empty one if none found. |
149 const CellularDataPlanList& plans = cellular.GetDataPlans(); | |
150 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0]; | 149 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0]; |
151 // If connected cellular network changed, or data plan is different, then | 150 // If connected cellular network changed, or data plan is different, then |
152 // it's a new network. Then hide all previous notifications. | 151 // it's a new network. Then hide all previous notifications. |
153 bool new_plan = false; | 152 bool new_plan = false; |
154 if (cellular.service_path() != cellular_service_path_) { | 153 if (service_path != cellular_service_path_) { |
155 cellular_service_path_ = cellular.service_path(); | 154 cellular_service_path_ = service_path; |
156 new_plan = true; | 155 new_plan = true; |
157 } else if (plan.plan_name != cellular_data_plan_.plan_name || | 156 } else if (plan.plan_name != cellular_data_plan_.plan_name || |
158 plan.plan_type != cellular_data_plan_.plan_type) { | 157 plan.plan_type != cellular_data_plan_.plan_type) { |
159 new_plan = true; | 158 new_plan = true; |
160 } | 159 } |
161 if (new_plan) { | 160 if (new_plan) { |
162 // New network, so hide the notifications and set the notifications title. | 161 // New network, so hide the notifications and set the notifications title. |
163 notification_low_data_.Hide(); | 162 notification_low_data_.Hide(); |
164 notification_no_data_.Hide(); | 163 notification_no_data_.Hide(); |
165 if (plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { | 164 if (plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { |
166 notification_no_data_.set_title( | 165 notification_no_data_.set_title( |
167 l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_EXPIRED_TITLE, | 166 l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_EXPIRED_TITLE, |
168 ASCIIToUTF16(plan.plan_name))); | 167 ASCIIToUTF16(plan.plan_name))); |
169 notification_low_data_.set_title( | 168 notification_low_data_.set_title( |
170 l10n_util::GetStringFUTF16(IDS_NETWORK_NEARING_EXPIRATION_TITLE, | 169 l10n_util::GetStringFUTF16(IDS_NETWORK_NEARING_EXPIRATION_TITLE, |
171 ASCIIToUTF16(plan.plan_name))); | 170 ASCIIToUTF16(plan.plan_name))); |
172 } else { | 171 } else { |
173 notification_no_data_.set_title( | 172 notification_no_data_.set_title( |
174 l10n_util::GetStringFUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE, | 173 l10n_util::GetStringFUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE, |
175 ASCIIToUTF16(plan.plan_name))); | 174 ASCIIToUTF16(plan.plan_name))); |
176 notification_low_data_.set_title( | 175 notification_low_data_.set_title( |
177 l10n_util::GetStringFUTF16(IDS_NETWORK_LOW_DATA_TITLE, | 176 l10n_util::GetStringFUTF16(IDS_NETWORK_LOW_DATA_TITLE, |
178 ASCIIToUTF16(plan.plan_name))); | 177 ASCIIToUTF16(plan.plan_name))); |
179 } | 178 } |
180 } | 179 } |
181 | 180 |
182 if (plan.plan_type != CELLULAR_DATA_PLAN_UNKNOWN) { | 181 if (plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { |
183 if (cellular.data_left() == CellularNetwork::DATA_NONE) { | 182 // Time based plan. Show nearing expiration and data expiration. |
| 183 int64 time_left = plan.plan_end_time - plan.update_time; |
| 184 if (time_left <= 0) { |
184 notification_low_data_.Hide(); | 185 notification_low_data_.Hide(); |
185 int message = plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED ? | |
186 IDS_NETWORK_MINUTES_REMAINING_MESSAGE : | |
187 IDS_NETWORK_DATA_REMAINING_MESSAGE; | |
188 notification_no_data_.Show(l10n_util::GetStringFUTF16( | 186 notification_no_data_.Show(l10n_util::GetStringFUTF16( |
189 message, ASCIIToUTF16("0")), | 187 IDS_NETWORK_MINUTES_REMAINING_MESSAGE, ASCIIToUTF16("0")), |
190 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), | 188 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
191 NewCallback(this, &NetworkMessageObserver::MobileSetup), | 189 NewCallback(this, &NetworkMessageObserver::MobileSetup), |
192 false, false); | 190 false, false); |
193 } else if (cellular.data_left() == CellularNetwork::DATA_VERY_LOW) { | 191 } else if (time_left <= kDataNearingExpirationSecs) { |
194 notification_no_data_.Hide(); | 192 notification_no_data_.Hide(); |
195 int message = plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED ? | |
196 IDS_NETWORK_MINUTES_REMAINING_MESSAGE : | |
197 IDS_NETWORK_DATA_REMAINING_MESSAGE; | |
198 int64 remaining = plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED ? | |
199 (plan.plan_end_time - plan.update_time) / 60 : | |
200 (plan.plan_data_bytes - plan.data_bytes_used) / (1024 * 1024); | |
201 notification_low_data_.Show(l10n_util::GetStringFUTF16( | 193 notification_low_data_.Show(l10n_util::GetStringFUTF16( |
202 message, UTF8ToUTF16(base::Int64ToString(remaining))), | 194 IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE, |
| 195 UTF8ToUTF16(base::Int64ToString(time_left/60))), |
203 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), | 196 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
204 NewCallback(this, &NetworkMessageObserver::MobileSetup), | 197 NewCallback(this, &NetworkMessageObserver::MobileSetup), |
205 false, false); | 198 false, false); |
206 } else { | 199 } else { |
207 // Got data, so hide notifications. | 200 // Got more data, so hide notifications. |
| 201 notification_low_data_.Hide(); |
| 202 notification_no_data_.Hide(); |
| 203 } |
| 204 } else if (plan.plan_type == CELLULAR_DATA_PLAN_METERED_PAID || |
| 205 plan.plan_type == CELLULAR_DATA_PLAN_METERED_BASE) { |
| 206 // Metered plan. Show low data and out of data. |
| 207 int64 bytes_remaining = plan.plan_data_bytes - plan.data_bytes_used; |
| 208 if (bytes_remaining <= 0) { |
| 209 notification_low_data_.Hide(); |
| 210 notification_no_data_.Show(l10n_util::GetStringFUTF16( |
| 211 IDS_NETWORK_DATA_REMAINING_MESSAGE, ASCIIToUTF16("0")), |
| 212 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
| 213 NewCallback(this, &NetworkMessageObserver::MobileSetup), |
| 214 false, false); |
| 215 } else if (bytes_remaining <= kDataLowDataBytes) { |
| 216 notification_no_data_.Hide(); |
| 217 notification_low_data_.Show(l10n_util::GetStringFUTF16( |
| 218 IDS_NETWORK_DATA_REMAINING_MESSAGE, |
| 219 UTF8ToUTF16(base::Int64ToString(bytes_remaining/1024))), |
| 220 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
| 221 NewCallback(this, &NetworkMessageObserver::MobileSetup), |
| 222 false, false); |
| 223 } else { |
| 224 // Got more data, so hide notifications. |
208 notification_low_data_.Hide(); | 225 notification_low_data_.Hide(); |
209 notification_no_data_.Hide(); | 226 notification_no_data_.Hide(); |
210 } | 227 } |
211 } | 228 } |
212 | 229 |
213 cellular_data_plan_ = plan; | 230 cellular_data_plan_ = plan; |
214 } | 231 } |
215 | 232 |
216 } // namespace chromeos | 233 } // namespace chromeos |
OLD | NEW |