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

Side by Side Diff: chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc

Issue 5072001: Improved activation logic to cover few more edge cases. Removed button that w... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/resources/mobile_setup.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h" 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/callback.h" 13 #include "base/callback.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/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/metrics/histogram.h"
18 #include "base/string_piece.h" 19 #include "base/string_piece.h"
19 #include "base/string_util.h" 20 #include "base/string_util.h"
20 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "base/weak_ptr.h" 23 #include "base/weak_ptr.h"
23 #include "chrome/browser/browser.h" 24 #include "chrome/browser/browser.h"
24 #include "chrome/browser/browser_list.h" 25 #include "chrome/browser/browser_list.h"
25 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/browser_thread.h" 27 #include "chrome/browser/browser_thread.h"
27 #include "chrome/browser/chromeos/cros/cros_library.h" 28 #include "chrome/browser/chromeos/cros/cros_library.h"
28 #include "chrome/browser/chromeos/cros/network_library.h" 29 #include "chrome/browser/chromeos/cros/network_library.h"
29 #include "chrome/browser/chromeos/cros/system_library.h" 30 #include "chrome/browser/chromeos/cros/system_library.h"
30 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" 31 #include "chrome/browser/dom_ui/chrome_url_data_manager.h"
31 #include "chrome/browser/prefs/pref_service.h" 32 #include "chrome/browser/prefs/pref_service.h"
32 #include "chrome/browser/profile.h" 33 #include "chrome/browser/profile.h"
33 #include "chrome/browser/tab_contents/tab_contents.h" 34 #include "chrome/browser/tab_contents/tab_contents.h"
34 #include "chrome/common/jstemplate_builder.h" 35 #include "chrome/common/jstemplate_builder.h"
35 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "googleurl/src/gurl.h" 38 #include "googleurl/src/gurl.h"
38 #include "grit/browser_resources.h" 39 #include "grit/browser_resources.h"
39 #include "grit/chromium_strings.h" 40 #include "grit/chromium_strings.h"
40 #include "grit/generated_resources.h" 41 #include "grit/generated_resources.h"
41 #include "grit/locale_settings.h" 42 #include "grit/locale_settings.h"
42 43
43 namespace { 44 namespace {
44 45
45 // Host page JS API function names. 46 // Host page JS API function names.
46 const char kJsApiStartActivation[] = "startActivation"; 47 const char kJsApiStartActivation[] = "startActivation";
47 const char kJsApiCloseTab[] = "closeTab";
48 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; 48 const char kJsApiSetTransactionStatus[] = "setTransactionStatus";
49 49
50 const wchar_t kJsDeviceStatusChangedHandler[] = 50 const wchar_t kJsDeviceStatusChangedHandler[] =
51 L"mobile.MobileSetup.deviceStateChanged"; 51 L"mobile.MobileSetup.deviceStateChanged";
52 52
53 // Error codes matching codes defined in the cellular config file. 53 // Error codes matching codes defined in the cellular config file.
54 const char kErrorDefault[] = "default"; 54 const char kErrorDefault[] = "default";
55 const char kErrorBadConnectionPartial[] = "bad_connection_partial"; 55 const char kErrorBadConnectionPartial[] = "bad_connection_partial";
56 const char kErrorBadConnectionActivated[] = "bad_connection_activated"; 56 const char kErrorBadConnectionActivated[] = "bad_connection_activated";
57 const char kErrorRoamingOnConnection[] = "roaming_connection"; 57 const char kErrorRoamingOnConnection[] = "roaming_connection";
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (handler_) 175 if (handler_)
176 handler_->SetTransactionStatus(status_); 176 handler_->SetTransactionStatus(status_);
177 } 177 }
178 private: 178 private:
179 base::WeakPtr<MobileSetupHandler> handler_; 179 base::WeakPtr<MobileSetupHandler> handler_;
180 std::string status_; 180 std::string status_;
181 DISALLOW_COPY_AND_ASSIGN(TaskProxy); 181 DISALLOW_COPY_AND_ASSIGN(TaskProxy);
182 }; 182 };
183 183
184 // Handlers for JS DOMUI messages. 184 // Handlers for JS DOMUI messages.
185 void HandleCloseTab(const ListValue* args);
186 void HandleSetTransactionStatus(const ListValue* args); 185 void HandleSetTransactionStatus(const ListValue* args);
187 void HandleStartActivation(const ListValue* args); 186 void HandleStartActivation(const ListValue* args);
188 void SetTransactionStatus(const std::string& status); 187 void SetTransactionStatus(const std::string& status);
189 void StartActivation(); 188 void StartActivation();
190 189
191 // Sends message to host registration page with system/user info data. 190 // Sends message to host registration page with system/user info data.
192 void SendDeviceInfo(); 191 void SendDeviceInfo();
193 192
194 // Verify the state of cellular network and modify internal state. 193 // Verify the state of cellular network and modify internal state.
195 void EvaluateCellularNetwork(chromeos::CellularNetwork* network); 194 void EvaluateCellularNetwork(chromeos::CellularNetwork* network);
196 // Check the current cellular network for error conditions. 195 // Check the current cellular network for error conditions.
197 bool GotActivationError(const chromeos::CellularNetwork* network, 196 bool GotActivationError(const chromeos::CellularNetwork* network,
198 std::string* error); 197 std::string* error);
198 // Sends status updates to DOMUI page.
199 void UpdatePage(chromeos::CellularNetwork* network,
200 const std::string& error_description);
201 // Changes internal state.
199 void ChangeState(chromeos::CellularNetwork* network, 202 void ChangeState(chromeos::CellularNetwork* network,
200 PlanActivationState new_state, 203 PlanActivationState new_state,
201 const std::string& error_description); 204 const std::string& error_description);
202 // Prepares network devices for cellular activation process. 205 // Prepares network devices for cellular activation process.
203 void SetupActivationProcess(chromeos::CellularNetwork* network); 206 void SetupActivationProcess(chromeos::CellularNetwork* network);
204 // Resets network devices after cellular activation process. 207 // Resets network devices after cellular activation process.
205 // |network| should be NULL if the activation process failed. 208 // |network| should be NULL if the activation process failed.
206 void CompleteActivation(chromeos::CellularNetwork* network); 209 void CompleteActivation(chromeos::CellularNetwork* network);
207 // Control routines for handling other types of connections during 210 // Control routines for handling other types of connections during
208 // cellular activation. 211 // cellular activation.
(...skipping 23 matching lines...) Expand all
232 // Internal handler state. 235 // Internal handler state.
233 PlanActivationState state_; 236 PlanActivationState state_;
234 std::string service_path_; 237 std::string service_path_;
235 // Flags that control if wifi and ethernet connection needs to be restored 238 // Flags that control if wifi and ethernet connection needs to be restored
236 // after the activation of cellular network. 239 // after the activation of cellular network.
237 bool reenable_wifi_; 240 bool reenable_wifi_;
238 bool reenable_ethernet_; 241 bool reenable_ethernet_;
239 bool reenable_cert_check_; 242 bool reenable_cert_check_;
240 bool transaction_complete_signalled_; 243 bool transaction_complete_signalled_;
241 bool activation_status_test_; 244 bool activation_status_test_;
245 bool evaluating_;
242 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); 246 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
243 }; 247 };
244 248
245 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; 249 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_;
246 250
247 //////////////////////////////////////////////////////////////////////////////// 251 ////////////////////////////////////////////////////////////////////////////////
248 // 252 //
249 // CellularConfigDocument 253 // CellularConfigDocument
250 // 254 //
251 //////////////////////////////////////////////////////////////////////////////// 255 ////////////////////////////////////////////////////////////////////////////////
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // 349 //
346 //////////////////////////////////////////////////////////////////////////////// 350 ////////////////////////////////////////////////////////////////////////////////
347 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) 351 MobileSetupHandler::MobileSetupHandler(const std::string& service_path)
348 : tab_contents_(NULL), 352 : tab_contents_(NULL),
349 state_(PLAN_ACTIVATION_PAGE_LOADING), 353 state_(PLAN_ACTIVATION_PAGE_LOADING),
350 service_path_(service_path), 354 service_path_(service_path),
351 reenable_wifi_(false), 355 reenable_wifi_(false),
352 reenable_ethernet_(false), 356 reenable_ethernet_(false),
353 reenable_cert_check_(false), 357 reenable_cert_check_(false),
354 transaction_complete_signalled_(false), 358 transaction_complete_signalled_(false),
355 activation_status_test_(false) { 359 activation_status_test_(false),
360 evaluating_(false) {
356 } 361 }
357 362
358 MobileSetupHandler::~MobileSetupHandler() { 363 MobileSetupHandler::~MobileSetupHandler() {
359 chromeos::NetworkLibrary* lib = 364 chromeos::NetworkLibrary* lib =
360 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 365 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
361 lib->RemoveNetworkManagerObserver(this); 366 lib->RemoveNetworkManagerObserver(this);
362 lib->RemoveObserverForAllNetworks(this); 367 lib->RemoveObserverForAllNetworks(this);
363 ReEnableOtherConnections(); 368 ReEnableOtherConnections();
364 } 369 }
365 370
366 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { 371 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) {
367 return DOMMessageHandler::Attach(dom_ui); 372 return DOMMessageHandler::Attach(dom_ui);
368 } 373 }
369 374
370 void MobileSetupHandler::Init(TabContents* contents) { 375 void MobileSetupHandler::Init(TabContents* contents) {
371 tab_contents_ = contents; 376 tab_contents_ = contents;
372 LoadCellularConfig(); 377 LoadCellularConfig();
373 SetupActivationProcess(GetCellularNetwork(service_path_)); 378 SetupActivationProcess(GetCellularNetwork(service_path_));
374 } 379 }
375 380
376 void MobileSetupHandler::RegisterMessages() { 381 void MobileSetupHandler::RegisterMessages() {
377 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, 382 dom_ui_->RegisterMessageCallback(kJsApiStartActivation,
378 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); 383 NewCallback(this, &MobileSetupHandler::HandleStartActivation));
379 dom_ui_->RegisterMessageCallback(kJsApiCloseTab,
380 NewCallback(this, &MobileSetupHandler::HandleCloseTab));
381 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, 384 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus,
382 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); 385 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus));
383 } 386 }
384 387
385 void MobileSetupHandler::OnNetworkManagerChanged( 388 void MobileSetupHandler::OnNetworkManagerChanged(
386 chromeos::NetworkLibrary* cros) { 389 chromeos::NetworkLibrary* cros) {
387 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) 390 if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
388 return; 391 return;
389 // Note that even though we get here when the service has 392 // Note that even though we get here when the service has
390 // reappeared after disappearing earlier in the activation 393 // reappeared after disappearing earlier in the activation
391 // process, there's no need to re-establish the NetworkObserver, 394 // process, there's no need to re-establish the NetworkObserver,
392 // because the service path remains the same. 395 // because the service path remains the same.
393 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); 396 EvaluateCellularNetwork(GetCellularNetwork(service_path_));
394 } 397 }
395 398
396 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros, 399 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros,
397 const chromeos::Network* network) { 400 const chromeos::Network* network) {
398 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) 401 if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
399 return; 402 return;
400 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR); 403 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR);
401 EvaluateCellularNetwork( 404 EvaluateCellularNetwork(
402 static_cast<chromeos::CellularNetwork*>( 405 static_cast<chromeos::CellularNetwork*>(
403 const_cast<chromeos::Network*>(network))); 406 const_cast<chromeos::Network*>(network)));
404 } 407 }
405 408
406 void MobileSetupHandler::HandleCloseTab(const ListValue* args) {
407 if (!dom_ui_)
408 return;
409 Browser* browser = BrowserList::FindBrowserWithFeature(
410 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP);
411 if (browser)
412 browser->CloseTabContents(tab_contents_);
413 }
414
415 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { 409 void MobileSetupHandler::HandleStartActivation(const ListValue* args) {
416 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr()); 410 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr());
417 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 411 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
418 NewRunnableMethod(task.get(), &TaskProxy::HandleStartActivation)); 412 NewRunnableMethod(task.get(), &TaskProxy::HandleStartActivation));
413 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1);
419 } 414 }
420 415
421 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { 416 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) {
422 const size_t kSetTransactionStatusParamCount = 1; 417 const size_t kSetTransactionStatusParamCount = 1;
423 if (args->GetSize() != kSetTransactionStatusParamCount) 418 if (args->GetSize() != kSetTransactionStatusParamCount)
424 return; 419 return;
425 // Get change callback function name. 420 // Get change callback function name.
426 std::string status; 421 std::string status;
427 if (!args->GetString(0, &status)) 422 if (!args->GetString(0, &status))
428 return; 423 return;
(...skipping 18 matching lines...) Expand all
447 state_ = PLAN_ACTIVATION_START; 442 state_ = PLAN_ACTIVATION_START;
448 EvaluateCellularNetwork(network); 443 EvaluateCellularNetwork(network);
449 } 444 }
450 445
451 void MobileSetupHandler::SetTransactionStatus(const std::string& status) { 446 void MobileSetupHandler::SetTransactionStatus(const std::string& status) {
452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
453 // The payment is received, try to reconnect and check the status all over 448 // The payment is received, try to reconnect and check the status all over
454 // again. 449 // again.
455 if (LowerCaseEqualsASCII(status, "ok") && 450 if (LowerCaseEqualsASCII(status, "ok") &&
456 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { 451 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) {
452 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1);
457 if (transaction_complete_signalled_) { 453 if (transaction_complete_signalled_) {
458 LOG(WARNING) << "Transaction completion signaled more than once!?"; 454 LOG(WARNING) << "Transaction completion signaled more than once!?";
459 return; 455 return;
460 } 456 }
461 transaction_complete_signalled_ = true; 457 transaction_complete_signalled_ = true;
462 activation_status_test_ = false; 458 activation_status_test_ = false;
463 state_ = PLAN_ACTIVATION_START; 459 state_ = PLAN_ACTIVATION_START;
464 chromeos::CellularNetwork* network = GetCellularNetwork(); 460 chromeos::CellularNetwork* network = GetCellularNetwork();
465 if (network && 461 if (network &&
466 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED) { 462 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED) {
467 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 463 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
468 DisconnectFromWirelessNetwork(network); 464 DisconnectFromWirelessNetwork(network);
469 } else { 465 } else {
470 EvaluateCellularNetwork(network); 466 EvaluateCellularNetwork(network);
471 } 467 }
468 } else {
469 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1);
472 } 470 }
473 } 471 }
474 472
475 void MobileSetupHandler::EvaluateCellularNetwork( 473 void MobileSetupHandler::EvaluateCellularNetwork(
476 chromeos::CellularNetwork* network) { 474 chromeos::CellularNetwork* network) {
477 if (!dom_ui_) 475 if (!dom_ui_)
478 return; 476 return;
479 477
480 PlanActivationState new_state = state_; 478 PlanActivationState new_state = state_;
481 if (!network) { 479 if (!network) {
482 LOG(WARNING) << "Cellular service lost"; 480 LOG(WARNING) << "Cellular service lost";
483 return; 481 return;
484 } 482 }
485 483
484 // Prevent this method from being called if it is already on the stack.
485 // This might happen on some state transitions (ie. connect, disconnect).
486 if (evaluating_)
487 return;
488 evaluating_ = true;
489
486 LOG(INFO) << "Cellular:\n service=" << network->GetStateString().c_str() 490 LOG(INFO) << "Cellular:\n service=" << network->GetStateString().c_str()
487 << "\n ui=" << GetStateDescription(state_) 491 << "\n ui=" << GetStateDescription(state_)
488 << "\n activation=" << network->GetActivationStateString().c_str() 492 << "\n activation=" << network->GetActivationStateString().c_str()
489 << "\n restricted=" << (network->restricted_pool() ? "yes" : "no") 493 << "\n restricted=" << (network->restricted_pool() ? "yes" : "no")
490 << "\n error=" << network->GetErrorString().c_str() 494 << "\n error=" << network->GetErrorString().c_str()
491 << "\n setvice_path=" << network->service_path().c_str(); 495 << "\n setvice_path=" << network->service_path().c_str();
492 switch (state_) { 496 switch (state_) {
493 case PLAN_ACTIVATION_START: { 497 case PLAN_ACTIVATION_START: {
494 switch (network->activation_state()) { 498 switch (network->activation_state()) {
495 case chromeos::ACTIVATION_STATE_ACTIVATED: { 499 case chromeos::ACTIVATION_STATE_ACTIVATED: {
496 if (network->failed_or_disconnected()) { 500 if (network->failed_or_disconnected()) {
497 new_state = PLAN_ACTIVATION_RECONNECTING; 501 new_state = PLAN_ACTIVATION_RECONNECTING;
498 } else if (network->connection_state() == chromeos::STATE_READY) { 502 } else if (network->connected()) {
499 if (network->restricted_pool()) { 503 if (network->restricted_pool()) {
500 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 504 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
501 } else { 505 } else {
502 new_state = PLAN_ACTIVATION_DONE; 506 new_state = PLAN_ACTIVATION_DONE;
503 } 507 }
504 } 508 }
505 break; 509 break;
506 } 510 }
507 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: { 511 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: {
508 if (!activation_status_test_) { 512 if (!activation_status_test_) {
509 if (network->failed_or_disconnected()) { 513 if (network->failed_or_disconnected()) {
510 activation_status_test_ = true; 514 activation_status_test_ = true;
511 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; 515 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
512 } else if (network->connected()) { 516 } else if (network->connected()) {
513 LOG(INFO) << "Disconnecting from " << 517 LOG(INFO) << "Disconnecting from " <<
514 network->service_path().c_str(); 518 network->service_path().c_str();
515 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 519 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
516 DisconnectFromWirelessNetwork(network); 520 DisconnectFromWirelessNetwork(network);
517 // Disconnect will force networks to be reevaluated, so 521 // Disconnect will force networks to be reevaluated, so
518 // we don't want to continue processing on this path anymore. 522 // we don't want to continue processing on this path anymore.
523 evaluating_ = false;
519 return; 524 return;
520 } 525 }
521 } else { 526 } else {
522 if (network->connected()) 527 if (network->connected()) {
523 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 528 if (network->restricted_pool())
524 else 529 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
530 } else {
525 new_state = PLAN_ACTIVATION_RECONNECTING; 531 new_state = PLAN_ACTIVATION_RECONNECTING;
532 }
526 break; 533 break;
527 } 534 }
528 break; 535 break;
529 } 536 }
530 case chromeos::ACTIVATION_STATE_UNKNOWN: 537 case chromeos::ACTIVATION_STATE_UNKNOWN:
531 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: { 538 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: {
532 if (network->failed_or_disconnected()) { 539 if (network->failed_or_disconnected()) {
533 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; 540 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
534 } else if (network->connected()) { 541 } else if (network->connected()) {
535 LOG(INFO) << "Disconnecting from " << 542 LOG(INFO) << "Disconnecting from " <<
536 network->service_path().c_str(); 543 network->service_path().c_str();
537 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 544 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
538 DisconnectFromWirelessNetwork(network); 545 DisconnectFromWirelessNetwork(network);
539 // Disconnect will force networks to be reevaluated, so 546 // Disconnect will force networks to be reevaluated, so
540 // we don't want to continue processing on this path anymore. 547 // we don't want to continue processing on this path anymore.
548 evaluating_ = false;
541 return; 549 return;
542 } 550 }
543 break; 551 break;
544 } 552 }
545 default: { 553 default:
546 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
547 break; 554 break;
548 }
549 } 555 }
550 break; 556 break;
551 } 557 }
552 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { 558 case PLAN_ACTIVATION_INITIATING_ACTIVATION: {
553 switch (network->activation_state()) { 559 switch (network->activation_state()) {
554 case chromeos::ACTIVATION_STATE_ACTIVATED: 560 case chromeos::ACTIVATION_STATE_ACTIVATED:
555 if (network->failed_or_disconnected()) { 561 if (network->failed_or_disconnected()) {
556 new_state = PLAN_ACTIVATION_RECONNECTING; 562 new_state = PLAN_ACTIVATION_RECONNECTING;
557 } else if (network->connection_state() == chromeos::STATE_READY) { 563 } else if (network->connected()) {
558 if (network->restricted_pool()) { 564 if (network->restricted_pool()) {
559 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 565 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
560 } else { 566 } else {
561 new_state = PLAN_ACTIVATION_DONE; 567 new_state = PLAN_ACTIVATION_DONE;
562 } 568 }
563 } 569 }
564 break; 570 break;
565 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: 571 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
566 if (network->connected()) 572 if (network->connected()) {
567 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 573 if (network->restricted_pool())
568 else 574 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
575 } else {
569 new_state = PLAN_ACTIVATION_RECONNECTING; 576 new_state = PLAN_ACTIVATION_RECONNECTING;
577 }
570 break; 578 break;
571 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: 579 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED:
572 // Wait in this state until activation state changes. 580 // Wait in this state until activation state changes.
573 break; 581 break;
574 case chromeos::ACTIVATION_STATE_ACTIVATING: 582 case chromeos::ACTIVATION_STATE_ACTIVATING:
575 break; 583 break;
576 default: 584 default:
577 break; 585 break;
578 } 586 }
579 break; 587 break;
580 } 588 }
581 case PLAN_ACTIVATION_RECONNECTING: { 589 case PLAN_ACTIVATION_RECONNECTING: {
582 // Wait until the service shows up and gets activated. 590 // Wait until the service shows up and gets activated.
583 switch (network->activation_state()) { 591 switch (network->activation_state()) {
584 case chromeos::ACTIVATION_STATE_ACTIVATED: 592 case chromeos::ACTIVATION_STATE_ACTIVATED:
585 if (network->connection_state() == chromeos::STATE_READY) { 593 if (network->connected()) {
586 if (network->restricted_pool()) { 594 if (network->restricted_pool()) {
587 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 595 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
588 } else { 596 } else {
589 new_state = PLAN_ACTIVATION_DONE; 597 new_state = PLAN_ACTIVATION_DONE;
590 } 598 }
599 } else if (network->failed()) {
600 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
601 ConnectToCellularNetwork(network);
602 evaluating_ = false;
603 return;
591 } 604 }
592 break; 605 break;
593 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: 606 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
594 if (network->connected()) { 607 if (network->connected()) {
595 if (network->restricted_pool()) 608 if (network->restricted_pool())
596 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 609 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
597 } 610 }
598 break; 611 break;
599 default: 612 default:
600 break; 613 break;
(...skipping 11 matching lines...) Expand all
612 } 625 }
613 626
614 std::string error_description; 627 std::string error_description;
615 if (GotActivationError(network, &error_description)) { 628 if (GotActivationError(network, &error_description)) {
616 // Check for this special case when we try to do activate partially 629 // Check for this special case when we try to do activate partially
617 // activated device. If that attempt failed, try to disconnect to clear the 630 // activated device. If that attempt failed, try to disconnect to clear the
618 // state and reconnect again. 631 // state and reconnect again.
619 if ((network->activation_state() == 632 if ((network->activation_state() ==
620 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED || 633 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED ||
621 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) && 634 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) &&
622 network->error() == chromeos::ERROR_UNKNOWN && 635 (network->error() == chromeos::ERROR_UNKNOWN ||
636 network->error() == chromeos::ERROR_OTASP_FAILED)&&
623 (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION || 637 (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION ||
624 state_ == PLAN_ACTIVATION_RECONNECTING) && 638 state_ == PLAN_ACTIVATION_RECONNECTING) &&
625 activation_status_test_ && 639 activation_status_test_ &&
626 network->connection_state() == chromeos::STATE_ACTIVATION_FAILURE) { 640 network->connection_state() == chromeos::STATE_ACTIVATION_FAILURE) {
627 new_state = PLAN_ACTIVATION_RECONNECTING; 641 new_state = PLAN_ACTIVATION_RECONNECTING;
628 } else { 642 } else {
629 new_state = PLAN_ACTIVATION_ERROR; 643 new_state = PLAN_ACTIVATION_ERROR;
630 } 644 }
631 } 645 }
632 ChangeState(network, new_state, error_description); 646 ChangeState(network, new_state, error_description);
647 evaluating_ = false;
633 } 648 }
634 649
635 // Debugging helper function, will take it out at the end. 650 // Debugging helper function, will take it out at the end.
636 const char* MobileSetupHandler::GetStateDescription( 651 const char* MobileSetupHandler::GetStateDescription(
637 PlanActivationState state) { 652 PlanActivationState state) {
638 switch (state) { 653 switch (state) {
639 case PLAN_ACTIVATION_PAGE_LOADING: 654 case PLAN_ACTIVATION_PAGE_LOADING:
640 return "PAGE_LOADING"; 655 return "PAGE_LOADING";
641 case PLAN_ACTIVATION_START: 656 case PLAN_ACTIVATION_START:
642 return "ACTIVATION_START"; 657 return "ACTIVATION_START";
(...skipping 22 matching lines...) Expand all
665 network->set_auto_connect(true); 680 network->set_auto_connect(true);
666 lib->SaveCellularNetwork(network); 681 lib->SaveCellularNetwork(network);
667 } 682 }
668 lib->RemoveNetworkManagerObserver(this); 683 lib->RemoveNetworkManagerObserver(this);
669 lib->RemoveObserverForAllNetworks(this); 684 lib->RemoveObserverForAllNetworks(this);
670 // Reactivate other types of connections if we have 685 // Reactivate other types of connections if we have
671 // shut them down previously. 686 // shut them down previously.
672 ReEnableOtherConnections(); 687 ReEnableOtherConnections();
673 } 688 }
674 689
690 void MobileSetupHandler::UpdatePage(chromeos::CellularNetwork* network,
691 const std::string& error_description) {
692 DictionaryValue device_dict;
693 if (network)
694 GetDeviceInfo(network, &device_dict);
695 device_dict.SetInteger("state", state_);
696 if (error_description.length())
697 device_dict.SetString("error", error_description);
698 dom_ui_->CallJavascriptFunction(
699 kJsDeviceStatusChangedHandler, device_dict);
700 }
675 701
676 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, 702 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
677 PlanActivationState new_state, 703 PlanActivationState new_state,
678 const std::string& error_description) { 704 const std::string& error_description) {
679 static bool first_time = true; 705 static bool first_time = true;
680 if (state_ == new_state && !first_time) 706 if (state_ == new_state && !first_time)
681 return; 707 return;
682 LOG(INFO) << "Activation state flip old = " << 708 LOG(INFO) << "Activation state flip old = " <<
683 GetStateDescription(state_) << ", new = " << 709 GetStateDescription(state_) << ", new = " <<
684 GetStateDescription(new_state); 710 GetStateDescription(new_state);
685 first_time = false; 711 first_time = false;
686 state_ = new_state; 712 state_ = new_state;
687 DictionaryValue device_dict;
688 713
689 // Signal to JS layer that the state is changing. 714 // Signal to JS layer that the state is changing.
690 if (network) 715 UpdatePage(network, error_description);
691 GetDeviceInfo(network, &device_dict);
692 device_dict.SetInteger("state", new_state);
693 if (error_description.length())
694 device_dict.SetString("error", error_description);
695 dom_ui_->CallJavascriptFunction(
696 kJsDeviceStatusChangedHandler, device_dict);
697 716
698 // Decide what to do with network object as a result of the new state. 717 // Decide what to do with network object as a result of the new state.
699 switch (new_state) { 718 switch (new_state) {
700 case PLAN_ACTIVATION_START: 719 case PLAN_ACTIVATION_START:
701 break; 720 break;
702 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 721 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
703 DCHECK(network); 722 DCHECK(network);
704 LOG(INFO) << "Activating service " << network->service_path().c_str(); 723 LOG(INFO) << "Activating service " << network->service_path().c_str();
705 if (!network->StartActivation()) 724 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1);
706 new_state = PLAN_ACTIVATION_ERROR; 725 if (!network->StartActivation()) {
726 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1);
727 ChangeState(network, PLAN_ACTIVATION_ERROR, std::string());
728 }
707 break; 729 break;
708 case PLAN_ACTIVATION_RECONNECTING: { 730 case PLAN_ACTIVATION_RECONNECTING: {
709 DCHECK(network); 731 DCHECK(network);
710 if (network) { 732 if (network) {
711 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 733 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
712 ConnectToCellularNetwork(network); 734 ConnectToCellularNetwork(network);
713 } 735 }
714 break; 736 break;
715 } 737 }
716 case PLAN_ACTIVATION_PAGE_LOADING: 738 case PLAN_ACTIVATION_PAGE_LOADING:
717 return; 739 return;
718 case PLAN_ACTIVATION_SHOWING_PAYMENT: 740 case PLAN_ACTIVATION_SHOWING_PAYMENT:
719 // Fix for fix SSL for the walled gardens where cert chain verification 741 // Fix for fix SSL for the walled gardens where cert chain verification
720 // might not work. 742 // might not work.
721 break; 743 break;
722 case PLAN_ACTIVATION_DONE: 744 case PLAN_ACTIVATION_DONE:
723 DCHECK(network); 745 DCHECK(network);
724 CompleteActivation(network); 746 CompleteActivation(network);
747 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1);
725 break; 748 break;
726 case PLAN_ACTIVATION_ERROR: { 749 case PLAN_ACTIVATION_ERROR: {
727 CompleteActivation(NULL); 750 CompleteActivation(NULL);
751 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1);
728 break; 752 break;
729 } 753 }
730 default: 754 default:
731 break; 755 break;
732 } 756 }
733 } 757 }
734 758
735 void MobileSetupHandler::ReEnableOtherConnections() { 759 void MobileSetupHandler::ReEnableOtherConnections() {
736 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> 760 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
737 GetNetworkLibrary(); 761 GetNetworkLibrary();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 new MobileSetupUIHTMLSource(service_path); 908 new MobileSetupUIHTMLSource(service_path);
885 909
886 // Set up the chrome://mobilesetup/ source. 910 // Set up the chrome://mobilesetup/ source.
887 BrowserThread::PostTask( 911 BrowserThread::PostTask(
888 BrowserThread::IO, FROM_HERE, 912 BrowserThread::IO, FROM_HERE,
889 NewRunnableMethod( 913 NewRunnableMethod(
890 Singleton<ChromeURLDataManager>::get(), 914 Singleton<ChromeURLDataManager>::get(),
891 &ChromeURLDataManager::AddDataSource, 915 &ChromeURLDataManager::AddDataSource,
892 make_scoped_refptr(html_source))); 916 make_scoped_refptr(html_source)));
893 } 917 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/mobile_setup.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698