OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 private: | 119 private: |
120 virtual ~MobileSetupUIHTMLSource() {} | 120 virtual ~MobileSetupUIHTMLSource() {} |
121 | 121 |
122 std::string service_path_; | 122 std::string service_path_; |
123 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); | 123 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); |
124 }; | 124 }; |
125 | 125 |
126 // The handler for Javascript messages related to the "register" view. | 126 // The handler for Javascript messages related to the "register" view. |
127 class MobileSetupHandler | 127 class MobileSetupHandler : public DOMMessageHandler, |
128 : public DOMMessageHandler, | 128 public chromeos::NetworkLibrary::Observer, |
129 public chromeos::NetworkLibrary::NetworkManagerObserver, | 129 public chromeos::NetworkLibrary::PropertyObserver, |
130 public chromeos::NetworkLibrary::NetworkObserver, | 130 public base::SupportsWeakPtr<MobileSetupHandler> { |
131 public base::SupportsWeakPtr<MobileSetupHandler> { | |
132 | |
133 public: | 131 public: |
134 explicit MobileSetupHandler(const std::string& service_path); | 132 explicit MobileSetupHandler(const std::string& service_path); |
135 virtual ~MobileSetupHandler(); | 133 virtual ~MobileSetupHandler(); |
136 | 134 |
137 // Init work after Attach. | 135 // Init work after Attach. |
138 void Init(TabContents* contents); | 136 void Init(TabContents* contents); |
139 | 137 |
140 // DOMMessageHandler implementation. | 138 // DOMMessageHandler implementation. |
141 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 139 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
142 virtual void RegisterMessages(); | 140 virtual void RegisterMessages(); |
143 | 141 |
144 // NetworkLibrary::NetworkManagerObserver implementation. | 142 // NetworkLibrary::Observer implementation. |
145 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj); | 143 virtual void NetworkChanged(chromeos::NetworkLibrary* obj); |
146 // NetworkLibrary::NetworkObserver implementation. | 144 // NetworkLibrary::PropertyObserver implementation. |
147 virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj, | 145 virtual void PropertyChanged(const char* service_path, |
148 const chromeos::Network* network); | 146 const char* key, |
| 147 const Value* value); |
149 | 148 |
150 private: | 149 private: |
151 typedef enum PlanActivationState { | 150 typedef enum PlanActivationState { |
152 PLAN_ACTIVATION_PAGE_LOADING = -1, | 151 PLAN_ACTIVATION_PAGE_LOADING = -1, |
153 PLAN_ACTIVATION_START = 0, | 152 PLAN_ACTIVATION_START = 0, |
154 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, | 153 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, |
155 PLAN_ACTIVATION_RECONNECTING = 2, | 154 PLAN_ACTIVATION_RECONNECTING = 2, |
156 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, | 155 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, |
157 PLAN_ACTIVATION_DONE = 4, | 156 PLAN_ACTIVATION_DONE = 4, |
158 PLAN_ACTIVATION_ERROR = 5, | 157 PLAN_ACTIVATION_ERROR = 5, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 state_(PLAN_ACTIVATION_PAGE_LOADING), | 321 state_(PLAN_ACTIVATION_PAGE_LOADING), |
323 service_path_(service_path), | 322 service_path_(service_path), |
324 reenable_wifi_(false), | 323 reenable_wifi_(false), |
325 reenable_ethernet_(false), | 324 reenable_ethernet_(false), |
326 reenable_cert_check_(false) { | 325 reenable_cert_check_(false) { |
327 } | 326 } |
328 | 327 |
329 MobileSetupHandler::~MobileSetupHandler() { | 328 MobileSetupHandler::~MobileSetupHandler() { |
330 chromeos::NetworkLibrary* lib = | 329 chromeos::NetworkLibrary* lib = |
331 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 330 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
332 lib->RemoveNetworkManagerObserver(this); | 331 lib->RemoveObserver(this); |
333 lib->RemoveObserverForAllNetworks(this); | 332 lib->RemoveProperyObserver(this); |
334 ReEnableOtherConnections(); | 333 ReEnableOtherConnections(); |
335 } | 334 } |
336 | 335 |
337 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { | 336 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { |
338 return DOMMessageHandler::Attach(dom_ui); | 337 return DOMMessageHandler::Attach(dom_ui); |
339 } | 338 } |
340 | 339 |
341 void MobileSetupHandler::Init(TabContents* contents) { | 340 void MobileSetupHandler::Init(TabContents* contents) { |
342 tab_contents_ = contents; | 341 tab_contents_ = contents; |
343 LoadCellularConfig(); | 342 LoadCellularConfig(); |
344 SetupActivationProcess(GetCellularNetwork(service_path_)); | 343 SetupActivationProcess(GetCellularNetwork(service_path_)); |
345 } | 344 } |
346 | 345 |
347 void MobileSetupHandler::RegisterMessages() { | 346 void MobileSetupHandler::RegisterMessages() { |
348 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, | 347 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, |
349 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); | 348 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); |
350 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, | 349 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, |
351 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); | 350 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); |
352 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, | 351 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, |
353 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); | 352 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); |
354 } | 353 } |
355 | 354 |
356 void MobileSetupHandler::OnNetworkManagerChanged( | 355 void MobileSetupHandler::NetworkChanged(chromeos::NetworkLibrary* lib) { |
357 chromeos::NetworkLibrary* cros) { | |
358 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 356 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
359 return; | 357 return; |
360 // Note that even though we get here when the service has | |
361 // reappeared after disappearing earlier in the activation | |
362 // process, there's no need to re-establish the NetworkObserver, | |
363 // because the service path remains the same. | |
364 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); | 358 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); |
365 } | 359 } |
366 | 360 |
367 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros, | 361 void MobileSetupHandler::PropertyChanged(const char* service_path, |
368 const chromeos::Network* network) { | 362 const char* key, |
| 363 const Value* value) { |
| 364 |
369 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 365 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
370 return; | 366 return; |
371 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR); | 367 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
372 EvaluateCellularNetwork( | 368 if (!network) { |
373 static_cast<chromeos::CellularNetwork*>( | 369 EvaluateCellularNetwork(NULL); |
374 const_cast<chromeos::Network*>(network))); | 370 return; |
| 371 } |
| 372 if (network->service_path() != service_path) { |
| 373 NOTREACHED(); |
| 374 return; |
| 375 } |
| 376 std::string value_string; |
| 377 LOG(INFO) << "Cellular property change: " << key << " = " << |
| 378 value_string.c_str(); |
| 379 |
| 380 // TODO(zelidrag, ers): Remove this once we flip the notification machanism. |
| 381 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->UpdateSystemInfo(); |
| 382 EvaluateCellularNetwork(network); |
375 } | 383 } |
376 | 384 |
377 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { | 385 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { |
378 if (!dom_ui_) | 386 if (!dom_ui_) |
379 return; | 387 return; |
380 Browser* browser = BrowserList::FindBrowserWithFeature( | 388 Browser* browser = BrowserList::FindBrowserWithFeature( |
381 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); | 389 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); |
382 if (browser) | 390 if (browser) |
383 browser->CloseTabContents(tab_contents_); | 391 browser->CloseTabContents(tab_contents_); |
384 } | 392 } |
385 | 393 |
386 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { | 394 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { |
387 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); | 395 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
388 if (!network) { | 396 if (!network) { |
389 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); | 397 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); |
390 return; | 398 return; |
391 } | 399 } |
392 // Start monitoring network property changes. | 400 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
393 chromeos::NetworkLibrary* lib = | 401 GetNetworkLibrary(); |
394 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 402 lib->RemoveObserver(this); |
395 lib->AddNetworkManagerObserver(this); | 403 lib->RemoveProperyObserver(this); |
396 lib->RemoveObserverForAllNetworks(this); | 404 // Start monitoring network and service property changes. |
397 lib->AddNetworkObserver(network->service_path(), this); | 405 lib->AddObserver(this); |
| 406 lib->AddProperyObserver(network->service_path().c_str(), |
| 407 this); |
398 ChangeState(network, PLAN_ACTIVATION_START, std::string()); | 408 ChangeState(network, PLAN_ACTIVATION_START, std::string()); |
399 EvaluateCellularNetwork(network); | 409 EvaluateCellularNetwork(network); |
400 } | 410 } |
401 | 411 |
402 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { | 412 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { |
403 const size_t kSetTransactionStatusParamCount = 1; | 413 const size_t kSetTransactionStatusParamCount = 1; |
404 if (args->GetSize() != kSetTransactionStatusParamCount) | 414 if (args->GetSize() != kSetTransactionStatusParamCount) |
405 return; | 415 return; |
406 | 416 |
407 // Get change callback function name. | 417 // Get change callback function name. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 void MobileSetupHandler::CompleteActivation( | 574 void MobileSetupHandler::CompleteActivation( |
565 chromeos::CellularNetwork* network) { | 575 chromeos::CellularNetwork* network) { |
566 // Remove observers, we are done with this page. | 576 // Remove observers, we are done with this page. |
567 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 577 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
568 GetNetworkLibrary(); | 578 GetNetworkLibrary(); |
569 // If we have successfully activated the connection, set autoconnect flag. | 579 // If we have successfully activated the connection, set autoconnect flag. |
570 if (network) { | 580 if (network) { |
571 network->set_auto_connect(true); | 581 network->set_auto_connect(true); |
572 lib->SaveCellularNetwork(network); | 582 lib->SaveCellularNetwork(network); |
573 } | 583 } |
574 lib->RemoveNetworkManagerObserver(this); | 584 lib->RemoveObserver(this); |
575 lib->RemoveObserverForAllNetworks(this); | 585 lib->RemoveProperyObserver(this); |
576 // Reactivate other types of connections if we have | 586 // Reactivate other types of connections if we have |
577 // shut them down previously. | 587 // shut them down previously. |
578 ReEnableOtherConnections(); | 588 ReEnableOtherConnections(); |
579 } | 589 } |
580 | 590 |
581 | 591 |
582 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, | 592 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, |
583 PlanActivationState new_state, | 593 PlanActivationState new_state, |
584 const std::string& error_description) { | 594 const std::string& error_description) { |
585 static bool first_time = true; | 595 static bool first_time = true; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 new MobileSetupUIHTMLSource(service_path); | 797 new MobileSetupUIHTMLSource(service_path); |
788 | 798 |
789 // Set up the chrome://mobilesetup/ source. | 799 // Set up the chrome://mobilesetup/ source. |
790 BrowserThread::PostTask( | 800 BrowserThread::PostTask( |
791 BrowserThread::IO, FROM_HERE, | 801 BrowserThread::IO, FROM_HERE, |
792 NewRunnableMethod( | 802 NewRunnableMethod( |
793 Singleton<ChromeURLDataManager>::get(), | 803 Singleton<ChromeURLDataManager>::get(), |
794 &ChromeURLDataManager::AddDataSource, | 804 &ChromeURLDataManager::AddDataSource, |
795 make_scoped_refptr(html_source))); | 805 make_scoped_refptr(html_source))); |
796 } | 806 } |
OLD | NEW |