| 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/mobile/mobile_activator.h" | 5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 iccid_.clear(); | 182 iccid_.clear(); |
| 183 service_path_.clear(); | 183 service_path_.clear(); |
| 184 state_ = PLAN_ACTIVATION_PAGE_LOADING; | 184 state_ = PLAN_ACTIVATION_PAGE_LOADING; |
| 185 reenable_cert_check_ = false; | 185 reenable_cert_check_ = false; |
| 186 terminated_ = true; | 186 terminated_ = true; |
| 187 // Release the previous cellular config and setup a new empty one. | 187 // Release the previous cellular config and setup a new empty one. |
| 188 cellular_config_ = new CellularConfigDocument(); | 188 cellular_config_ = new CellularConfigDocument(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { | 191 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { |
| 192 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 192 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || |
| 193 state_ == PLAN_ACTIVATION_DONE || |
| 194 state_ == PLAN_ACTIVATION_ERROR) { |
| 193 return; | 195 return; |
| 194 EvaluateCellularNetwork(FindMatchingCellularNetwork(true)); | 196 } |
| 197 |
| 198 CellularNetwork* network = FindMatchingCellularNetwork(true); |
| 199 if (network->activate_over_non_cellular_network()) { |
| 200 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); |
| 201 bool is_online = |
| 202 cros->connected_network() && cros->connected_network()->online(); |
| 203 if (waiting && is_online) { |
| 204 ChangeState(network, post_reconnect_state_, ""); |
| 205 } else if (!waiting && !is_online) { |
| 206 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); |
| 207 } |
| 208 } |
| 209 |
| 210 EvaluateCellularNetwork(network); |
| 195 } | 211 } |
| 196 | 212 |
| 197 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, | 213 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, |
| 198 const Network* network) { | 214 const Network* network) { |
| 199 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 215 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
| 200 return; | 216 return; |
| 201 | 217 |
| 202 if (!network || network->type() != TYPE_CELLULAR) { | 218 if (!network || network->type() != TYPE_CELLULAR) { |
| 203 NOTREACHED(); | 219 NOTREACHED(); |
| 204 return; | 220 return; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 231 lib->FindNetworkDeviceByPath(network->device_path()); | 247 lib->FindNetworkDeviceByPath(network->device_path()); |
| 232 if (!device) { | 248 if (!device) { |
| 233 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); | 249 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); |
| 234 return; | 250 return; |
| 235 } | 251 } |
| 236 | 252 |
| 237 terminated_ = false; | 253 terminated_ = false; |
| 238 meid_ = device->meid(); | 254 meid_ = device->meid(); |
| 239 iccid_ = device->iccid(); | 255 iccid_ = device->iccid(); |
| 240 service_path_ = service_path; | 256 service_path_ = service_path; |
| 257 |
| 258 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); |
| 259 |
| 241 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 260 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 242 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, | 261 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, |
| 243 cellular_config_.get()), | 262 cellular_config_.get()), |
| 244 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); | 263 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); |
| 245 } | 264 } |
| 246 | 265 |
| 247 void MobileActivator::ContinueActivation() { | 266 void MobileActivator::ContinueActivation() { |
| 248 CellularNetwork* network = FindMatchingCellularNetwork(false); | 267 CellularNetwork* network = FindMatchingCellularNetwork(false); |
| 249 if (!network || !network->SupportsActivation()) | 268 if (!network || !network->SupportsActivation()) |
| 250 return; | 269 return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 271 // The payment is received, try to reconnect and check the status all over | 290 // The payment is received, try to reconnect and check the status all over |
| 272 // again. | 291 // again. |
| 273 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 292 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
| 274 NetworkLibrary* lib = GetNetworkLibrary(); | 293 NetworkLibrary* lib = GetNetworkLibrary(); |
| 275 lib->SignalCellularPlanPayment(); | 294 lib->SignalCellularPlanPayment(); |
| 276 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); | 295 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); |
| 277 CellularNetwork* network = FindMatchingCellularNetwork(true); | 296 CellularNetwork* network = FindMatchingCellularNetwork(true); |
| 278 if (network && network->activate_over_non_cellular_network()) { | 297 if (network && network->activate_over_non_cellular_network()) { |
| 279 state_ = PLAN_ACTIVATION_DONE; | 298 state_ = PLAN_ACTIVATION_DONE; |
| 280 network->CompleteActivation(); | 299 network->CompleteActivation(); |
| 281 EvaluateCellularNetwork(network); | |
| 282 } else { | 300 } else { |
| 283 StartOTASP(); | 301 StartOTASP(); |
| 284 } | 302 } |
| 285 } else { | 303 } else { |
| 286 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); | 304 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); |
| 287 } | 305 } |
| 288 } | 306 } |
| 289 | 307 |
| 290 void MobileActivator::OnPortalLoaded(bool success) { | 308 void MobileActivator::OnPortalLoaded(bool success) { |
| 291 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 309 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 292 base::Bind(&MobileActivator::HandlePortalLoaded, | 310 base::Bind(&MobileActivator::HandlePortalLoaded, |
| 293 AsWeakPtr(), success)); | 311 AsWeakPtr(), success)); |
| 294 } | 312 } |
| 295 | 313 |
| 296 void MobileActivator::HandlePortalLoaded(bool success) { | 314 void MobileActivator::HandlePortalLoaded(bool success) { |
| 297 CellularNetwork* network = FindMatchingCellularNetwork(true); | 315 CellularNetwork* network = FindMatchingCellularNetwork(true); |
| 298 if (!network) { | 316 if (!network) { |
| 299 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 317 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
| 300 GetErrorMessage(kErrorNoService)); | 318 GetErrorMessage(kErrorNoService)); |
| 301 return; | 319 return; |
| 302 } | 320 } |
| 303 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || | 321 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || |
| 304 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 322 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
| 305 if (success) { | 323 if (success) { |
| 306 payment_reconnect_count_ = 0; | 324 payment_reconnect_count_ = 0; |
| 307 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); | 325 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); |
| 308 } else { | 326 } else { |
| 327 // There is no point in forcing reconnecting the cellular network if the |
| 328 // activation should not be done over it. |
| 329 if (network->activate_over_non_cellular_network()) |
| 330 return; |
| 331 |
| 309 payment_reconnect_count_++; | 332 payment_reconnect_count_++; |
| 310 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { | 333 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { |
| 311 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 334 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
| 312 GetErrorMessage(kErrorNoService)); | 335 GetErrorMessage(kErrorNoService)); |
| 313 return; | 336 return; |
| 314 } | 337 } |
| 315 | 338 |
| 316 // Reconnect and try and load the frame again. | 339 // Reconnect and try and load the frame again. |
| 317 ChangeState(network, | 340 ChangeState(network, |
| 318 PLAN_ACTIVATION_RECONNECTING, | 341 PLAN_ACTIVATION_RECONNECTING, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // Start monitoring network property changes. | 398 // Start monitoring network property changes. |
| 376 lib->AddNetworkManagerObserver(this); | 399 lib->AddNetworkManagerObserver(this); |
| 377 if (network->activate_over_non_cellular_network()) { | 400 if (network->activate_over_non_cellular_network()) { |
| 378 // Fast forward to payment portal loading if the activation is performed | 401 // Fast forward to payment portal loading if the activation is performed |
| 379 // over a non-cellular network. | 402 // over a non-cellular network. |
| 380 ChangeState(network, | 403 ChangeState(network, |
| 381 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? | 404 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? |
| 382 PLAN_ACTIVATION_DONE : | 405 PLAN_ACTIVATION_DONE : |
| 383 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, | 406 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, |
| 384 ""); | 407 ""); |
| 385 } else if (lib->HasRecentCellularPlanPayment() && | 408 // Verify that there is no need to wait for the connection. This will also |
| 386 network->activation_state() == | 409 // evaluate the network. |
| 387 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 410 OnNetworkManagerChanged(lib); |
| 411 return; |
| 412 } |
| 413 |
| 414 if (lib->HasRecentCellularPlanPayment() && |
| 415 network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
| 388 // Try to start with OTASP immediately if we have received payment recently. | 416 // Try to start with OTASP immediately if we have received payment recently. |
| 389 state_ = PLAN_ACTIVATION_START_OTASP; | 417 state_ = PLAN_ACTIVATION_START_OTASP; |
| 390 } else { | 418 } else { |
| 391 state_ = PLAN_ACTIVATION_START; | 419 state_ = PLAN_ACTIVATION_START; |
| 392 } | 420 } |
| 393 | 421 |
| 394 EvaluateCellularNetwork(network); | 422 EvaluateCellularNetwork(network); |
| 395 } | 423 } |
| 396 | 424 |
| 397 void MobileActivator::RetryOTASP() { | 425 void MobileActivator::RetryOTASP() { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 return; | 540 return; |
| 513 } | 541 } |
| 514 | 542 |
| 515 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString() | 543 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString() |
| 516 << "\n ui=" << GetStateDescription(state_) | 544 << "\n ui=" << GetStateDescription(state_) |
| 517 << "\n activation=" << network->GetActivationStateString() | 545 << "\n activation=" << network->GetActivationStateString() |
| 518 << "\n error=" << network->GetErrorString() | 546 << "\n error=" << network->GetErrorString() |
| 519 << "\n setvice_path=" << network->service_path() | 547 << "\n setvice_path=" << network->service_path() |
| 520 << "\n connected=" << network->connected(); | 548 << "\n connected=" << network->connected(); |
| 521 | 549 |
| 550 // If the network is activated over non cellular network, the activator state |
| 551 // does not depend on the network's own state. |
| 552 if (network->activate_over_non_cellular_network()) |
| 553 return; |
| 554 |
| 522 std::string error_description; | 555 std::string error_description; |
| 523 PlanActivationState new_state = PickNextState(network, &error_description); | 556 PlanActivationState new_state = PickNextState(network, &error_description); |
| 524 | 557 |
| 525 ChangeState(network, new_state, error_description); | 558 ChangeState(network, new_state, error_description); |
| 526 } | 559 } |
| 527 | 560 |
| 528 MobileActivator::PlanActivationState MobileActivator::PickNextState( | 561 MobileActivator::PlanActivationState MobileActivator::PickNextState( |
| 529 CellularNetwork* network, std::string* error_description) const { | 562 CellularNetwork* network, std::string* error_description) const { |
| 530 PlanActivationState new_state = state_; | 563 PlanActivationState new_state = state_; |
| 531 if (!network->connected()) | 564 if (!network->connected()) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 new_state = PLAN_ACTIVATION_DONE; | 715 new_state = PLAN_ACTIVATION_DONE; |
| 683 else | 716 else |
| 684 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 717 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 685 break; | 718 break; |
| 686 // Initial state | 719 // Initial state |
| 687 case PLAN_ACTIVATION_PAGE_LOADING: | 720 case PLAN_ACTIVATION_PAGE_LOADING: |
| 688 break; | 721 break; |
| 689 // Just ignore all signals until the site confirms payment. | 722 // Just ignore all signals until the site confirms payment. |
| 690 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 723 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| 691 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 724 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 725 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
| 692 break; | 726 break; |
| 693 // Go where we decided earlier. | 727 // Go where we decided earlier. |
| 694 case PLAN_ACTIVATION_RECONNECTING: | 728 case PLAN_ACTIVATION_RECONNECTING: |
| 695 new_state = post_reconnect_state_; | 729 new_state = post_reconnect_state_; |
| 696 break; | 730 break; |
| 697 // Activation completed/failed, ignore network changes. | 731 // Activation completed/failed, ignore network changes. |
| 698 case PLAN_ACTIVATION_DONE: | 732 case PLAN_ACTIVATION_DONE: |
| 699 case PLAN_ACTIVATION_ERROR: | 733 case PLAN_ACTIVATION_ERROR: |
| 700 break; | 734 break; |
| 701 } | 735 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 725 case PLAN_ACTIVATION_START_OTASP: | 759 case PLAN_ACTIVATION_START_OTASP: |
| 726 return "START_OTASP"; | 760 return "START_OTASP"; |
| 727 case PLAN_ACTIVATION_OTASP: | 761 case PLAN_ACTIVATION_OTASP: |
| 728 return "OTASP"; | 762 return "OTASP"; |
| 729 case PLAN_ACTIVATION_DONE: | 763 case PLAN_ACTIVATION_DONE: |
| 730 return "DONE"; | 764 return "DONE"; |
| 731 case PLAN_ACTIVATION_ERROR: | 765 case PLAN_ACTIVATION_ERROR: |
| 732 return "ERROR"; | 766 return "ERROR"; |
| 733 case PLAN_ACTIVATION_RECONNECTING: | 767 case PLAN_ACTIVATION_RECONNECTING: |
| 734 return "RECONNECTING"; | 768 return "RECONNECTING"; |
| 769 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
| 770 return "WAITING FOR CONNECTION"; |
| 735 } | 771 } |
| 736 return "UNKNOWN"; | 772 return "UNKNOWN"; |
| 737 } | 773 } |
| 738 | 774 |
| 739 | 775 |
| 740 void MobileActivator::CompleteActivation( | 776 void MobileActivator::CompleteActivation( |
| 741 CellularNetwork* network) { | 777 CellularNetwork* network) { |
| 742 // Remove observers, we are done with this page. | 778 // Remove observers, we are done with this page. |
| 743 NetworkLibrary* lib = GetNetworkLibrary(); | 779 NetworkLibrary* lib = GetNetworkLibrary(); |
| 744 lib->RemoveNetworkManagerObserver(this); | 780 lib->RemoveNetworkManagerObserver(this); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 849 } |
| 814 break; | 850 break; |
| 815 case PLAN_ACTIVATION_PAGE_LOADING: | 851 case PLAN_ACTIVATION_PAGE_LOADING: |
| 816 return; | 852 return; |
| 817 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 853 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| 818 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 854 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 819 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 855 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
| 820 // Fix for fix SSL for the walled gardens where cert chain verification | 856 // Fix for fix SSL for the walled gardens where cert chain verification |
| 821 // might not work. | 857 // might not work. |
| 822 break; | 858 break; |
| 859 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
| 860 post_reconnect_state_ = old_state; |
| 861 break; |
| 823 case PLAN_ACTIVATION_RECONNECTING: { | 862 case PLAN_ACTIVATION_RECONNECTING: { |
| 824 PlanActivationState next_state = old_state; | 863 PlanActivationState next_state = old_state; |
| 825 // Pick where we want to return to after we reconnect. | 864 // Pick where we want to return to after we reconnect. |
| 826 switch (old_state) { | 865 switch (old_state) { |
| 827 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 866 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| 828 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 867 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 829 // We decide here what to do next based on the state of the modem. | 868 // We decide here what to do next based on the state of the modem. |
| 830 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; | 869 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; |
| 831 break; | 870 break; |
| 832 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 871 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 | 990 |
| 952 std::string MobileActivator::GetErrorMessage(const std::string& code) const { | 991 std::string MobileActivator::GetErrorMessage(const std::string& code) const { |
| 953 return cellular_config_->GetErrorMessage(code); | 992 return cellular_config_->GetErrorMessage(code); |
| 954 } | 993 } |
| 955 | 994 |
| 956 NetworkLibrary* MobileActivator::GetNetworkLibrary() const { | 995 NetworkLibrary* MobileActivator::GetNetworkLibrary() const { |
| 957 return CrosLibrary::Get()->GetNetworkLibrary(); | 996 return CrosLibrary::Get()->GetNetworkLibrary(); |
| 958 } | 997 } |
| 959 | 998 |
| 960 } // namespace chromeos | 999 } // namespace chromeos |
| OLD | NEW |