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 : public DOMMessageHandler, | 127 class MobileSetupHandler |
128 public chromeos::NetworkLibrary::Observer, | 128 : public DOMMessageHandler, |
129 public chromeos::NetworkLibrary::PropertyObserver, | 129 public chromeos::NetworkLibrary::NetworkManagerObserver, |
130 public base::SupportsWeakPtr<MobileSetupHandler> { | 130 public chromeos::NetworkLibrary::NetworkObserver, |
| 131 public base::SupportsWeakPtr<MobileSetupHandler> { |
| 132 |
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 state_(PLAN_ACTIVATION_PAGE_LOADING), | 322 state_(PLAN_ACTIVATION_PAGE_LOADING), |
322 service_path_(service_path), | 323 service_path_(service_path), |
323 reenable_wifi_(false), | 324 reenable_wifi_(false), |
324 reenable_ethernet_(false), | 325 reenable_ethernet_(false), |
325 reenable_cert_check_(false) { | 326 reenable_cert_check_(false) { |
326 } | 327 } |
327 | 328 |
328 MobileSetupHandler::~MobileSetupHandler() { | 329 MobileSetupHandler::~MobileSetupHandler() { |
329 chromeos::NetworkLibrary* lib = | 330 chromeos::NetworkLibrary* lib = |
330 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 331 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
331 lib->RemoveObserver(this); | 332 lib->RemoveNetworkManagerObserver(this); |
332 lib->RemoveProperyObserver(this); | 333 lib->RemoveObserverForAllNetworks(this); |
333 ReEnableOtherConnections(); | 334 ReEnableOtherConnections(); |
334 } | 335 } |
335 | 336 |
336 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { | 337 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { |
337 return DOMMessageHandler::Attach(dom_ui); | 338 return DOMMessageHandler::Attach(dom_ui); |
338 } | 339 } |
339 | 340 |
340 void MobileSetupHandler::Init(TabContents* contents) { | 341 void MobileSetupHandler::Init(TabContents* contents) { |
341 tab_contents_ = contents; | 342 tab_contents_ = contents; |
342 LoadCellularConfig(); | 343 LoadCellularConfig(); |
343 SetupActivationProcess(GetCellularNetwork(service_path_)); | 344 SetupActivationProcess(GetCellularNetwork(service_path_)); |
344 } | 345 } |
345 | 346 |
346 void MobileSetupHandler::RegisterMessages() { | 347 void MobileSetupHandler::RegisterMessages() { |
347 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, | 348 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, |
348 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); | 349 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); |
349 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, | 350 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, |
350 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); | 351 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); |
351 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, | 352 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, |
352 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); | 353 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); |
353 } | 354 } |
354 | 355 |
355 void MobileSetupHandler::NetworkChanged(chromeos::NetworkLibrary* lib) { | 356 void MobileSetupHandler::OnNetworkManagerChanged( |
| 357 chromeos::NetworkLibrary* cros) { |
356 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 358 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
357 return; | 359 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. |
358 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); | 364 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); |
359 } | 365 } |
360 | 366 |
361 void MobileSetupHandler::PropertyChanged(const char* service_path, | 367 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros, |
362 const char* key, | 368 const chromeos::Network* network) { |
363 const Value* value) { | |
364 | |
365 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 369 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
366 return; | 370 return; |
367 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); | 371 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR); |
368 if (!network) { | 372 EvaluateCellularNetwork( |
369 EvaluateCellularNetwork(NULL); | 373 static_cast<chromeos::CellularNetwork*>( |
370 return; | 374 const_cast<chromeos::Network*>(network))); |
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); | |
383 } | 375 } |
384 | 376 |
385 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { | 377 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { |
386 if (!dom_ui_) | 378 if (!dom_ui_) |
387 return; | 379 return; |
388 Browser* browser = BrowserList::FindBrowserWithFeature( | 380 Browser* browser = BrowserList::FindBrowserWithFeature( |
389 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); | 381 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); |
390 if (browser) | 382 if (browser) |
391 browser->CloseTabContents(tab_contents_); | 383 browser->CloseTabContents(tab_contents_); |
392 } | 384 } |
393 | 385 |
394 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { | 386 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { |
395 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); | 387 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
396 if (!network) { | 388 if (!network) { |
397 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); | 389 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); |
398 return; | 390 return; |
399 } | 391 } |
400 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 392 // Start monitoring network property changes. |
401 GetNetworkLibrary(); | 393 chromeos::NetworkLibrary* lib = |
402 lib->RemoveObserver(this); | 394 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
403 lib->RemoveProperyObserver(this); | 395 lib->AddNetworkManagerObserver(this); |
404 // Start monitoring network and service property changes. | 396 lib->RemoveObserverForAllNetworks(this); |
405 lib->AddObserver(this); | 397 lib->AddNetworkObserver(network->service_path(), this); |
406 lib->AddProperyObserver(network->service_path().c_str(), | |
407 this); | |
408 ChangeState(network, PLAN_ACTIVATION_START, std::string()); | 398 ChangeState(network, PLAN_ACTIVATION_START, std::string()); |
409 EvaluateCellularNetwork(network); | 399 EvaluateCellularNetwork(network); |
410 } | 400 } |
411 | 401 |
412 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { | 402 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { |
413 const size_t kSetTransactionStatusParamCount = 1; | 403 const size_t kSetTransactionStatusParamCount = 1; |
414 if (args->GetSize() != kSetTransactionStatusParamCount) | 404 if (args->GetSize() != kSetTransactionStatusParamCount) |
415 return; | 405 return; |
416 | 406 |
417 // Get change callback function name. | 407 // Get change callback function name. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 void MobileSetupHandler::CompleteActivation( | 564 void MobileSetupHandler::CompleteActivation( |
575 chromeos::CellularNetwork* network) { | 565 chromeos::CellularNetwork* network) { |
576 // Remove observers, we are done with this page. | 566 // Remove observers, we are done with this page. |
577 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 567 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
578 GetNetworkLibrary(); | 568 GetNetworkLibrary(); |
579 // If we have successfully activated the connection, set autoconnect flag. | 569 // If we have successfully activated the connection, set autoconnect flag. |
580 if (network) { | 570 if (network) { |
581 network->set_auto_connect(true); | 571 network->set_auto_connect(true); |
582 lib->SaveCellularNetwork(network); | 572 lib->SaveCellularNetwork(network); |
583 } | 573 } |
584 lib->RemoveObserver(this); | 574 lib->RemoveNetworkManagerObserver(this); |
585 lib->RemoveProperyObserver(this); | 575 lib->RemoveObserverForAllNetworks(this); |
586 // Reactivate other types of connections if we have | 576 // Reactivate other types of connections if we have |
587 // shut them down previously. | 577 // shut them down previously. |
588 ReEnableOtherConnections(); | 578 ReEnableOtherConnections(); |
589 } | 579 } |
590 | 580 |
591 | 581 |
592 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, | 582 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, |
593 PlanActivationState new_state, | 583 PlanActivationState new_state, |
594 const std::string& error_description) { | 584 const std::string& error_description) { |
595 static bool first_time = true; | 585 static bool first_time = true; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 new MobileSetupUIHTMLSource(service_path); | 787 new MobileSetupUIHTMLSource(service_path); |
798 | 788 |
799 // Set up the chrome://mobilesetup/ source. | 789 // Set up the chrome://mobilesetup/ source. |
800 BrowserThread::PostTask( | 790 BrowserThread::PostTask( |
801 BrowserThread::IO, FROM_HERE, | 791 BrowserThread::IO, FROM_HERE, |
802 NewRunnableMethod( | 792 NewRunnableMethod( |
803 Singleton<ChromeURLDataManager>::get(), | 793 Singleton<ChromeURLDataManager>::get(), |
804 &ChromeURLDataManager::AddDataSource, | 794 &ChromeURLDataManager::AddDataSource, |
805 make_scoped_refptr(html_source))); | 795 make_scoped_refptr(html_source))); |
806 } | 796 } |
OLD | NEW |