OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chromeos/network/device_state.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/stringprintf.h" | |
9 #include "base/values.h" | |
10 #include "third_party/cros_system_api/dbus/service_constants.h" | |
11 | |
12 namespace { | |
13 | |
14 // List of cellular operators names that should have data roaming always enabled | |
15 // to be able to connect to any network. | |
16 const char* kAlwaysInRoamingOperators[] = { | |
17 "CUBIC", | |
gauravsh
2012/10/25 23:41:05
Where does this list come from? Should it be in se
stevenjb
2012/10/26 21:36:39
Actually, this was recently replaced in NetworkLib
| |
18 "Cubic", | |
19 }; | |
20 | |
21 } // namespace | |
22 | |
23 namespace chromeos { | |
24 | |
25 DeviceState::DeviceState(const std::string& path) | |
26 : ManagedState(MANAGED_TYPE_DEVICE, path), | |
27 always_in_roaming_(false), | |
28 support_network_scan_(false) { | |
29 } | |
30 | |
31 bool DeviceState::PropertyChanged(const std::string& key, | |
32 const base::Value& value) { | |
33 if (key == flimflam::kNameProperty) { | |
gauravsh
2012/10/25 23:41:05
Do you expect to add more properties, or does this
stevenjb
2012/10/26 21:36:39
Don't know. This covers (almost all of) the status
| |
34 return value.GetAsString(&name_); | |
35 } else if (key == flimflam::kTypeProperty) { | |
36 return value.GetAsString(&type_); | |
37 } else if (key == flimflam::kAddressProperty) { | |
38 bool res = value.GetAsString(&mac_address_); | |
39 LOG(ERROR) << "Hardware Address: " << mac_address_; | |
gauravsh
2012/10/25 23:41:05
Why is this a LOG(ERROR)?
stevenjb
2012/10/26 21:36:39
Leftover debugging. Removed.
| |
40 return res; | |
41 } else if (key == flimflam::kSupportNetworkScanProperty) { | |
42 return value.GetAsBoolean(&support_network_scan_); | |
43 } else if (key == flimflam::kHomeProviderProperty) { | |
44 const DictionaryValue* dict = NULL; | |
45 if (value.GetAsDictionary(&dict)) { | |
46 std::string home_provider_country; | |
47 std::string home_provider_name; | |
48 dict->GetStringWithoutPathExpansion(flimflam::kOperatorCountryKey, | |
49 &home_provider_country); | |
50 dict->GetStringWithoutPathExpansion(flimflam::kOperatorNameKey, | |
51 &home_provider_name); | |
52 // Set always_in_roaming_ | |
53 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) { | |
gauravsh
2012/10/25 23:41:05
You could also consider using find() here.
stevenjb
2012/10/26 21:36:39
Removed.
| |
54 if (home_provider_name == kAlwaysInRoamingOperators[i]) | |
55 always_in_roaming_ = true; | |
56 } | |
57 // Set home_provider_id_ | |
58 if (!home_provider_name.empty() && !home_provider_country.empty()) { | |
59 home_provider_id_ = base::StringPrintf( | |
60 "%s (%s)", | |
61 home_provider_name.c_str(), | |
62 home_provider_country.c_str()); | |
63 } else { | |
64 dict->GetStringWithoutPathExpansion(flimflam::kOperatorCodeKey, | |
65 &home_provider_id_); | |
66 LOG(WARNING) << "Carrier ID not defined, using code instead: " | |
67 << home_provider_id_; | |
68 } | |
69 } else { | |
70 return false; | |
gauravsh
2012/10/25 23:41:05
LOG a warning with the unknown key?
stevenjb
2012/10/26 21:36:39
No warning necessary, this is not intended to hand
| |
71 } | |
72 } | |
73 return true; | |
74 } | |
75 | |
76 } // namespace chromeos | |
OLD | NEW |