| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/local_discovery/wifi/wifi_manager_nonchromeos.h" | 5 #include "chrome/browser/local_discovery/wifi/wifi_manager_nonchromeos.h" |
| 6 | 6 |
| 7 #include "base/cancelable_callback.h" | 7 #include "base/cancelable_callback.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "components/onc/onc_constants.h" | 10 #include "components/onc/onc_constants.h" |
| 11 #include "components/wifi/wifi_service.h" | 11 #include "components/wifi/wifi_service.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
| 14 | 14 |
| 15 #if defined(OS_WIN) |
| 16 #include "chrome/browser/local_discovery/wifi/credential_getter_win.h" |
| 17 #endif // OS_WIN |
| 18 |
| 15 using ::wifi::WiFiService; | 19 using ::wifi::WiFiService; |
| 16 | 20 |
| 17 namespace local_discovery { | 21 namespace local_discovery { |
| 18 | 22 |
| 19 namespace wifi { | 23 namespace wifi { |
| 20 | 24 |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 const int kConnectionTimeoutSeconds = 10; | 27 const int kConnectionTimeoutSeconds = 10; |
| 24 | 28 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 bool IsConnected(const std::string& network_guid); | 93 bool IsConnected(const std::string& network_guid); |
| 90 | 94 |
| 91 void OnConnectToNetworkTimeout(); | 95 void OnConnectToNetworkTimeout(); |
| 92 | 96 |
| 93 void PostClosure(const base::Closure& closure); | 97 void PostClosure(const base::Closure& closure); |
| 94 | 98 |
| 95 bool FindAndConfigureNetwork(const std::string& ssid, | 99 bool FindAndConfigureNetwork(const std::string& ssid, |
| 96 const std::string& password, | 100 const std::string& password, |
| 97 std::string* network_guid); | 101 std::string* network_guid); |
| 98 | 102 |
| 103 #if defined(OS_WIN) |
| 104 void PostCredentialsCallback(const WifiManager::CredentialsCallback& callback, |
| 105 const std::string& ssid, |
| 106 bool success, |
| 107 const std::string& password); |
| 108 #endif // OS_WIN |
| 109 |
| 99 scoped_ptr<WiFiService> wifi_service_; | 110 scoped_ptr<WiFiService> wifi_service_; |
| 100 | 111 |
| 101 base::WeakPtr<WifiManagerNonChromeos> wifi_manager_; | 112 base::WeakPtr<WifiManagerNonChromeos> wifi_manager_; |
| 102 | 113 |
| 103 WifiManager::SuccessCallback connect_success_callback_; | 114 WifiManager::SuccessCallback connect_success_callback_; |
| 104 base::CancelableClosure connect_failure_callback_; | 115 base::CancelableClosure connect_failure_callback_; |
| 105 | 116 |
| 106 // SSID of previously connected network. | 117 // SSID of previously connected network. |
| 107 std::string connected_network_guid_; | 118 std::string connected_network_guid_; |
| 108 | 119 |
| 109 // SSID of network we are connecting to. | 120 // SSID of network we are connecting to. |
| 110 std::string connecting_network_guid_; | 121 std::string connecting_network_guid_; |
| 111 | 122 |
| 112 scoped_refptr<base::MessageLoopProxy> callback_runner_; | 123 scoped_refptr<base::MessageLoopProxy> callback_runner_; |
| 113 | 124 |
| 114 base::WeakPtrFactory<WifiServiceWrapper> weak_factory_; | 125 base::WeakPtrFactory<WifiServiceWrapper> weak_factory_; |
| 115 | 126 |
| 127 #if defined(OS_WIN) |
| 128 scoped_refptr<CredentialGetterWin> credential_getter_; |
| 129 #endif // OS_WIN |
| 130 |
| 116 DISALLOW_COPY_AND_ASSIGN(WifiServiceWrapper); | 131 DISALLOW_COPY_AND_ASSIGN(WifiServiceWrapper); |
| 117 }; | 132 }; |
| 118 | 133 |
| 119 WifiManagerNonChromeos::WifiServiceWrapper::WifiServiceWrapper( | 134 WifiManagerNonChromeos::WifiServiceWrapper::WifiServiceWrapper( |
| 120 base::WeakPtr<WifiManagerNonChromeos> wifi_manager) | 135 base::WeakPtr<WifiManagerNonChromeos> wifi_manager) |
| 121 : wifi_manager_(wifi_manager), | 136 : wifi_manager_(wifi_manager), |
| 122 callback_runner_(base::MessageLoopProxy::current()), | 137 callback_runner_(base::MessageLoopProxy::current()), |
| 123 weak_factory_(this) { | 138 weak_factory_(this) { |
| 124 } | 139 } |
| 125 | 140 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 294 |
| 280 void WifiManagerNonChromeos::WifiServiceWrapper::RequestNetworkCredentials( | 295 void WifiManagerNonChromeos::WifiServiceWrapper::RequestNetworkCredentials( |
| 281 const std::string& ssid, | 296 const std::string& ssid, |
| 282 const WifiManager::CredentialsCallback& callback) { | 297 const WifiManager::CredentialsCallback& callback) { |
| 283 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 298 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 284 | 299 |
| 285 bool success = true; | 300 bool success = true; |
| 286 std::string guid; | 301 std::string guid; |
| 287 std::string key; | 302 std::string key; |
| 288 | 303 |
| 289 #if defined(OS_WIN) | |
| 290 NOTIMPLEMENTED(); | |
| 291 success = false; | |
| 292 #else | |
| 293 NetworkPropertiesList network_list; | 304 NetworkPropertiesList network_list; |
| 294 | 305 |
| 295 GetSSIDListInternal(&network_list); | 306 GetSSIDListInternal(&network_list); |
| 296 | 307 |
| 297 for (NetworkPropertiesList::iterator i = network_list.begin(); | 308 for (NetworkPropertiesList::iterator i = network_list.begin(); |
| 298 i != network_list.end(); | 309 i != network_list.end(); |
| 299 i++) { | 310 i++) { |
| 300 if (i->ssid == ssid) { | 311 if (i->ssid == ssid) { |
| 301 guid = i->guid; | 312 guid = i->guid; |
| 302 break; | 313 break; |
| 303 } | 314 } |
| 304 } | 315 } |
| 305 | 316 |
| 306 if (guid.empty()) { | 317 if (guid.empty()) { |
| 307 success = false; | 318 success = false; |
| 308 } | 319 } |
| 309 | 320 |
| 321 if (!success) { |
| 322 PostClosure(base::Bind(callback, success, "", "")); |
| 323 return; |
| 324 } |
| 325 |
| 326 #if defined(OS_WIN) |
| 327 credential_getter_ = new CredentialGetterWin(); |
| 328 credential_getter_->StartGetCredentials( |
| 329 guid, |
| 330 base::Bind(&WifiServiceWrapper::PostCredentialsCallback, |
| 331 AsWeakPtr(), |
| 332 callback, |
| 333 ssid)); |
| 334 #else |
| 310 if (success) { | 335 if (success) { |
| 311 std::string error_string; | 336 std::string error_string; |
| 312 wifi_service_->GetKeyFromSystem(guid, &key, &error_string); | 337 wifi_service_->GetKeyFromSystem(guid, &key, &error_string); |
| 313 | 338 |
| 314 if (!error_string.empty()) { | 339 if (!error_string.empty()) { |
| 315 LOG(ERROR) << "Could not get key from system: " << error_string; | 340 LOG(ERROR) << "Could not get key from system: " << error_string; |
| 316 success = false; | 341 success = false; |
| 317 } | 342 } |
| 343 |
| 344 PostClosure(base::Bind(callback, success, ssid, key)); |
| 318 } | 345 } |
| 319 #endif // OS_WIN | 346 #endif // OS_WIN |
| 320 PostClosure(base::Bind(callback, success, ssid, key)); | |
| 321 } | 347 } |
| 322 | 348 |
| 323 void WifiManagerNonChromeos::WifiServiceWrapper::OnNetworkChanged( | 349 void WifiManagerNonChromeos::WifiServiceWrapper::OnNetworkChanged( |
| 324 net::NetworkChangeNotifier::ConnectionType type) { | 350 net::NetworkChangeNotifier::ConnectionType type) { |
| 325 wifi_service_->RequestConnectedNetworkUpdate(); | 351 wifi_service_->RequestConnectedNetworkUpdate(); |
| 326 } | 352 } |
| 327 | 353 |
| 328 void WifiManagerNonChromeos::WifiServiceWrapper::GetSSIDListInternal( | 354 void WifiManagerNonChromeos::WifiServiceWrapper::GetSSIDListInternal( |
| 329 NetworkPropertiesList* ssid_list) { | 355 NetworkPropertiesList* ssid_list) { |
| 330 base::ListValue visible_networks; | 356 base::ListValue visible_networks; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 return true; | 437 return true; |
| 412 } | 438 } |
| 413 | 439 |
| 414 void WifiManagerNonChromeos::WifiServiceWrapper::PostClosure( | 440 void WifiManagerNonChromeos::WifiServiceWrapper::PostClosure( |
| 415 const base::Closure& closure) { | 441 const base::Closure& closure) { |
| 416 callback_runner_->PostTask( | 442 callback_runner_->PostTask( |
| 417 FROM_HERE, | 443 FROM_HERE, |
| 418 base::Bind(&WifiManagerNonChromeos::PostClosure, wifi_manager_, closure)); | 444 base::Bind(&WifiManagerNonChromeos::PostClosure, wifi_manager_, closure)); |
| 419 } | 445 } |
| 420 | 446 |
| 447 #if defined(OS_WIN) |
| 448 void WifiManagerNonChromeos::WifiServiceWrapper::PostCredentialsCallback( |
| 449 const WifiManager::CredentialsCallback& callback, |
| 450 const std::string& ssid, |
| 451 bool success, |
| 452 const std::string& password) { |
| 453 PostClosure(base::Bind(callback, success, ssid, password)); |
| 454 } |
| 455 |
| 456 #endif // OS_WIN |
| 457 |
| 421 scoped_ptr<WifiManager> WifiManager::CreateDefault() { | 458 scoped_ptr<WifiManager> WifiManager::CreateDefault() { |
| 422 return scoped_ptr<WifiManager>(new WifiManagerNonChromeos()); | 459 return scoped_ptr<WifiManager>(new WifiManagerNonChromeos()); |
| 423 } | 460 } |
| 424 | 461 |
| 425 WifiManagerNonChromeos::WifiManagerNonChromeos() | 462 WifiManagerNonChromeos::WifiManagerNonChromeos() |
| 426 : wifi_wrapper_(NULL), weak_factory_(this) { | 463 : wifi_wrapper_(NULL), weak_factory_(this) { |
| 427 } | 464 } |
| 428 | 465 |
| 429 WifiManagerNonChromeos::~WifiManagerNonChromeos() { | 466 WifiManagerNonChromeos::~WifiManagerNonChromeos() { |
| 430 if (wifi_wrapper_) { | 467 if (wifi_wrapper_) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 } | 562 } |
| 526 | 563 |
| 527 void WifiManagerNonChromeos::RemoveNetworkListObserver( | 564 void WifiManagerNonChromeos::RemoveNetworkListObserver( |
| 528 NetworkListObserver* observer) { | 565 NetworkListObserver* observer) { |
| 529 network_list_observers_.RemoveObserver(observer); | 566 network_list_observers_.RemoveObserver(observer); |
| 530 } | 567 } |
| 531 | 568 |
| 532 } // namespace wifi | 569 } // namespace wifi |
| 533 | 570 |
| 534 } // namespace local_discovery | 571 } // namespace local_discovery |
| OLD | NEW |