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 |
| 11 namespace { |
| 12 |
| 13 // List of cellular operators names that should have data roaming always enabled |
| 14 // to be able to connect to any network. |
| 15 const char* kAlwaysInRoamingOperators[] = { |
| 16 "CUBIC", |
| 17 "Cubic", |
| 18 }; |
| 19 |
| 20 } // namespace |
| 21 |
| 22 namespace chromeos { |
| 23 |
| 24 DeviceState::DeviceState(const std::string& path) |
| 25 : ManagedState(MANAGED_TYPE_DEVICE, path), |
| 26 always_in_roaming_(false), |
| 27 support_network_scan_(false) { |
| 28 } |
| 29 |
| 30 bool DeviceState::PropertyChanged(const std::string& key, |
| 31 const base::Value& value) { |
| 32 if (key == flimflam::kNameProperty) { |
| 33 return value.GetAsString(&name_); |
| 34 } else if (key == flimflam::kTypeProperty) { |
| 35 return value.GetAsString(&type_); |
| 36 } else if (key == flimflam::kAddressProperty) { |
| 37 bool res = value.GetAsString(&mac_address_); |
| 38 LOG(ERROR) << "Hardware Address: " << mac_address_; |
| 39 return res; |
| 40 } else if (key == flimflam::kSupportNetworkScanProperty) { |
| 41 return value.GetAsBoolean(&support_network_scan_); |
| 42 } else if (key == flimflam::kHomeProviderProperty) { |
| 43 const DictionaryValue* dict = NULL; |
| 44 if (value.GetAsDictionary(&dict)) { |
| 45 std::string home_provider_country; |
| 46 std::string home_provider_name; |
| 47 dict->GetStringWithoutPathExpansion(flimflam::kOperatorCountryKey, |
| 48 &home_provider_country); |
| 49 dict->GetStringWithoutPathExpansion(flimflam::kOperatorNameKey, |
| 50 &home_provider_name); |
| 51 // Set always_in_roaming_ |
| 52 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) { |
| 53 if (home_provider_name == kAlwaysInRoamingOperators[i]) |
| 54 always_in_roaming_ = true; |
| 55 } |
| 56 // Set home_provider_id_ |
| 57 if (!home_provider_name.empty() && !home_provider_country.empty()) { |
| 58 home_provider_id_ = base::StringPrintf( |
| 59 "%s (%s)", |
| 60 home_provider_name.c_str(), |
| 61 home_provider_country.c_str()); |
| 62 } else { |
| 63 dict->GetStringWithoutPathExpansion(flimflam::kOperatorCodeKey, |
| 64 &home_provider_id_); |
| 65 LOG(WARNING) << "Carrier ID not defined, using code instead: " |
| 66 << home_provider_id_; |
| 67 } |
| 68 } else { |
| 69 return false; |
| 70 } |
| 71 } |
| 72 return true; |
| 73 } |
| 74 |
| 75 } // namespace chromeos |
OLD | NEW |