| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/network/favorite_state.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "chromeos/network/network_event_log.h" | |
| 11 #include "chromeos/network/network_profile_handler.h" | |
| 12 #include "chromeos/network/network_state.h" | |
| 13 #include "chromeos/network/onc/onc_utils.h" | |
| 14 #include "chromeos/network/shill_property_util.h" | |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 16 | |
| 17 namespace chromeos { | |
| 18 | |
| 19 FavoriteState::FavoriteState(const std::string& path) | |
| 20 : ManagedState(MANAGED_TYPE_FAVORITE, path) { | |
| 21 } | |
| 22 | |
| 23 FavoriteState::~FavoriteState() { | |
| 24 } | |
| 25 | |
| 26 bool FavoriteState::PropertyChanged(const std::string& key, | |
| 27 const base::Value& value) { | |
| 28 if (ManagedStatePropertyChanged(key, value)) | |
| 29 return true; | |
| 30 if (key == shill::kProfileProperty) { | |
| 31 return GetStringValue(key, value, &profile_path_); | |
| 32 } else if (key == shill::kUIDataProperty) { | |
| 33 scoped_ptr<NetworkUIData> new_ui_data = | |
| 34 shill_property_util::GetUIDataFromValue(value); | |
| 35 if (!new_ui_data) { | |
| 36 NET_LOG_ERROR("Failed to parse " + key, path()); | |
| 37 return false; | |
| 38 } | |
| 39 ui_data_ = *new_ui_data; | |
| 40 return true; | |
| 41 } else if (key == shill::kGuidProperty) { | |
| 42 return GetStringValue(key, value, &guid_); | |
| 43 } else if (key == shill::kProxyConfigProperty) { | |
| 44 std::string proxy_config_str; | |
| 45 if (!value.GetAsString(&proxy_config_str)) { | |
| 46 NET_LOG_ERROR("Failed to parse " + key, path()); | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 proxy_config_.Clear(); | |
| 51 if (proxy_config_str.empty()) | |
| 52 return true; | |
| 53 | |
| 54 scoped_ptr<base::DictionaryValue> proxy_config_dict( | |
| 55 onc::ReadDictionaryFromJson(proxy_config_str)); | |
| 56 if (proxy_config_dict) { | |
| 57 // Warning: The DictionaryValue returned from | |
| 58 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | |
| 59 // doesn't allow releasing ownership of nested values. A Swap in the wrong | |
| 60 // order leads to memory access errors. | |
| 61 proxy_config_.MergeDictionary(proxy_config_dict.get()); | |
| 62 } else { | |
| 63 NET_LOG_ERROR("Failed to parse " + key, path()); | |
| 64 } | |
| 65 return true; | |
| 66 } else if (key == shill::kSecurityProperty) { | |
| 67 return GetStringValue(key, value, &security_); | |
| 68 } | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 void FavoriteState::GetStateProperties( | |
| 73 base::DictionaryValue* dictionary) const { | |
| 74 ManagedState::GetStateProperties(dictionary); | |
| 75 | |
| 76 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid()); | |
| 77 dictionary->SetStringWithoutPathExpansion(shill::kSecurityProperty, | |
| 78 security_); | |
| 79 | |
| 80 // Note: The following are added for debugging, but do not translate to ONC. | |
| 81 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, | |
| 82 profile_path()); | |
| 83 dictionary->SetStringWithoutPathExpansion(NetworkUIData::kKeyONCSource, | |
| 84 ui_data_.GetONCSourceAsString()); | |
| 85 } | |
| 86 | |
| 87 std::string FavoriteState::GetSpecifier() const { | |
| 88 if (!update_received()) { | |
| 89 NET_LOG_ERROR("GetSpecifier called before update", path()); | |
| 90 return std::string(); | |
| 91 } | |
| 92 if (type() == shill::kTypeWifi) | |
| 93 return name() + "_" + security_; | |
| 94 if (!name().empty()) | |
| 95 return name(); | |
| 96 return type(); // For unnamed networks such as ethernet. | |
| 97 } | |
| 98 | |
| 99 void FavoriteState::SetGuid(const std::string& guid) { | |
| 100 DCHECK(guid_.empty()); | |
| 101 guid_ = guid; | |
| 102 } | |
| 103 | |
| 104 bool FavoriteState::IsInProfile() const { | |
| 105 // kTypeEthernetEap is always saved. We need this check because it does | |
| 106 // not show up in the visible list, but its properties may not be available | |
| 107 // when it first shows up in ServiceCompleteList. See crbug.com/355117. | |
| 108 return !profile_path_.empty() || type() == shill::kTypeEthernetEap; | |
| 109 } | |
| 110 | |
| 111 bool FavoriteState::IsPrivate() const { | |
| 112 return !profile_path_.empty() && | |
| 113 profile_path_ != NetworkProfileHandler::GetSharedProfilePath(); | |
| 114 } | |
| 115 | |
| 116 } // namespace chromeos | |
| OLD | NEW |