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.
5 #include "chromeos/network/favorite_state.h"
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"
19 FavoriteState::FavoriteState(const std::string
& path
)
20 : ManagedState(MANAGED_TYPE_FAVORITE
, path
) {
23 FavoriteState::~FavoriteState() {
26 bool FavoriteState::PropertyChanged(const std::string
& key
,
27 const base::Value
& value
) {
28 if (ManagedStatePropertyChanged(key
, value
))
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
);
36 NET_LOG_ERROR("Failed to parse " + key
, path());
39 ui_data_
= *new_ui_data
;
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());
50 proxy_config_
.Clear();
51 if (proxy_config_str
.empty())
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());
63 NET_LOG_ERROR("Failed to parse " + key
, path());
70 bool FavoriteState::IsPrivate() const {
71 return !profile_path_
.empty() &&
72 profile_path_
!= NetworkProfileHandler::kSharedProfilePath
;
75 } // namespace chromeos