Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(809)

Side by Side Diff: components/wifi/network_properties.cc

Issue 226883002: WiFi client for GCD bootstrapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/wifi/network_properties.h ('k') | components/wifi/wifi_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/network_properties.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"
11 11
12 namespace wifi { 12 namespace wifi {
13 13
14 const char WiFiService::kErrorAssociateToNetwork[] = "Error.AssociateToNetwork"; 14 NetworkProperties::NetworkProperties()
15 const char WiFiService::kErrorInvalidData[] = "Error.InvalidData";
16 const char WiFiService::kErrorNotConfigured[] ="Error.NotConfigured";
17 const char WiFiService::kErrorNotConnected[] = "Error.NotConnected";
18 const char WiFiService::kErrorNotFound[] = "Error.NotFound";
19 const char WiFiService::kErrorNotImplemented[] = "Error.NotImplemented";
20 const char WiFiService::kErrorScanForNetworksWithName[] =
21 "Error.ScanForNetworksWithName";
22 const char WiFiService::kErrorWiFiService[] = "Error.WiFiService";
23
24 WiFiService::NetworkProperties::NetworkProperties()
25 : connection_state(onc::connection_state::kNotConnected), 15 : connection_state(onc::connection_state::kNotConnected),
26 security(onc::wifi::kNone), 16 security(onc::wifi::kNone),
27 signal_strength(0), 17 signal_strength(0),
28 auto_connect(false), 18 auto_connect(false),
29 frequency(WiFiService::kFrequencyUnknown) {} 19 frequency(kFrequencyUnknown) {
20 }
30 21
31 WiFiService::NetworkProperties::~NetworkProperties() {} 22 NetworkProperties::~NetworkProperties() {
23 }
32 24
33 scoped_ptr<base::DictionaryValue> WiFiService::NetworkProperties::ToValue( 25 scoped_ptr<base::DictionaryValue> NetworkProperties::ToValue(
34 bool network_list) const { 26 bool network_list) const {
mef 2014/06/04 14:17:47 I guess we should change |network_list| flag to ma
Noam Samuel 2014/06/04 17:11:27 Thought of doing this, was afraid I'd introduce bu
35 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 27 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
36 28
37 value->SetString(onc::network_config::kGUID, guid); 29 value->SetString(onc::network_config::kGUID, guid);
38 value->SetString(onc::network_config::kName, name); 30 value->SetString(onc::network_config::kName, name);
39 value->SetString(onc::network_config::kConnectionState, connection_state); 31 value->SetString(onc::network_config::kConnectionState, connection_state);
40 DCHECK(type == onc::network_type::kWiFi); 32 DCHECK(type == onc::network_type::kWiFi);
41 value->SetString(onc::network_config::kType, type); 33 value->SetString(onc::network_config::kType, type);
42 34
43 // For now, assume all WiFi services are connectable. 35 // For now, assume all WiFi services are connectable.
44 value->SetBoolean(onc::network_config::kConnectable, true); 36 value->SetBoolean(onc::network_config::kConnectable, true);
45 37
46 scoped_ptr<base::DictionaryValue> wifi(new base::DictionaryValue()); 38 scoped_ptr<base::DictionaryValue> wifi(new base::DictionaryValue());
47 wifi->SetString(onc::wifi::kSecurity, security); 39 wifi->SetString(onc::wifi::kSecurity, security);
48 wifi->SetInteger(onc::wifi::kSignalStrength, signal_strength); 40 wifi->SetInteger(onc::wifi::kSignalStrength, signal_strength);
49 41
50 // Network list expects subset of data. 42 // Network list expects subset of data.
51 if (!network_list) { 43 if (!network_list) {
52 if (frequency != WiFiService::kFrequencyUnknown) 44 if (frequency != kFrequencyUnknown)
53 wifi->SetInteger(onc::wifi::kFrequency, frequency); 45 wifi->SetInteger(onc::wifi::kFrequency, frequency);
54 scoped_ptr<base::ListValue> frequency_list(new base::ListValue()); 46 scoped_ptr<base::ListValue> frequency_list(new base::ListValue());
55 for (FrequencySet::const_iterator it = this->frequency_set.begin(); 47 for (FrequencySet::const_iterator it = this->frequency_set.begin();
56 it != this->frequency_set.end(); 48 it != this->frequency_set.end();
57 ++it) { 49 ++it) {
58 frequency_list->AppendInteger(*it); 50 frequency_list->AppendInteger(*it);
59 } 51 }
60 if (!frequency_list->empty()) 52 if (!frequency_list->empty())
61 wifi->Set(onc::wifi::kFrequencyList, frequency_list.release()); 53 wifi->Set(onc::wifi::kFrequencyList, frequency_list.release());
62 if (!bssid.empty()) 54 if (!bssid.empty())
63 wifi->SetString(onc::wifi::kBSSID, bssid); 55 wifi->SetString(onc::wifi::kBSSID, bssid);
64 wifi->SetString(onc::wifi::kSSID, ssid); 56 wifi->SetString(onc::wifi::kSSID, ssid);
65 } 57 }
66 value->Set(onc::network_type::kWiFi, wifi.release()); 58 value->Set(onc::network_type::kWiFi, wifi.release());
67 59
68 if (!network_list && !json_extra.empty()) { 60 if (!network_list && !json_extra.empty()) {
69 base::Value* value_extra = base::JSONReader::Read(json_extra); 61 base::Value* value_extra = base::JSONReader::Read(json_extra);
70 CHECK(value_extra); 62 CHECK(value_extra);
71 base::DictionaryValue* value_dictionary; 63 base::DictionaryValue* value_dictionary;
72 if (value_extra->GetAsDictionary(&value_dictionary)) 64 if (value_extra->GetAsDictionary(&value_dictionary))
73 value->MergeDictionary(value_dictionary); 65 value->MergeDictionary(value_dictionary);
74 } 66 }
75 67
76 return value.Pass(); 68 return value.Pass();
77 } 69 }
78 70
79 bool WiFiService::NetworkProperties::UpdateFromValue( 71 bool NetworkProperties::UpdateFromValue(const base::DictionaryValue& value) {
80 const base::DictionaryValue& value) {
81 const base::DictionaryValue* wifi = NULL; 72 const base::DictionaryValue* wifi = NULL;
82 std::string network_type; 73 std::string network_type;
83 // Get network type and make sure that it is WiFi (if specified). 74 // Get network type and make sure that it is WiFi (if specified).
84 if (value.GetString(onc::network_config::kType, &network_type)) { 75 if (value.GetString(onc::network_config::kType, &network_type)) {
85 if (network_type != onc::network_type::kWiFi) 76 if (network_type != onc::network_type::kWiFi)
86 return false; 77 return false;
87 type = network_type; 78 type = network_type;
88 } 79 }
89 if (value.GetDictionary(onc::network_type::kWiFi, &wifi)) { 80 if (value.GetDictionary(onc::network_type::kWiFi, &wifi)) {
81 value.GetString(onc::network_config::kName, &name);
82 value.GetString(onc::network_config::kGUID, &guid);
83 value.GetString(onc::network_config::kConnectionState, &connection_state);
90 wifi->GetString(onc::wifi::kSecurity, &security); 84 wifi->GetString(onc::wifi::kSecurity, &security);
91 wifi->GetString(onc::wifi::kSSID, &ssid); 85 wifi->GetString(onc::wifi::kSSID, &ssid);
92 wifi->GetString(onc::wifi::kPassphrase, &password); 86 wifi->GetString(onc::wifi::kPassphrase, &password);
93 wifi->GetBoolean(onc::wifi::kAutoConnect, &auto_connect); 87 wifi->GetBoolean(onc::wifi::kAutoConnect, &auto_connect);
94 return true; 88 return true;
95 } 89 }
96 return false; 90 return false;
97 } 91 }
98 92
99 std::string WiFiService::NetworkProperties::MacAddressAsString( 93 std::string NetworkProperties::MacAddressAsString(const uint8 mac_as_int[6]) {
100 const uint8 mac_as_int[6]) {
101 // mac_as_int is big-endian. Write in byte chunks. 94 // mac_as_int is big-endian. Write in byte chunks.
102 // Format is XX:XX:XX:XX:XX:XX. 95 // Format is XX:XX:XX:XX:XX:XX.
103 static const char* const kMacFormatString = "%02x:%02x:%02x:%02x:%02x:%02x"; 96 static const char* const kMacFormatString = "%02x:%02x:%02x:%02x:%02x:%02x";
104 return base::StringPrintf(kMacFormatString, 97 return base::StringPrintf(kMacFormatString,
105 mac_as_int[0], 98 mac_as_int[0],
106 mac_as_int[1], 99 mac_as_int[1],
107 mac_as_int[2], 100 mac_as_int[2],
108 mac_as_int[3], 101 mac_as_int[3],
109 mac_as_int[4], 102 mac_as_int[4],
110 mac_as_int[5]); 103 mac_as_int[5]);
111 } 104 }
112 105
113 bool WiFiService::NetworkProperties::OrderByType(const NetworkProperties& l, 106 bool NetworkProperties::OrderByType(const NetworkProperties& l,
114 const NetworkProperties& r) { 107 const NetworkProperties& r) {
115 if (l.connection_state != r.connection_state) 108 if (l.connection_state != r.connection_state)
116 return l.connection_state < r.connection_state; 109 return l.connection_state < r.connection_state;
117 // This sorting order is needed only for browser_tests, which expect this 110 // This sorting order is needed only for browser_tests, which expect this
118 // network type sort order: ethernet < wifi < vpn < cellular. 111 // network type sort order: ethernet < wifi < vpn < cellular.
119 if (l.type == r.type) 112 if (l.type == r.type)
120 return l.guid < r.guid; 113 return l.guid < r.guid;
121 if (l.type == onc::network_type::kEthernet) 114 if (l.type == onc::network_type::kEthernet)
122 return true; 115 return true;
123 if (r.type == onc::network_type::kEthernet) 116 if (r.type == onc::network_type::kEthernet)
124 return false; 117 return false;
125 return l.type > r.type; 118 return l.type > r.type;
126 } 119 }
127 120
128 } // namespace wifi 121 } // namespace wifi
OLDNEW
« no previous file with comments | « components/wifi/network_properties.h ('k') | components/wifi/wifi_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698