| 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 <map> | 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 11 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 14 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 118 } |
| 118 | 119 |
| 119 private: | 120 private: |
| 120 virtual ~MobileSetupUIHTMLSource() {} | 121 virtual ~MobileSetupUIHTMLSource() {} |
| 121 | 122 |
| 122 std::string service_path_; | 123 std::string service_path_; |
| 123 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); | 124 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 // The handler for Javascript messages related to the "register" view. | 127 // The handler for Javascript messages related to the "register" view. |
| 127 class MobileSetupHandler : public DOMMessageHandler, | 128 class MobileSetupHandler |
| 128 public chromeos::NetworkLibrary::Observer, | 129 : public DOMMessageHandler, |
| 129 public chromeos::NetworkLibrary::PropertyObserver, | 130 public chromeos::NetworkLibrary::NetworkManagerObserver, |
| 130 public base::SupportsWeakPtr<MobileSetupHandler> { | 131 public chromeos::NetworkLibrary::NetworkObserver, |
| 132 public base::SupportsWeakPtr<MobileSetupHandler> { |
| 131 public: | 133 public: |
| 132 explicit MobileSetupHandler(const std::string& service_path); | 134 explicit MobileSetupHandler(const std::string& service_path); |
| 133 virtual ~MobileSetupHandler(); | 135 virtual ~MobileSetupHandler(); |
| 134 | 136 |
| 135 // Init work after Attach. | 137 // Init work after Attach. |
| 136 void Init(TabContents* contents); | 138 void Init(TabContents* contents); |
| 137 | 139 |
| 138 // DOMMessageHandler implementation. | 140 // DOMMessageHandler implementation. |
| 139 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 141 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 140 virtual void RegisterMessages(); | 142 virtual void RegisterMessages(); |
| 141 | 143 |
| 142 // NetworkLibrary::Observer implementation. | 144 // NetworkLibrary::NetworkManagerObserver implementation. |
| 143 virtual void NetworkChanged(chromeos::NetworkLibrary* obj); | 145 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj); |
| 144 // NetworkLibrary::PropertyObserver implementation. | 146 // NetworkLibrary::NetworkObserver implementation. |
| 145 virtual void PropertyChanged(const char* service_path, | 147 virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj, |
| 146 const char* key, | 148 const chromeos::Network* network); |
| 147 const Value* value); | |
| 148 | 149 |
| 149 private: | 150 private: |
| 150 typedef enum PlanActivationState { | 151 typedef enum PlanActivationState { |
| 151 PLAN_ACTIVATION_PAGE_LOADING = -1, | 152 PLAN_ACTIVATION_PAGE_LOADING = -1, |
| 152 PLAN_ACTIVATION_START = 0, | 153 PLAN_ACTIVATION_START = 0, |
| 153 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, | 154 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, |
| 154 PLAN_ACTIVATION_RECONNECTING = 2, | 155 PLAN_ACTIVATION_RECONNECTING = 2, |
| 155 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, | 156 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, |
| 156 PLAN_ACTIVATION_DONE = 4, | 157 PLAN_ACTIVATION_DONE = 4, |
| 157 PLAN_ACTIVATION_ERROR = 5, | 158 PLAN_ACTIVATION_ERROR = 5, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 service_path_(service_path), | 349 service_path_(service_path), |
| 349 reenable_wifi_(false), | 350 reenable_wifi_(false), |
| 350 reenable_ethernet_(false), | 351 reenable_ethernet_(false), |
| 351 reenable_cert_check_(false), | 352 reenable_cert_check_(false), |
| 352 transaction_complete_signalled_(false) { | 353 transaction_complete_signalled_(false) { |
| 353 } | 354 } |
| 354 | 355 |
| 355 MobileSetupHandler::~MobileSetupHandler() { | 356 MobileSetupHandler::~MobileSetupHandler() { |
| 356 chromeos::NetworkLibrary* lib = | 357 chromeos::NetworkLibrary* lib = |
| 357 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 358 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 358 lib->RemoveObserver(this); | 359 lib->RemoveNetworkManagerObserver(this); |
| 359 lib->RemoveProperyObserver(this); | 360 lib->RemoveObserverForAllNetworks(this); |
| 360 ReEnableOtherConnections(); | 361 ReEnableOtherConnections(); |
| 361 } | 362 } |
| 362 | 363 |
| 363 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { | 364 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { |
| 364 return DOMMessageHandler::Attach(dom_ui); | 365 return DOMMessageHandler::Attach(dom_ui); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void MobileSetupHandler::Init(TabContents* contents) { | 368 void MobileSetupHandler::Init(TabContents* contents) { |
| 368 tab_contents_ = contents; | 369 tab_contents_ = contents; |
| 369 LoadCellularConfig(); | 370 LoadCellularConfig(); |
| 370 SetupActivationProcess(GetCellularNetwork(service_path_)); | 371 SetupActivationProcess(GetCellularNetwork(service_path_)); |
| 371 } | 372 } |
| 372 | 373 |
| 373 void MobileSetupHandler::RegisterMessages() { | 374 void MobileSetupHandler::RegisterMessages() { |
| 374 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, | 375 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, |
| 375 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); | 376 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); |
| 376 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, | 377 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, |
| 377 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); | 378 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); |
| 378 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, | 379 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, |
| 379 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); | 380 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); |
| 380 } | 381 } |
| 381 | 382 |
| 382 void MobileSetupHandler::NetworkChanged(chromeos::NetworkLibrary* lib) { | 383 void MobileSetupHandler::OnNetworkManagerChanged( |
| 384 chromeos::NetworkLibrary* cros) { |
| 383 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 385 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
| 384 return; | 386 return; |
| 387 // Note that even though we get here when the service has |
| 388 // reappeared after disappearing earlier in the activation |
| 389 // process, there's no need to re-establish the NetworkObserver, |
| 390 // because the service path remains the same. |
| 385 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); | 391 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); |
| 386 } | 392 } |
| 387 | 393 |
| 388 void MobileSetupHandler::PropertyChanged(const char* service_path, | 394 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros, |
| 389 const char* key, | 395 const chromeos::Network* network) { |
| 390 const Value* value) { | |
| 391 | |
| 392 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 396 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
| 393 return; | 397 return; |
| 394 // TODO(zelidrag, ers): Remove this once we flip the notification machanism. | 398 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR); |
| 395 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->UpdateSystemInfo(); | 399 EvaluateCellularNetwork( |
| 396 | 400 static_cast<chromeos::CellularNetwork*>( |
| 397 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); | 401 const_cast<chromeos::Network*>(network))); |
| 398 if (!network) { | |
| 399 EvaluateCellularNetwork(NULL); | |
| 400 return; | |
| 401 } | |
| 402 if (network->service_path() != service_path) { | |
| 403 NOTREACHED(); | |
| 404 return; | |
| 405 } | |
| 406 std::string value_string; | |
| 407 LOG(INFO) << "Cellular property change: " << key << " = " << | |
| 408 value_string.c_str(); | |
| 409 | |
| 410 EvaluateCellularNetwork(network); | |
| 411 } | 402 } |
| 412 | 403 |
| 413 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { | 404 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { |
| 414 if (!dom_ui_) | 405 if (!dom_ui_) |
| 415 return; | 406 return; |
| 416 Browser* browser = BrowserList::FindBrowserWithFeature( | 407 Browser* browser = BrowserList::FindBrowserWithFeature( |
| 417 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); | 408 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); |
| 418 if (browser) | 409 if (browser) |
| 419 browser->CloseTabContents(tab_contents_); | 410 browser->CloseTabContents(tab_contents_); |
| 420 } | 411 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 438 NewRunnableMethod(task.get(), &TaskProxy::HandleSetTransactionStatus)); | 429 NewRunnableMethod(task.get(), &TaskProxy::HandleSetTransactionStatus)); |
| 439 } | 430 } |
| 440 | 431 |
| 441 void MobileSetupHandler::StartActivation() { | 432 void MobileSetupHandler::StartActivation() { |
| 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 443 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); | 434 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
| 444 if (!network) { | 435 if (!network) { |
| 445 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); | 436 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); |
| 446 return; | 437 return; |
| 447 } | 438 } |
| 448 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 439 // Start monitoring network property changes. |
| 449 GetNetworkLibrary(); | 440 chromeos::NetworkLibrary* lib = |
| 450 lib->RemoveObserver(this); | 441 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 451 lib->RemoveProperyObserver(this); | 442 lib->AddNetworkManagerObserver(this); |
| 452 // Start monitoring network and service property changes. | 443 lib->RemoveObserverForAllNetworks(this); |
| 453 lib->AddObserver(this); | 444 lib->AddNetworkObserver(network->service_path(), this); |
| 454 lib->AddProperyObserver(network->service_path().c_str(), | |
| 455 this); | |
| 456 state_ = PLAN_ACTIVATION_START; | 445 state_ = PLAN_ACTIVATION_START; |
| 457 EvaluateCellularNetwork(network); | 446 EvaluateCellularNetwork(network); |
| 458 } | 447 } |
| 459 | 448 |
| 460 void MobileSetupHandler::SetTransactionStatus(const std::string& status) { | 449 void MobileSetupHandler::SetTransactionStatus(const std::string& status) { |
| 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 462 // The payment is received, try to reconnect and check the status all over | 451 // The payment is received, try to reconnect and check the status all over |
| 463 // again. | 452 // again. |
| 464 if (LowerCaseEqualsASCII(status, "ok") && | 453 if (LowerCaseEqualsASCII(status, "ok") && |
| 465 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 454 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 void MobileSetupHandler::CompleteActivation( | 611 void MobileSetupHandler::CompleteActivation( |
| 623 chromeos::CellularNetwork* network) { | 612 chromeos::CellularNetwork* network) { |
| 624 // Remove observers, we are done with this page. | 613 // Remove observers, we are done with this page. |
| 625 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 614 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 626 GetNetworkLibrary(); | 615 GetNetworkLibrary(); |
| 627 // If we have successfully activated the connection, set autoconnect flag. | 616 // If we have successfully activated the connection, set autoconnect flag. |
| 628 if (network) { | 617 if (network) { |
| 629 network->set_auto_connect(true); | 618 network->set_auto_connect(true); |
| 630 lib->SaveCellularNetwork(network); | 619 lib->SaveCellularNetwork(network); |
| 631 } | 620 } |
| 632 lib->RemoveObserver(this); | 621 lib->RemoveNetworkManagerObserver(this); |
| 633 lib->RemoveProperyObserver(this); | 622 lib->RemoveObserverForAllNetworks(this); |
| 634 // Reactivate other types of connections if we have | 623 // Reactivate other types of connections if we have |
| 635 // shut them down previously. | 624 // shut them down previously. |
| 636 ReEnableOtherConnections(); | 625 ReEnableOtherConnections(); |
| 637 } | 626 } |
| 638 | 627 |
| 639 | 628 |
| 640 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, | 629 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, |
| 641 PlanActivationState new_state, | 630 PlanActivationState new_state, |
| 642 const std::string& error_description) { | 631 const std::string& error_description) { |
| 643 static bool first_time = true; | 632 static bool first_time = true; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 } | 821 } |
| 833 } | 822 } |
| 834 | 823 |
| 835 | 824 |
| 836 //////////////////////////////////////////////////////////////////////////////// | 825 //////////////////////////////////////////////////////////////////////////////// |
| 837 // | 826 // |
| 838 // MobileSetupUI | 827 // MobileSetupUI |
| 839 // | 828 // |
| 840 //////////////////////////////////////////////////////////////////////////////// | 829 //////////////////////////////////////////////////////////////////////////////// |
| 841 | 830 |
| 842 MobileSetupUI::MobileSetupUI(TabContents* contents) : DOMUI(contents){ | 831 MobileSetupUI::MobileSetupUI(TabContents* contents) : DOMUI(contents) { |
| 843 const chromeos::CellularNetwork* network = GetCellularNetwork(); | 832 const chromeos::CellularNetwork* network = GetCellularNetwork(); |
| 844 std::string service_path = network ? network->service_path() : std::string(); | 833 std::string service_path = network ? network->service_path() : std::string(); |
| 845 MobileSetupHandler* handler = new MobileSetupHandler(service_path); | 834 MobileSetupHandler* handler = new MobileSetupHandler(service_path); |
| 846 AddMessageHandler((handler)->Attach(this)); | 835 AddMessageHandler((handler)->Attach(this)); |
| 847 handler->Init(contents); | 836 handler->Init(contents); |
| 848 MobileSetupUIHTMLSource* html_source = | 837 MobileSetupUIHTMLSource* html_source = |
| 849 new MobileSetupUIHTMLSource(service_path); | 838 new MobileSetupUIHTMLSource(service_path); |
| 850 | 839 |
| 851 // Set up the chrome://mobilesetup/ source. | 840 // Set up the chrome://mobilesetup/ source. |
| 852 BrowserThread::PostTask( | 841 BrowserThread::PostTask( |
| 853 BrowserThread::IO, FROM_HERE, | 842 BrowserThread::IO, FROM_HERE, |
| 854 NewRunnableMethod( | 843 NewRunnableMethod( |
| 855 Singleton<ChromeURLDataManager>::get(), | 844 Singleton<ChromeURLDataManager>::get(), |
| 856 &ChromeURLDataManager::AddDataSource, | 845 &ChromeURLDataManager::AddDataSource, |
| 857 make_scoped_refptr(html_source))); | 846 make_scoped_refptr(html_source))); |
| 858 } | 847 } |
| OLD | NEW |