Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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/dom_ui/mobile_setup_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 const char kErrorBadConnectionActivated[] = "bad_connection_activated"; | 55 const char kErrorBadConnectionActivated[] = "bad_connection_activated"; |
| 56 const char kErrorRoamingOnConnection[] = "roaming_connection"; | 56 const char kErrorRoamingOnConnection[] = "roaming_connection"; |
| 57 const char kErrorNoEVDO[] = "no_evdo"; | 57 const char kErrorNoEVDO[] = "no_evdo"; |
| 58 const char kErrorRoamingActivation[] = "roaming_activation"; | 58 const char kErrorRoamingActivation[] = "roaming_activation"; |
| 59 const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated"; | 59 const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated"; |
| 60 const char kErrorNoService[] = "no_service"; | 60 const char kErrorNoService[] = "no_service"; |
| 61 const char kErrorDisabled[] = "disabled"; | 61 const char kErrorDisabled[] = "disabled"; |
| 62 const char kErrorNoDevice[] = "no_device"; | 62 const char kErrorNoDevice[] = "no_device"; |
| 63 const char kFailedPaymentError[] = "failed_payment"; | 63 const char kFailedPaymentError[] = "failed_payment"; |
| 64 const char kFailedConnectivity[] = "connectivity"; | 64 const char kFailedConnectivity[] = "connectivity"; |
| 65 const char kErrorAlreadyRunning[] = "already_running"; | |
| 65 | 66 |
| 66 // Cellular configuration file path. | 67 // Cellular configuration file path. |
| 67 const char kCellularConfigPath[] = | 68 const char kCellularConfigPath[] = |
| 68 "/usr/share/chromeos-assets/mobile/mobile_config.json"; | 69 "/usr/share/chromeos-assets/mobile/mobile_config.json"; |
| 69 | 70 |
| 70 // Cellular config file field names. | 71 // Cellular config file field names. |
| 71 const char kVersionField[] = "version"; | 72 const char kVersionField[] = "version"; |
| 72 const char kErrorsField[] = "errors"; | 73 const char kErrorsField[] = "errors"; |
| 73 | 74 |
| 74 // Number of times we will retry to restart the activation process in case | 75 // Number of times we will retry to restart the activation process in case |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 TabContents* tab_contents_; | 303 TabContents* tab_contents_; |
| 303 // Internal handler state. | 304 // Internal handler state. |
| 304 PlanActivationState state_; | 305 PlanActivationState state_; |
| 305 std::string service_path_; | 306 std::string service_path_; |
| 306 // Flags that control if wifi and ethernet connection needs to be restored | 307 // Flags that control if wifi and ethernet connection needs to be restored |
| 307 // after the activation of cellular network. | 308 // after the activation of cellular network. |
| 308 bool reenable_wifi_; | 309 bool reenable_wifi_; |
| 309 bool reenable_ethernet_; | 310 bool reenable_ethernet_; |
| 310 bool reenable_cert_check_; | 311 bool reenable_cert_check_; |
| 311 bool evaluating_; | 312 bool evaluating_; |
| 313 // True if we think that another tab is already running activation. | |
| 314 bool already_running_; | |
| 312 // Connection retry counter. | 315 // Connection retry counter. |
| 313 int connection_retry_count_; | 316 int connection_retry_count_; |
| 314 // Post payment reconnect wait counters. | 317 // Post payment reconnect wait counters. |
| 315 int reconnect_wait_count_; | 318 int reconnect_wait_count_; |
| 316 // Activation retry attempt count; | 319 // Activation retry attempt count; |
| 317 int activation_attempt_; | 320 int activation_attempt_; |
| 318 // Connection start time. | 321 // Connection start time. |
| 319 base::Time connection_start_time_; | 322 base::Time connection_start_time_; |
| 320 // Timer that monitors reconnection timeouts. | 323 // Timer that monitors reconnection timeouts. |
| 321 base::RepeatingTimer<MobileSetupHandler> reconnect_timer_; | 324 base::RepeatingTimer<MobileSetupHandler> reconnect_timer_; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 // | 434 // |
| 432 //////////////////////////////////////////////////////////////////////////////// | 435 //////////////////////////////////////////////////////////////////////////////// |
| 433 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) | 436 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) |
| 434 : tab_contents_(NULL), | 437 : tab_contents_(NULL), |
| 435 state_(PLAN_ACTIVATION_PAGE_LOADING), | 438 state_(PLAN_ACTIVATION_PAGE_LOADING), |
| 436 service_path_(service_path), | 439 service_path_(service_path), |
| 437 reenable_wifi_(false), | 440 reenable_wifi_(false), |
| 438 reenable_ethernet_(false), | 441 reenable_ethernet_(false), |
| 439 reenable_cert_check_(false), | 442 reenable_cert_check_(false), |
| 440 evaluating_(false), | 443 evaluating_(false), |
| 444 already_running_(false), | |
| 441 connection_retry_count_(0), | 445 connection_retry_count_(0), |
| 442 reconnect_wait_count_(0), | 446 reconnect_wait_count_(0), |
| 443 activation_attempt_(0) { | 447 activation_attempt_(0) { |
| 444 } | 448 } |
| 445 | 449 |
| 446 MobileSetupHandler::~MobileSetupHandler() { | 450 MobileSetupHandler::~MobileSetupHandler() { |
| 447 reconnect_timer_.Stop(); | 451 reconnect_timer_.Stop(); |
| 448 chromeos::NetworkLibrary* lib = | 452 chromeos::NetworkLibrary* lib = |
| 449 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 453 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 454 if (lib->IsLocked()) | |
|
Charlie Lee
2011/01/20 20:05:43
probably want to remove network manager observer b
zel
2011/01/20 22:06:14
Done.
| |
| 455 lib->Unlock(); | |
| 450 lib->RemoveNetworkManagerObserver(this); | 456 lib->RemoveNetworkManagerObserver(this); |
| 451 lib->RemoveObserverForAllNetworks(this); | 457 lib->RemoveObserverForAllNetworks(this); |
| 452 ReEnableOtherConnections(); | 458 ReEnableOtherConnections(); |
| 453 } | 459 } |
| 454 | 460 |
| 455 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { | 461 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { |
| 456 return DOMMessageHandler::Attach(dom_ui); | 462 return DOMMessageHandler::Attach(dom_ui); |
| 457 } | 463 } |
| 458 | 464 |
| 459 void MobileSetupHandler::Init(TabContents* contents) { | 465 void MobileSetupHandler::Init(TabContents* contents) { |
| 460 tab_contents_ = contents; | 466 tab_contents_ = contents; |
| 461 LoadCellularConfig(); | 467 LoadCellularConfig(); |
| 462 SetupActivationProcess(GetCellularNetwork(service_path_)); | 468 if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()->IsLocked()) |
|
Charlie Lee
2011/01/20 20:05:43
if we are using locked only for network activation
zel
2011/01/20 22:06:14
Actually, I wanted to keep this generic at least f
| |
| 469 SetupActivationProcess(GetCellularNetwork(service_path_)); | |
| 470 else | |
| 471 already_running_ = true; | |
| 463 } | 472 } |
| 464 | 473 |
| 465 void MobileSetupHandler::RegisterMessages() { | 474 void MobileSetupHandler::RegisterMessages() { |
| 466 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, | 475 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, |
| 467 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); | 476 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); |
| 468 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, | 477 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, |
| 469 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); | 478 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); |
| 470 } | 479 } |
| 471 | 480 |
| 472 void MobileSetupHandler::OnNetworkManagerChanged( | 481 void MobileSetupHandler::OnNetworkManagerChanged( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 void MobileSetupHandler::InitiateActivation() { | 520 void MobileSetupHandler::InitiateActivation() { |
| 512 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0); | 521 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0); |
| 513 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 522 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 514 NewRunnableMethod(task.get(), &TaskProxy::HandleStartActivation)); | 523 NewRunnableMethod(task.get(), &TaskProxy::HandleStartActivation)); |
| 515 } | 524 } |
| 516 | 525 |
| 517 void MobileSetupHandler::StartActivation() { | 526 void MobileSetupHandler::StartActivation() { |
| 518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 519 chromeos::NetworkLibrary* lib = | 528 chromeos::NetworkLibrary* lib = |
| 520 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 529 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 521 | |
| 522 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); | 530 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
| 523 // Check if we can start activation process. | 531 // Check if we can start activation process. |
| 524 if (!network) { | 532 if (!network || already_running_) { |
| 525 std::string error(kErrorNoService); | 533 std::string error; |
| 526 if (!lib->cellular_available()) | 534 if (already_running_) |
| 535 error = kErrorAlreadyRunning; | |
| 536 else if (!lib->cellular_available()) | |
| 527 error = kErrorNoDevice; | 537 error = kErrorNoDevice; |
| 528 else if (!lib->cellular_enabled()) | 538 else if (!lib->cellular_enabled()) |
| 529 error = kErrorDisabled; | 539 error = kErrorDisabled; |
| 540 else | |
| 541 error = kErrorNoService; | |
| 530 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); | 542 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); |
| 531 return; | 543 return; |
| 532 } | 544 } |
| 533 | 545 |
| 534 // Start monitoring network property changes. | 546 // Start monitoring network property changes. |
| 535 lib->AddNetworkManagerObserver(this); | 547 lib->AddNetworkManagerObserver(this); |
| 536 lib->RemoveObserverForAllNetworks(this); | 548 lib->RemoveObserverForAllNetworks(this); |
| 537 lib->AddNetworkObserver(network->service_path(), this); | 549 lib->AddNetworkObserver(network->service_path(), this); |
| 538 // Try to start with OTASP immediately if we have received payment recently. | 550 // Try to start with OTASP immediately if we have received payment recently. |
| 539 state_ = lib->HasRecentCellularPlanPayment() ? | 551 state_ = lib->HasRecentCellularPlanPayment() ? |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 } | 1013 } |
| 1002 return "UNKNOWN"; | 1014 return "UNKNOWN"; |
| 1003 } | 1015 } |
| 1004 | 1016 |
| 1005 | 1017 |
| 1006 void MobileSetupHandler::CompleteActivation( | 1018 void MobileSetupHandler::CompleteActivation( |
| 1007 chromeos::CellularNetwork* network) { | 1019 chromeos::CellularNetwork* network) { |
| 1008 // Remove observers, we are done with this page. | 1020 // Remove observers, we are done with this page. |
| 1009 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 1021 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 1010 GetNetworkLibrary(); | 1022 GetNetworkLibrary(); |
| 1023 lib->Unlock(); | |
|
Charlie Lee
2011/01/20 20:05:43
same here. move this below remove network manager
zel
2011/01/20 22:06:14
Done.
| |
| 1011 // If we have successfully activated the connection, set autoconnect flag. | 1024 // If we have successfully activated the connection, set autoconnect flag. |
| 1012 if (network) { | 1025 if (network) { |
| 1013 network->set_auto_connect(true); | 1026 network->set_auto_connect(true); |
| 1014 lib->SaveCellularNetwork(network); | 1027 lib->SaveCellularNetwork(network); |
| 1015 } | 1028 } |
| 1016 lib->RemoveNetworkManagerObserver(this); | 1029 lib->RemoveNetworkManagerObserver(this); |
| 1017 lib->RemoveObserverForAllNetworks(this); | 1030 lib->RemoveObserverForAllNetworks(this); |
| 1018 // Reactivate other types of connections if we have | 1031 // Reactivate other types of connections if we have |
| 1019 // shut them down previously. | 1032 // shut them down previously. |
| 1020 ReEnableOtherConnections(); | 1033 ReEnableOtherConnections(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 reenable_cert_check_ = true; | 1169 reenable_cert_check_ = true; |
| 1157 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); | 1170 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); |
| 1158 } | 1171 } |
| 1159 | 1172 |
| 1160 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 1173 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 1161 GetNetworkLibrary(); | 1174 GetNetworkLibrary(); |
| 1162 // Disable autoconnect to cellular network. | 1175 // Disable autoconnect to cellular network. |
| 1163 network->set_auto_connect(false); | 1176 network->set_auto_connect(false); |
| 1164 lib->SaveCellularNetwork(network); | 1177 lib->SaveCellularNetwork(network); |
| 1165 | 1178 |
| 1179 // Prevent any other network interference. | |
| 1166 DisableOtherNetworks(); | 1180 DisableOtherNetworks(); |
| 1181 lib->Lock(); | |
| 1167 } | 1182 } |
| 1168 | 1183 |
| 1169 void MobileSetupHandler::DisableOtherNetworks() { | 1184 void MobileSetupHandler::DisableOtherNetworks() { |
| 1170 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 1185 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 1171 GetNetworkLibrary(); | 1186 GetNetworkLibrary(); |
| 1172 // Disable ethernet and wifi. | 1187 // Disable ethernet and wifi. |
| 1173 if (lib->ethernet_enabled()) { | 1188 if (lib->ethernet_enabled()) { |
| 1174 reenable_ethernet_ = true; | 1189 reenable_ethernet_ = true; |
| 1175 lib->EnableEthernetNetworkDevice(false); | 1190 lib->EnableEthernetNetworkDevice(false); |
| 1176 } | 1191 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1278 new MobileSetupUIHTMLSource(service_path); | 1293 new MobileSetupUIHTMLSource(service_path); |
| 1279 | 1294 |
| 1280 // Set up the chrome://mobilesetup/ source. | 1295 // Set up the chrome://mobilesetup/ source. |
| 1281 BrowserThread::PostTask( | 1296 BrowserThread::PostTask( |
| 1282 BrowserThread::IO, FROM_HERE, | 1297 BrowserThread::IO, FROM_HERE, |
| 1283 NewRunnableMethod( | 1298 NewRunnableMethod( |
| 1284 ChromeURLDataManager::GetInstance(), | 1299 ChromeURLDataManager::GetInstance(), |
| 1285 &ChromeURLDataManager::AddDataSource, | 1300 &ChromeURLDataManager::AddDataSource, |
| 1286 make_scoped_refptr(html_source))); | 1301 make_scoped_refptr(html_source))); |
| 1287 } | 1302 } |
| OLD | NEW |