OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 const char kFailedPaymentError[] = "failed_payment"; | 62 const char kFailedPaymentError[] = "failed_payment"; |
63 | 63 |
64 // Cellular configuration file path. | 64 // Cellular configuration file path. |
65 const char kCellularConfigPath[] = | 65 const char kCellularConfigPath[] = |
66 "/usr/share/chromeos-assets/mobile/mobile_config.json"; | 66 "/usr/share/chromeos-assets/mobile/mobile_config.json"; |
67 | 67 |
68 // Cellular config file field names. | 68 // Cellular config file field names. |
69 const char kVersionField[] = "version"; | 69 const char kVersionField[] = "version"; |
70 const char kErrorsField[] = "errors"; | 70 const char kErrorsField[] = "errors"; |
71 | 71 |
| 72 // Number of times we will retry to reconnect if connection fails. |
| 73 const int kMaxConnectionRetry = 10; |
| 74 // Connection timeout in seconds. |
| 75 const int kConnectionTimeoutSeconds = 30; |
| 76 |
72 chromeos::CellularNetwork* GetCellularNetwork() { | 77 chromeos::CellularNetwork* GetCellularNetwork() { |
73 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 78 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
74 GetNetworkLibrary(); | 79 GetNetworkLibrary(); |
75 if (lib->cellular_networks().begin() != lib->cellular_networks().end()) { | 80 if (lib->cellular_networks().begin() != lib->cellular_networks().end()) { |
76 return *(lib->cellular_networks().begin()); | 81 return *(lib->cellular_networks().begin()); |
77 } | 82 } |
78 return NULL; | 83 return NULL; |
79 } | 84 } |
80 | 85 |
81 chromeos::CellularNetwork* GetCellularNetwork(const std::string& service_path) { | 86 chromeos::CellularNetwork* GetCellularNetwork(const std::string& service_path) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 188 |
184 // Handlers for JS DOMUI messages. | 189 // Handlers for JS DOMUI messages. |
185 void HandleSetTransactionStatus(const ListValue* args); | 190 void HandleSetTransactionStatus(const ListValue* args); |
186 void HandleStartActivation(const ListValue* args); | 191 void HandleStartActivation(const ListValue* args); |
187 void SetTransactionStatus(const std::string& status); | 192 void SetTransactionStatus(const std::string& status); |
188 void StartActivation(); | 193 void StartActivation(); |
189 | 194 |
190 // Sends message to host registration page with system/user info data. | 195 // Sends message to host registration page with system/user info data. |
191 void SendDeviceInfo(); | 196 void SendDeviceInfo(); |
192 | 197 |
| 198 // Connects to cellular network, resets connection timer. |
| 199 void ConnectToNetwork(chromeos::CellularNetwork* network); |
| 200 // Reports connection timeout. |
| 201 bool ConnectionTimeout(); |
193 // Verify the state of cellular network and modify internal state. | 202 // Verify the state of cellular network and modify internal state. |
194 void EvaluateCellularNetwork(chromeos::CellularNetwork* network); | 203 void EvaluateCellularNetwork(chromeos::CellularNetwork* network); |
195 // Check the current cellular network for error conditions. | 204 // Check the current cellular network for error conditions. |
196 bool GotActivationError(const chromeos::CellularNetwork* network, | 205 bool GotActivationError(const chromeos::CellularNetwork* network, |
197 std::string* error); | 206 std::string* error); |
198 // Sends status updates to DOMUI page. | 207 // Sends status updates to DOMUI page. |
199 void UpdatePage(chromeos::CellularNetwork* network, | 208 void UpdatePage(chromeos::CellularNetwork* network, |
200 const std::string& error_description); | 209 const std::string& error_description); |
201 // Changes internal state. | 210 // Changes internal state. |
202 void ChangeState(chromeos::CellularNetwork* network, | 211 void ChangeState(chromeos::CellularNetwork* network, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 PlanActivationState state_; | 245 PlanActivationState state_; |
237 std::string service_path_; | 246 std::string service_path_; |
238 // Flags that control if wifi and ethernet connection needs to be restored | 247 // Flags that control if wifi and ethernet connection needs to be restored |
239 // after the activation of cellular network. | 248 // after the activation of cellular network. |
240 bool reenable_wifi_; | 249 bool reenable_wifi_; |
241 bool reenable_ethernet_; | 250 bool reenable_ethernet_; |
242 bool reenable_cert_check_; | 251 bool reenable_cert_check_; |
243 bool transaction_complete_signalled_; | 252 bool transaction_complete_signalled_; |
244 bool activation_status_test_; | 253 bool activation_status_test_; |
245 bool evaluating_; | 254 bool evaluating_; |
| 255 // Connection retry counter. |
| 256 int connection_retry_count_; |
| 257 // Connection start time. |
| 258 base::Time connection_start_time_; |
246 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); | 259 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); |
247 }; | 260 }; |
248 | 261 |
249 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; | 262 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; |
250 | 263 |
251 //////////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////////// |
252 // | 265 // |
253 // CellularConfigDocument | 266 // CellularConfigDocument |
254 // | 267 // |
255 //////////////////////////////////////////////////////////////////////////////// | 268 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, | 334 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, |
322 network ? UTF8ToUTF16(network->name()) : string16())); | 335 network ? UTF8ToUTF16(network->name()) : string16())); |
323 strings.SetString("error_header", | 336 strings.SetString("error_header", |
324 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); | 337 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); |
325 strings.SetString("activating_header", | 338 strings.SetString("activating_header", |
326 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); | 339 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); |
327 strings.SetString("completed_header", | 340 strings.SetString("completed_header", |
328 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); | 341 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); |
329 strings.SetString("completed_text", | 342 strings.SetString("completed_text", |
330 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); | 343 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); |
| 344 strings.SetString("close_button", |
| 345 l10n_util::GetStringUTF16(IDS_CLOSE)); |
331 SetFontAndTextDirection(&strings); | 346 SetFontAndTextDirection(&strings); |
332 | 347 |
333 static const base::StringPiece html( | 348 static const base::StringPiece html( |
334 ResourceBundle::GetSharedInstance().GetRawDataResource( | 349 ResourceBundle::GetSharedInstance().GetRawDataResource( |
335 IDR_MOBILE_SETUP_PAGE_HTML)); | 350 IDR_MOBILE_SETUP_PAGE_HTML)); |
336 const std::string full_html = jstemplate_builder::GetTemplatesHtml( | 351 const std::string full_html = jstemplate_builder::GetTemplatesHtml( |
337 html, &strings, "t" /* template root node id */); | 352 html, &strings, "t" /* template root node id */); |
338 | 353 |
339 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 354 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
340 html_bytes->data.resize(full_html.size()); | 355 html_bytes->data.resize(full_html.size()); |
341 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | 356 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
342 | 357 |
343 SendResponse(request_id, html_bytes); | 358 SendResponse(request_id, html_bytes); |
344 } | 359 } |
345 | 360 |
346 //////////////////////////////////////////////////////////////////////////////// | 361 //////////////////////////////////////////////////////////////////////////////// |
347 // | 362 // |
348 // MobileSetupHandler | 363 // MobileSetupHandler |
349 // | 364 // |
350 //////////////////////////////////////////////////////////////////////////////// | 365 //////////////////////////////////////////////////////////////////////////////// |
351 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) | 366 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) |
352 : tab_contents_(NULL), | 367 : tab_contents_(NULL), |
353 state_(PLAN_ACTIVATION_PAGE_LOADING), | 368 state_(PLAN_ACTIVATION_PAGE_LOADING), |
354 service_path_(service_path), | 369 service_path_(service_path), |
355 reenable_wifi_(false), | 370 reenable_wifi_(false), |
356 reenable_ethernet_(false), | 371 reenable_ethernet_(false), |
357 reenable_cert_check_(false), | 372 reenable_cert_check_(false), |
358 transaction_complete_signalled_(false), | 373 transaction_complete_signalled_(false), |
359 activation_status_test_(false), | 374 activation_status_test_(false), |
360 evaluating_(false) { | 375 evaluating_(false), |
| 376 connection_retry_count_(0) { |
361 } | 377 } |
362 | 378 |
363 MobileSetupHandler::~MobileSetupHandler() { | 379 MobileSetupHandler::~MobileSetupHandler() { |
364 chromeos::NetworkLibrary* lib = | 380 chromeos::NetworkLibrary* lib = |
365 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 381 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
366 lib->RemoveNetworkManagerObserver(this); | 382 lib->RemoveNetworkManagerObserver(this); |
367 lib->RemoveObserverForAllNetworks(this); | 383 lib->RemoveObserverForAllNetworks(this); |
368 ReEnableOtherConnections(); | 384 ReEnableOtherConnections(); |
369 } | 385 } |
370 | 386 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 479 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
464 DisconnectFromWirelessNetwork(network); | 480 DisconnectFromWirelessNetwork(network); |
465 } else { | 481 } else { |
466 EvaluateCellularNetwork(network); | 482 EvaluateCellularNetwork(network); |
467 } | 483 } |
468 } else { | 484 } else { |
469 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); | 485 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); |
470 } | 486 } |
471 } | 487 } |
472 | 488 |
| 489 |
| 490 void MobileSetupHandler::ConnectToNetwork(chromeos::CellularNetwork* network) { |
| 491 connection_retry_count_++; |
| 492 connection_start_time_ = base::Time::Now(); |
| 493 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
| 494 ConnectToCellularNetwork(network); |
| 495 } |
| 496 |
| 497 bool MobileSetupHandler::ConnectionTimeout() { |
| 498 return (base::Time::Now() - |
| 499 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; |
| 500 } |
| 501 |
473 void MobileSetupHandler::EvaluateCellularNetwork( | 502 void MobileSetupHandler::EvaluateCellularNetwork( |
474 chromeos::CellularNetwork* network) { | 503 chromeos::CellularNetwork* network) { |
475 if (!dom_ui_) | 504 if (!dom_ui_) |
476 return; | 505 return; |
477 | 506 |
478 PlanActivationState new_state = state_; | 507 PlanActivationState new_state = state_; |
479 if (!network) { | 508 if (!network) { |
480 LOG(WARNING) << "Cellular service lost"; | 509 LOG(WARNING) << "Cellular service lost"; |
481 return; | 510 return; |
482 } | 511 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 // Wait in this state until activation state changes. | 609 // Wait in this state until activation state changes. |
581 break; | 610 break; |
582 case chromeos::ACTIVATION_STATE_ACTIVATING: | 611 case chromeos::ACTIVATION_STATE_ACTIVATING: |
583 break; | 612 break; |
584 default: | 613 default: |
585 break; | 614 break; |
586 } | 615 } |
587 break; | 616 break; |
588 } | 617 } |
589 case PLAN_ACTIVATION_RECONNECTING: { | 618 case PLAN_ACTIVATION_RECONNECTING: { |
590 // Wait until the service shows up and gets activated. | 619 if (network->connected()) { |
591 switch (network->activation_state()) { | 620 // Wait until the service shows up and gets activated. |
592 case chromeos::ACTIVATION_STATE_ACTIVATED: | 621 switch (network->activation_state()) { |
593 if (network->connected()) { | 622 case chromeos::ACTIVATION_STATE_ACTIVATED: |
594 if (network->restricted_pool()) { | |
595 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | |
596 } else { | |
597 new_state = PLAN_ACTIVATION_DONE; | |
598 } | |
599 } else if (network->failed()) { | |
600 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | |
601 ConnectToCellularNetwork(network); | |
602 evaluating_ = false; | |
603 return; | |
604 } | |
605 break; | |
606 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | |
607 if (network->connected()) { | |
608 if (network->restricted_pool()) | 623 if (network->restricted_pool()) |
609 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | 624 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
610 } | 625 else |
611 break; | 626 new_state = PLAN_ACTIVATION_DONE; |
612 default: | 627 break; |
613 break; | 628 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 629 if (network->restricted_pool()) |
| 630 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
| 631 break; |
| 632 default: |
| 633 break; |
| 634 } |
| 635 } else if (network->failed() || ConnectionTimeout()) { |
| 636 // Try to reconnect again if reconnect failed, or if for some |
| 637 // reasons we are still not connected after 30 seconds. |
| 638 if (connection_retry_count_ < kMaxConnectionRetry) { |
| 639 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionRetry", 1); |
| 640 ConnectToNetwork(network); |
| 641 evaluating_ = false; |
| 642 return; |
| 643 } else { |
| 644 // We simply can't connect anymore after all these tries. |
| 645 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionFailed", 1); |
| 646 new_state = PLAN_ACTIVATION_ERROR; |
| 647 } |
614 } | 648 } |
615 break; | 649 break; |
616 } | 650 } |
617 case PLAN_ACTIVATION_PAGE_LOADING: | 651 case PLAN_ACTIVATION_PAGE_LOADING: |
618 break; | 652 break; |
619 // Just ignore all signals until the site confirms payment. | 653 // Just ignore all signals until the site confirms payment. |
620 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 654 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
621 // Activation completed/failed, ignore network changes. | 655 // Activation completed/failed, ignore network changes. |
622 case PLAN_ACTIVATION_DONE: | 656 case PLAN_ACTIVATION_DONE: |
623 case PLAN_ACTIVATION_ERROR: | 657 case PLAN_ACTIVATION_ERROR: |
624 break; | 658 break; |
625 } | 659 } |
626 | 660 |
627 std::string error_description; | 661 std::string error_description; |
628 if (GotActivationError(network, &error_description)) { | 662 if (new_state != PLAN_ACTIVATION_ERROR && |
| 663 GotActivationError(network, &error_description)) { |
629 // Check for this special case when we try to do activate partially | 664 // Check for this special case when we try to do activate partially |
630 // activated device. If that attempt failed, try to disconnect to clear the | 665 // activated device. If that attempt failed, try to disconnect to clear the |
631 // state and reconnect again. | 666 // state and reconnect again. |
632 if ((network->activation_state() == | 667 if ((network->activation_state() == |
633 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED || | 668 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED || |
634 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) && | 669 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) && |
635 (network->error() == chromeos::ERROR_UNKNOWN || | 670 (network->error() == chromeos::ERROR_UNKNOWN || |
636 network->error() == chromeos::ERROR_OTASP_FAILED)&& | 671 network->error() == chromeos::ERROR_OTASP_FAILED)&& |
637 (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION || | 672 (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION || |
638 state_ == PLAN_ACTIVATION_RECONNECTING) && | 673 state_ == PLAN_ACTIVATION_RECONNECTING) && |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 756 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
722 DCHECK(network); | 757 DCHECK(network); |
723 LOG(INFO) << "Activating service " << network->service_path().c_str(); | 758 LOG(INFO) << "Activating service " << network->service_path().c_str(); |
724 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | 759 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); |
725 if (!network->StartActivation()) { | 760 if (!network->StartActivation()) { |
726 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | 761 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); |
727 ChangeState(network, PLAN_ACTIVATION_ERROR, std::string()); | 762 ChangeState(network, PLAN_ACTIVATION_ERROR, std::string()); |
728 } | 763 } |
729 break; | 764 break; |
730 case PLAN_ACTIVATION_RECONNECTING: { | 765 case PLAN_ACTIVATION_RECONNECTING: { |
731 DCHECK(network); | 766 // Reset connection metrics and try to connect. |
732 if (network) { | 767 connection_retry_count_ = 0; |
733 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 768 connection_start_time_ = base::Time::Now(); |
734 ConnectToCellularNetwork(network); | 769 ConnectToNetwork(network); |
735 } | |
736 break; | 770 break; |
737 } | 771 } |
738 case PLAN_ACTIVATION_PAGE_LOADING: | 772 case PLAN_ACTIVATION_PAGE_LOADING: |
739 return; | 773 return; |
740 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 774 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
741 // Fix for fix SSL for the walled gardens where cert chain verification | 775 // Fix for fix SSL for the walled gardens where cert chain verification |
742 // might not work. | 776 // might not work. |
743 break; | 777 break; |
744 case PLAN_ACTIVATION_DONE: | 778 case PLAN_ACTIVATION_DONE: |
745 DCHECK(network); | 779 DCHECK(network); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 new MobileSetupUIHTMLSource(service_path); | 942 new MobileSetupUIHTMLSource(service_path); |
909 | 943 |
910 // Set up the chrome://mobilesetup/ source. | 944 // Set up the chrome://mobilesetup/ source. |
911 BrowserThread::PostTask( | 945 BrowserThread::PostTask( |
912 BrowserThread::IO, FROM_HERE, | 946 BrowserThread::IO, FROM_HERE, |
913 NewRunnableMethod( | 947 NewRunnableMethod( |
914 Singleton<ChromeURLDataManager>::get(), | 948 Singleton<ChromeURLDataManager>::get(), |
915 &ChromeURLDataManager::AddDataSource, | 949 &ChromeURLDataManager::AddDataSource, |
916 make_scoped_refptr(html_source))); | 950 make_scoped_refptr(html_source))); |
917 } | 951 } |
OLD | NEW |