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 "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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 networks_.push_back(network_properties); | 81 networks_.push_back(network_properties); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 virtual void Initialize( | 85 virtual void Initialize( |
86 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE {} | 86 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE {} |
87 | 87 |
88 virtual void UnInitialize() OVERRIDE {} | 88 virtual void UnInitialize() OVERRIDE {} |
89 | 89 |
90 virtual void GetProperties(const std::string& network_guid, | 90 virtual void GetProperties(const std::string& network_guid, |
91 DictionaryValue* properties, | 91 base::DictionaryValue* properties, |
92 std::string* error) OVERRIDE { | 92 std::string* error) OVERRIDE { |
93 NetworkList::iterator network_properties = FindNetwork(network_guid); | 93 NetworkList::iterator network_properties = FindNetwork(network_guid); |
94 if (network_properties != networks_.end()) { | 94 if (network_properties != networks_.end()) { |
95 properties->Swap(network_properties->ToValue(false).get()); | 95 properties->Swap(network_properties->ToValue(false).get()); |
96 } else { | 96 } else { |
97 *error = "Error.DBusFailed"; | 97 *error = "Error.DBusFailed"; |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 virtual void GetManagedProperties(const std::string& network_guid, | 101 virtual void GetManagedProperties(const std::string& network_guid, |
102 DictionaryValue* managed_properties, | 102 base::DictionaryValue* managed_properties, |
103 std::string* error) OVERRIDE { | 103 std::string* error) OVERRIDE { |
104 const std::string network_properties = | 104 const std::string network_properties = |
105 "{" | 105 "{" |
106 " \"ConnectionState\": {" | 106 " \"ConnectionState\": {" |
107 " \"Active\": \"NotConnected\"," | 107 " \"Active\": \"NotConnected\"," |
108 " \"Effective\": \"Unmanaged\"" | 108 " \"Effective\": \"Unmanaged\"" |
109 " }," | 109 " }," |
110 " \"GUID\": \"stub_wifi2\"," | 110 " \"GUID\": \"stub_wifi2\"," |
111 " \"Name\": {" | 111 " \"Name\": {" |
112 " \"Active\": \"wifi2_PSK\"," | 112 " \"Active\": \"wifi2_PSK\"," |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 " \"Active\": \"WPA-PSK\"," | 145 " \"Active\": \"WPA-PSK\"," |
146 " \"Effective\": \"UserPolicy\"," | 146 " \"Effective\": \"UserPolicy\"," |
147 " \"UserPolicy\": \"WPA-PSK\"" | 147 " \"UserPolicy\": \"WPA-PSK\"" |
148 " }," | 148 " }," |
149 " \"SignalStrength\": {" | 149 " \"SignalStrength\": {" |
150 " \"Active\": 80," | 150 " \"Active\": 80," |
151 " \"Effective\": \"Unmanaged\"" | 151 " \"Effective\": \"Unmanaged\"" |
152 " }" | 152 " }" |
153 " }" | 153 " }" |
154 "}"; | 154 "}"; |
155 scoped_ptr<DictionaryValue> properties_value( | 155 scoped_ptr<base::DictionaryValue> properties_value( |
156 reinterpret_cast<DictionaryValue*>( | 156 reinterpret_cast<base::DictionaryValue*>( |
157 base::JSONReader::Read(network_properties))); | 157 base::JSONReader::Read(network_properties))); |
158 managed_properties->MergeDictionary(properties_value.get()); | 158 managed_properties->MergeDictionary(properties_value.get()); |
159 } | 159 } |
160 | 160 |
161 virtual void GetState(const std::string& network_guid, | 161 virtual void GetState(const std::string& network_guid, |
162 DictionaryValue* properties, | 162 base::DictionaryValue* properties, |
163 std::string* error) OVERRIDE { | 163 std::string* error) OVERRIDE { |
164 NetworkList::iterator network_properties = FindNetwork(network_guid); | 164 NetworkList::iterator network_properties = FindNetwork(network_guid); |
165 if (network_properties == networks_.end()) { | 165 if (network_properties == networks_.end()) { |
166 *error = "Error.InvalidParameter"; | 166 *error = "Error.InvalidParameter"; |
167 return; | 167 return; |
168 } | 168 } |
169 | 169 |
170 const std::string network_state = | 170 const std::string network_state = |
171 "{" | 171 "{" |
172 " \"ConnectionState\": \"NotConnected\"," | 172 " \"ConnectionState\": \"NotConnected\"," |
173 " \"GUID\": \"stub_wifi2\"," | 173 " \"GUID\": \"stub_wifi2\"," |
174 " \"Name\": \"wifi2_PSK\"," | 174 " \"Name\": \"wifi2_PSK\"," |
175 " \"Type\": \"WiFi\"," | 175 " \"Type\": \"WiFi\"," |
176 " \"WiFi\": {" | 176 " \"WiFi\": {" |
177 " \"Security\": \"WPA-PSK\"," | 177 " \"Security\": \"WPA-PSK\"," |
178 " \"SignalStrength\": 80" | 178 " \"SignalStrength\": 80" |
179 " }" | 179 " }" |
180 "}"; | 180 "}"; |
181 scoped_ptr<DictionaryValue> properties_value( | 181 scoped_ptr<base::DictionaryValue> properties_value( |
182 reinterpret_cast<DictionaryValue*>( | 182 reinterpret_cast<base::DictionaryValue*>( |
183 base::JSONReader::Read(network_state))); | 183 base::JSONReader::Read(network_state))); |
184 properties->MergeDictionary(properties_value.get()); | 184 properties->MergeDictionary(properties_value.get()); |
185 } | 185 } |
186 | 186 |
187 virtual void SetProperties(const std::string& network_guid, | 187 virtual void SetProperties(const std::string& network_guid, |
188 scoped_ptr<base::DictionaryValue> properties, | 188 scoped_ptr<base::DictionaryValue> properties, |
189 std::string* error) OVERRIDE { | 189 std::string* error) OVERRIDE { |
190 NetworkList::iterator network_properties = FindNetwork(network_guid); | 190 NetworkList::iterator network_properties = FindNetwork(network_guid); |
191 if (network_properties == networks_.end() || | 191 if (network_properties == networks_.end() || |
192 !network_properties->UpdateFromValue(*properties)) { | 192 !network_properties->UpdateFromValue(*properties)) { |
193 *error = "Error.DBusFailed"; | 193 *error = "Error.DBusFailed"; |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 virtual void CreateNetwork(bool shared, | 197 virtual void CreateNetwork(bool shared, |
198 scoped_ptr<base::DictionaryValue> properties, | 198 scoped_ptr<base::DictionaryValue> properties, |
199 std::string* network_guid, | 199 std::string* network_guid, |
200 std::string* error) OVERRIDE { | 200 std::string* error) OVERRIDE { |
201 WiFiService::NetworkProperties network_properties; | 201 WiFiService::NetworkProperties network_properties; |
202 if (network_properties.UpdateFromValue(*properties)) { | 202 if (network_properties.UpdateFromValue(*properties)) { |
203 network_properties.guid = network_properties.ssid; | 203 network_properties.guid = network_properties.ssid; |
204 networks_.push_back(network_properties); | 204 networks_.push_back(network_properties); |
205 *network_guid = network_properties.guid; | 205 *network_guid = network_properties.guid; |
206 } else { | 206 } else { |
207 *error = "Error.DBusFailed"; | 207 *error = "Error.DBusFailed"; |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 virtual void GetVisibleNetworks(const std::string& network_type, | 211 virtual void GetVisibleNetworks(const std::string& network_type, |
212 ListValue* network_list) OVERRIDE { | 212 base::ListValue* network_list) OVERRIDE { |
213 for (WiFiService::NetworkList::const_iterator it = networks_.begin(); | 213 for (WiFiService::NetworkList::const_iterator it = networks_.begin(); |
214 it != networks_.end(); | 214 it != networks_.end(); |
215 ++it) { | 215 ++it) { |
216 if (network_type.empty() || | 216 if (network_type.empty() || |
217 network_type == onc::network_type::kAllTypes || | 217 network_type == onc::network_type::kAllTypes || |
218 it->type == network_type) { | 218 it->type == network_type) { |
219 scoped_ptr<DictionaryValue> network(it->ToValue(true)); | 219 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); |
220 network_list->Append(network.release()); | 220 network_list->Append(network.release()); |
221 } | 221 } |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 virtual void RequestNetworkScan() OVERRIDE { | 225 virtual void RequestNetworkScan() OVERRIDE { |
226 NotifyNetworkListChanged(networks_); | 226 NotifyNetworkListChanged(networks_); |
227 } | 227 } |
228 | 228 |
229 virtual void StartConnect(const std::string& network_guid, | 229 virtual void StartConnect(const std::string& network_guid, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 309 |
310 NetworkList networks_; | 310 NetworkList networks_; |
311 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 311 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
312 NetworkGuidListCallback networks_changed_observer_; | 312 NetworkGuidListCallback networks_changed_observer_; |
313 NetworkGuidListCallback network_list_changed_observer_; | 313 NetworkGuidListCallback network_list_changed_observer_; |
314 }; | 314 }; |
315 | 315 |
316 WiFiService* WiFiService::CreateForTest() { return new FakeWiFiService(); } | 316 WiFiService* WiFiService::CreateForTest() { return new FakeWiFiService(); } |
317 | 317 |
318 } // namespace wifi | 318 } // namespace wifi |
OLD | NEW |