Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chromeos/network/network_device_handler_impl.cc

Issue 156353002: Implement networkingPrivate.setWifiTDLSEnabledState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 int retry_count,
144 const std::string& ip_or_mac_address,
145 const network_handler::StringResultCallback& callback,
146 const network_handler::ErrorCallback& error_callback);
147
148 void TDLSOperationCallback(
149 const std::string& device_path,
150 const std::string& operation,
151 int retry_count,
152 const std::string& ip_or_mac_address,
153 const network_handler::StringResultCallback& callback,
154 const network_handler::ErrorCallback& error_callback,
155 const std::string& result) {
156 std::string event_desc = "TDLSOperationCallback: " + operation;
157 if (!result.empty())
158 event_desc += ": " + result;
159 NET_LOG_EVENT(event_desc, device_path);
160 if (operation != shill::kTDLSSetupOperation) {
161 if (!callback.is_null())
162 callback.Run(result);
163 return;
164 }
165
166 // Handle 'Setup'
167 std::string next_operation;
168 base::TimeDelta request_delay;
169 const int kMaxRetries = 5;
170 if (result.empty()) {
171 // Success, request Status after a short delay.
172 const int64 kRequestStatusDelayMs = 500;
173 next_operation = shill::kTDLSStatusOperation;
174 request_delay = base::TimeDelta::FromMilliseconds(kRequestStatusDelayMs);
175 } else if (result == shill::kErrorResultInProgress &&
Paul Stewart 2014/02/13 19:46:06 I don't think this will work the way you think it
stevenjb 2014/02/13 20:58:27 Ugh, right, I should have realized that. Will a su
Paul Stewart 2014/02/13 21:06:30 The only time PerformTDLSOperation (conventionally
176 retry_count < kMaxRetries) {
177 // InProgress error: retry.
178 const int64 kReRequestDelayMs = 1000;
179 next_operation = shill::kTDLSSetupOperation;
180 request_delay = base::TimeDelta::FromMilliseconds(kReRequestDelayMs);
181 ++retry_count;
182 } else {
183 // Other error: fail.
184 NET_LOG_ERROR("TDLSOperation Failed: " + result, device_path);
185 if (!error_callback.is_null()) {
186 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
187 error_data->SetString(network_handler::kErrorName, result);
188 error_callback.Run(result, error_data.Pass());
189 }
190 return;
191 }
192
193 base::MessageLoopProxy::current()->PostDelayedTask(
194 FROM_HERE,
195 base::Bind(&CallPerformTDLSOperation,
196 device_path, next_operation, retry_count, ip_or_mac_address,
197 callback, error_callback),
198 request_delay);
199 }
200
201 void CallPerformTDLSOperation(
202 const std::string& device_path,
203 const std::string& operation,
204 int retry_count,
205 const std::string& ip_or_mac_address,
206 const network_handler::StringResultCallback& callback,
207 const network_handler::ErrorCallback& error_callback) {
208 NET_LOG_EVENT("CallPerformTDLSOperation: " + operation, device_path);
209 DBusThreadManager::Get()->GetShillDeviceClient()->PerformTDLSOperation(
210 dbus::ObjectPath(device_path),
211 operation,
212 ip_or_mac_address,
213 base::Bind(&TDLSOperationCallback,
214 device_path, operation, retry_count, ip_or_mac_address,
215 callback, error_callback),
216 base::Bind(&network_handler::ShillErrorCallbackFunction,
217 "Device.PerformTDLSOperation Failed: " + operation,
218 device_path,
219 error_callback));
220 }
221
137 } // namespace 222 } // namespace
138 223
139 NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() { 224 NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() {
140 network_state_handler_->RemoveObserver(this, FROM_HERE); 225 network_state_handler_->RemoveObserver(this, FROM_HERE);
141 } 226 }
142 227
143 void NetworkDeviceHandlerImpl::GetDeviceProperties( 228 void NetworkDeviceHandlerImpl::GetDeviceProperties(
144 const std::string& device_path, 229 const std::string& device_path,
145 const network_handler::DictionaryResultCallback& callback, 230 const network_handler::DictionaryResultCallback& callback,
146 const network_handler::ErrorCallback& error_callback) const { 231 const network_handler::ErrorCallback& error_callback) const {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 callback, 356 callback,
272 base::Bind(&HandleShillCallFailure, device_path, error_callback)); 357 base::Bind(&HandleShillCallFailure, device_path, error_callback));
273 } 358 }
274 359
275 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( 360 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming(
276 const bool allow_roaming) { 361 const bool allow_roaming) {
277 cellular_allow_roaming_ = allow_roaming; 362 cellular_allow_roaming_ = allow_roaming;
278 ApplyCellularAllowRoamingToShill(); 363 ApplyCellularAllowRoamingToShill();
279 } 364 }
280 365
366 void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled(
367 const std::string& ip_or_mac_address,
368 bool enabled,
369 const network_handler::StringResultCallback& callback,
370 const network_handler::ErrorCallback& error_callback) {
371 const DeviceState* device_state =
372 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi());
373 if (!device_state) {
374 if (error_callback.is_null())
375 return;
376 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
377 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
378 error_callback.Run(kErrorDeviceMissing, error_data.Pass());
379 return;
380 }
381 std::string operation = enabled ? shill::kTDLSSetupOperation
382 : shill::kTDLSTeardownOperation;
383 CallPerformTDLSOperation(device_state->path(),
384 operation, 0, ip_or_mac_address,
385 callback, error_callback);
386 }
387
388 void NetworkDeviceHandlerImpl::GetWifiTDLSStatus(
389 const std::string& ip_or_mac_address,
390 const network_handler::StringResultCallback& callback,
391 const network_handler::ErrorCallback& error_callback) {
392 const DeviceState* device_state =
393 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi());
394 if (!device_state) {
395 if (error_callback.is_null())
396 return;
397 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
398 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
399 error_callback.Run(kErrorDeviceMissing, error_data.Pass());
400 return;
401 }
402 std::string operation = shill::kTDLSStatusOperation;
403 CallPerformTDLSOperation(device_state->path(),
404 operation, 0, ip_or_mac_address,
405 callback, error_callback);
406 }
407
281 void NetworkDeviceHandlerImpl::DeviceListChanged() { 408 void NetworkDeviceHandlerImpl::DeviceListChanged() {
282 ApplyCellularAllowRoamingToShill(); 409 ApplyCellularAllowRoamingToShill();
283 } 410 }
284 411
285 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() 412 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl()
286 : network_state_handler_(NULL), 413 : network_state_handler_(NULL),
287 cellular_allow_roaming_(false) {} 414 cellular_allow_roaming_(false) {}
288 415
289 void NetworkDeviceHandlerImpl::Init( 416 void NetworkDeviceHandlerImpl::Init(
290 NetworkStateHandler* network_state_handler) { 417 NetworkStateHandler* network_state_handler) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 453
327 SetDevicePropertyInternal(device_state->path(), 454 SetDevicePropertyInternal(device_state->path(),
328 shill::kCellularAllowRoamingProperty, 455 shill::kCellularAllowRoamingProperty,
329 base::FundamentalValue(new_device_value), 456 base::FundamentalValue(new_device_value),
330 base::Bind(&base::DoNothing), 457 base::Bind(&base::DoNothing),
331 network_handler::ErrorCallback()); 458 network_handler::ErrorCallback());
332 } 459 }
333 } 460 }
334 461
335 } // namespace chromeos 462 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_device_handler_impl.h ('k') | chromeos/network/network_device_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698