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/shill_property_handler.h" | 5 #include "chromeos/network/shill_property_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 Handler handler_; | 93 Handler handler_; |
94 | 94 |
95 DISALLOW_COPY_AND_ASSIGN(ShillPropertyObserver); | 95 DISALLOW_COPY_AND_ASSIGN(ShillPropertyObserver); |
96 }; | 96 }; |
97 | 97 |
98 //------------------------------------------------------------------------------ | 98 //------------------------------------------------------------------------------ |
99 // ShillPropertyHandler | 99 // ShillPropertyHandler |
100 | 100 |
101 ShillPropertyHandler::ShillPropertyHandler(Listener* listener) | 101 ShillPropertyHandler::ShillPropertyHandler(Listener* listener) |
102 : listener_(listener), | 102 : listener_(listener), |
103 shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()), | 103 shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()) { |
104 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
105 } | 104 } |
106 | 105 |
107 ShillPropertyHandler::~ShillPropertyHandler() { | 106 ShillPropertyHandler::~ShillPropertyHandler() { |
108 // Delete network service observers. | 107 // Delete network service observers. |
109 STLDeleteContainerPairSecondPointers( | 108 STLDeleteContainerPairSecondPointers( |
110 observed_networks_.begin(), observed_networks_.end()); | 109 observed_networks_.begin(), observed_networks_.end()); |
111 STLDeleteContainerPairSecondPointers( | 110 STLDeleteContainerPairSecondPointers( |
112 observed_devices_.begin(), observed_devices_.end()); | 111 observed_devices_.begin(), observed_devices_.end()); |
113 CHECK(shill_manager_ == DBusThreadManager::Get()->GetShillManagerClient()); | 112 CHECK(shill_manager_ == DBusThreadManager::Get()->GetShillManagerClient()); |
114 shill_manager_->RemovePropertyChangedObserver(this); | 113 shill_manager_->RemovePropertyChangedObserver(this); |
115 } | 114 } |
116 | 115 |
117 void ShillPropertyHandler::Init() { | 116 void ShillPropertyHandler::Init() { |
118 shill_manager_->GetProperties( | 117 shill_manager_->GetProperties( |
119 base::Bind(&ShillPropertyHandler::ManagerPropertiesCallback, | 118 base::Bind(&ShillPropertyHandler::ManagerPropertiesCallback, |
120 weak_ptr_factory_.GetWeakPtr())); | 119 AsWeakPtr())); |
121 shill_manager_->AddPropertyChangedObserver(this); | 120 shill_manager_->AddPropertyChangedObserver(this); |
122 } | 121 } |
123 | 122 |
124 bool ShillPropertyHandler::TechnologyAvailable( | 123 bool ShillPropertyHandler::TechnologyAvailable( |
125 const std::string& technology) const { | 124 const std::string& technology) const { |
126 return available_technologies_.count(technology) != 0; | 125 return available_technologies_.count(technology) != 0; |
127 } | 126 } |
128 | 127 |
129 bool ShillPropertyHandler::TechnologyEnabled( | 128 bool ShillPropertyHandler::TechnologyEnabled( |
130 const std::string& technology) const { | 129 const std::string& technology) const { |
(...skipping 25 matching lines...) Expand all Loading... |
156 } | 155 } |
157 | 156 |
158 void ShillPropertyHandler::RequestScan() const { | 157 void ShillPropertyHandler::RequestScan() const { |
159 shill_manager_->RequestScan( | 158 shill_manager_->RequestScan( |
160 "", | 159 "", |
161 base::Bind(&base::DoNothing), | 160 base::Bind(&base::DoNothing), |
162 base::Bind(&network_handler::ShillErrorCallbackFunction, | 161 base::Bind(&network_handler::ShillErrorCallbackFunction, |
163 kLogModule, "", network_handler::ErrorCallback())); | 162 kLogModule, "", network_handler::ErrorCallback())); |
164 } | 163 } |
165 | 164 |
| 165 void ShillPropertyHandler::ConnectToBestServices() const { |
| 166 network_event_log::AddEntry(kLogModule, "ConnectToBestServices", ""); |
| 167 shill_manager_->ConnectToBestServices( |
| 168 base::Bind(&base::DoNothing), |
| 169 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 170 kLogModule, "", network_handler::ErrorCallback())); |
| 171 } |
| 172 |
166 void ShillPropertyHandler::RequestProperties(ManagedState::ManagedType type, | 173 void ShillPropertyHandler::RequestProperties(ManagedState::ManagedType type, |
167 const std::string& path) { | 174 const std::string& path) { |
168 if (pending_updates_[type].find(path) != pending_updates_[type].end()) | 175 if (pending_updates_[type].find(path) != pending_updates_[type].end()) |
169 return; // Update already requested. | 176 return; // Update already requested. |
170 | 177 |
171 pending_updates_[type].insert(path); | 178 pending_updates_[type].insert(path); |
172 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 179 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
173 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( | 180 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( |
174 dbus::ObjectPath(path), | 181 dbus::ObjectPath(path), |
175 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, | 182 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, |
176 weak_ptr_factory_.GetWeakPtr(), type, path)); | 183 AsWeakPtr(), type, path)); |
177 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 184 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
178 DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties( | 185 DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties( |
179 dbus::ObjectPath(path), | 186 dbus::ObjectPath(path), |
180 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, | 187 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, |
181 weak_ptr_factory_.GetWeakPtr(), type, path)); | 188 AsWeakPtr(), type, path)); |
182 } else { | 189 } else { |
183 NOTREACHED(); | 190 NOTREACHED(); |
184 } | 191 } |
185 } | 192 } |
186 | 193 |
187 void ShillPropertyHandler::OnPropertyChanged(const std::string& key, | 194 void ShillPropertyHandler::OnPropertyChanged(const std::string& key, |
188 const base::Value& value) { | 195 const base::Value& value) { |
189 if (ManagerPropertyChanged(key, value)) | 196 if (ManagerPropertyChanged(key, value)) |
190 listener_->ManagerPropertyChanged(); | 197 listener_->ManagerPropertyChanged(); |
191 // If the service watch or device list changed and there are no pending | 198 // If the service watch or device list changed and there are no pending |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 continue; | 297 continue; |
291 ShillPropertyObserverMap::iterator iter2 = observer_map.find(path); | 298 ShillPropertyObserverMap::iterator iter2 = observer_map.find(path); |
292 if (iter2 != observer_map.end()) { | 299 if (iter2 != observer_map.end()) { |
293 new_observed[path] = iter2->second; | 300 new_observed[path] = iter2->second; |
294 } else { | 301 } else { |
295 // Request an update. | 302 // Request an update. |
296 RequestProperties(type, path); | 303 RequestProperties(type, path); |
297 // Create an observer for future updates. | 304 // Create an observer for future updates. |
298 new_observed[path] = new ShillPropertyObserver( | 305 new_observed[path] = new ShillPropertyObserver( |
299 type, path, base::Bind( | 306 type, path, base::Bind( |
300 &ShillPropertyHandler::PropertyChangedCallback, | 307 &ShillPropertyHandler::PropertyChangedCallback, AsWeakPtr())); |
301 weak_ptr_factory_.GetWeakPtr())); | |
302 network_event_log::AddEntry(kLogModule, "StartObserving", path); | 308 network_event_log::AddEntry(kLogModule, "StartObserving", path); |
303 } | 309 } |
304 observer_map.erase(path); | 310 observer_map.erase(path); |
305 // Limit the number of observed services. | 311 // Limit the number of observed services. |
306 if (new_observed.size() >= kMaxObserved) | 312 if (new_observed.size() >= kMaxObserved) |
307 break; | 313 break; |
308 } | 314 } |
309 // Delete network service observers still in observer_map. | 315 // Delete network service observers still in observer_map. |
310 for (ShillPropertyObserverMap::iterator iter = observer_map.begin(); | 316 for (ShillPropertyObserverMap::iterator iter = observer_map.begin(); |
311 iter != observer_map.end(); ++iter) { | 317 iter != observer_map.end(); ++iter) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 listener_->UpdateManagedStateProperties(type, path, properties); | 381 listener_->UpdateManagedStateProperties(type, path, properties); |
376 | 382 |
377 if (properties.HasKey(shill::kIPConfigProperty)) { | 383 if (properties.HasKey(shill::kIPConfigProperty)) { |
378 // Since this is the first time we received properties for this network, | 384 // Since this is the first time we received properties for this network, |
379 // also request its IPConfig parameters. | 385 // also request its IPConfig parameters. |
380 std::string ip_config_path; | 386 std::string ip_config_path; |
381 if (properties.GetString(shill::kIPConfigProperty, &ip_config_path)) { | 387 if (properties.GetString(shill::kIPConfigProperty, &ip_config_path)) { |
382 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( | 388 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( |
383 dbus::ObjectPath(ip_config_path), | 389 dbus::ObjectPath(ip_config_path), |
384 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, | 390 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, |
385 weak_ptr_factory_.GetWeakPtr(), path)); | 391 AsWeakPtr(), path)); |
386 } | 392 } |
387 } | 393 } |
388 | 394 |
389 // Notify the listener only when all updates for that type have completed. | 395 // Notify the listener only when all updates for that type have completed. |
390 if (pending_updates_[type].size() == 0) | 396 if (pending_updates_[type].size() == 0) |
391 listener_->ManagedStateListChanged(type); | 397 listener_->ManagedStateListChanged(type); |
392 } | 398 } |
393 | 399 |
394 void ShillPropertyHandler::PropertyChangedCallback( | 400 void ShillPropertyHandler::PropertyChangedCallback( |
395 ManagedState::ManagedType type, | 401 ManagedState::ManagedType type, |
(...skipping 14 matching lines...) Expand all Loading... |
410 const base::Value& value) { | 416 const base::Value& value) { |
411 if (key == shill::kIPConfigProperty) { | 417 if (key == shill::kIPConfigProperty) { |
412 // Handle IPConfig here and call listener_->UpdateNetworkServiceIPAddress | 418 // Handle IPConfig here and call listener_->UpdateNetworkServiceIPAddress |
413 // when the request completes. | 419 // when the request completes. |
414 std::string ip_config_path; | 420 std::string ip_config_path; |
415 value.GetAsString(&ip_config_path); | 421 value.GetAsString(&ip_config_path); |
416 DCHECK(!ip_config_path.empty()); | 422 DCHECK(!ip_config_path.empty()); |
417 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( | 423 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( |
418 dbus::ObjectPath(ip_config_path), | 424 dbus::ObjectPath(ip_config_path), |
419 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, | 425 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, |
420 weak_ptr_factory_.GetWeakPtr(), path)); | 426 AsWeakPtr(), path)); |
421 } else { | 427 } else { |
422 listener_->UpdateNetworkServiceProperty(path, key, value); | 428 listener_->UpdateNetworkServiceProperty(path, key, value); |
423 } | 429 } |
424 } | 430 } |
425 | 431 |
426 void ShillPropertyHandler::GetIPConfigCallback( | 432 void ShillPropertyHandler::GetIPConfigCallback( |
427 const std::string& service_path, | 433 const std::string& service_path, |
428 DBusMethodCallStatus call_status, | 434 DBusMethodCallStatus call_status, |
429 const base::DictionaryValue& properties) { | 435 const base::DictionaryValue& properties) { |
430 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 436 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
(...skipping 11 matching lines...) Expand all Loading... |
442 | 448 |
443 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( | 449 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( |
444 const std::string& path, | 450 const std::string& path, |
445 const std::string& key, | 451 const std::string& key, |
446 const base::Value& value) { | 452 const base::Value& value) { |
447 listener_->UpdateDeviceProperty(path, key, value); | 453 listener_->UpdateDeviceProperty(path, key, value); |
448 } | 454 } |
449 | 455 |
450 } // namespace internal | 456 } // namespace internal |
451 } // namespace chromeos | 457 } // namespace chromeos |
OLD | NEW |