OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/network_profile_handler.h" | 5 #include "chromeos/network/network_profile_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "chromeos/dbus/shill_manager_client.h" | 13 #include "chromeos/dbus/shill_manager_client.h" |
14 #include "chromeos/dbus/shill_profile_client.h" | 14 #include "chromeos/dbus/shill_profile_client.h" |
15 #include "chromeos/network/network_profile_observer.h" | 15 #include "chromeos/network/network_profile_observer.h" |
16 #include "chromeos/network/network_state_handler.h" | |
17 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 | 18 |
20 namespace chromeos { | 19 namespace chromeos { |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 23 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
25 std::vector<std::string>* result) { | 24 std::vector<std::string>* result) { |
26 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 25 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 continue; | 124 continue; |
126 | 125 |
127 VLOG(2) << "Requesting properties of profile path " << *it << "."; | 126 VLOG(2) << "Requesting properties of profile path " << *it << "."; |
128 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( | 127 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( |
129 dbus::ObjectPath(*it), | 128 dbus::ObjectPath(*it), |
130 base::Bind(&NetworkProfileHandler::GetProfilePropertiesCallback, | 129 base::Bind(&NetworkProfileHandler::GetProfilePropertiesCallback, |
131 weak_ptr_factory_.GetWeakPtr(), | 130 weak_ptr_factory_.GetWeakPtr(), |
132 *it), | 131 *it), |
133 base::Bind(&LogProfileRequestError, *it)); | 132 base::Bind(&LogProfileRequestError, *it)); |
134 } | 133 } |
135 | |
136 // When the profile list changes, ServiceCompleteList may also change, so | |
137 // trigger a Manager update to request the updated list. | |
138 if (network_state_handler_) | |
139 network_state_handler_->UpdateManagerProperties(); | |
140 } | 134 } |
141 | 135 |
142 void NetworkProfileHandler::GetProfilePropertiesCallback( | 136 void NetworkProfileHandler::GetProfilePropertiesCallback( |
143 const std::string& profile_path, | 137 const std::string& profile_path, |
144 const base::DictionaryValue& properties) { | 138 const base::DictionaryValue& properties) { |
145 std::string userhash; | 139 std::string userhash; |
146 properties.GetStringWithoutPathExpansion(shill::kUserHashProperty, &userhash); | 140 properties.GetStringWithoutPathExpansion(shill::kUserHashProperty, &userhash); |
147 | 141 |
148 AddProfile(NetworkProfile(profile_path, userhash)); | 142 AddProfile(NetworkProfile(profile_path, userhash)); |
149 } | 143 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 for (NetworkProfileHandler::ProfileList::const_iterator it = | 187 for (NetworkProfileHandler::ProfileList::const_iterator it = |
194 profiles_.begin(); | 188 profiles_.begin(); |
195 it != profiles_.end(); ++it) { | 189 it != profiles_.end(); ++it) { |
196 if (!it->userhash.empty()) | 190 if (!it->userhash.empty()) |
197 return &*it; | 191 return &*it; |
198 } | 192 } |
199 return NULL; | 193 return NULL; |
200 } | 194 } |
201 | 195 |
202 NetworkProfileHandler::NetworkProfileHandler() | 196 NetworkProfileHandler::NetworkProfileHandler() |
203 : network_state_handler_(NULL), | 197 : weak_ptr_factory_(this) { |
204 weak_ptr_factory_(this) { | |
205 } | 198 } |
206 | 199 |
207 void NetworkProfileHandler::Init(NetworkStateHandler* network_state_handler) { | 200 void NetworkProfileHandler::Init() { |
208 network_state_handler_ = network_state_handler; | |
209 | |
210 DBusThreadManager::Get()->GetShillManagerClient()-> | 201 DBusThreadManager::Get()->GetShillManagerClient()-> |
211 AddPropertyChangedObserver(this); | 202 AddPropertyChangedObserver(this); |
212 | 203 |
213 // Request the initial profile list. | 204 // Request the initial profile list. |
214 DBusThreadManager::Get()->GetShillManagerClient()->GetProperties( | 205 DBusThreadManager::Get()->GetShillManagerClient()->GetProperties( |
215 base::Bind(&NetworkProfileHandler::GetManagerPropertiesCallback, | 206 base::Bind(&NetworkProfileHandler::GetManagerPropertiesCallback, |
216 weak_ptr_factory_.GetWeakPtr())); | 207 weak_ptr_factory_.GetWeakPtr())); |
217 } | 208 } |
218 | 209 |
219 NetworkProfileHandler::~NetworkProfileHandler() { | 210 NetworkProfileHandler::~NetworkProfileHandler() { |
220 DBusThreadManager::Get()->GetShillManagerClient()-> | 211 DBusThreadManager::Get()->GetShillManagerClient()-> |
221 RemovePropertyChangedObserver(this); | 212 RemovePropertyChangedObserver(this); |
222 } | 213 } |
223 | 214 |
224 } // namespace chromeos | 215 } // namespace chromeos |
OLD | NEW |