OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_device_handler_impl.h" | 5 #include "chromeos/network/network_device_handler_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | |
10 #include "base/time/time.h" | |
9 #include "base/values.h" | 11 #include "base/values.h" |
10 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
11 #include "chromeos/dbus/shill_device_client.h" | 13 #include "chromeos/dbus/shill_device_client.h" |
12 #include "chromeos/dbus/shill_ipconfig_client.h" | 14 #include "chromeos/dbus/shill_ipconfig_client.h" |
13 #include "chromeos/network/device_state.h" | 15 #include "chromeos/network/device_state.h" |
14 #include "chromeos/network/network_event_log.h" | 16 #include "chromeos/network/network_event_log.h" |
15 #include "chromeos/network/network_handler_callbacks.h" | 17 #include "chromeos/network/network_handler_callbacks.h" |
16 #include "chromeos/network/network_state_handler.h" | 18 #include "chromeos/network/network_state_handler.h" |
17 #include "chromeos/network/shill_property_util.h" | 19 #include "chromeos/network/shill_property_util.h" |
18 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 const base::Closure& callback, | 129 const base::Closure& callback, |
128 const network_handler::ErrorCallback& error_callback) { | 130 const network_handler::ErrorCallback& error_callback) { |
129 DBusThreadManager::Get()->GetShillDeviceClient()->SetProperty( | 131 DBusThreadManager::Get()->GetShillDeviceClient()->SetProperty( |
130 dbus::ObjectPath(device_path), | 132 dbus::ObjectPath(device_path), |
131 property_name, | 133 property_name, |
132 value, | 134 value, |
133 callback, | 135 callback, |
134 base::Bind(&HandleShillCallFailure, device_path, error_callback)); | 136 base::Bind(&HandleShillCallFailure, device_path, error_callback)); |
135 } | 137 } |
136 | 138 |
139 // Forward declare for PostDelayedTask. | |
140 void CallPerformTDLSOperation( | |
141 const std::string& device_path, | |
142 const std::string& operation, | |
143 const std::string& ip_or_mac_address, | |
144 const network_handler::StringResultCallback& callback, | |
145 const network_handler::ErrorCallback& error_callback); | |
146 | |
147 void TDLSOperationCallback( | |
148 const std::string& device_path, | |
149 const std::string& operation, | |
150 const std::string& ip_or_mac_address, | |
151 const network_handler::StringResultCallback& callback, | |
152 const network_handler::ErrorCallback& error_callback, | |
153 const std::string& result) { | |
154 std::string event_desc = "TDLSOperationCallback: " + operation; | |
155 if (!result.empty()) | |
156 event_desc += ": " + result; | |
157 NET_LOG_EVENT(event_desc, device_path); | |
158 if (operation != shill::kTDLSSetupOperation) { | |
159 if (!callback.is_null()) | |
160 callback.Run(result); | |
161 return; | |
162 } | |
163 // Setup operation will retry if there was an error (result is not empty), | |
164 // or request the status. | |
165 std::string next_operation; | |
166 base::TimeDelta request_delay; | |
167 if (!result.empty()) { | |
168 const int64 kReRequestDelayMs = 1000; | |
169 next_operation = shill::kTDLSSetupOperation; | |
170 request_delay = base::TimeDelta::FromMilliseconds(kReRequestDelayMs); | |
Paul Stewart
2014/02/06 22:58:40
I'm not sure I understand, but:
- Does this just
stevenjb
2014/02/12 23:22:52
You're right, we definitely need a timeout here. I
| |
171 } else { | |
172 next_operation = shill::kTDLSStatusOperation; | |
Paul Stewart
2014/02/06 22:58:40
What is request_delay set to at this point? Does
Paul Stewart
2014/02/06 23:01:43
Just spotted this was an object, which probably is
stevenjb
2014/02/12 23:22:52
I will set the delay to 500ms so that there is an
| |
173 } | |
174 | |
175 base::MessageLoopProxy::current()->PostDelayedTask( | |
176 FROM_HERE, | |
177 base::Bind(&CallPerformTDLSOperation, | |
178 device_path, next_operation, ip_or_mac_address, | |
179 callback, error_callback), | |
180 request_delay); | |
181 } | |
182 | |
183 void CallPerformTDLSOperation( | |
184 const std::string& device_path, | |
185 const std::string& operation, | |
186 const std::string& ip_or_mac_address, | |
187 const network_handler::StringResultCallback& callback, | |
188 const network_handler::ErrorCallback& error_callback) { | |
189 NET_LOG_EVENT("CallPerformTDLSOperation: " + operation, device_path); | |
190 DBusThreadManager::Get()->GetShillDeviceClient()->PerformTDLSOperation( | |
191 dbus::ObjectPath(device_path), | |
192 operation, | |
193 ip_or_mac_address, | |
194 base::Bind(&TDLSOperationCallback, | |
195 device_path, operation, ip_or_mac_address, | |
196 callback, error_callback), | |
197 base::Bind(&network_handler::ShillErrorCallbackFunction, | |
198 "Device.PerformTDLSOperation Failed: " + operation, | |
199 device_path, | |
200 error_callback)); | |
201 } | |
202 | |
137 } // namespace | 203 } // namespace |
138 | 204 |
139 NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() { | 205 NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() { |
140 network_state_handler_->RemoveObserver(this, FROM_HERE); | 206 network_state_handler_->RemoveObserver(this, FROM_HERE); |
141 } | 207 } |
142 | 208 |
143 void NetworkDeviceHandlerImpl::GetDeviceProperties( | 209 void NetworkDeviceHandlerImpl::GetDeviceProperties( |
144 const std::string& device_path, | 210 const std::string& device_path, |
145 const network_handler::DictionaryResultCallback& callback, | 211 const network_handler::DictionaryResultCallback& callback, |
146 const network_handler::ErrorCallback& error_callback) const { | 212 const network_handler::ErrorCallback& error_callback) const { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 callback, | 337 callback, |
272 base::Bind(&HandleShillCallFailure, device_path, error_callback)); | 338 base::Bind(&HandleShillCallFailure, device_path, error_callback)); |
273 } | 339 } |
274 | 340 |
275 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( | 341 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( |
276 const bool allow_roaming) { | 342 const bool allow_roaming) { |
277 cellular_allow_roaming_ = allow_roaming; | 343 cellular_allow_roaming_ = allow_roaming; |
278 ApplyCellularAllowRoamingToShill(); | 344 ApplyCellularAllowRoamingToShill(); |
279 } | 345 } |
280 | 346 |
347 void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled( | |
348 const std::string& ip_or_mac_address, | |
349 bool enabled, | |
350 const network_handler::StringResultCallback& callback, | |
351 const network_handler::ErrorCallback& error_callback) { | |
352 const DeviceState* device_state = | |
353 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); | |
354 if (!device_state) { | |
355 if (error_callback.is_null()) | |
356 return; | |
357 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); | |
358 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); | |
359 error_callback.Run(kErrorDeviceMissing, error_data.Pass()); | |
360 return; | |
361 } | |
362 std::string operation = | |
363 enabled ? shill::kTDLSSetupOperation : shill::kTDLSTeardownOperation; | |
364 CallPerformTDLSOperation(device_state->path(), | |
365 operation, ip_or_mac_address, | |
366 callback, error_callback); | |
367 } | |
368 | |
281 void NetworkDeviceHandlerImpl::DeviceListChanged() { | 369 void NetworkDeviceHandlerImpl::DeviceListChanged() { |
282 ApplyCellularAllowRoamingToShill(); | 370 ApplyCellularAllowRoamingToShill(); |
283 } | 371 } |
284 | 372 |
285 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() | 373 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() |
286 : network_state_handler_(NULL), | 374 : network_state_handler_(NULL), |
287 cellular_allow_roaming_(false) {} | 375 cellular_allow_roaming_(false) {} |
288 | 376 |
289 void NetworkDeviceHandlerImpl::Init( | 377 void NetworkDeviceHandlerImpl::Init( |
290 NetworkStateHandler* network_state_handler) { | 378 NetworkStateHandler* network_state_handler) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 | 414 |
327 SetDevicePropertyInternal(device_state->path(), | 415 SetDevicePropertyInternal(device_state->path(), |
328 shill::kCellularAllowRoamingProperty, | 416 shill::kCellularAllowRoamingProperty, |
329 base::FundamentalValue(new_device_value), | 417 base::FundamentalValue(new_device_value), |
330 base::Bind(&base::DoNothing), | 418 base::Bind(&base::DoNothing), |
331 network_handler::ErrorCallback()); | 419 network_handler::ErrorCallback()); |
332 } | 420 } |
333 } | 421 } |
334 | 422 |
335 } // namespace chromeos | 423 } // namespace chromeos |
OLD | NEW |