OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/wifi/wifi_service.h" | 5 #include "components/wifi/wifi_service.h" |
6 | 6 |
7 #include <iphlpapi.h> | 7 #include <iphlpapi.h> |
8 #include <objbase.h> | 8 #include <objbase.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <wlanapi.h> | 11 #include <wlanapi.h> |
12 | 12 |
| 13 #include <memory> |
13 #include <set> | 14 #include <set> |
| 15 #include <utility> |
14 | 16 |
15 #include "base/base_paths_win.h" | 17 #include "base/base_paths_win.h" |
16 #include "base/bind.h" | 18 #include "base/bind.h" |
17 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
18 #include "base/macros.h" | 20 #include "base/macros.h" |
19 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
20 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
21 #include "base/path_service.h" | 23 #include "base/path_service.h" |
22 #include "base/strings/string16.h" | 24 #include "base/strings/string16.h" |
23 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/values.h" |
25 #include "base/win/registry.h" | 28 #include "base/win/registry.h" |
26 #include "components/onc/onc_constants.h" | 29 #include "components/onc/onc_constants.h" |
27 #include "components/wifi/network_properties.h" | 30 #include "components/wifi/network_properties.h" |
28 #include "third_party/libxml/chromium/libxml_utils.h" | 31 #include "third_party/libxml/chromium/libxml_utils.h" |
29 | 32 |
30 namespace { | 33 namespace { |
31 const wchar_t kNwCategoryWizardRegKey[] = | 34 const wchar_t kNwCategoryWizardRegKey[] = |
32 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" | 35 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" |
33 L"NwCategoryWizard"; | 36 L"NwCategoryWizard"; |
34 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; | 37 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 577 } |
575 | 578 |
576 base::DictionaryValue* existing_properties; | 579 base::DictionaryValue* existing_properties; |
577 // If the network properties already exist, don't override previously set | 580 // If the network properties already exist, don't override previously set |
578 // properties, unless they are set in |properties|. | 581 // properties, unless they are set in |properties|. |
579 if (connect_properties_.GetDictionaryWithoutPathExpansion( | 582 if (connect_properties_.GetDictionaryWithoutPathExpansion( |
580 network_guid, &existing_properties)) { | 583 network_guid, &existing_properties)) { |
581 existing_properties->MergeDictionary(properties.get()); | 584 existing_properties->MergeDictionary(properties.get()); |
582 } else { | 585 } else { |
583 connect_properties_.SetWithoutPathExpansion(network_guid, | 586 connect_properties_.SetWithoutPathExpansion(network_guid, |
584 properties.release()); | 587 std::move(properties)); |
585 } | 588 } |
586 } | 589 } |
587 | 590 |
588 void WiFiServiceImpl::CreateNetwork( | 591 void WiFiServiceImpl::CreateNetwork( |
589 bool shared, | 592 bool shared, |
590 std::unique_ptr<base::DictionaryValue> properties, | 593 std::unique_ptr<base::DictionaryValue> properties, |
591 std::string* network_guid, | 594 std::string* network_guid, |
592 std::string* error) { | 595 std::string* error) { |
593 DWORD error_code = EnsureInitialized(); | 596 DWORD error_code = EnsureInitialized(); |
594 if (CheckError(error_code, kErrorWiFiService, error)) | 597 if (CheckError(error_code, kErrorWiFiService, error)) |
(...skipping 28 matching lines...) Expand all Loading... |
623 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); | 626 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); |
624 return; | 627 return; |
625 } | 628 } |
626 | 629 |
627 if (tkip_profile_xml != profile_xml) { | 630 if (tkip_profile_xml != profile_xml) { |
628 std::unique_ptr<base::DictionaryValue> tkip_profile( | 631 std::unique_ptr<base::DictionaryValue> tkip_profile( |
629 new base::DictionaryValue()); | 632 new base::DictionaryValue()); |
630 tkip_profile->SetString(kProfileXmlKey, tkip_profile_xml); | 633 tkip_profile->SetString(kProfileXmlKey, tkip_profile_xml); |
631 tkip_profile->SetBoolean(kProfileSharedKey, shared); | 634 tkip_profile->SetBoolean(kProfileSharedKey, shared); |
632 created_profiles_.SetWithoutPathExpansion(network_properties.guid, | 635 created_profiles_.SetWithoutPathExpansion(network_properties.guid, |
633 tkip_profile.release()); | 636 std::move(tkip_profile)); |
634 } | 637 } |
635 | 638 |
636 *network_guid = network_properties.guid; | 639 *network_guid = network_properties.guid; |
637 } | 640 } |
638 | 641 |
639 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, | 642 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, |
640 base::ListValue* network_list, | 643 base::ListValue* network_list, |
641 bool include_details) { | 644 bool include_details) { |
642 if (!network_type.empty() && | 645 if (!network_type.empty() && |
643 network_type != onc::network_type::kAllTypes && | 646 network_type != onc::network_type::kAllTypes && |
644 network_type != onc::network_type::kWiFi) { | 647 network_type != onc::network_type::kWiFi) { |
645 return; | 648 return; |
646 } | 649 } |
647 | 650 |
648 DWORD error = EnsureInitialized(); | 651 DWORD error = EnsureInitialized(); |
649 if (error == ERROR_SUCCESS) { | 652 if (error == ERROR_SUCCESS) { |
650 NetworkList networks; | 653 NetworkList networks; |
651 error = GetVisibleNetworkList(&networks); | 654 error = GetVisibleNetworkList(&networks); |
652 if (error == ERROR_SUCCESS && !networks.empty()) { | 655 if (error == ERROR_SUCCESS && !networks.empty()) { |
653 SortNetworks(&networks); | 656 SortNetworks(&networks); |
654 for (NetworkList::const_iterator it = networks.begin(); | 657 for (NetworkList::const_iterator it = networks.begin(); |
655 it != networks.end(); | 658 it != networks.end(); |
656 ++it) { | 659 ++it) { |
657 std::unique_ptr<base::DictionaryValue> network( | 660 std::unique_ptr<base::DictionaryValue> network( |
658 it->ToValue(!include_details)); | 661 it->ToValue(!include_details)); |
659 network_list->Append(network.release()); | 662 network_list->Append(std::move(network)); |
660 } | 663 } |
661 } | 664 } |
662 } | 665 } |
663 } | 666 } |
664 | 667 |
665 void WiFiServiceImpl::RequestNetworkScan() { | 668 void WiFiServiceImpl::RequestNetworkScan() { |
666 DWORD error = EnsureInitialized(); | 669 DWORD error = EnsureInitialized(); |
667 if (error == ERROR_SUCCESS) { | 670 if (error == ERROR_SUCCESS) { |
668 WlanScan_function_(client_, &interface_guid_, NULL, NULL, NULL); | 671 WlanScan_function_(client_, &interface_guid_, NULL, NULL, NULL); |
669 } | 672 } |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; | 1897 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; |
1895 NetworkGuidList changed_networks(1, network_guid); | 1898 NetworkGuidList changed_networks(1, network_guid); |
1896 event_task_runner_->PostTask( | 1899 event_task_runner_->PostTask( |
1897 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); | 1900 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); |
1898 } | 1901 } |
1899 } | 1902 } |
1900 | 1903 |
1901 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1904 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
1902 | 1905 |
1903 } // namespace wifi | 1906 } // namespace wifi |
OLD | NEW |