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/favorite_state.h" | |
11 #include "chromeos/network/network_event_log.h" | 10 #include "chromeos/network/network_event_log.h" |
12 #include "chromeos/network/network_state.h" | 11 #include "chromeos/network/network_state.h" |
13 #include "chromeos/network/network_type_pattern.h" | 12 #include "chromeos/network/network_type_pattern.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 14 |
16 namespace chromeos { | 15 namespace chromeos { |
17 | 16 |
18 bool ManagedState::Matches(const NetworkTypePattern& pattern) const { | 17 bool ManagedState::Matches(const NetworkTypePattern& pattern) const { |
19 return pattern.MatchesType(type()); | 18 return pattern.MatchesType(type()); |
20 } | 19 } |
21 | 20 |
22 // static | 21 // static |
23 std::string ManagedState::TypeToString(ManagedType type) { | 22 std::string ManagedState::TypeToString(ManagedType type) { |
24 switch (type) { | 23 switch (type) { |
25 case MANAGED_TYPE_NETWORK: | 24 case MANAGED_TYPE_NETWORK: |
26 return "Network"; | 25 return "Network"; |
27 case MANAGED_TYPE_FAVORITE: | |
28 return "Favorite"; | |
29 case MANAGED_TYPE_DEVICE: | 26 case MANAGED_TYPE_DEVICE: |
30 return "Device"; | 27 return "Device"; |
31 } | 28 } |
32 return "Unknown"; | 29 return "Unknown"; |
33 } | 30 } |
34 | 31 |
35 ManagedState::ManagedState(ManagedType type, const std::string& path) | 32 ManagedState::ManagedState(ManagedType type, const std::string& path) |
36 : managed_type_(type), | 33 : managed_type_(type), |
37 path_(path), | 34 path_(path), |
38 update_received_(false), | 35 update_received_(false), |
39 update_requested_(false) { | 36 update_requested_(false) { |
40 } | 37 } |
41 | 38 |
42 ManagedState::~ManagedState() { | 39 ManagedState::~ManagedState() { |
43 } | 40 } |
44 | 41 |
45 ManagedState* ManagedState::Create(ManagedType type, const std::string& path) { | 42 ManagedState* ManagedState::Create(ManagedType type, const std::string& path) { |
46 switch (type) { | 43 switch (type) { |
47 case MANAGED_TYPE_NETWORK: | 44 case MANAGED_TYPE_NETWORK: |
48 return new NetworkState(path); | 45 return new NetworkState(path); |
49 case MANAGED_TYPE_FAVORITE: | |
50 return new FavoriteState(path); | |
51 case MANAGED_TYPE_DEVICE: | 46 case MANAGED_TYPE_DEVICE: |
52 return new DeviceState(path); | 47 return new DeviceState(path); |
53 } | 48 } |
54 return NULL; | 49 return NULL; |
55 } | 50 } |
56 | 51 |
57 NetworkState* ManagedState::AsNetworkState() { | 52 NetworkState* ManagedState::AsNetworkState() { |
58 if (managed_type() == MANAGED_TYPE_NETWORK) | 53 if (managed_type() == MANAGED_TYPE_NETWORK) |
59 return static_cast<NetworkState*>(this); | 54 return static_cast<NetworkState*>(this); |
60 return NULL; | 55 return NULL; |
61 } | 56 } |
62 | 57 |
63 DeviceState* ManagedState::AsDeviceState() { | 58 DeviceState* ManagedState::AsDeviceState() { |
64 if (managed_type() == MANAGED_TYPE_DEVICE) | 59 if (managed_type() == MANAGED_TYPE_DEVICE) |
65 return static_cast<DeviceState*>(this); | 60 return static_cast<DeviceState*>(this); |
66 return NULL; | 61 return NULL; |
67 } | 62 } |
68 | 63 |
69 FavoriteState* ManagedState::AsFavoriteState() { | |
70 if (managed_type() == MANAGED_TYPE_FAVORITE) | |
71 return static_cast<FavoriteState*>(this); | |
72 return NULL; | |
73 } | |
74 | |
75 bool ManagedState::InitialPropertiesReceived( | 64 bool ManagedState::InitialPropertiesReceived( |
76 const base::DictionaryValue& properties) { | 65 const base::DictionaryValue& properties) { |
77 return false; | 66 return false; |
78 } | 67 } |
79 | 68 |
80 void ManagedState::GetStateProperties(base::DictionaryValue* dictionary) const { | 69 void ManagedState::GetStateProperties(base::DictionaryValue* dictionary) const { |
81 dictionary->SetStringWithoutPathExpansion(shill::kNameProperty, name()); | 70 dictionary->SetStringWithoutPathExpansion(shill::kNameProperty, name()); |
82 dictionary->SetStringWithoutPathExpansion(shill::kTypeProperty, type()); | 71 dictionary->SetStringWithoutPathExpansion(shill::kTypeProperty, type()); |
83 } | 72 } |
84 | 73 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 return false; | 136 return false; |
148 } | 137 } |
149 new_value = static_cast<uint32>(double_value); | 138 new_value = static_cast<uint32>(double_value); |
150 if (*out_value == new_value) | 139 if (*out_value == new_value) |
151 return false; | 140 return false; |
152 *out_value = new_value; | 141 *out_value = new_value; |
153 return true; | 142 return true; |
154 } | 143 } |
155 | 144 |
156 } // namespace chromeos | 145 } // namespace chromeos |
OLD | NEW |