| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/chromeos/mobile_setup_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/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 "base/callback.h" | 11 #include "base/bind.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/timer.h" | 21 #include "base/timer.h" |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { | 516 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { |
| 517 const size_t kSetTransactionStatusParamCount = 1; | 517 const size_t kSetTransactionStatusParamCount = 1; |
| 518 if (args->GetSize() != kSetTransactionStatusParamCount) | 518 if (args->GetSize() != kSetTransactionStatusParamCount) |
| 519 return; | 519 return; |
| 520 // Get change callback function name. | 520 // Get change callback function name. |
| 521 std::string status; | 521 std::string status; |
| 522 if (!args->GetString(0, &status)) | 522 if (!args->GetString(0, &status)) |
| 523 return; | 523 return; |
| 524 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), status); | 524 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), status); |
| 525 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 525 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 526 NewRunnableMethod(task.get(), &TaskProxy::HandleSetTransactionStatus)); | 526 base::Bind(&TaskProxy::HandleSetTransactionStatus, task.get())); |
| 527 } | 527 } |
| 528 | 528 |
| 529 void MobileSetupHandler::InitiateActivation() { | 529 void MobileSetupHandler::InitiateActivation() { |
| 530 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0); | 530 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0); |
| 531 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 531 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 532 NewRunnableMethod(task.get(), &TaskProxy::HandleStartActivation)); | 532 base::Bind(&TaskProxy::HandleStartActivation, task.get())); |
| 533 } | 533 } |
| 534 | 534 |
| 535 void MobileSetupHandler::StartActivation() { | 535 void MobileSetupHandler::StartActivation() { |
| 536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 537 chromeos::NetworkLibrary* lib = | 537 chromeos::NetworkLibrary* lib = |
| 538 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 538 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 539 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); | 539 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
| 540 // Check if we can start activation process. | 540 // Check if we can start activation process. |
| 541 if (!network || already_running_) { | 541 if (!network || already_running_) { |
| 542 std::string error; | 542 std::string error; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 connection_retry_count_++; | 673 connection_retry_count_++; |
| 674 connection_start_time_ = base::Time::Now(); | 674 connection_start_time_ = base::Time::Now(); |
| 675 if (!network) { | 675 if (!network) { |
| 676 LOG(WARNING) << "Connect failed." | 676 LOG(WARNING) << "Connect failed." |
| 677 << (network ? network->service_path().c_str() : "no service"); | 677 << (network ? network->service_path().c_str() : "no service"); |
| 678 // If we coudn't connect during reconnection phase, try to reconnect | 678 // If we coudn't connect during reconnection phase, try to reconnect |
| 679 // with a delay (and try to reconnect if needed). | 679 // with a delay (and try to reconnect if needed). |
| 680 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), | 680 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), |
| 681 delay); | 681 delay); |
| 682 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 682 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 683 NewRunnableMethod(task.get(), &TaskProxy::ContinueConnecting), | 683 base::Bind(&TaskProxy::ContinueConnecting, task.get()), delay); |
| 684 delay); | |
| 685 return false; | 684 return false; |
| 686 } | 685 } |
| 687 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 686 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
| 688 ConnectToCellularNetwork(network); | 687 ConnectToCellularNetwork(network); |
| 689 return true; | 688 return true; |
| 690 } | 689 } |
| 691 | 690 |
| 692 void MobileSetupHandler::ForceReconnect( | 691 void MobileSetupHandler::ForceReconnect( |
| 693 chromeos::CellularNetwork* network, | 692 chromeos::CellularNetwork* network, |
| 694 int delay) { | 693 int delay) { |
| 695 DCHECK(network); | 694 DCHECK(network); |
| 696 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); | 695 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); |
| 697 // Reset reconnect metrics. | 696 // Reset reconnect metrics. |
| 698 connection_retry_count_ = 0; | 697 connection_retry_count_ = 0; |
| 699 connection_start_time_ = base::Time(); | 698 connection_start_time_ = base::Time(); |
| 700 // First, disconnect... | 699 // First, disconnect... |
| 701 LOG(INFO) << "Disconnecting from " << network->service_path(); | 700 LOG(INFO) << "Disconnecting from " << network->service_path(); |
| 702 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 701 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
| 703 DisconnectFromNetwork(network); | 702 DisconnectFromNetwork(network); |
| 704 // Check the network state 3s after we disconnect to make sure. | 703 // Check the network state 3s after we disconnect to make sure. |
| 705 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), | 704 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), |
| 706 delay); | 705 delay); |
| 707 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 706 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 708 NewRunnableMethod(task.get(), &TaskProxy::ContinueConnecting), | 707 base::Bind(&TaskProxy::ContinueConnecting, task.get()), delay); |
| 709 delay); | |
| 710 } | 708 } |
| 711 | 709 |
| 712 bool MobileSetupHandler::ConnectionTimeout() { | 710 bool MobileSetupHandler::ConnectionTimeout() { |
| 713 return (base::Time::Now() - | 711 return (base::Time::Now() - |
| 714 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; | 712 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; |
| 715 } | 713 } |
| 716 | 714 |
| 717 void MobileSetupHandler::EvaluateCellularNetwork( | 715 void MobileSetupHandler::EvaluateCellularNetwork( |
| 718 chromeos::CellularNetwork* network) { | 716 chromeos::CellularNetwork* network) { |
| 719 if (!web_ui_) | 717 if (!web_ui_) |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 UpdatePage(network, error_description); | 1091 UpdatePage(network, error_description); |
| 1094 | 1092 |
| 1095 // Pick action that should happen on entering the new state. | 1093 // Pick action that should happen on entering the new state. |
| 1096 switch (new_state) { | 1094 switch (new_state) { |
| 1097 case PLAN_ACTIVATION_START: | 1095 case PLAN_ACTIVATION_START: |
| 1098 break; | 1096 break; |
| 1099 case PLAN_ACTIVATION_DELAY_OTASP: { | 1097 case PLAN_ACTIVATION_DELAY_OTASP: { |
| 1100 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); | 1098 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); |
| 1101 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0); | 1099 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0); |
| 1102 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 1100 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 1103 NewRunnableMethod(task.get(), &TaskProxy::RetryOTASP), | 1101 base::Bind(&TaskProxy::RetryOTASP, task.get()), kOTASPRetryDelay); |
| 1104 kOTASPRetryDelay); | |
| 1105 break; | 1102 break; |
| 1106 } | 1103 } |
| 1107 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 1104 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 1108 case PLAN_ACTIVATION_TRYING_OTASP: | 1105 case PLAN_ACTIVATION_TRYING_OTASP: |
| 1109 case PLAN_ACTIVATION_OTASP: | 1106 case PLAN_ACTIVATION_OTASP: |
| 1110 DCHECK(network); | 1107 DCHECK(network); |
| 1111 LOG(WARNING) << "Activating service " << network->service_path().c_str(); | 1108 LOG(WARNING) << "Activating service " << network->service_path().c_str(); |
| 1112 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | 1109 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); |
| 1113 if (!network->StartActivation()) { | 1110 if (!network->StartActivation()) { |
| 1114 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | 1111 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 MobileSetupHandler* handler = new MobileSetupHandler(service_path); | 1323 MobileSetupHandler* handler = new MobileSetupHandler(service_path); |
| 1327 AddMessageHandler((handler)->Attach(this)); | 1324 AddMessageHandler((handler)->Attach(this)); |
| 1328 handler->Init(contents); | 1325 handler->Init(contents); |
| 1329 MobileSetupUIHTMLSource* html_source = | 1326 MobileSetupUIHTMLSource* html_source = |
| 1330 new MobileSetupUIHTMLSource(service_path); | 1327 new MobileSetupUIHTMLSource(service_path); |
| 1331 | 1328 |
| 1332 // Set up the chrome://mobilesetup/ source. | 1329 // Set up the chrome://mobilesetup/ source. |
| 1333 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 1330 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
| 1334 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 1331 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
| 1335 } | 1332 } |
| OLD | NEW |