OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chromeos/network/managed_state.h" | 5 #include "chromeos/network/managed_state.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chromeos/network/device_state.h" | 9 #include "chromeos/network/device_state.h" |
| 10 #include "chromeos/network/network_event_log.h" |
10 #include "chromeos/network/network_state.h" | 11 #include "chromeos/network/network_state.h" |
11 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
12 | 13 |
13 namespace chromeos { | 14 namespace chromeos { |
14 | 15 |
15 ManagedState::ManagedState(ManagedType type, const std::string& path) | 16 ManagedState::ManagedState(ManagedType type, const std::string& path) |
16 : managed_type_(type), | 17 : managed_type_(type), |
17 path_(path), | 18 path_(path), |
18 is_observed_(false) { | 19 is_observed_(false) { |
19 } | 20 } |
20 | 21 |
21 ManagedState::~ManagedState() { | 22 ManagedState::~ManagedState() { |
22 } | 23 } |
23 | 24 |
24 ManagedState* ManagedState::Create(ManagedType type, const std::string& path) { | 25 ManagedState* ManagedState::Create(ManagedType type, const std::string& path) { |
25 switch(type) { | 26 switch (type) { |
26 case MANAGED_TYPE_NETWORK: | 27 case MANAGED_TYPE_NETWORK: |
27 return new NetworkState(path); | 28 return new NetworkState(path); |
28 case MANAGED_TYPE_DEVICE: | 29 case MANAGED_TYPE_DEVICE: |
29 return new DeviceState(path); | 30 return new DeviceState(path); |
30 } | 31 } |
31 return NULL; | 32 return NULL; |
32 } | 33 } |
33 | 34 |
34 NetworkState* ManagedState::AsNetworkState() { | 35 NetworkState* ManagedState::AsNetworkState() { |
35 if (managed_type() == MANAGED_TYPE_NETWORK) | 36 if (managed_type() == MANAGED_TYPE_NETWORK) |
(...skipping 18 matching lines...) Expand all Loading... |
54 return GetStringValue(key, value, &type_); | 55 return GetStringValue(key, value, &type_); |
55 } | 56 } |
56 return false; | 57 return false; |
57 } | 58 } |
58 | 59 |
59 bool ManagedState::GetBooleanValue(const std::string& key, | 60 bool ManagedState::GetBooleanValue(const std::string& key, |
60 const base::Value& value, | 61 const base::Value& value, |
61 bool* out_value) { | 62 bool* out_value) { |
62 bool new_value; | 63 bool new_value; |
63 if (!value.GetAsBoolean(&new_value)) { | 64 if (!value.GetAsBoolean(&new_value)) { |
64 LOG(WARNING) << "Failed to parse boolean value for:" << key; | 65 NET_LOG_ERROR("Error parsing state value", path() + "." + key); |
65 return false; | 66 return false; |
66 } | 67 } |
67 if (*out_value == new_value) | 68 if (*out_value == new_value) |
68 return false; | 69 return false; |
69 *out_value = new_value; | 70 *out_value = new_value; |
70 return true; | 71 return true; |
71 } | 72 } |
72 | 73 |
73 bool ManagedState::GetIntegerValue(const std::string& key, | 74 bool ManagedState::GetIntegerValue(const std::string& key, |
74 const base::Value& value, | 75 const base::Value& value, |
75 int* out_value) { | 76 int* out_value) { |
76 int new_value; | 77 int new_value; |
77 if (!value.GetAsInteger(&new_value)) { | 78 if (!value.GetAsInteger(&new_value)) { |
78 LOG(WARNING) << "Failed to parse integer value for:" << key; | 79 NET_LOG_ERROR("Error parsing state value", path() + "." + key); |
79 return false; | 80 return false; |
80 } | 81 } |
81 if (*out_value == new_value) | 82 if (*out_value == new_value) |
82 return false; | 83 return false; |
83 *out_value = new_value; | 84 *out_value = new_value; |
84 return true; | 85 return true; |
85 } | 86 } |
86 | 87 |
87 bool ManagedState::GetStringValue(const std::string& key, | 88 bool ManagedState::GetStringValue(const std::string& key, |
88 const base::Value& value, | 89 const base::Value& value, |
89 std::string* out_value) { | 90 std::string* out_value) { |
90 std::string new_value; | 91 std::string new_value; |
91 if (!value.GetAsString(&new_value)) { | 92 if (!value.GetAsString(&new_value)) { |
92 LOG(WARNING) << "Failed to parse string value for:" << key; | 93 NET_LOG_ERROR("Error parsing state value", path() + "." + key); |
93 return false; | 94 return false; |
94 } | 95 } |
95 if (*out_value == new_value) | 96 if (*out_value == new_value) |
96 return false; | 97 return false; |
97 *out_value = new_value; | 98 *out_value = new_value; |
98 return true; | 99 return true; |
99 } | 100 } |
100 | 101 |
101 } // namespace chromeos | 102 } // namespace chromeos |
OLD | NEW |