Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(940)

Side by Side Diff: chrome/browser/chromeos/mobile/mobile_activator.cc

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

Powered by Google App Engine
This is Rietveld 408576698