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/fake_wifi_service.h" | 5 #include "components/wifi/fake_wifi_service.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
9 #include "components/onc/onc_constants.h" | 11 #include "components/onc/onc_constants.h" |
10 | 12 |
11 namespace wifi { | 13 namespace wifi { |
12 | 14 |
13 FakeWiFiService::FakeWiFiService() { | 15 FakeWiFiService::FakeWiFiService() { |
14 // Populate data expected by unit test. | 16 // Populate data expected by unit test. |
15 { | 17 { |
16 NetworkProperties network_properties; | 18 NetworkProperties network_properties; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 NetworkList::iterator network_properties = FindNetwork(network_guid); | 77 NetworkList::iterator network_properties = FindNetwork(network_guid); |
76 if (network_properties == networks_.end()) { | 78 if (network_properties == networks_.end()) { |
77 *error = "Error.InvalidNetworkGuid"; | 79 *error = "Error.InvalidNetworkGuid"; |
78 return; | 80 return; |
79 } | 81 } |
80 properties->Swap(network_properties->ToValue(true).get()); | 82 properties->Swap(network_properties->ToValue(true).get()); |
81 } | 83 } |
82 | 84 |
83 void FakeWiFiService::SetProperties( | 85 void FakeWiFiService::SetProperties( |
84 const std::string& network_guid, | 86 const std::string& network_guid, |
85 scoped_ptr<base::DictionaryValue> properties, | 87 std::unique_ptr<base::DictionaryValue> properties, |
86 std::string* error) { | 88 std::string* error) { |
87 NetworkList::iterator network_properties = FindNetwork(network_guid); | 89 NetworkList::iterator network_properties = FindNetwork(network_guid); |
88 if (network_properties == networks_.end() || | 90 if (network_properties == networks_.end() || |
89 !network_properties->UpdateFromValue(*properties)) { | 91 !network_properties->UpdateFromValue(*properties)) { |
90 *error = "Error.DBusFailed"; | 92 *error = "Error.DBusFailed"; |
91 } | 93 } |
92 } | 94 } |
93 | 95 |
94 void FakeWiFiService::CreateNetwork( | 96 void FakeWiFiService::CreateNetwork( |
95 bool shared, | 97 bool shared, |
96 scoped_ptr<base::DictionaryValue> properties, | 98 std::unique_ptr<base::DictionaryValue> properties, |
97 std::string* network_guid, | 99 std::string* network_guid, |
98 std::string* error) { | 100 std::string* error) { |
99 NetworkProperties network_properties; | 101 NetworkProperties network_properties; |
100 if (network_properties.UpdateFromValue(*properties)) { | 102 if (network_properties.UpdateFromValue(*properties)) { |
101 network_properties.guid = network_properties.ssid; | 103 network_properties.guid = network_properties.ssid; |
102 networks_.push_back(network_properties); | 104 networks_.push_back(network_properties); |
103 *network_guid = network_properties.guid; | 105 *network_guid = network_properties.guid; |
104 } else { | 106 } else { |
105 *error = "Error.DBusFailed"; | 107 *error = "Error.DBusFailed"; |
106 } | 108 } |
107 } | 109 } |
108 | 110 |
109 void FakeWiFiService::GetVisibleNetworks(const std::string& network_type, | 111 void FakeWiFiService::GetVisibleNetworks(const std::string& network_type, |
110 base::ListValue* network_list, | 112 base::ListValue* network_list, |
111 bool include_details) { | 113 bool include_details) { |
112 for (NetworkList::const_iterator it = networks_.begin(); | 114 for (NetworkList::const_iterator it = networks_.begin(); |
113 it != networks_.end(); | 115 it != networks_.end(); |
114 ++it) { | 116 ++it) { |
115 if (network_type.empty() || network_type == onc::network_type::kAllTypes || | 117 if (network_type.empty() || network_type == onc::network_type::kAllTypes || |
116 it->type == network_type) { | 118 it->type == network_type) { |
117 scoped_ptr<base::DictionaryValue> network(it->ToValue(!include_details)); | 119 std::unique_ptr<base::DictionaryValue> network( |
| 120 it->ToValue(!include_details)); |
118 network_list->Append(network.release()); | 121 network_list->Append(network.release()); |
119 } | 122 } |
120 } | 123 } |
121 } | 124 } |
122 | 125 |
123 void FakeWiFiService::RequestNetworkScan() { | 126 void FakeWiFiService::RequestNetworkScan() { |
124 NotifyNetworkListChanged(networks_); | 127 NotifyNetworkListChanged(networks_); |
125 } | 128 } |
126 | 129 |
127 void FakeWiFiService::StartConnect(const std::string& network_guid, | 130 void FakeWiFiService::StartConnect(const std::string& network_guid, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); | 213 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); |
211 } | 214 } |
212 | 215 |
213 void FakeWiFiService::NotifyNetworkChanged(const std::string& network_guid) { | 216 void FakeWiFiService::NotifyNetworkChanged(const std::string& network_guid) { |
214 WiFiService::NetworkGuidList changed_networks(1, network_guid); | 217 WiFiService::NetworkGuidList changed_networks(1, network_guid); |
215 task_runner_->PostTask( | 218 task_runner_->PostTask( |
216 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); | 219 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); |
217 } | 220 } |
218 | 221 |
219 } // namespace wifi | 222 } // namespace wifi |
OLD | NEW |