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& network_guid, | 296 const std::string& network_guid, |
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 ssid; | 301 std::string ssid; |
287 std::string key; | 302 std::string key; |
288 | 303 |
289 #if defined(OS_WIN) | |
290 NOTIMPLEMENTED(); | |
291 success = false; | |
292 #else | |
293 base::DictionaryValue properties; | 304 base::DictionaryValue properties; |
294 std::string error_string; | 305 std::string error_string; |
295 wifi_service_->GetProperties(network_guid, &properties, &error_string); | 306 wifi_service_->GetProperties(network_guid, &properties, &error_string); |
296 | 307 |
297 if (!error_string.empty()) { | 308 if (!error_string.empty()) { |
298 LOG(ERROR) << "Could not get network properties: " << error_string; | 309 LOG(ERROR) << "Could not get network properties: " << error_string; |
299 success = false; | 310 success = false; |
300 } | 311 } |
301 | 312 |
302 if (!properties.GetString(onc::network_config::kName, &ssid)) { | 313 if (!properties.GetString(onc::network_config::kName, &ssid)) { |
303 LOG(ERROR) << "Could not get network SSID"; | 314 LOG(ERROR) << "Could not get network SSID"; |
304 success = false; | 315 success = false; |
305 } | 316 } |
306 | 317 |
307 if (success) { | 318 if (!success) { |
| 319 PostClosure(base::Bind(callback, success, "", "")); |
| 320 return; |
| 321 } |
| 322 |
| 323 #if defined(OS_WIN) |
| 324 credential_getter_ = new CredentialGetterWin(); |
| 325 credential_getter_->StartGetCredentials( |
| 326 network_guid, |
| 327 base::Bind(&WifiServiceWrapper::PostCredentialsCallback, |
| 328 AsWeakPtr(), |
| 329 callback, |
| 330 ssid)); |
| 331 #else |
308 wifi_service_->GetKeyFromSystem(network_guid, &key, &error_string); | 332 wifi_service_->GetKeyFromSystem(network_guid, &key, &error_string); |
309 | 333 |
310 if (!error_string.empty()) { | 334 if (!error_string.empty()) { |
311 LOG(ERROR) << "Could not get key from system: " << error_string; | 335 LOG(ERROR) << "Could not get key from system: " << error_string; |
312 success = false; | 336 success = false; |
313 } | 337 } |
314 } | 338 |
| 339 PostClosure(base::Bind(callback, success, ssid, key)); |
315 #endif // OS_WIN | 340 #endif // OS_WIN |
316 PostClosure(base::Bind(callback, success, ssid, key)); | |
317 } | 341 } |
318 | 342 |
319 void WifiManagerNonChromeos::WifiServiceWrapper::OnNetworkChanged( | 343 void WifiManagerNonChromeos::WifiServiceWrapper::OnNetworkChanged( |
320 net::NetworkChangeNotifier::ConnectionType type) { | 344 net::NetworkChangeNotifier::ConnectionType type) { |
321 wifi_service_->RequestConnectedNetworkUpdate(); | 345 wifi_service_->RequestConnectedNetworkUpdate(); |
322 } | 346 } |
323 | 347 |
324 void WifiManagerNonChromeos::WifiServiceWrapper::GetSSIDListInternal( | 348 void WifiManagerNonChromeos::WifiServiceWrapper::GetSSIDListInternal( |
325 NetworkPropertiesList* ssid_list) { | 349 NetworkPropertiesList* ssid_list) { |
326 base::ListValue visible_networks; | 350 base::ListValue visible_networks; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return true; | 431 return true; |
408 } | 432 } |
409 | 433 |
410 void WifiManagerNonChromeos::WifiServiceWrapper::PostClosure( | 434 void WifiManagerNonChromeos::WifiServiceWrapper::PostClosure( |
411 const base::Closure& closure) { | 435 const base::Closure& closure) { |
412 callback_runner_->PostTask( | 436 callback_runner_->PostTask( |
413 FROM_HERE, | 437 FROM_HERE, |
414 base::Bind(&WifiManagerNonChromeos::PostClosure, wifi_manager_, closure)); | 438 base::Bind(&WifiManagerNonChromeos::PostClosure, wifi_manager_, closure)); |
415 } | 439 } |
416 | 440 |
| 441 #if defined(OS_WIN) |
| 442 |
| 443 void WifiManagerNonChromeos::WifiServiceWrapper::PostCredentialsCallback( |
| 444 const WifiManager::CredentialsCallback& callback, |
| 445 const std::string& ssid, |
| 446 bool success, |
| 447 const std::string& password) { |
| 448 PostClosure(base::Bind(callback, success, ssid, password)); |
| 449 } |
| 450 |
| 451 #endif // OS_WIN |
| 452 |
417 scoped_ptr<WifiManager> WifiManager::CreateDefault() { | 453 scoped_ptr<WifiManager> WifiManager::CreateDefault() { |
418 return scoped_ptr<WifiManager>(new WifiManagerNonChromeos()); | 454 return scoped_ptr<WifiManager>(new WifiManagerNonChromeos()); |
419 } | 455 } |
420 | 456 |
421 WifiManagerNonChromeos::WifiManagerNonChromeos() | 457 WifiManagerNonChromeos::WifiManagerNonChromeos() |
422 : wifi_wrapper_(NULL), weak_factory_(this) { | 458 : wifi_wrapper_(NULL), weak_factory_(this) { |
423 } | 459 } |
424 | 460 |
425 WifiManagerNonChromeos::~WifiManagerNonChromeos() { | 461 WifiManagerNonChromeos::~WifiManagerNonChromeos() { |
426 if (wifi_wrapper_) { | 462 if (wifi_wrapper_) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 } | 557 } |
522 | 558 |
523 void WifiManagerNonChromeos::RemoveNetworkListObserver( | 559 void WifiManagerNonChromeos::RemoveNetworkListObserver( |
524 NetworkListObserver* observer) { | 560 NetworkListObserver* observer) { |
525 network_list_observers_.RemoveObserver(observer); | 561 network_list_observers_.RemoveObserver(observer); |
526 } | 562 } |
527 | 563 |
528 } // namespace wifi | 564 } // namespace wifi |
529 | 565 |
530 } // namespace local_discovery | 566 } // namespace local_discovery |
OLD | NEW |