| 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( | 146 void NetworkMessageObserver::CellularDataPlanChanged(NetworkLibrary* obj) { |
| 147 const std::string& service_path, const CellularDataPlanList& plans) { | 147 const CellularNetwork& cellular = obj->cellular_network(); |
| 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(); |
| 149 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0]; | 150 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0]; |
| 150 // If connected cellular network changed, or data plan is different, then | 151 // If connected cellular network changed, or data plan is different, then |
| 151 // it's a new network. Then hide all previous notifications. | 152 // it's a new network. Then hide all previous notifications. |
| 152 bool new_plan = false; | 153 bool new_plan = false; |
| 153 if (service_path != cellular_service_path_) { | 154 if (cellular.service_path() != cellular_service_path_) { |
| 154 cellular_service_path_ = service_path; | 155 cellular_service_path_ = cellular.service_path(); |
| 155 new_plan = true; | 156 new_plan = true; |
| 156 } else if (plan.plan_name != cellular_data_plan_.plan_name || | 157 } else if (plan.plan_name != cellular_data_plan_.plan_name || |
| 157 plan.plan_type != cellular_data_plan_.plan_type) { | 158 plan.plan_type != cellular_data_plan_.plan_type) { |
| 158 new_plan = true; | 159 new_plan = true; |
| 159 } | 160 } |
| 160 if (new_plan) { | 161 if (new_plan) { |
| 161 // New network, so hide the notifications and set the notifications title. | 162 // New network, so hide the notifications and set the notifications title. |
| 162 notification_low_data_.Hide(); | 163 notification_low_data_.Hide(); |
| 163 notification_no_data_.Hide(); | 164 notification_no_data_.Hide(); |
| 164 if (plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { | 165 if (plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { |
| 165 notification_no_data_.set_title( | 166 notification_no_data_.set_title( |
| 166 l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_EXPIRED_TITLE, | 167 l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_EXPIRED_TITLE, |
| 167 ASCIIToUTF16(plan.plan_name))); | 168 ASCIIToUTF16(plan.plan_name))); |
| 168 notification_low_data_.set_title( | 169 notification_low_data_.set_title( |
| 169 l10n_util::GetStringFUTF16(IDS_NETWORK_NEARING_EXPIRATION_TITLE, | 170 l10n_util::GetStringFUTF16(IDS_NETWORK_NEARING_EXPIRATION_TITLE, |
| 170 ASCIIToUTF16(plan.plan_name))); | 171 ASCIIToUTF16(plan.plan_name))); |
| 171 } else { | 172 } else { |
| 172 notification_no_data_.set_title( | 173 notification_no_data_.set_title( |
| 173 l10n_util::GetStringFUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE, | 174 l10n_util::GetStringFUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE, |
| 174 ASCIIToUTF16(plan.plan_name))); | 175 ASCIIToUTF16(plan.plan_name))); |
| 175 notification_low_data_.set_title( | 176 notification_low_data_.set_title( |
| 176 l10n_util::GetStringFUTF16(IDS_NETWORK_LOW_DATA_TITLE, | 177 l10n_util::GetStringFUTF16(IDS_NETWORK_LOW_DATA_TITLE, |
| 177 ASCIIToUTF16(plan.plan_name))); | 178 ASCIIToUTF16(plan.plan_name))); |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 | 181 |
| 181 if (plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { | 182 if (plan.plan_type != CELLULAR_DATA_PLAN_UNKNOWN) { |
| 182 // Time based plan. Show nearing expiration and data expiration. | 183 if (cellular.data_left() == CellularNetwork::DATA_NONE) { |
| 183 int64 time_left = plan.plan_end_time - plan.update_time; | |
| 184 if (time_left <= 0) { | |
| 185 notification_low_data_.Hide(); | 184 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; |
| 186 notification_no_data_.Show(l10n_util::GetStringFUTF16( | 188 notification_no_data_.Show(l10n_util::GetStringFUTF16( |
| 187 IDS_NETWORK_MINUTES_REMAINING_MESSAGE, ASCIIToUTF16("0")), | 189 message, ASCIIToUTF16("0")), |
| 188 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), | 190 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
| 189 NewCallback(this, &NetworkMessageObserver::MobileSetup), | 191 NewCallback(this, &NetworkMessageObserver::MobileSetup), |
| 190 false, false); | 192 false, false); |
| 191 } else if (time_left <= kDataNearingExpirationSecs) { | 193 } else if (cellular.data_left() == CellularNetwork::DATA_VERY_LOW) { |
| 192 notification_no_data_.Hide(); | 194 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); |
| 193 notification_low_data_.Show(l10n_util::GetStringFUTF16( | 201 notification_low_data_.Show(l10n_util::GetStringFUTF16( |
| 194 IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE, | 202 message, UTF8ToUTF16(base::Int64ToString(remaining))), |
| 195 UTF8ToUTF16(base::Int64ToString(time_left/60))), | |
| 196 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), | 203 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
| 197 NewCallback(this, &NetworkMessageObserver::MobileSetup), | 204 NewCallback(this, &NetworkMessageObserver::MobileSetup), |
| 198 false, false); | 205 false, false); |
| 199 } else { | 206 } else { |
| 200 // Got more data, so hide notifications. | 207 // Got 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. | |
| 225 notification_low_data_.Hide(); | 208 notification_low_data_.Hide(); |
| 226 notification_no_data_.Hide(); | 209 notification_no_data_.Hide(); |
| 227 } | 210 } |
| 228 } | 211 } |
| 229 | 212 |
| 230 cellular_data_plan_ = plan; | 213 cellular_data_plan_ = plan; |
| 231 } | 214 } |
| 232 | 215 |
| 233 } // namespace chromeos | 216 } // namespace chromeos |
| OLD | NEW |