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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "components/onc/onc_constants.h" | 10 #include "components/onc/onc_constants.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 WiFiService::NetworkProperties::~NetworkProperties() {} | 31 WiFiService::NetworkProperties::~NetworkProperties() {} |
32 | 32 |
33 scoped_ptr<base::DictionaryValue> WiFiService::NetworkProperties::ToValue( | 33 scoped_ptr<base::DictionaryValue> WiFiService::NetworkProperties::ToValue( |
34 bool network_list) const { | 34 bool network_list) const { |
35 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 35 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
36 | 36 |
37 value->SetString(onc::network_config::kGUID, guid); | 37 value->SetString(onc::network_config::kGUID, guid); |
38 value->SetString(onc::network_config::kName, name); | 38 value->SetString(onc::network_config::kName, name); |
39 value->SetString(onc::network_config::kConnectionState, connection_state); | 39 value->SetString(onc::network_config::kConnectionState, connection_state); |
| 40 DCHECK(type == onc::network_type::kWiFi); |
40 value->SetString(onc::network_config::kType, type); | 41 value->SetString(onc::network_config::kType, type); |
41 | 42 |
42 if (type == onc::network_type::kWiFi) { | 43 // For now, assume all WiFi services are connectable. |
43 scoped_ptr<base::DictionaryValue> wifi(new base::DictionaryValue()); | 44 value->SetBoolean(onc::network_config::kConnectable, true); |
44 wifi->SetString(onc::wifi::kSecurity, security); | |
45 wifi->SetInteger(onc::wifi::kSignalStrength, signal_strength); | |
46 | 45 |
47 // Network list expects subset of data. | 46 scoped_ptr<base::DictionaryValue> wifi(new base::DictionaryValue()); |
48 if (!network_list) { | 47 wifi->SetString(onc::wifi::kSecurity, security); |
49 if (frequency != WiFiService::kFrequencyUnknown) | 48 wifi->SetInteger(onc::wifi::kSignalStrength, signal_strength); |
50 wifi->SetInteger(onc::wifi::kFrequency, frequency); | 49 |
51 scoped_ptr<base::ListValue> frequency_list(new base::ListValue()); | 50 // Network list expects subset of data. |
52 for (FrequencySet::const_iterator it = this->frequency_set.begin(); | 51 if (!network_list) { |
53 it != this->frequency_set.end(); | 52 if (frequency != WiFiService::kFrequencyUnknown) |
54 ++it) { | 53 wifi->SetInteger(onc::wifi::kFrequency, frequency); |
55 frequency_list->AppendInteger(*it); | 54 scoped_ptr<base::ListValue> frequency_list(new base::ListValue()); |
56 } | 55 for (FrequencySet::const_iterator it = this->frequency_set.begin(); |
57 if (!frequency_list->empty()) | 56 it != this->frequency_set.end(); |
58 wifi->Set(onc::wifi::kFrequencyList, frequency_list.release()); | 57 ++it) { |
59 if (!bssid.empty()) | 58 frequency_list->AppendInteger(*it); |
60 wifi->SetString(onc::wifi::kBSSID, bssid); | |
61 wifi->SetString(onc::wifi::kSSID, ssid); | |
62 } | 59 } |
63 value->Set(onc::network_type::kWiFi, wifi.release()); | 60 if (!frequency_list->empty()) |
64 } else { | 61 wifi->Set(onc::wifi::kFrequencyList, frequency_list.release()); |
65 // Add properites from json extra if present. | 62 if (!bssid.empty()) |
66 if (!json_extra.empty()) { | 63 wifi->SetString(onc::wifi::kBSSID, bssid); |
67 base::Value* value_extra = base::JSONReader::Read(json_extra); | 64 wifi->SetString(onc::wifi::kSSID, ssid); |
68 value->Set(type, value_extra); | |
69 } | |
70 } | 65 } |
| 66 value->Set(onc::network_type::kWiFi, wifi.release()); |
| 67 |
| 68 if (!network_list && !json_extra.empty()) { |
| 69 base::Value* value_extra = base::JSONReader::Read(json_extra); |
| 70 CHECK(value_extra); |
| 71 base::DictionaryValue* value_dictionary; |
| 72 if (value_extra->GetAsDictionary(&value_dictionary)) |
| 73 value->MergeDictionary(value_dictionary); |
| 74 } |
| 75 |
71 return value.Pass(); | 76 return value.Pass(); |
72 } | 77 } |
73 | 78 |
74 bool WiFiService::NetworkProperties::UpdateFromValue( | 79 bool WiFiService::NetworkProperties::UpdateFromValue( |
75 const base::DictionaryValue& value) { | 80 const base::DictionaryValue& value) { |
76 const base::DictionaryValue* wifi = NULL; | 81 const base::DictionaryValue* wifi = NULL; |
77 std::string network_type; | 82 std::string network_type; |
78 // Get network type and make sure that it is WiFi (if specified). | 83 // Get network type and make sure that it is WiFi (if specified). |
79 if (value.GetString(onc::network_config::kType, &network_type)) { | 84 if (value.GetString(onc::network_config::kType, &network_type)) { |
80 if (network_type != onc::network_type::kWiFi) | 85 if (network_type != onc::network_type::kWiFi) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (l.type == r.type) | 119 if (l.type == r.type) |
115 return l.guid < r.guid; | 120 return l.guid < r.guid; |
116 if (l.type == onc::network_type::kEthernet) | 121 if (l.type == onc::network_type::kEthernet) |
117 return true; | 122 return true; |
118 if (r.type == onc::network_type::kEthernet) | 123 if (r.type == onc::network_type::kEthernet) |
119 return false; | 124 return false; |
120 return l.type > r.type; | 125 return l.type > r.type; |
121 } | 126 } |
122 | 127 |
123 } // namespace wifi | 128 } // namespace wifi |
OLD | NEW |