| OLD | NEW |
| 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 "chrome/browser/chromeos/network_message_observer.h" | 5 #include "chrome/browser/chromeos/network_message_observer.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 10 #include "ash/system/network/network_observer.h" | 10 #include "ash/system/network/network_observer.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // ((start time - 1 sec) <= end time of currently active plan). | 168 // ((start time - 1 sec) <= end time of currently active plan). |
| 169 // In other words, there is data available and there is no gap of more than a | 169 // In other words, there is data available and there is no gap of more than a |
| 170 // second in time between the old plan and the new plan. | 170 // second in time between the old plan and the new plan. |
| 171 bool has_data = other_plan->plan_type == CELLULAR_DATA_PLAN_UNLIMITED || | 171 bool has_data = other_plan->plan_type == CELLULAR_DATA_PLAN_UNLIMITED || |
| 172 other_plan->remaining_data() > 0; | 172 other_plan->remaining_data() > 0; |
| 173 bool will_apply = | 173 bool will_apply = |
| 174 (other_plan->plan_start_time - plan->plan_end_time).InSeconds() <= 1; | 174 (other_plan->plan_start_time - plan->plan_end_time).InSeconds() <= 1; |
| 175 return has_data && will_apply; | 175 return has_data && will_apply; |
| 176 } | 176 } |
| 177 | 177 |
| 178 void NetworkMessageObserver::OpenMobileSetupPage(const ListValue* args) { | 178 void NetworkMessageObserver::OpenMobileSetupPage( |
| 179 ash::Shell::GetInstance()->delegate()->OpenMobileSetup(); | 179 const std::string& service_path, const ListValue* args) { |
| 180 ash::Shell::GetInstance()->delegate()->OpenMobileSetup(service_path); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void NetworkMessageObserver::OpenMoreInfoPage(const ListValue* args) { | 183 void NetworkMessageObserver::OpenMoreInfoPage(const ListValue* args) { |
| 183 Browser* browser = browser::FindOrCreateTabbedBrowser( | 184 Browser* browser = browser::FindOrCreateTabbedBrowser( |
| 184 ProfileManager::GetDefaultProfileOrOffTheRecord()); | 185 ProfileManager::GetDefaultProfileOrOffTheRecord()); |
| 185 chromeos::NetworkLibrary* lib = | 186 chromeos::NetworkLibrary* lib = |
| 186 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 187 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 187 const chromeos::CellularNetwork* cellular = lib->cellular_network(); | 188 const chromeos::CellularNetwork* cellular = lib->cellular_network(); |
| 188 if (!cellular) | 189 if (!cellular) |
| 189 return; | 190 return; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 213 void NetworkMessageObserver::ShowNeedsPlanNotification( | 214 void NetworkMessageObserver::ShowNeedsPlanNotification( |
| 214 const CellularNetwork* cellular) { | 215 const CellularNetwork* cellular) { |
| 215 notification_no_data_->SetTitle( | 216 notification_no_data_->SetTitle( |
| 216 l10n_util::GetStringFUTF16(IDS_NETWORK_NO_DATA_PLAN_TITLE, | 217 l10n_util::GetStringFUTF16(IDS_NETWORK_NO_DATA_PLAN_TITLE, |
| 217 UTF8ToUTF16(cellular->name()))); | 218 UTF8ToUTF16(cellular->name()))); |
| 218 notification_no_data_->Show( | 219 notification_no_data_->Show( |
| 219 l10n_util::GetStringFUTF16( | 220 l10n_util::GetStringFUTF16( |
| 220 IDS_NETWORK_NO_DATA_PLAN_MESSAGE, | 221 IDS_NETWORK_NO_DATA_PLAN_MESSAGE, |
| 221 UTF8ToUTF16(cellular->name())), | 222 UTF8ToUTF16(cellular->name())), |
| 222 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), | 223 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
| 223 base::Bind(&NetworkMessageObserver::OpenMobileSetupPage, AsWeakPtr()), | 224 base::Bind(&NetworkMessageObserver::OpenMobileSetupPage, |
| 225 AsWeakPtr(), |
| 226 cellular->service_path()), |
| 224 false, false); | 227 false, false); |
| 225 } | 228 } |
| 226 | 229 |
| 227 void NetworkMessageObserver::ShowNoDataNotification( | 230 void NetworkMessageObserver::ShowNoDataNotification( |
| 231 const CellularNetwork* cellular, |
| 228 CellularDataPlanType plan_type) { | 232 CellularDataPlanType plan_type) { |
| 229 notification_low_data_->Hide(); // Hide previous low data notification. | 233 notification_low_data_->Hide(); // Hide previous low data notification. |
| 230 string16 message = plan_type == CELLULAR_DATA_PLAN_UNLIMITED ? | 234 string16 message = plan_type == CELLULAR_DATA_PLAN_UNLIMITED ? |
| 231 TimeFormat::TimeRemaining(base::TimeDelta()) : | 235 TimeFormat::TimeRemaining(base::TimeDelta()) : |
| 232 l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_REMAINING_MESSAGE, | 236 l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_REMAINING_MESSAGE, |
| 233 ASCIIToUTF16("0")); | 237 ASCIIToUTF16("0")); |
| 234 notification_no_data_->Show(message, | 238 notification_no_data_->Show(message, |
| 235 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), | 239 l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), |
| 236 base::Bind(&NetworkMessageObserver::OpenMobileSetupPage, AsWeakPtr()), | 240 base::Bind(&NetworkMessageObserver::OpenMobileSetupPage, |
| 241 AsWeakPtr(), |
| 242 cellular->service_path()), |
| 237 false, false); | 243 false, false); |
| 238 } | 244 } |
| 239 | 245 |
| 240 void NetworkMessageObserver::ShowLowDataNotification( | 246 void NetworkMessageObserver::ShowLowDataNotification( |
| 241 const CellularDataPlan* plan) { | 247 const CellularDataPlan* plan) { |
| 242 string16 message; | 248 string16 message; |
| 243 if (plan->plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { | 249 if (plan->plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { |
| 244 message = plan->GetPlanExpiration(); | 250 message = plan->GetPlanExpiration(); |
| 245 } else { | 251 } else { |
| 246 int64 remaining_mbytes = plan->remaining_data() / (1024 * 1024); | 252 int64 remaining_mbytes = plan->remaining_data() / (1024 * 1024); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 if (!cellular || !cellular->SupportsDataPlan()) | 324 if (!cellular || !cellular->SupportsDataPlan()) |
| 319 return; | 325 return; |
| 320 | 326 |
| 321 const CellularDataPlanVector* plans = | 327 const CellularDataPlanVector* plans = |
| 322 cros->GetDataPlans(cellular->service_path()); | 328 cros->GetDataPlans(cellular->service_path()); |
| 323 // If no plans available, check to see if we need a new plan. | 329 // If no plans available, check to see if we need a new plan. |
| 324 if (!plans || plans->empty()) { | 330 if (!plans || plans->empty()) { |
| 325 // If previously, we had low data, we know that a plan was near expiring. | 331 // If previously, we had low data, we know that a plan was near expiring. |
| 326 // In that case, because the plan disappeared, we assume that it expired. | 332 // In that case, because the plan disappeared, we assume that it expired. |
| 327 if (cellular_data_left_ == CellularNetwork::DATA_LOW) { | 333 if (cellular_data_left_ == CellularNetwork::DATA_LOW) { |
| 328 ShowNoDataNotification(cellular_data_plan_type_); | 334 ShowNoDataNotification(cellular, cellular_data_plan_type_); |
| 329 } else if (cellular->needs_new_plan()) { | 335 } else if (cellular->needs_new_plan()) { |
| 330 ShowNeedsPlanNotification(cellular); | 336 ShowNeedsPlanNotification(cellular); |
| 331 } | 337 } |
| 332 SaveLastCellularInfo(cellular, NULL); | 338 SaveLastCellularInfo(cellular, NULL); |
| 333 return; | 339 return; |
| 334 } | 340 } |
| 335 | 341 |
| 336 CellularDataPlanVector::const_iterator iter = plans->begin(); | 342 CellularDataPlanVector::const_iterator iter = plans->begin(); |
| 337 const CellularDataPlan* current_plan = *iter; | 343 const CellularDataPlan* current_plan = *iter; |
| 338 | 344 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 349 // If connected cellular network changed, or data plan is different, then | 355 // If connected cellular network changed, or data plan is different, then |
| 350 // it's a new network. Then hide all previous notifications. | 356 // it's a new network. Then hide all previous notifications. |
| 351 bool new_plan = cellular->service_path() != cellular_service_path_ || | 357 bool new_plan = cellular->service_path() != cellular_service_path_ || |
| 352 current_plan->GetUniqueIdentifier() != cellular_data_plan_unique_id_; | 358 current_plan->GetUniqueIdentifier() != cellular_data_plan_unique_id_; |
| 353 | 359 |
| 354 if (new_plan) { | 360 if (new_plan) { |
| 355 InitNewPlan(current_plan); | 361 InitNewPlan(current_plan); |
| 356 } | 362 } |
| 357 | 363 |
| 358 if (cellular->data_left() == CellularNetwork::DATA_NONE) { | 364 if (cellular->data_left() == CellularNetwork::DATA_NONE) { |
| 359 ShowNoDataNotification(current_plan->plan_type); | 365 ShowNoDataNotification(cellular, current_plan->plan_type); |
| 360 } else if (cellular->data_left() == CellularNetwork::DATA_VERY_LOW) { | 366 } else if (cellular->data_left() == CellularNetwork::DATA_VERY_LOW) { |
| 361 // Only show low data notification if we transition to very low data | 367 // Only show low data notification if we transition to very low data |
| 362 // and we are on the same plan. This is so that users don't get a | 368 // and we are on the same plan. This is so that users don't get a |
| 363 // notification whenever they connect to a low data 3g network. | 369 // notification whenever they connect to a low data 3g network. |
| 364 if (!new_plan && (cellular_data_left_ != CellularNetwork::DATA_VERY_LOW)) | 370 if (!new_plan && (cellular_data_left_ != CellularNetwork::DATA_VERY_LOW)) |
| 365 ShowLowDataNotification(current_plan); | 371 ShowLowDataNotification(current_plan); |
| 366 } | 372 } |
| 367 | 373 |
| 368 SaveLastCellularInfo(cellular, current_plan); | 374 SaveLastCellularInfo(cellular, current_plan); |
| 369 } | 375 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 382 if (plan) { | 388 if (plan) { |
| 383 cellular_data_plan_unique_id_ = plan->GetUniqueIdentifier(); | 389 cellular_data_plan_unique_id_ = plan->GetUniqueIdentifier(); |
| 384 cellular_data_plan_type_ = plan->plan_type; | 390 cellular_data_plan_type_ = plan->plan_type; |
| 385 } else { | 391 } else { |
| 386 cellular_data_plan_unique_id_ = std::string(); | 392 cellular_data_plan_unique_id_ = std::string(); |
| 387 cellular_data_plan_type_ = CELLULAR_DATA_PLAN_UNKNOWN; | 393 cellular_data_plan_type_ = CELLULAR_DATA_PLAN_UNKNOWN; |
| 388 } | 394 } |
| 389 } | 395 } |
| 390 | 396 |
| 391 } // namespace chromeos | 397 } // namespace chromeos |
| OLD | NEW |