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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "components/onc/onc_constants.h" | 10 #include "components/onc/onc_constants.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 void FakeWiFiService::UnInitialize() { | 64 void FakeWiFiService::UnInitialize() { |
65 } | 65 } |
66 | 66 |
67 void FakeWiFiService::GetProperties(const std::string& network_guid, | 67 void FakeWiFiService::GetProperties(const std::string& network_guid, |
68 base::DictionaryValue* properties, | 68 base::DictionaryValue* properties, |
69 std::string* error) { | 69 std::string* error) { |
70 WiFiService::NetworkList::iterator network_properties = | 70 WiFiService::NetworkList::iterator network_properties = |
71 FindNetwork(network_guid); | 71 FindNetwork(network_guid); |
72 if (network_properties != networks_.end()) { | 72 if (network_properties == networks_.end()) { |
73 properties->Swap(network_properties->ToValue(false).get()); | 73 *error = "Error.InvalidNetworkGuid"; |
74 } else { | 74 return; |
75 *error = "Error.DBusFailed"; | |
76 } | 75 } |
| 76 properties->Swap(network_properties->ToValue(false).get()); |
77 } | 77 } |
78 | 78 |
79 void FakeWiFiService::GetManagedProperties( | 79 void FakeWiFiService::GetManagedProperties( |
80 const std::string& network_guid, | 80 const std::string& network_guid, |
81 base::DictionaryValue* managed_properties, | 81 base::DictionaryValue* managed_properties, |
82 std::string* error) { | 82 std::string* error) { |
83 // Not implemented | 83 // Not implemented |
84 *error = kErrorWiFiService; | 84 *error = kErrorWiFiService; |
85 } | 85 } |
86 | 86 |
87 void FakeWiFiService::GetState(const std::string& network_guid, | 87 void FakeWiFiService::GetState(const std::string& network_guid, |
88 base::DictionaryValue* properties, | 88 base::DictionaryValue* properties, |
89 std::string* error) { | 89 std::string* error) { |
90 WiFiService::NetworkList::iterator network_properties = | 90 WiFiService::NetworkList::iterator network_properties = |
91 FindNetwork(network_guid); | 91 FindNetwork(network_guid); |
92 if (network_properties == networks_.end()) { | 92 if (network_properties == networks_.end()) { |
93 *error = "Error.InvalidParameter"; | 93 *error = "Error.InvalidNetworkGuid"; |
94 return; | 94 return; |
95 } | 95 } |
96 properties->Swap(network_properties->ToValue(true).get()); | 96 properties->Swap(network_properties->ToValue(true).get()); |
97 } | 97 } |
98 | 98 |
99 void FakeWiFiService::SetProperties( | 99 void FakeWiFiService::SetProperties( |
100 const std::string& network_guid, | 100 const std::string& network_guid, |
101 scoped_ptr<base::DictionaryValue> properties, | 101 scoped_ptr<base::DictionaryValue> properties, |
102 std::string* error) { | 102 std::string* error) { |
103 WiFiService::NetworkList::iterator network_properties = | 103 WiFiService::NetworkList::iterator network_properties = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void FakeWiFiService::RequestNetworkScan() { | 139 void FakeWiFiService::RequestNetworkScan() { |
140 NotifyNetworkListChanged(networks_); | 140 NotifyNetworkListChanged(networks_); |
141 } | 141 } |
142 | 142 |
143 void FakeWiFiService::StartConnect(const std::string& network_guid, | 143 void FakeWiFiService::StartConnect(const std::string& network_guid, |
144 std::string* error) { | 144 std::string* error) { |
145 NetworkList::iterator network_properties = FindNetwork(network_guid); | 145 NetworkList::iterator network_properties = FindNetwork(network_guid); |
146 if (network_properties != networks_.end()) { | 146 if (network_properties == networks_.end()) { |
147 DisconnectAllNetworksOfType(network_properties->type); | 147 *error = "Error.InvalidNetworkGuid"; |
148 network_properties->connection_state = onc::connection_state::kConnected; | 148 return; |
149 SortNetworks(); | |
150 NotifyNetworkListChanged(networks_); | |
151 NotifyNetworkChanged(network_guid); | |
152 } else { | |
153 *error = "configure-failed"; | |
154 } | 149 } |
| 150 DisconnectAllNetworksOfType(network_properties->type); |
| 151 network_properties->connection_state = onc::connection_state::kConnected; |
| 152 SortNetworks(); |
| 153 NotifyNetworkListChanged(networks_); |
| 154 NotifyNetworkChanged(network_guid); |
155 } | 155 } |
156 | 156 |
157 void FakeWiFiService::StartDisconnect(const std::string& network_guid, | 157 void FakeWiFiService::StartDisconnect(const std::string& network_guid, |
158 std::string* error) { | 158 std::string* error) { |
159 WiFiService::NetworkList::iterator network_properties = | 159 WiFiService::NetworkList::iterator network_properties = |
160 FindNetwork(network_guid); | 160 FindNetwork(network_guid); |
161 if (network_properties != networks_.end()) { | 161 if (network_properties == networks_.end()) { |
162 network_properties->connection_state = onc::connection_state::kNotConnected; | 162 *error = "Error.InvalidNetworkGuid"; |
163 SortNetworks(); | 163 return; |
164 NotifyNetworkListChanged(networks_); | |
165 NotifyNetworkChanged(network_guid); | |
166 } else { | |
167 *error = "not-found"; | |
168 } | 164 } |
| 165 network_properties->connection_state = onc::connection_state::kNotConnected; |
| 166 SortNetworks(); |
| 167 NotifyNetworkListChanged(networks_); |
| 168 NotifyNetworkChanged(network_guid); |
169 } | 169 } |
170 | 170 |
171 void FakeWiFiService::GetKeyFromSystem(const std::string& network_guid, | 171 void FakeWiFiService::GetKeyFromSystem(const std::string& network_guid, |
172 std::string* key_data, | 172 std::string* key_data, |
173 std::string* error) { | 173 std::string* error) { |
174 *error = "not-found"; | 174 *error = "not-found"; |
175 } | 175 } |
176 | 176 |
177 void FakeWiFiService::SetEventObservers( | 177 void FakeWiFiService::SetEventObservers( |
178 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 178 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); | 225 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); |
226 } | 226 } |
227 | 227 |
228 void FakeWiFiService::NotifyNetworkChanged(const std::string& network_guid) { | 228 void FakeWiFiService::NotifyNetworkChanged(const std::string& network_guid) { |
229 WiFiService::NetworkGuidList changed_networks(1, network_guid); | 229 WiFiService::NetworkGuidList changed_networks(1, network_guid); |
230 message_loop_proxy_->PostTask( | 230 message_loop_proxy_->PostTask( |
231 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); | 231 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); |
232 } | 232 } |
233 | 233 |
234 } // namespace wifi | 234 } // namespace wifi |
OLD | NEW |