| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void OnConfigureService(void* object, | 227 void OnConfigureService(void* object, |
| 228 const char* service_path, | 228 const char* service_path, |
| 229 NetworkMethodErrorType error, | 229 NetworkMethodErrorType error, |
| 230 const char* error_message) { | 230 const char* error_message) { |
| 231 if (error != NETWORK_METHOD_ERROR_NONE) { | 231 if (error != NETWORK_METHOD_ERROR_NONE) { |
| 232 LOG(WARNING) << "Error from ConfigureService callback: " | 232 LOG(WARNING) << "Error from ConfigureService callback: " |
| 233 << " Error: " << error << " Message: " << error_message; | 233 << " Error: " << error << " Message: " << error_message; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 // A callback used to call a NetworkActionCallback on success. |
| 238 void OnNetworkActionSuccess(const std::string& path, |
| 239 NetworkActionCallback callback, |
| 240 void* object) { |
| 241 callback(object, path.c_str(), NETWORK_METHOD_ERROR_NONE, ""); |
| 242 } |
| 243 |
| 244 // A callback used to call a NetworkActionCallback on error. |
| 245 void OnNetworkActionError(const std::string& path, |
| 246 NetworkActionCallback callback, |
| 247 void* object, |
| 248 const std::string& error_name, |
| 249 const std::string& error_message) { |
| 250 if (error_name.empty()) { |
| 251 callback(object, path.c_str(), NETWORK_METHOD_ERROR_LOCAL, ""); |
| 252 } else { |
| 253 callback(object, path.c_str(), NETWORK_METHOD_ERROR_REMOTE, |
| 254 error_message.c_str()); |
| 255 } |
| 256 } |
| 257 |
| 237 // Safe string constructor since we can't rely on non NULL pointers | 258 // Safe string constructor since we can't rely on non NULL pointers |
| 238 // for string values from libcros. | 259 // for string values from libcros. |
| 239 std::string SafeString(const char* s) { | 260 std::string SafeString(const char* s) { |
| 240 return s ? std::string(s) : std::string(); | 261 return s ? std::string(s) : std::string(); |
| 241 } | 262 } |
| 242 | 263 |
| 243 // A bool to remember whether we are using Libcros network functions or not. | 264 // A bool to remember whether we are using Libcros network functions or not. |
| 244 bool g_libcros_network_functions_enabled = true; | 265 bool g_libcros_network_functions_enabled = true; |
| 245 | 266 |
| 246 } // namespace | 267 } // namespace |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 401 |
| 381 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, | 402 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, |
| 382 MonitorSMSCallback callback, | 403 MonitorSMSCallback callback, |
| 383 void* object) { | 404 void* object) { |
| 384 return new CrosSMSWatcher(modem_device_path, callback, object); | 405 return new CrosSMSWatcher(modem_device_path, callback, object); |
| 385 } | 406 } |
| 386 | 407 |
| 387 void CrosRequestNetworkServiceConnect(const std::string& service_path, | 408 void CrosRequestNetworkServiceConnect(const std::string& service_path, |
| 388 NetworkActionCallback callback, | 409 NetworkActionCallback callback, |
| 389 void* object) { | 410 void* object) { |
| 390 chromeos::RequestNetworkServiceConnect(service_path.c_str(), callback, | 411 if (g_libcros_network_functions_enabled) { |
| 391 object); | 412 chromeos::RequestNetworkServiceConnect(service_path.c_str(), callback, |
| 413 object); |
| 414 } else { |
| 415 DBusThreadManager::Get()->GetFlimflamServiceClient()->Connect( |
| 416 dbus::ObjectPath(service_path), |
| 417 base::Bind(&OnNetworkActionSuccess, service_path, callback, object), |
| 418 base::Bind(&OnNetworkActionError, service_path, callback, object)); |
| 419 } |
| 392 } | 420 } |
| 393 | 421 |
| 394 void CrosRequestNetworkManagerProperties( | 422 void CrosRequestNetworkManagerProperties( |
| 395 const NetworkPropertiesCallback& callback) { | 423 const NetworkPropertiesCallback& callback) { |
| 396 if (g_libcros_network_functions_enabled) { | 424 if (g_libcros_network_functions_enabled) { |
| 397 // The newly allocated callback will be deleted in | 425 // The newly allocated callback will be deleted in |
| 398 // OnRequestNetworkProperties. | 426 // OnRequestNetworkProperties. |
| 399 chromeos::RequestNetworkManagerProperties( | 427 chromeos::RequestNetworkManagerProperties( |
| 400 &OnRequestNetworkProperties, | 428 &OnRequestNetworkProperties, |
| 401 new OnRequestNetworkPropertiesCallback(callback)); | 429 new OnRequestNetworkPropertiesCallback(callback)); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 network_type, base::Bind(&DoNothing)); | 623 network_type, base::Bind(&DoNothing)); |
| 596 } | 624 } |
| 597 } | 625 } |
| 598 } | 626 } |
| 599 | 627 |
| 600 void CrosRequestRequirePin(const std::string& device_path, | 628 void CrosRequestRequirePin(const std::string& device_path, |
| 601 const std::string& pin, | 629 const std::string& pin, |
| 602 bool enable, | 630 bool enable, |
| 603 NetworkActionCallback callback, | 631 NetworkActionCallback callback, |
| 604 void* object) { | 632 void* object) { |
| 605 chromeos::RequestRequirePin(device_path.c_str(), pin.c_str(), enable, | 633 if (g_libcros_network_functions_enabled) { |
| 606 callback, object); | 634 chromeos::RequestRequirePin(device_path.c_str(), pin.c_str(), enable, |
| 635 callback, object); |
| 636 } else { |
| 637 DBusThreadManager::Get()->GetFlimflamDeviceClient()->RequirePin( |
| 638 dbus::ObjectPath(device_path), pin, enable, |
| 639 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 640 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 641 } |
| 607 } | 642 } |
| 608 | 643 |
| 609 void CrosRequestEnterPin(const std::string& device_path, | 644 void CrosRequestEnterPin(const std::string& device_path, |
| 610 const std::string& pin, | 645 const std::string& pin, |
| 611 NetworkActionCallback callback, | 646 NetworkActionCallback callback, |
| 612 void* object) { | 647 void* object) { |
| 613 chromeos::RequestEnterPin(device_path.c_str(), pin.c_str(), callback, object); | 648 if (g_libcros_network_functions_enabled) { |
| 649 chromeos::RequestEnterPin(device_path.c_str(), pin.c_str(), callback, |
| 650 object); |
| 651 } else { |
| 652 DBusThreadManager::Get()->GetFlimflamDeviceClient()->EnterPin( |
| 653 dbus::ObjectPath(device_path), pin, |
| 654 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 655 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 656 } |
| 614 } | 657 } |
| 615 | 658 |
| 616 void CrosRequestUnblockPin(const std::string& device_path, | 659 void CrosRequestUnblockPin(const std::string& device_path, |
| 617 const std::string& unblock_code, | 660 const std::string& unblock_code, |
| 618 const std::string& pin, | 661 const std::string& pin, |
| 619 NetworkActionCallback callback, | 662 NetworkActionCallback callback, |
| 620 void* object) { | 663 void* object) { |
| 621 chromeos::RequestUnblockPin(device_path.c_str(), unblock_code.c_str(), | 664 if (g_libcros_network_functions_enabled) { |
| 622 pin.c_str(), callback, object); | 665 chromeos::RequestUnblockPin(device_path.c_str(), unblock_code.c_str(), |
| 666 pin.c_str(), callback, object); |
| 667 } else { |
| 668 DBusThreadManager::Get()->GetFlimflamDeviceClient()->UnblockPin( |
| 669 dbus::ObjectPath(device_path), unblock_code, pin, |
| 670 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 671 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 672 } |
| 623 } | 673 } |
| 624 | 674 |
| 625 void CrosRequestChangePin(const std::string& device_path, | 675 void CrosRequestChangePin(const std::string& device_path, |
| 626 const std::string& old_pin, | 676 const std::string& old_pin, |
| 627 const std::string& new_pin, | 677 const std::string& new_pin, |
| 628 NetworkActionCallback callback, | 678 NetworkActionCallback callback, |
| 629 void* object) { | 679 void* object) { |
| 630 chromeos::RequestChangePin(device_path.c_str(), old_pin.c_str(), | 680 if (g_libcros_network_functions_enabled) { |
| 631 new_pin.c_str(), callback, object); | 681 chromeos::RequestChangePin(device_path.c_str(), old_pin.c_str(), |
| 682 new_pin.c_str(), callback, object); |
| 683 } else { |
| 684 DBusThreadManager::Get()->GetFlimflamDeviceClient()->ChangePin( |
| 685 dbus::ObjectPath(device_path), old_pin, new_pin, |
| 686 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 687 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 688 } |
| 632 } | 689 } |
| 633 | 690 |
| 634 void CrosProposeScan(const std::string& device_path) { | 691 void CrosProposeScan(const std::string& device_path) { |
| 635 if (g_libcros_network_functions_enabled) { | 692 if (g_libcros_network_functions_enabled) { |
| 636 chromeos::ProposeScan(device_path.c_str()); | 693 chromeos::ProposeScan(device_path.c_str()); |
| 637 } else { | 694 } else { |
| 638 DBusThreadManager::Get()->GetFlimflamDeviceClient()->ProposeScan( | 695 DBusThreadManager::Get()->GetFlimflamDeviceClient()->ProposeScan( |
| 639 dbus::ObjectPath(device_path), base::Bind(&DoNothing)); | 696 dbus::ObjectPath(device_path), base::Bind(&DoNothing)); |
| 640 } | 697 } |
| 641 } | 698 } |
| 642 | 699 |
| 643 void CrosRequestCellularRegister(const std::string& device_path, | 700 void CrosRequestCellularRegister(const std::string& device_path, |
| 644 const std::string& network_id, | 701 const std::string& network_id, |
| 645 chromeos::NetworkActionCallback callback, | 702 chromeos::NetworkActionCallback callback, |
| 646 void* object) { | 703 void* object) { |
| 647 chromeos::RequestCellularRegister(device_path.c_str(), network_id.c_str(), | 704 if (g_libcros_network_functions_enabled) { |
| 648 callback, object); | 705 chromeos::RequestCellularRegister(device_path.c_str(), network_id.c_str(), |
| 706 callback, object); |
| 707 } else { |
| 708 DBusThreadManager::Get()->GetFlimflamDeviceClient()->Register( |
| 709 dbus::ObjectPath(device_path), network_id, |
| 710 base::Bind(&OnNetworkActionSuccess, device_path, callback, object), |
| 711 base::Bind(&OnNetworkActionError, device_path, callback, object)); |
| 712 } |
| 649 } | 713 } |
| 650 | 714 |
| 651 bool CrosSetOfflineMode(bool offline) { | 715 bool CrosSetOfflineMode(bool offline) { |
| 652 return chromeos::SetOfflineMode(offline); | 716 return chromeos::SetOfflineMode(offline); |
| 653 } | 717 } |
| 654 | 718 |
| 655 IPConfigStatus* CrosListIPConfigs(const std::string& device_path) { | 719 IPConfigStatus* CrosListIPConfigs(const std::string& device_path) { |
| 656 return chromeos::ListIPConfigs(device_path.c_str()); | 720 return chromeos::ListIPConfigs(device_path.c_str()); |
| 657 } | 721 } |
| 658 | 722 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 ScopedGHashTable ghash( | 802 ScopedGHashTable ghash( |
| 739 ConvertDictionaryValueToStringValueGHashTable(properties)); | 803 ConvertDictionaryValueToStringValueGHashTable(properties)); |
| 740 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); | 804 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); |
| 741 } else { | 805 } else { |
| 742 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( | 806 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( |
| 743 properties, base::Bind(&DoNothing)); | 807 properties, base::Bind(&DoNothing)); |
| 744 } | 808 } |
| 745 } | 809 } |
| 746 | 810 |
| 747 } // namespace chromeos | 811 } // namespace chromeos |
| OLD | NEW |