| 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 "chrome/browser/chromeos/cros/cros_network_functions.h" | 5 #include "chrome/browser/chromeos/cros/cros_network_functions.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/cros/gvalue_util.h" | 10 #include "chrome/browser/chromeos/cros/gvalue_util.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 void OnConfigureService(void* object, | 215 void OnConfigureService(void* object, |
| 216 const char* service_path, | 216 const char* service_path, |
| 217 NetworkMethodErrorType error, | 217 NetworkMethodErrorType error, |
| 218 const char* error_message) { | 218 const char* error_message) { |
| 219 if (error != NETWORK_METHOD_ERROR_NONE) { | 219 if (error != NETWORK_METHOD_ERROR_NONE) { |
| 220 LOG(WARNING) << "Error from ConfigureService callback: " | 220 LOG(WARNING) << "Error from ConfigureService callback: " |
| 221 << " Error: " << error << " Message: " << error_message; | 221 << " Error: " << error << " Message: " << error_message; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 // A callback used to call a NetworkActionCallback on success. |
| 226 void OnNetworkActionSuccess(const std::string& path, |
| 227 NetworkActionCallback callback, |
| 228 void* object) { |
| 229 callback(object, path.c_str(), NETWORK_METHOD_ERROR_NONE, ""); |
| 230 } |
| 231 |
| 232 // A callback used to call a NetworkActionCallback on error. |
| 233 void OnNetworkActionError(const std::string& path, |
| 234 NetworkActionCallback callback, |
| 235 void* object, |
| 236 const std::string& error_name, |
| 237 const std::string& error_message) { |
| 238 if (error_name.empty()) { |
| 239 callback(object, path.c_str(), NETWORK_METHOD_ERROR_LOCAL, ""); |
| 240 } else { |
| 241 callback(object, path.c_str(), NETWORK_METHOD_ERROR_REMOTE, |
| 242 error_message.c_str()); |
| 243 } |
| 244 } |
| 245 |
| 225 // Safe string constructor since we can't rely on non NULL pointers | 246 // Safe string constructor since we can't rely on non NULL pointers |
| 226 // for string values from libcros. | 247 // for string values from libcros. |
| 227 std::string SafeString(const char* s) { | 248 std::string SafeString(const char* s) { |
| 228 return s ? std::string(s) : std::string(); | 249 return s ? std::string(s) : std::string(); |
| 229 } | 250 } |
| 230 | 251 |
| 231 // A bool to remember whether we are using Libcros network functions or not. | 252 // A bool to remember whether we are using Libcros network functions or not. |
| 232 bool g_libcros_network_functions_enabled = true; | 253 bool g_libcros_network_functions_enabled = true; |
| 233 | 254 |
| 234 } // namespace | 255 } // namespace |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 382 |
| 362 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, | 383 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, |
| 363 MonitorSMSCallback callback, | 384 MonitorSMSCallback callback, |
| 364 void* object) { | 385 void* object) { |
| 365 return new CrosSMSWatcher(modem_device_path, callback, object); | 386 return new CrosSMSWatcher(modem_device_path, callback, object); |
| 366 } | 387 } |
| 367 | 388 |
| 368 void CrosRequestNetworkServiceConnect(const std::string& service_path, | 389 void CrosRequestNetworkServiceConnect(const std::string& service_path, |
| 369 NetworkActionCallback callback, | 390 NetworkActionCallback callback, |
| 370 void* object) { | 391 void* object) { |
| 371 chromeos::RequestNetworkServiceConnect(service_path.c_str(), callback, | 392 if (g_libcros_network_functions_enabled) { |
| 372 object); | 393 chromeos::RequestNetworkServiceConnect(service_path.c_str(), callback, |
| 394 object); |
| 395 } else { |
| 396 DBusThreadManager::Get()->GetFlimflamServiceClient()->Connect( |
| 397 dbus::ObjectPath(service_path), |
| 398 base::Bind(&OnNetworkActionSuccess, service_path, callback, object), |
| 399 base::Bind(&OnNetworkActionError, service_path, callback, object)); |
| 400 } |
| 373 } | 401 } |
| 374 | 402 |
| 375 void CrosRequestNetworkManagerProperties( | 403 void CrosRequestNetworkManagerProperties( |
| 376 const NetworkPropertiesCallback& callback) { | 404 const NetworkPropertiesCallback& callback) { |
| 377 if (g_libcros_network_functions_enabled) { | 405 if (g_libcros_network_functions_enabled) { |
| 378 // The newly allocated callback will be deleted in | 406 // The newly allocated callback will be deleted in |
| 379 // OnRequestNetworkProperties. | 407 // OnRequestNetworkProperties. |
| 380 chromeos::RequestNetworkManagerProperties( | 408 chromeos::RequestNetworkManagerProperties( |
| 381 &OnRequestNetworkProperties, | 409 &OnRequestNetworkProperties, |
| 382 new OnRequestNetworkPropertiesCallback(callback)); | 410 new OnRequestNetworkPropertiesCallback(callback)); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 network_type, base::Bind(&DoNothing)); | 555 network_type, base::Bind(&DoNothing)); |
| 528 } | 556 } |
| 529 } | 557 } |
| 530 } | 558 } |
| 531 | 559 |
| 532 void CrosRequestRequirePin(const std::string& device_path, | 560 void CrosRequestRequirePin(const std::string& device_path, |
| 533 const std::string& pin, | 561 const std::string& pin, |
| 534 bool enable, | 562 bool enable, |
| 535 NetworkActionCallback callback, | 563 NetworkActionCallback callback, |
| 536 void* object) { | 564 void* object) { |
| 537 chromeos::RequestRequirePin(device_path.c_str(), pin.c_str(), enable, | 565 if (g_libcros_network_functions_enabled) { |
| 538 callback, object); | 566 chromeos::RequestRequirePin(device_path.c_str(), pin.c_str(), enable, |
| 567 callback, object); |
| 568 } else { |
| 569 DBusThreadManager::Get()->GetFlimflamDeviceClient()->RequirePin( |
| 570 dbus::ObjectPath(device_path), pin, enable, |
| 571 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 572 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 573 } |
| 539 } | 574 } |
| 540 | 575 |
| 541 void CrosRequestEnterPin(const std::string& device_path, | 576 void CrosRequestEnterPin(const std::string& device_path, |
| 542 const std::string& pin, | 577 const std::string& pin, |
| 543 NetworkActionCallback callback, | 578 NetworkActionCallback callback, |
| 544 void* object) { | 579 void* object) { |
| 545 chromeos::RequestEnterPin(device_path.c_str(), pin.c_str(), callback, object); | 580 if (g_libcros_network_functions_enabled) { |
| 581 chromeos::RequestEnterPin(device_path.c_str(), pin.c_str(), callback, |
| 582 object); |
| 583 } else { |
| 584 DBusThreadManager::Get()->GetFlimflamDeviceClient()->EnterPin( |
| 585 dbus::ObjectPath(device_path), pin, |
| 586 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 587 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 588 } |
| 546 } | 589 } |
| 547 | 590 |
| 548 void CrosRequestUnblockPin(const std::string& device_path, | 591 void CrosRequestUnblockPin(const std::string& device_path, |
| 549 const std::string& unblock_code, | 592 const std::string& unblock_code, |
| 550 const std::string& pin, | 593 const std::string& pin, |
| 551 NetworkActionCallback callback, | 594 NetworkActionCallback callback, |
| 552 void* object) { | 595 void* object) { |
| 553 chromeos::RequestUnblockPin(device_path.c_str(), unblock_code.c_str(), | 596 if (g_libcros_network_functions_enabled) { |
| 554 pin.c_str(), callback, object); | 597 chromeos::RequestUnblockPin(device_path.c_str(), unblock_code.c_str(), |
| 598 pin.c_str(), callback, object); |
| 599 } else { |
| 600 DBusThreadManager::Get()->GetFlimflamDeviceClient()->UnblockPin( |
| 601 dbus::ObjectPath(device_path), unblock_code, pin, |
| 602 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 603 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 604 } |
| 555 } | 605 } |
| 556 | 606 |
| 557 void CrosRequestChangePin(const std::string& device_path, | 607 void CrosRequestChangePin(const std::string& device_path, |
| 558 const std::string& old_pin, | 608 const std::string& old_pin, |
| 559 const std::string& new_pin, | 609 const std::string& new_pin, |
| 560 NetworkActionCallback callback, | 610 NetworkActionCallback callback, |
| 561 void* object) { | 611 void* object) { |
| 562 chromeos::RequestChangePin(device_path.c_str(), old_pin.c_str(), | 612 if (g_libcros_network_functions_enabled) { |
| 563 new_pin.c_str(), callback, object); | 613 chromeos::RequestChangePin(device_path.c_str(), old_pin.c_str(), |
| 614 new_pin.c_str(), callback, object); |
| 615 } else { |
| 616 DBusThreadManager::Get()->GetFlimflamDeviceClient()->ChangePin( |
| 617 dbus::ObjectPath(device_path), old_pin, new_pin, |
| 618 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 619 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 620 } |
| 564 } | 621 } |
| 565 | 622 |
| 566 void CrosProposeScan(const std::string& device_path) { | 623 void CrosProposeScan(const std::string& device_path) { |
| 567 chromeos::ProposeScan(device_path.c_str()); | 624 chromeos::ProposeScan(device_path.c_str()); |
| 568 } | 625 } |
| 569 | 626 |
| 570 void CrosRequestCellularRegister(const std::string& device_path, | 627 void CrosRequestCellularRegister(const std::string& device_path, |
| 571 const std::string& network_id, | 628 const std::string& network_id, |
| 572 chromeos::NetworkActionCallback callback, | 629 chromeos::NetworkActionCallback callback, |
| 573 void* object) { | 630 void* object) { |
| 574 chromeos::RequestCellularRegister(device_path.c_str(), network_id.c_str(), | 631 if (g_libcros_network_functions_enabled) { |
| 575 callback, object); | 632 chromeos::RequestCellularRegister(device_path.c_str(), network_id.c_str(), |
| 633 callback, object); |
| 634 } else { |
| 635 DBusThreadManager::Get()->GetFlimflamDeviceClient()->Register( |
| 636 dbus::ObjectPath(device_path), network_id, |
| 637 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 638 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 639 } |
| 576 } | 640 } |
| 577 | 641 |
| 578 bool CrosSetOfflineMode(bool offline) { | 642 bool CrosSetOfflineMode(bool offline) { |
| 579 return chromeos::SetOfflineMode(offline); | 643 return chromeos::SetOfflineMode(offline); |
| 580 } | 644 } |
| 581 | 645 |
| 582 IPConfigStatus* CrosListIPConfigs(const std::string& device_path) { | 646 IPConfigStatus* CrosListIPConfigs(const std::string& device_path) { |
| 583 return chromeos::ListIPConfigs(device_path.c_str()); | 647 return chromeos::ListIPConfigs(device_path.c_str()); |
| 584 } | 648 } |
| 585 | 649 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 ScopedGHashTable ghash( | 729 ScopedGHashTable ghash( |
| 666 ConvertDictionaryValueToStringValueGHashTable(properties)); | 730 ConvertDictionaryValueToStringValueGHashTable(properties)); |
| 667 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); | 731 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); |
| 668 } else { | 732 } else { |
| 669 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( | 733 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( |
| 670 properties, base::Bind(&DoNothing)); | 734 properties, base::Bind(&DoNothing)); |
| 671 } | 735 } |
| 672 } | 736 } |
| 673 | 737 |
| 674 } // namespace chromeos | 738 } // namespace chromeos |
| OLD | NEW |