Chromium Code Reviews| 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 |
| 11 #include "ash/system/chromeos/network/network_connect.h" | 11 #include "ash/system/chromeos/network/network_connect.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 16 #include "base/location.h" | |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
| 18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 19 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 20 #include "base/observer_list_threadsafe.h" | 21 #include "base/observer_list_threadsafe.h" |
| 21 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
| 22 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
| 23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/timer/timer.h" | 26 #include "base/timer/timer.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/chromeos/cros/network_library.h" | |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chromeos/network/device_state.h" | |
| 31 #include "chromeos/network/network_activation_handler.h" | |
| 32 #include "chromeos/network/network_configuration_handler.h" | |
| 33 #include "chromeos/network/network_connection_handler.h" | |
| 34 #include "chromeos/network/network_event_log.h" | |
| 35 #include "chromeos/network/network_handler_callbacks.h" | |
| 36 #include "chromeos/network/network_state.h" | |
| 37 #include "chromeos/network/network_state_handler.h" | |
| 30 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 39 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 31 | 40 |
| 32 using content::BrowserThread; | 41 using content::BrowserThread; |
| 33 | 42 |
| 34 namespace { | 43 namespace { |
| 35 | 44 |
| 36 // Cellular configuration file path. | 45 // Cellular configuration file path. |
| 37 const char kCellularConfigPath[] = | 46 const char kCellularConfigPath[] = |
| 38 "/usr/share/chromeos-assets/mobile/mobile_config.json"; | 47 "/usr/share/chromeos-assets/mobile/mobile_config.json"; |
| 39 | 48 |
| 40 // Cellular config file field names. | 49 // Cellular config file field names. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 //////////////////////////////////////////////////////////////////////////////// | 153 //////////////////////////////////////////////////////////////////////////////// |
| 145 // | 154 // |
| 146 // MobileActivator | 155 // MobileActivator |
| 147 // | 156 // |
| 148 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
| 149 MobileActivator::MobileActivator() | 158 MobileActivator::MobileActivator() |
| 150 : cellular_config_(new CellularConfigDocument()), | 159 : cellular_config_(new CellularConfigDocument()), |
| 151 state_(PLAN_ACTIVATION_PAGE_LOADING), | 160 state_(PLAN_ACTIVATION_PAGE_LOADING), |
| 152 reenable_cert_check_(false), | 161 reenable_cert_check_(false), |
| 153 terminated_(true), | 162 terminated_(true), |
| 163 pending_activation_request_(false), | |
| 154 connection_retry_count_(0), | 164 connection_retry_count_(0), |
| 155 payment_reconnect_count_(0) { | 165 payment_reconnect_count_(0) { |
| 156 } | 166 } |
| 157 | 167 |
| 158 MobileActivator::~MobileActivator() { | 168 MobileActivator::~MobileActivator() { |
| 159 TerminateActivation(); | 169 TerminateActivation(); |
| 160 } | 170 } |
| 161 | 171 |
| 162 MobileActivator* MobileActivator::GetInstance() { | 172 MobileActivator* MobileActivator::GetInstance() { |
| 163 return Singleton<MobileActivator>::get(); | 173 return Singleton<MobileActivator>::get(); |
| 164 } | 174 } |
| 165 | 175 |
| 166 void MobileActivator::TerminateActivation() { | 176 void MobileActivator::TerminateActivation() { |
| 167 // We're exiting; don't continue with termination. | |
| 168 if (!NetworkLibrary::Get()) | |
| 169 return; | |
| 170 | |
| 171 state_duration_timer_.Stop(); | 177 state_duration_timer_.Stop(); |
| 172 continue_reconnect_timer_.Stop(); | 178 continue_reconnect_timer_.Stop(); |
| 173 reconnect_timeout_timer_.Stop(); | 179 reconnect_timeout_timer_.Stop(); |
| 174 | 180 |
| 175 NetworkLibrary* lib = GetNetworkLibrary(); | 181 if (NetworkHandler::IsInitialized()) |
| 176 lib->RemoveNetworkManagerObserver(this); | 182 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 177 lib->RemoveObserverForAllNetworks(this); | 183 FROM_HERE); |
| 178 ReEnableCertRevocationChecking(); | 184 ReEnableCertRevocationChecking(); |
| 179 meid_.clear(); | 185 meid_.clear(); |
| 180 iccid_.clear(); | 186 iccid_.clear(); |
| 181 service_path_.clear(); | 187 service_path_.clear(); |
| 182 state_ = PLAN_ACTIVATION_PAGE_LOADING; | 188 state_ = PLAN_ACTIVATION_PAGE_LOADING; |
| 183 reenable_cert_check_ = false; | 189 reenable_cert_check_ = false; |
| 184 terminated_ = true; | 190 terminated_ = true; |
| 185 // Release the previous cellular config and setup a new empty one. | 191 // Release the previous cellular config and setup a new empty one. |
| 186 cellular_config_ = new CellularConfigDocument(); | 192 cellular_config_ = new CellularConfigDocument(); |
| 187 } | 193 } |
| 188 | 194 |
| 189 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { | 195 void MobileActivator::DefaultNetworkChanged(const NetworkState* network) { |
| 190 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || | 196 RefreshCellularNetworks(); |
| 191 state_ == PLAN_ACTIVATION_DONE || | 197 } |
| 192 state_ == PLAN_ACTIVATION_ERROR) { | 198 |
| 199 void MobileActivator::NetworkPropertiesUpdated(const NetworkState* network) { | |
| 200 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | |
| 193 return; | 201 return; |
| 194 } | |
| 195 | 202 |
| 196 CellularNetwork* network = FindMatchingCellularNetwork(true); | 203 if (!network || network->type() != flimflam::kTypeCellular) |
| 197 if (network && network->activate_over_non_cellular_network()) { | 204 return; |
| 198 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); | 205 if (network->path() != service_path_) { |
| 199 bool is_online = | 206 LOG(WARNING) << "Ignoring property update for unknown cellular service " |
| 200 cros->connected_network() && cros->connected_network()->online(); | 207 << network->path() << " (Expected " << service_path_<< ")"; |
| 201 if (waiting && is_online) { | 208 return; |
| 202 ChangeState(network, post_reconnect_state_, ""); | |
| 203 } else if (!waiting && !is_online) { | |
| 204 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); | |
| 205 } | |
| 206 } | 209 } |
| 207 | 210 |
| 208 EvaluateCellularNetwork(network); | 211 EvaluateCellularNetwork(network); |
| 209 } | 212 } |
| 210 | 213 |
| 211 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, | |
| 212 const Network* network) { | |
| 213 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | |
| 214 return; | |
| 215 | |
| 216 if (!network || network->type() != TYPE_CELLULAR) { | |
| 217 NOTREACHED(); | |
| 218 return; | |
| 219 } | |
| 220 | |
| 221 EvaluateCellularNetwork( | |
| 222 static_cast<CellularNetwork*>(const_cast<Network*>(network))); | |
| 223 } | |
| 224 | |
| 225 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { | 214 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { |
| 226 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 215 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 227 observers_.AddObserver(observer); | 216 observers_.AddObserver(observer); |
| 228 } | 217 } |
| 229 | 218 |
| 230 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { | 219 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { |
| 231 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 220 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 232 observers_.RemoveObserver(observer); | 221 observers_.RemoveObserver(observer); |
| 233 } | 222 } |
| 234 | 223 |
| 235 void MobileActivator::InitiateActivation(const std::string& service_path) { | 224 void MobileActivator::InitiateActivation(const std::string& service_path) { |
| 236 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 225 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 237 NetworkLibrary* lib = GetNetworkLibrary(); | 226 const NetworkState* network = GetNetworkState(service_path); |
| 238 CellularNetwork* network = lib->FindCellularNetworkByPath(service_path); | |
| 239 if (!network) { | 227 if (!network) { |
| 240 LOG(ERROR) << "Cellular service can't be found: " << service_path; | 228 LOG(ERROR) << "Cellular service can't be found: " << service_path; |
| 241 return; | 229 return; |
| 242 } | 230 } |
| 243 | 231 |
| 244 const chromeos::NetworkDevice* device = | 232 const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> |
| 245 lib->FindNetworkDeviceByPath(network->device_path()); | 233 GetDeviceState(network->device_path()); |
| 246 if (!device) { | 234 if (!device) { |
| 247 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); | 235 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); |
| 248 return; | 236 return; |
| 249 } | 237 } |
| 250 | 238 |
| 251 terminated_ = false; | 239 terminated_ = false; |
| 252 meid_ = device->meid(); | 240 meid_ = device->meid(); |
| 253 iccid_ = device->iccid(); | 241 iccid_ = device->iccid(); |
| 254 service_path_ = service_path; | 242 service_path_ = service_path; |
| 255 | 243 |
| 256 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); | 244 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); |
| 257 | 245 |
| 258 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 246 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 259 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, | 247 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, |
| 260 cellular_config_.get()), | 248 cellular_config_.get()), |
| 261 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); | 249 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); |
| 262 } | 250 } |
| 263 | 251 |
| 264 void MobileActivator::ContinueActivation() { | 252 void MobileActivator::ContinueActivation() { |
| 265 CellularNetwork* network = FindMatchingCellularNetwork(false); | 253 const NetworkState* network = GetNetworkState(service_path_); |
| 266 if (!network || !network->SupportsActivation()) | 254 if (!network || |
| 255 (network->payment_url().empty() && network->usage_url().empty())) | |
| 267 return; | 256 return; |
| 268 | 257 |
| 269 DisableCertRevocationChecking(); | 258 DisableCertRevocationChecking(); |
| 270 // We want shill to connect us after activations. | |
| 271 network->SetAutoConnect(true); | |
| 272 | 259 |
| 260 // We want shill to connect us after activations, so enable autoconnect. | |
| 261 DictionaryValue auto_connect_property; | |
| 262 auto_connect_property.SetBoolean(flimflam::kAutoConnectProperty, true); | |
| 263 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | |
| 264 network->path(), | |
| 265 auto_connect_property, | |
| 266 base::Bind(&base::DoNothing), | |
| 267 network_handler::ErrorCallback()); | |
| 273 StartActivation(); | 268 StartActivation(); |
| 274 } | 269 } |
| 275 | 270 |
| 276 void MobileActivator::OnSetTransactionStatus(bool success) { | 271 void MobileActivator::OnSetTransactionStatus(bool success) { |
| 277 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 272 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 278 base::Bind(&MobileActivator::HandleSetTransactionStatus, | 273 base::Bind(&MobileActivator::HandleSetTransactionStatus, |
| 279 AsWeakPtr(), success)); | 274 AsWeakPtr(), success)); |
| 280 } | 275 } |
| 281 | 276 |
| 282 void MobileActivator::HandleSetTransactionStatus(bool success) { | 277 void MobileActivator::HandleSetTransactionStatus(bool success) { |
| 283 // The payment is received, try to reconnect and check the status all over | 278 // The payment is received, try to reconnect and check the status all over |
| 284 // again. | 279 // again. |
| 285 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 280 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
| 286 NetworkLibrary* lib = GetNetworkLibrary(); | 281 SignalCellularPlanPayment(); |
| 287 lib->SignalCellularPlanPayment(); | |
| 288 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); | 282 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); |
| 289 CellularNetwork* network = FindMatchingCellularNetwork(true); | 283 const NetworkState* network = |
| 290 if (network && network->activate_over_non_cellular_network()) { | 284 NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
| 285 service_path_); | |
|
stevenjb
2013/08/23 00:10:55
GetNetworkState()?
gauravsh
2013/08/27 22:58:12
Done.
| |
| 286 if (network && network->activate_over_non_cellular_networks()) { | |
| 291 state_ = PLAN_ACTIVATION_DONE; | 287 state_ = PLAN_ACTIVATION_DONE; |
| 292 network->CompleteActivation(); | 288 NetworkHandler::Get()->network_activation_handler()-> |
| 289 CompleteActivation(network->path(), | |
| 290 base::Bind(&base::DoNothing), | |
| 291 network_handler::ErrorCallback()); | |
| 293 } else { | 292 } else { |
| 294 StartOTASP(); | 293 StartOTASP(); |
| 295 } | 294 } |
| 296 } else { | 295 } else { |
| 297 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); | 296 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); |
| 298 } | 297 } |
| 299 } | 298 } |
| 300 | 299 |
| 301 void MobileActivator::OnPortalLoaded(bool success) { | 300 void MobileActivator::OnPortalLoaded(bool success) { |
| 302 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 301 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 303 base::Bind(&MobileActivator::HandlePortalLoaded, | 302 base::Bind(&MobileActivator::HandlePortalLoaded, |
| 304 AsWeakPtr(), success)); | 303 AsWeakPtr(), success)); |
| 305 } | 304 } |
| 306 | 305 |
| 307 void MobileActivator::HandlePortalLoaded(bool success) { | 306 void MobileActivator::HandlePortalLoaded(bool success) { |
| 308 CellularNetwork* network = FindMatchingCellularNetwork(true); | 307 const NetworkState* network = GetNetworkState(service_path_); |
| 309 if (!network) { | 308 if (!network) { |
| 310 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 309 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
| 311 GetErrorMessage(kErrorNoService)); | 310 GetErrorMessage(kErrorNoService)); |
| 312 return; | 311 return; |
| 313 } | 312 } |
| 314 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || | 313 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || |
| 315 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 314 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
| 316 if (success) { | 315 if (success) { |
| 317 payment_reconnect_count_ = 0; | 316 payment_reconnect_count_ = 0; |
| 318 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); | 317 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); |
| 319 } else { | 318 } else { |
| 320 // There is no point in forcing reconnecting the cellular network if the | 319 // There is no point in forcing reconnecting the cellular network if the |
| 321 // activation should not be done over it. | 320 // activation should not be done over it. |
| 322 if (network->activate_over_non_cellular_network()) | 321 if (network->activate_over_non_cellular_networks()) |
| 323 return; | 322 return; |
| 324 | 323 |
| 325 payment_reconnect_count_++; | 324 payment_reconnect_count_++; |
| 326 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { | 325 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { |
| 327 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 326 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
| 328 GetErrorMessage(kErrorNoService)); | 327 GetErrorMessage(kErrorNoService)); |
| 329 return; | 328 return; |
| 330 } | 329 } |
| 331 | 330 |
| 332 // Reconnect and try and load the frame again. | 331 // Reconnect and try and load the frame again. |
| 333 ChangeState(network, | 332 ChangeState(network, |
| 334 PLAN_ACTIVATION_RECONNECTING, | 333 PLAN_ACTIVATION_RECONNECTING, |
| 335 GetErrorMessage(kFailedPaymentError)); | 334 GetErrorMessage(kFailedPaymentError)); |
| 336 } | 335 } |
| 337 } else { | 336 } else { |
| 338 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " | 337 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " |
| 339 << GetStateDescription(state_); | 338 << GetStateDescription(state_); |
| 340 } | 339 } |
| 341 } | 340 } |
| 342 | 341 |
| 343 CellularNetwork* MobileActivator::FindMatchingCellularNetwork( | |
| 344 bool reattach_observer) { | |
| 345 NetworkLibrary* lib = GetNetworkLibrary(); | |
| 346 for (CellularNetworkVector::const_iterator it = | |
| 347 lib->cellular_networks().begin(); | |
| 348 it != lib->cellular_networks().end(); ++it) { | |
| 349 const chromeos::NetworkDevice* device = | |
| 350 lib->FindNetworkDeviceByPath((*it)->device_path()); | |
| 351 if (device && ((!meid_.empty() && meid_ == device->meid()) || | |
| 352 (!iccid_.empty() && iccid_ == device->iccid()))) { | |
| 353 CellularNetwork* network = *it; | |
| 354 // If service path has changed, reattach the event observer for this | |
| 355 // network service. | |
| 356 if (reattach_observer && service_path_ != network->service_path()) { | |
| 357 lib->RemoveObserverForAllNetworks(this); | |
| 358 lib->AddNetworkObserver(network->service_path(), this); | |
| 359 service_path_ = network->service_path(); | |
| 360 } | |
| 361 return network; | |
| 362 } | |
| 363 } | |
| 364 return NULL; | |
| 365 } | |
| 366 | |
| 367 void MobileActivator::StartOTASPTimer() { | 342 void MobileActivator::StartOTASPTimer() { |
| 343 pending_activation_request_ = false; | |
| 368 state_duration_timer_.Start( | 344 state_duration_timer_.Start( |
| 369 FROM_HERE, | 345 FROM_HERE, |
| 370 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay), | 346 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay), |
| 371 this, &MobileActivator::HandleOTASPTimeout); | 347 this, &MobileActivator::HandleOTASPTimeout); |
| 372 } | 348 } |
| 373 | 349 |
| 374 void MobileActivator::StartActivation() { | 350 void MobileActivator::StartActivation() { |
| 375 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); | 351 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); |
| 376 NetworkLibrary* lib = GetNetworkLibrary(); | 352 const NetworkState* network = GetNetworkState(service_path_); |
| 377 CellularNetwork* network = FindMatchingCellularNetwork(true); | |
| 378 // Check if we can start activation process. | 353 // Check if we can start activation process. |
| 379 if (!network) { | 354 if (!network) { |
| 355 NetworkStateHandler::TechnologyState technology_state = | |
| 356 NetworkHandler::Get()->network_state_handler()->GetTechnologyState( | |
| 357 flimflam::kTypeCellular); | |
| 380 std::string error; | 358 std::string error; |
| 381 if (!lib->cellular_available()) | 359 if (technology_state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { |
| 382 error = kErrorNoDevice; | 360 error = kErrorNoDevice; |
| 383 else if (!lib->cellular_enabled()) | 361 } else if (technology_state !=NetworkStateHandler::TECHNOLOGY_ENABLED) { |
| 384 error = kErrorDisabled; | 362 error = kErrorDisabled; |
| 385 else | 363 } else { |
| 386 error = kErrorNoService; | 364 error = kErrorNoService; |
| 365 } | |
| 387 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); | 366 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); |
| 388 return; | 367 return; |
| 389 } | 368 } |
| 390 | 369 |
| 391 // Start monitoring network property changes. | 370 // Start monitoring network property changes. |
| 392 lib->AddNetworkManagerObserver(this); | 371 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
| 393 if (network->activate_over_non_cellular_network()) { | 372 if (network->activate_over_non_cellular_networks()) { |
| 394 // Fast forward to payment portal loading if the activation is performed | 373 // Fast forward to payment portal loading if the activation is performed |
| 395 // over a non-cellular network. | 374 // over a non-cellular network. |
| 396 ChangeState(network, | 375 ChangeState( |
| 397 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? | 376 network, |
| 398 PLAN_ACTIVATION_DONE : | 377 (network->activation_state() == flimflam::kActivationStateActivated) ? |
| 399 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, | 378 PLAN_ACTIVATION_DONE : |
| 400 ""); | 379 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, |
| 380 ""); | |
| 401 // Verify that there is no need to wait for the connection. This will also | 381 // Verify that there is no need to wait for the connection. This will also |
| 402 // evaluate the network. | 382 // evaluate the network. |
| 403 OnNetworkManagerChanged(lib); | 383 RefreshCellularNetworks(); |
| 404 return; | 384 return; |
| 405 } | 385 } |
| 406 | 386 |
| 407 if (lib->HasRecentCellularPlanPayment() && | 387 if (HasRecentCellularPlanPayment() && |
| 408 network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 388 (network->activation_state() == |
| 389 flimflam::kActivationStatePartiallyActivated)) { | |
| 409 // Try to start with OTASP immediately if we have received payment recently. | 390 // Try to start with OTASP immediately if we have received payment recently. |
| 410 state_ = PLAN_ACTIVATION_START_OTASP; | 391 state_ = PLAN_ACTIVATION_START_OTASP; |
| 411 } else { | 392 } else { |
| 412 state_ = PLAN_ACTIVATION_START; | 393 state_ = PLAN_ACTIVATION_START; |
| 413 } | 394 } |
| 414 | 395 |
| 415 EvaluateCellularNetwork(network); | 396 EvaluateCellularNetwork(network); |
| 416 } | 397 } |
| 417 | 398 |
| 418 void MobileActivator::RetryOTASP() { | 399 void MobileActivator::RetryOTASP() { |
| 419 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); | 400 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); |
| 420 StartOTASP(); | 401 StartOTASP(); |
| 421 } | 402 } |
| 422 | 403 |
| 423 void MobileActivator::StartOTASP() { | 404 void MobileActivator::StartOTASP() { |
| 424 CellularNetwork* network = FindMatchingCellularNetwork(true); | 405 const NetworkState* network = GetNetworkState(service_path_); |
| 425 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); | 406 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); |
| 426 EvaluateCellularNetwork(network); | 407 EvaluateCellularNetwork(network); |
| 427 } | 408 } |
| 428 | 409 |
| 429 void MobileActivator::HandleOTASPTimeout() { | 410 void MobileActivator::HandleOTASPTimeout() { |
| 430 LOG(WARNING) << "OTASP seems to be taking too long."; | 411 LOG(WARNING) << "OTASP seems to be taking too long."; |
| 431 CellularNetwork* network = FindMatchingCellularNetwork(true); | 412 const NetworkState* network = GetNetworkState(service_path_); |
| 432 // We're here because one of OTASP steps is taking too long to complete. | 413 // We're here because one of OTASP steps is taking too long to complete. |
| 433 // Usually, this means something bad has happened below us. | 414 // Usually, this means something bad has happened below us. |
| 434 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { | 415 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { |
| 435 ++initial_OTASP_attempts_; | 416 ++initial_OTASP_attempts_; |
| 436 if (initial_OTASP_attempts_ <= kMaxOTASPTries) { | 417 if (initial_OTASP_attempts_ <= kMaxOTASPTries) { |
| 437 ChangeState(network, | 418 ChangeState(network, |
| 438 PLAN_ACTIVATION_RECONNECTING, | 419 PLAN_ACTIVATION_RECONNECTING, |
| 439 GetErrorMessage(kErrorDefault)); | 420 GetErrorMessage(kErrorDefault)); |
| 440 return; | 421 return; |
| 441 } | 422 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 458 } | 439 } |
| 459 } else { | 440 } else { |
| 460 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?"; | 441 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?"; |
| 461 } | 442 } |
| 462 LOG(ERROR) << "OTASP failed too many times; aborting."; | 443 LOG(ERROR) << "OTASP failed too many times; aborting."; |
| 463 ChangeState(network, | 444 ChangeState(network, |
| 464 PLAN_ACTIVATION_ERROR, | 445 PLAN_ACTIVATION_ERROR, |
| 465 GetErrorMessage(kErrorDefault)); | 446 GetErrorMessage(kErrorDefault)); |
| 466 } | 447 } |
| 467 | 448 |
| 468 void MobileActivator::ForceReconnect(CellularNetwork* network, | 449 void MobileActivator::ForceReconnect(const NetworkState* network, |
| 469 PlanActivationState next_state) { | 450 PlanActivationState next_state) { |
| 470 DCHECK(network); | 451 DCHECK(network); |
| 471 // Store away our next destination for when we complete. | 452 // Store away our next destination for when we complete. |
| 472 post_reconnect_state_ = next_state; | 453 post_reconnect_state_ = next_state; |
| 473 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); | 454 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); |
| 474 // First, disconnect... | 455 // First, disconnect... |
| 475 LOG(INFO) << "Disconnecting from " << network->service_path(); | 456 LOG(INFO) << "Disconnecting from " << network->path(); |
| 476 // Explicit service Disconnect()s disable autoconnect on the service until | 457 // Explicit service Disconnect()s disable autoconnect on the service until |
| 477 // Connect() is called on the service again. Hence this dance to explicitly | 458 // Connect() is called on the service again. Hence this dance to explicitly |
| 478 // call Connect(). | 459 // call Connect(). |
| 479 GetNetworkLibrary()->DisconnectFromNetwork(network); | 460 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
| 461 network->path(), | |
| 462 base::Bind(&base::DoNothing), | |
| 463 network_handler::ErrorCallback()); | |
| 480 // Keep trying to connect until told otherwise. | 464 // Keep trying to connect until told otherwise. |
| 481 continue_reconnect_timer_.Stop(); | 465 continue_reconnect_timer_.Stop(); |
| 482 continue_reconnect_timer_.Start( | 466 continue_reconnect_timer_.Start( |
| 483 FROM_HERE, | 467 FROM_HERE, |
| 484 base::TimeDelta::FromMilliseconds(kReconnectDelayMS), | 468 base::TimeDelta::FromMilliseconds(kReconnectDelayMS), |
| 485 this, &MobileActivator::ContinueConnecting); | 469 this, &MobileActivator::ContinueConnecting); |
| 486 // If we don't ever connect again, we're going to call this a failure. | 470 // If we don't ever connect again, we're going to call this a failure. |
| 487 reconnect_timeout_timer_.Stop(); | 471 reconnect_timeout_timer_.Stop(); |
| 488 reconnect_timeout_timer_.Start( | 472 reconnect_timeout_timer_.Start( |
| 489 FROM_HERE, | 473 FROM_HERE, |
| 490 base::TimeDelta::FromMilliseconds(kMaxReconnectTime), | 474 base::TimeDelta::FromMilliseconds(kMaxReconnectTime), |
| 491 this, &MobileActivator::ReconnectTimedOut); | 475 this, &MobileActivator::ReconnectTimedOut); |
| 492 } | 476 } |
| 493 | 477 |
| 494 void MobileActivator::ReconnectTimedOut() { | 478 void MobileActivator::ReconnectTimedOut() { |
| 495 LOG(ERROR) << "Ending activation attempt after failing to reconnect."; | 479 LOG(ERROR) << "Ending activation attempt after failing to reconnect."; |
| 496 ChangeState(FindMatchingCellularNetwork(true), | 480 const NetworkState* network = GetNetworkState(service_path_); |
| 481 ChangeState(network, | |
| 497 PLAN_ACTIVATION_ERROR, | 482 PLAN_ACTIVATION_ERROR, |
| 498 GetErrorMessage(kFailedConnectivity)); | 483 GetErrorMessage(kFailedConnectivity)); |
| 499 } | 484 } |
| 500 | 485 |
| 501 void MobileActivator::ContinueConnecting() { | 486 void MobileActivator::ContinueConnecting() { |
| 502 CellularNetwork* network = FindMatchingCellularNetwork(true); | 487 const NetworkState* network = GetNetworkState(service_path_); |
| 503 if (network && network->connected()) { | 488 if (network && network->IsConnectedState()) { |
| 504 if (network->restricted_pool() && | 489 if (network->connection_state() == flimflam::kStatePortal && |
| 505 network->error() == ERROR_DNS_LOOKUP_FAILED) { | 490 network->error() == flimflam::kErrorDNSLookupFailed) { |
| 506 // It isn't an error to be in a restricted pool, but if DNS doesn't work, | 491 // It isn't an error to be in a restricted pool, but if DNS doesn't work, |
| 507 // then we're not getting traffic through at all. Just disconnect and | 492 // then we're not getting traffic through at all. Just disconnect and |
| 508 // try again. | 493 // try again. |
| 509 GetNetworkLibrary()->DisconnectFromNetwork(network); | 494 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
| 495 network->path(), | |
| 496 base::Bind(&base::DoNothing), | |
| 497 network_handler::ErrorCallback()); | |
| 510 return; | 498 return; |
| 511 } | 499 } |
| 512 // Stop this callback | 500 // Stop this callback |
| 513 continue_reconnect_timer_.Stop(); | 501 continue_reconnect_timer_.Stop(); |
| 514 EvaluateCellularNetwork(network); | 502 EvaluateCellularNetwork(network); |
| 515 } else { | 503 } else { |
| 516 LOG(WARNING) << "Connect failed, will try again in a little bit."; | 504 LOG(WARNING) << "Connect failed, will try again in a little bit."; |
| 517 if (network) { | 505 if (network) { |
| 518 LOG(INFO) << "Connecting to: " << network->service_path(); | 506 LOG(INFO) << "Connecting to: " << network->path(); |
| 519 ash::network_connect::ConnectToNetwork( | 507 ash::network_connect::ConnectToNetwork( |
| 520 network->service_path(), NULL /* no parent window */); | 508 network->path(), NULL /* no parent window */); |
| 521 } | 509 } |
| 522 } | 510 } |
| 523 } | 511 } |
| 524 | 512 |
| 525 void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { | 513 void MobileActivator::RefreshCellularNetworks() { |
| 514 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || | |
| 515 state_ == PLAN_ACTIVATION_DONE || | |
| 516 state_ == PLAN_ACTIVATION_ERROR) { | |
| 517 return; | |
| 518 } | |
| 519 | |
| 520 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); | |
| 521 const NetworkState* network = GetNetworkState(service_path_); | |
| 522 if (network && network->activate_over_non_cellular_networks()) { | |
| 523 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); | |
| 524 bool is_online = nsh->DefaultNetwork() && | |
| 525 nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline; | |
| 526 if (waiting && is_online) { | |
| 527 ChangeState(network, post_reconnect_state_, ""); | |
| 528 } else if (!waiting && !is_online) { | |
| 529 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); | |
| 530 } | |
| 531 } | |
| 532 | |
| 533 EvaluateCellularNetwork(network); | |
| 534 } | |
| 535 | |
| 536 const NetworkState*MobileActivator::GetNetworkState( | |
| 537 const std::string& service_path) { | |
|
stevenjb
2013/08/23 00:10:55
I think this is always called with service_path_,
gauravsh
2013/08/27 22:58:12
Not in 2 cases which matter for the unit tests - I
| |
| 538 return NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
| 539 service_path); | |
| 540 } | |
| 541 | |
| 542 void MobileActivator::EvaluateCellularNetwork(const NetworkState* network) { | |
| 526 if (terminated_) { | 543 if (terminated_) { |
| 527 LOG(ERROR) << "Tried to run MobileActivator state machine while " | 544 LOG(ERROR) << "Tried to run MobileActivator state machine while " |
| 528 << "terminated."; | 545 << "terminated."; |
| 529 return; | 546 return; |
| 530 } | 547 } |
| 531 | 548 |
| 532 if (!network) { | 549 if (!network) { |
| 533 LOG(WARNING) << "Cellular service lost"; | 550 LOG(WARNING) << "Cellular service lost"; |
| 534 return; | 551 return; |
| 535 } | 552 } |
| 536 | 553 |
| 537 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString() | 554 LOG(WARNING) << "Cellular:\n service state=" << network->connection_state() |
| 538 << "\n ui=" << GetStateDescription(state_) | 555 << "\n ui=" << GetStateDescription(state_) |
| 539 << "\n activation=" << network->GetActivationStateString() | 556 << "\n activation=" << network->activation_state() |
| 540 << "\n error=" << network->GetErrorString() | 557 << "\n error=" << network->error() |
| 541 << "\n setvice_path=" << network->service_path() | 558 << "\n setvice_path=" << network->path() |
| 542 << "\n connected=" << network->connected(); | 559 << "\n connected=" << network->IsConnectedState(); |
| 543 | 560 |
| 544 // If the network is activated over non cellular network, the activator state | 561 // If the network is activated over non cellular network, the activator state |
| 545 // does not depend on the network's own state. | 562 // does not depend on the network's own state. |
| 546 if (network->activate_over_non_cellular_network()) | 563 if (network->activate_over_non_cellular_networks()) |
| 547 return; | 564 return; |
| 548 | 565 |
| 549 std::string error_description; | 566 std::string error_description; |
| 550 PlanActivationState new_state = PickNextState(network, &error_description); | 567 PlanActivationState new_state = PickNextState(network, &error_description); |
| 551 | 568 |
| 552 ChangeState(network, new_state, error_description); | 569 ChangeState(network, new_state, error_description); |
| 553 } | 570 } |
| 554 | 571 |
| 555 MobileActivator::PlanActivationState MobileActivator::PickNextState( | 572 MobileActivator::PlanActivationState MobileActivator::PickNextState( |
| 556 CellularNetwork* network, std::string* error_description) const { | 573 const NetworkState* network, std::string* error_description) const { |
| 557 PlanActivationState new_state = state_; | 574 PlanActivationState new_state = state_; |
| 558 if (!network->connected()) | 575 if (!network->IsConnectedState()) |
| 559 new_state = PickNextOfflineState(network); | 576 new_state = PickNextOfflineState(network); |
| 560 else | 577 else |
| 561 new_state = PickNextOnlineState(network); | 578 new_state = PickNextOnlineState(network); |
| 562 if (new_state != PLAN_ACTIVATION_ERROR && | 579 if (new_state != PLAN_ACTIVATION_ERROR && |
| 563 GotActivationError(network, error_description)) { | 580 GotActivationError(network, error_description)) { |
| 564 // Check for this special case when we try to do activate partially | 581 // Check for this special case when we try to do activate partially |
| 565 // activated device. If that attempt failed, try to disconnect to clear the | 582 // activated device. If that attempt failed, try to disconnect to clear the |
| 566 // state and reconnect again. | 583 // state and reconnect again. |
| 567 if ((network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED || | 584 const std::string& activation = network->activation_state(); |
| 568 network->activation_state() == ACTIVATION_STATE_ACTIVATING) && | 585 bool is_partially_activated = |
| 569 (network->error() == ERROR_NO_ERROR || | 586 activation == flimflam::kActivationStatePartiallyActivated || |
| 570 network->error() == ERROR_OTASP_FAILED) && | 587 activation == flimflam::kActivationStateActivating; |
| 571 network->state() == STATE_ACTIVATION_FAILURE) { | 588 if (is_partially_activated && |
| 572 LOG(WARNING) << "Activation failure detected " | 589 (network->error().empty() || |
| 573 << network->service_path(); | 590 network->error() == flimflam::kErrorOtaspFailed) && |
| 591 network->connection_state() == flimflam::kStateActivationFailure) { | |
| 592 LOG(WARNING) << "Activation failure detected " << network->path(); | |
| 574 switch (state_) { | 593 switch (state_) { |
| 575 case PLAN_ACTIVATION_OTASP: | 594 case PLAN_ACTIVATION_OTASP: |
| 576 new_state = PLAN_ACTIVATION_DELAY_OTASP; | 595 new_state = PLAN_ACTIVATION_DELAY_OTASP; |
| 577 break; | 596 break; |
| 578 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 597 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 579 case PLAN_ACTIVATION_TRYING_OTASP: | 598 case PLAN_ACTIVATION_TRYING_OTASP: |
| 580 new_state = PLAN_ACTIVATION_START; | 599 new_state = PLAN_ACTIVATION_START; |
| 581 break; | 600 break; |
| 582 case PLAN_ACTIVATION_START: | 601 case PLAN_ACTIVATION_START: |
| 583 // We are just starting, so this must be previous activation attempt | 602 // We are just starting, so this must be previous activation attempt |
| 584 // failure. | 603 // failure. |
| 585 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 604 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
| 586 break; | 605 break; |
| 587 case PLAN_ACTIVATION_DELAY_OTASP: | 606 case PLAN_ACTIVATION_DELAY_OTASP: |
| 588 new_state = state_; | 607 new_state = state_; |
| 589 break; | 608 break; |
| 590 default: | 609 default: |
| 591 new_state = PLAN_ACTIVATION_ERROR; | 610 new_state = PLAN_ACTIVATION_ERROR; |
| 592 break; | 611 break; |
| 593 } | 612 } |
| 594 } else { | 613 } else { |
| 595 LOG(WARNING) << "Unexpected activation failure for " | 614 LOG(WARNING) << "Unexpected activation failure for " << network->path(); |
| 596 << network->service_path(); | |
| 597 new_state = PLAN_ACTIVATION_ERROR; | 615 new_state = PLAN_ACTIVATION_ERROR; |
| 598 } | 616 } |
| 599 } | 617 } |
| 600 | 618 |
| 601 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length()) | 619 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length()) |
| 602 *error_description = GetErrorMessage(kErrorDefault); | 620 *error_description = GetErrorMessage(kErrorDefault); |
| 603 return new_state; | 621 return new_state; |
| 604 } | 622 } |
| 605 | 623 |
| 606 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( | 624 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( |
| 607 CellularNetwork* network) const { | 625 const NetworkState* network) const { |
| 608 PlanActivationState new_state = state_; | 626 PlanActivationState new_state = state_; |
| 627 const std::string& activation = network->activation_state(); | |
| 609 switch (state_) { | 628 switch (state_) { |
| 610 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 629 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| 611 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 630 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 612 if (!network->activate_over_non_cellular_network()) | 631 if (!network->activate_over_non_cellular_networks()) |
| 613 new_state = PLAN_ACTIVATION_RECONNECTING; | 632 new_state = PLAN_ACTIVATION_RECONNECTING; |
| 614 break; | 633 break; |
| 615 case PLAN_ACTIVATION_START: | 634 case PLAN_ACTIVATION_START: |
| 616 switch (network->activation_state()) { | 635 if (activation == flimflam::kActivationStateActivated) { |
| 617 case ACTIVATION_STATE_ACTIVATED: | 636 if (network->connection_state() == flimflam::kStatePortal) |
| 618 if (network->restricted_pool()) | 637 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 619 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 638 else |
| 620 else | 639 new_state = PLAN_ACTIVATION_DONE; |
| 621 new_state = PLAN_ACTIVATION_DONE; | 640 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
| 622 break; | 641 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
| 623 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 642 } else { |
| 624 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 643 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
| 625 break; | |
| 626 default: | |
| 627 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | |
| 628 break; | |
| 629 } | 644 } |
| 630 break; | 645 break; |
| 631 default: { | 646 default: |
| 632 LOG(INFO) << "Waiting for cellular service to connect."; | 647 LOG(INFO) << "Waiting for cellular service to connect."; |
| 633 } break; | 648 break; |
| 634 } | 649 } |
| 635 return new_state; | 650 return new_state; |
| 636 } | 651 } |
| 637 | 652 |
| 638 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( | 653 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( |
| 639 CellularNetwork* network) const { | 654 const NetworkState* network) const { |
| 640 PlanActivationState new_state = state_; | 655 PlanActivationState new_state = state_; |
| 656 const std::string& activation = network->activation_state(); | |
| 641 switch (state_) { | 657 switch (state_) { |
| 642 case PLAN_ACTIVATION_START: | 658 case PLAN_ACTIVATION_START: |
| 643 switch (network->activation_state()) { | 659 if (activation == flimflam::kActivationStateActivated) { |
| 644 case ACTIVATION_STATE_ACTIVATED: | 660 if (network->connection_state() == flimflam::kStatePortal) |
| 645 if (network->restricted_pool()) | 661 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 646 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 662 else |
| 647 else | 663 new_state = PLAN_ACTIVATION_DONE; |
| 648 new_state = PLAN_ACTIVATION_DONE; | 664 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
| 649 break; | 665 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
| 650 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 666 } else { |
| 651 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 667 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
| 652 break; | |
| 653 default: | |
| 654 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | |
| 655 break; | |
| 656 } | 668 } |
| 657 break; | 669 break; |
| 658 case PLAN_ACTIVATION_START_OTASP: { | 670 case PLAN_ACTIVATION_START_OTASP: { |
| 659 switch (network->activation_state()) { | 671 if (activation == flimflam::kActivationStatePartiallyActivated) { |
| 660 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | |
| 661 new_state = PLAN_ACTIVATION_OTASP; | 672 new_state = PLAN_ACTIVATION_OTASP; |
| 662 break; | 673 } else if (activation == flimflam::kActivationStateActivated) { |
| 663 case ACTIVATION_STATE_ACTIVATED: | 674 new_state = PLAN_ACTIVATION_RECONNECTING; |
| 664 new_state = PLAN_ACTIVATION_RECONNECTING; | 675 } else { |
| 665 break; | 676 LOG(WARNING) << "Unexpected activation state for device " |
| 666 default: { | 677 << network->path(); |
| 667 LOG(WARNING) << "Unexpected activation state for device " | |
| 668 << network->service_path(); | |
| 669 break; | |
| 670 } | |
| 671 } | 678 } |
| 672 break; | 679 break; |
| 673 } | 680 } |
| 674 case PLAN_ACTIVATION_DELAY_OTASP: | 681 case PLAN_ACTIVATION_DELAY_OTASP: |
| 675 // Just ignore any changes until the OTASP retry timer kicks in. | 682 // Just ignore any changes until the OTASP retry timer kicks in. |
| 676 break; | 683 break; |
| 677 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { | 684 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { |
| 678 switch (network->activation_state()) { | 685 if (activation == flimflam::kActivationStateActivated || |
| 679 case ACTIVATION_STATE_ACTIVATED: | 686 activation == flimflam::kActivationStatePartiallyActivated) { |
| 680 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 687 new_state = PLAN_ACTIVATION_START; |
| 681 new_state = PLAN_ACTIVATION_START; | 688 } else if (activation == flimflam::kActivationStateNotActivated || |
| 682 break; | 689 activation == flimflam::kActivationStateActivating) { |
| 683 case ACTIVATION_STATE_NOT_ACTIVATED: | 690 // Wait in this state until activation state changes. |
| 684 case ACTIVATION_STATE_ACTIVATING: | 691 } else { |
| 685 // Wait in this state until activation state changes. | 692 LOG(WARNING) << "Unknown transition"; |
| 686 break; | |
| 687 default: | |
| 688 LOG(WARNING) << "Unknown transition"; | |
| 689 break; | |
| 690 } | 693 } |
| 691 break; | 694 break; |
| 692 } | 695 } |
| 693 case PLAN_ACTIVATION_OTASP: | 696 case PLAN_ACTIVATION_OTASP: |
| 694 case PLAN_ACTIVATION_TRYING_OTASP: | 697 case PLAN_ACTIVATION_TRYING_OTASP: |
| 695 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED || | 698 if (pending_activation_request_) { |
| 696 network->activation_state() == ACTIVATION_STATE_ACTIVATING) { | 699 LOG(INFO) << "Waiting for pending activation attempt to finish"; |
| 700 } | |
| 701 else if (activation == flimflam::kActivationStateNotActivated || | |
|
stevenjb
2013/08/23 00:10:55
} else
gauravsh
2013/08/27 22:58:12
Done.
| |
| 702 activation == flimflam::kActivationStateActivating) { | |
| 697 LOG(INFO) << "Waiting for the OTASP to finish and the service to " | 703 LOG(INFO) << "Waiting for the OTASP to finish and the service to " |
| 698 << "come back online"; | 704 << "come back online"; |
| 699 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { | 705 } else if (activation == flimflam::kActivationStateActivated) { |
| 700 new_state = PLAN_ACTIVATION_DONE; | 706 new_state = PLAN_ACTIVATION_DONE; |
| 701 } else { | 707 } else { |
| 702 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 708 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 703 } | 709 } |
| 704 break; | 710 break; |
| 705 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 711 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
| 706 if (!network->restricted_pool() && | 712 if (network->connection_state() != flimflam::kStatePortal && |
| 707 network->activation_state() == ACTIVATION_STATE_ACTIVATED) | 713 activation == flimflam::kActivationStateActivated) |
| 708 // We're not portalled, and we're already activated, so we're online! | 714 // We're not portalled, and we're already activated, so we're online! |
| 709 new_state = PLAN_ACTIVATION_DONE; | 715 new_state = PLAN_ACTIVATION_DONE; |
| 710 else | 716 else |
| 711 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 717 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 712 break; | 718 break; |
| 713 // Initial state | 719 // Initial state |
| 714 case PLAN_ACTIVATION_PAGE_LOADING: | 720 case PLAN_ACTIVATION_PAGE_LOADING: |
| 715 break; | 721 break; |
| 716 // Just ignore all signals until the site confirms payment. | 722 // Just ignore all signals until the site confirms payment. |
| 717 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 723 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 return "ERROR"; | 766 return "ERROR"; |
| 761 case PLAN_ACTIVATION_RECONNECTING: | 767 case PLAN_ACTIVATION_RECONNECTING: |
| 762 return "RECONNECTING"; | 768 return "RECONNECTING"; |
| 763 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: | 769 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
| 764 return "WAITING FOR CONNECTION"; | 770 return "WAITING FOR CONNECTION"; |
| 765 } | 771 } |
| 766 return "UNKNOWN"; | 772 return "UNKNOWN"; |
| 767 } | 773 } |
| 768 | 774 |
| 769 | 775 |
| 770 void MobileActivator::CompleteActivation( | 776 void MobileActivator::CompleteActivation(const NetworkState* network) { |
| 771 CellularNetwork* network) { | |
| 772 // Remove observers, we are done with this page. | 777 // Remove observers, we are done with this page. |
| 773 NetworkLibrary* lib = GetNetworkLibrary(); | 778 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| 774 lib->RemoveNetworkManagerObserver(this); | 779 this, FROM_HERE); |
| 775 lib->RemoveObserverForAllNetworks(this); | 780 |
| 776 // Reactivate other types of connections if we have | 781 // Reactivate other types of connections if we have |
| 777 // shut them down previously. | 782 // shut them down previously. |
| 778 ReEnableCertRevocationChecking(); | 783 ReEnableCertRevocationChecking(); |
| 779 } | 784 } |
| 780 | 785 |
| 781 bool MobileActivator::RunningActivation() const { | 786 bool MobileActivator::RunningActivation() const { |
| 782 return !(state_ == PLAN_ACTIVATION_DONE || | 787 return !(state_ == PLAN_ACTIVATION_DONE || |
| 783 state_ == PLAN_ACTIVATION_ERROR || | 788 state_ == PLAN_ACTIVATION_ERROR || |
| 784 state_ == PLAN_ACTIVATION_PAGE_LOADING); | 789 state_ == PLAN_ACTIVATION_PAGE_LOADING); |
| 785 } | 790 } |
| 786 | 791 |
| 787 void MobileActivator::ChangeState(CellularNetwork* network, | 792 void MobileActivator::HandleActivationFailure( |
| 793 const std::string& service_path, | |
| 794 PlanActivationState new_state, | |
| 795 const std::string& error_name, | |
| 796 scoped_ptr<base::DictionaryValue> error_data) { | |
| 797 pending_activation_request_ = false; | |
| 798 const NetworkState* network = GetNetworkState(service_path); | |
|
stevenjb
2013/08/23 00:10:55
This can probably use NSH->GetNetworkState()?
gauravsh
2013/08/27 22:58:12
This gets used in the test.
| |
| 799 if (!network) { | |
| 800 NET_LOG_ERROR("Cellular service no longer exists", service_path); | |
| 801 return; | |
| 802 } | |
| 803 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | |
| 804 NET_LOG_ERROR("Failed to call Activate() on service", service_path); | |
| 805 if (new_state == PLAN_ACTIVATION_OTASP) { | |
| 806 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); | |
| 807 } else { | |
| 808 ChangeState(network, | |
| 809 PLAN_ACTIVATION_ERROR, | |
| 810 GetErrorMessage(kFailedConnectivity)); | |
| 811 } | |
| 812 } | |
| 813 | |
| 814 void MobileActivator::RequestCellularActivation( | |
| 815 const NetworkState* network, | |
| 816 const base::Closure& success_callback, | |
| 817 const network_handler::ErrorCallback& error_callback) { | |
| 818 DCHECK(network); | |
| 819 NET_LOG_EVENT("Activating cellular service", network->path()); | |
| 820 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | |
| 821 pending_activation_request_ = true; | |
| 822 NetworkHandler::Get()->network_activation_handler()-> | |
| 823 Activate(network->path(), | |
| 824 "", // carrier | |
| 825 success_callback, | |
| 826 error_callback); | |
| 827 } | |
| 828 | |
| 829 void MobileActivator::ChangeState(const NetworkState* network, | |
| 788 PlanActivationState new_state, | 830 PlanActivationState new_state, |
| 789 const std::string& error_description) { | 831 const std::string& error_description) { |
| 790 static bool first_time = true; | 832 static bool first_time = true; |
| 791 LOG(INFO) << "Activation state flip old = " | 833 LOG(INFO) << "Activation state flip old = " |
| 792 << GetStateDescription(state_) | 834 << GetStateDescription(state_) |
| 793 << ", new = " << GetStateDescription(new_state); | 835 << ", new = " << GetStateDescription(new_state); |
| 794 if (state_ == new_state && !first_time) | 836 if (state_ == new_state && !first_time) |
| 795 return; | 837 return; |
| 796 first_time = false; | 838 first_time = false; |
| 797 LOG(INFO) << "Transitioning..."; | 839 LOG(INFO) << "Transitioning..."; |
| 798 | 840 |
| 799 // Kill all the possible timers and callbacks we might have outstanding. | 841 // Kill all the possible timers and callbacks we might have outstanding. |
| 800 state_duration_timer_.Stop(); | 842 state_duration_timer_.Stop(); |
| 801 continue_reconnect_timer_.Stop(); | 843 continue_reconnect_timer_.Stop(); |
| 802 reconnect_timeout_timer_.Stop(); | 844 reconnect_timeout_timer_.Stop(); |
| 803 const PlanActivationState old_state = state_; | 845 const PlanActivationState old_state = state_; |
| 804 state_ = new_state; | 846 state_ = new_state; |
| 805 | 847 |
| 806 // Signal to observers layer that the state is changing. | 848 // Signal to observers layer that the state is changing. |
| 807 FOR_EACH_OBSERVER(Observer, observers_, | 849 FOR_EACH_OBSERVER(Observer, observers_, |
| 808 OnActivationStateChanged(network, state_, error_description)); | 850 OnActivationStateChanged(network, state_, error_description)); |
| 809 | 851 |
| 852 network_handler::ErrorCallback on_activation_error = | |
| 853 base::Bind(&MobileActivator::HandleActivationFailure, AsWeakPtr(), | |
| 854 network->path(), | |
| 855 new_state); | |
| 810 // Pick action that should happen on entering the new state. | 856 // Pick action that should happen on entering the new state. |
| 811 switch (new_state) { | 857 switch (new_state) { |
| 812 case PLAN_ACTIVATION_START: | 858 case PLAN_ACTIVATION_START: |
| 813 break; | 859 break; |
| 814 case PLAN_ACTIVATION_DELAY_OTASP: { | 860 case PLAN_ACTIVATION_DELAY_OTASP: { |
| 815 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); | 861 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); |
| 816 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 862 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 817 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), | 863 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), |
| 818 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); | 864 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); |
| 819 break; | 865 break; |
| 820 } | 866 } |
| 821 case PLAN_ACTIVATION_START_OTASP: | 867 case PLAN_ACTIVATION_START_OTASP: |
| 822 break; | 868 break; |
| 823 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 869 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 824 case PLAN_ACTIVATION_TRYING_OTASP: | 870 case PLAN_ACTIVATION_TRYING_OTASP: |
| 825 case PLAN_ACTIVATION_OTASP: | 871 case PLAN_ACTIVATION_OTASP: |
| 826 DCHECK(network); | 872 RequestCellularActivation( |
| 827 LOG(WARNING) << "Activating service " << network->service_path(); | 873 network, |
| 828 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | 874 base::Bind(&MobileActivator::StartOTASPTimer, AsWeakPtr()), |
| 829 if (!network->StartActivation()) { | 875 on_activation_error); |
| 830 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | |
| 831 LOG(ERROR) << "Failed to call Activate() on service in shill."; | |
| 832 if (new_state == PLAN_ACTIVATION_OTASP) { | |
| 833 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); | |
| 834 } else { | |
| 835 ChangeState(network, | |
| 836 PLAN_ACTIVATION_ERROR, | |
| 837 GetErrorMessage(kFailedConnectivity)); | |
| 838 } | |
| 839 } else { | |
| 840 StartOTASPTimer(); | |
| 841 } | |
| 842 break; | 876 break; |
| 843 case PLAN_ACTIVATION_PAGE_LOADING: | 877 case PLAN_ACTIVATION_PAGE_LOADING: |
| 844 return; | 878 return; |
| 845 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 879 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| 846 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 880 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 847 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 881 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
| 848 // Fix for fix SSL for the walled gardens where cert chain verification | 882 // Fix for fix SSL for the walled gardens where cert chain verification |
| 849 // might not work. | 883 // might not work. |
| 850 break; | 884 break; |
| 851 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: | 885 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
| 852 post_reconnect_state_ = old_state; | 886 post_reconnect_state_ = old_state; |
| 853 break; | 887 break; |
| 854 case PLAN_ACTIVATION_RECONNECTING: { | 888 case PLAN_ACTIVATION_RECONNECTING: { |
| 855 PlanActivationState next_state = old_state; | 889 PlanActivationState next_state = old_state; |
| 856 // Pick where we want to return to after we reconnect. | 890 // Pick where we want to return to after we reconnect. |
| 857 switch (old_state) { | 891 switch (old_state) { |
| 858 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 892 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| 859 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 893 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 860 // We decide here what to do next based on the state of the modem. | 894 // We decide here what to do next based on the state of the modem. |
| 861 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; | 895 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; |
| 862 break; | 896 break; |
| 863 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 897 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 864 case PLAN_ACTIVATION_TRYING_OTASP: | 898 case PLAN_ACTIVATION_TRYING_OTASP: |
| 865 next_state = PLAN_ACTIVATION_START; | 899 next_state = PLAN_ACTIVATION_START; |
| 866 break; | 900 break; |
| 867 case PLAN_ACTIVATION_START_OTASP: | 901 case PLAN_ACTIVATION_START_OTASP: |
| 868 case PLAN_ACTIVATION_OTASP: | 902 case PLAN_ACTIVATION_OTASP: |
| 869 if (!network || !network->connected()) { | 903 if (!network || !network->IsConnectedState()) { |
| 870 next_state = PLAN_ACTIVATION_START_OTASP; | 904 next_state = PLAN_ACTIVATION_START_OTASP; |
| 871 } else { | 905 } else { |
| 872 // We're online, which means we've conspired with | 906 // We're online, which means we've conspired with |
| 873 // PickNextOnlineState to reconnect after activation (that's the | 907 // PickNextOnlineState to reconnect after activation (that's the |
| 874 // only way we see this transition). Thus, after we reconnect, we | 908 // only way we see this transition). Thus, after we reconnect, we |
| 875 // should be done. | 909 // should be done. |
| 876 next_state = PLAN_ACTIVATION_DONE; | 910 next_state = PLAN_ACTIVATION_DONE; |
| 877 } | 911 } |
| 878 break; | 912 break; |
| 879 default: | 913 default: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 PrefService* prefs = g_browser_process->local_state(); | 948 PrefService* prefs = g_browser_process->local_state(); |
| 915 if (!reenable_cert_check_ && | 949 if (!reenable_cert_check_ && |
| 916 prefs->GetBoolean( | 950 prefs->GetBoolean( |
| 917 prefs::kCertRevocationCheckingEnabled)) { | 951 prefs::kCertRevocationCheckingEnabled)) { |
| 918 reenable_cert_check_ = true; | 952 reenable_cert_check_ = true; |
| 919 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); | 953 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); |
| 920 } | 954 } |
| 921 } | 955 } |
| 922 | 956 |
| 923 bool MobileActivator::GotActivationError( | 957 bool MobileActivator::GotActivationError( |
| 924 CellularNetwork* network, std::string* error) const { | 958 const NetworkState* network, std::string* error) const { |
| 925 DCHECK(network); | 959 DCHECK(network); |
| 926 bool got_error = false; | 960 bool got_error = false; |
| 927 const char* error_code = kErrorDefault; | 961 const char* error_code = kErrorDefault; |
| 962 const std::string& activation = network->activation_state(); | |
| 928 | 963 |
| 929 // This is the magic for detection of errors in during activation process. | 964 // This is the magic for detection of errors in during activation process. |
| 930 if (network->state() == STATE_FAILURE && | 965 if (network->connection_state() == flimflam::kStateFailure && |
| 931 network->error() == ERROR_AAA_FAILED) { | 966 network->error() == flimflam::kErrorAaaFailed) { |
| 932 if (network->activation_state() == | 967 if (activation == flimflam::kActivationStatePartiallyActivated) { |
| 933 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | |
| 934 error_code = kErrorBadConnectionPartial; | 968 error_code = kErrorBadConnectionPartial; |
| 935 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { | 969 } else if (activation == flimflam::kActivationStateActivated) { |
| 936 if (network->roaming_state() == ROAMING_STATE_HOME) | 970 if (network->roaming() == flimflam::kRoamingStateHome) |
| 937 error_code = kErrorBadConnectionActivated; | 971 error_code = kErrorBadConnectionActivated; |
| 938 else if (network->roaming_state() == ROAMING_STATE_ROAMING) | 972 else if (network->roaming() == flimflam::kRoamingStateRoaming) |
| 939 error_code = kErrorRoamingOnConnection; | 973 error_code = kErrorRoamingOnConnection; |
| 940 } | 974 } |
| 941 got_error = true; | 975 got_error = true; |
| 942 } else if (network->state() == STATE_ACTIVATION_FAILURE) { | 976 } else if (network->connection_state() == flimflam::kStateActivationFailure) { |
| 943 if (network->error() == ERROR_NEED_EVDO) { | 977 if (network->error() == flimflam::kErrorNeedEvdo) { |
| 944 if (network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) | 978 if (activation == flimflam::kActivationStatePartiallyActivated) |
| 945 error_code = kErrorNoEVDO; | 979 error_code = kErrorNoEVDO; |
| 946 } else if (network->error() == ERROR_NEED_HOME_NETWORK) { | 980 } else if (network->error() == flimflam::kErrorNeedHomeNetwork) { |
| 947 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED) { | 981 if (activation == flimflam::kActivationStateNotActivated) { |
| 948 error_code = kErrorRoamingActivation; | 982 error_code = kErrorRoamingActivation; |
| 949 } else if (network->activation_state() == | 983 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
| 950 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | |
| 951 error_code = kErrorRoamingPartiallyActivated; | 984 error_code = kErrorRoamingPartiallyActivated; |
| 952 } | 985 } |
| 953 } | 986 } |
| 954 got_error = true; | 987 got_error = true; |
| 955 } | 988 } |
| 956 | 989 |
| 957 if (got_error) | 990 if (got_error) |
| 958 *error = GetErrorMessage(error_code); | 991 *error = GetErrorMessage(error_code); |
| 959 | 992 |
| 960 return got_error; | 993 return got_error; |
| 961 } | 994 } |
| 962 | 995 |
| 963 void MobileActivator::GetDeviceInfo(CellularNetwork* network, | 996 void MobileActivator::GetDeviceInfo(const NetworkState* network, |
| 964 DictionaryValue* value) { | 997 DictionaryValue* value) { |
| 965 DCHECK(network); | 998 DCHECK(network); |
| 966 NetworkLibrary* cros = NetworkLibrary::Get(); | |
| 967 if (!cros) | |
| 968 return; | |
| 969 value->SetString("carrier", network->name()); | 999 value->SetString("carrier", network->name()); |
| 970 value->SetString("payment_url", network->payment_url()); | 1000 value->SetString("payment_url", network->payment_url()); |
| 971 if (network->using_post() && network->post_data().length()) | 1001 if (network->post_method() == "post" && !network->post_data().empty()) |
| 972 value->SetString("post_data", network->post_data()); | 1002 value->SetString("post_data", network->post_data()); |
| 973 | 1003 |
| 974 const NetworkDevice* device = | 1004 const DeviceState* device = |
| 975 cros->FindNetworkDeviceByPath(network->device_path()); | 1005 NetworkHandler::Get()->network_state_handler()->GetDeviceState( |
| 1006 network->device_path()); | |
| 976 if (device) { | 1007 if (device) { |
| 977 value->SetString("MEID", device->meid()); | 1008 value->SetString("MEID", device->meid()); |
| 978 value->SetString("IMEI", device->imei()); | 1009 value->SetString("IMEI", device->imei()); |
| 979 value->SetString("MDN", device->mdn()); | 1010 value->SetString("MDN", device->mdn()); |
| 980 } | 1011 } |
| 981 } | 1012 } |
| 982 | 1013 |
| 983 std::string MobileActivator::GetErrorMessage(const std::string& code) const { | 1014 std::string MobileActivator::GetErrorMessage(const std::string& code) const { |
| 984 return cellular_config_->GetErrorMessage(code); | 1015 return cellular_config_->GetErrorMessage(code); |
| 985 } | 1016 } |
| 986 | 1017 |
| 987 NetworkLibrary* MobileActivator::GetNetworkLibrary() const { | 1018 void MobileActivator::SignalCellularPlanPayment() { |
| 988 return NetworkLibrary::Get(); | 1019 DCHECK(!HasRecentCellularPlanPayment()); |
| 1020 cellular_plan_payment_time_ = base::Time::Now(); | |
| 1021 } | |
| 1022 | |
| 1023 bool MobileActivator::HasRecentCellularPlanPayment() const { | |
| 1024 const int kRecentPlanPaymentHours = 6; | |
| 1025 return (base::Time::Now() - | |
| 1026 cellular_plan_payment_time_).InHours() < kRecentPlanPaymentHours; | |
| 989 } | 1027 } |
| 990 | 1028 |
| 991 } // namespace chromeos | 1029 } // namespace chromeos |
| OLD | NEW |