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

Side by Side Diff: chrome/browser/chromeos/cros/cros_network_functions.cc

Issue 10134027: Reimplement RequestNetworkServiceConnect, RequestRequirePin, RequestEnterPin, RequestEnterPin, Requ… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove reinterpret_cast Created 8 years, 8 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 (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
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 394
374 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, 395 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path,
375 MonitorSMSCallback callback, 396 MonitorSMSCallback callback,
376 void* object) { 397 void* object) {
377 return new CrosSMSWatcher(modem_device_path, callback, object); 398 return new CrosSMSWatcher(modem_device_path, callback, object);
378 } 399 }
379 400
380 void CrosRequestNetworkServiceConnect(const std::string& service_path, 401 void CrosRequestNetworkServiceConnect(const std::string& service_path,
381 NetworkActionCallback callback, 402 NetworkActionCallback callback,
382 void* object) { 403 void* object) {
383 chromeos::RequestNetworkServiceConnect(service_path.c_str(), callback, 404 if (g_libcros_network_functions_enabled) {
384 object); 405 chromeos::RequestNetworkServiceConnect(service_path.c_str(), callback,
406 object);
407 } else {
408 DBusThreadManager::Get()->GetFlimflamServiceClient()->Connect(
409 dbus::ObjectPath(service_path),
410 base::Bind(&OnNetworkActionSuccess, service_path, callback, object),
411 base::Bind(&OnNetworkActionError, service_path, callback, object));
412 }
385 } 413 }
386 414
387 void CrosRequestNetworkManagerProperties( 415 void CrosRequestNetworkManagerProperties(
388 const NetworkPropertiesCallback& callback) { 416 const NetworkPropertiesCallback& callback) {
389 if (g_libcros_network_functions_enabled) { 417 if (g_libcros_network_functions_enabled) {
390 // The newly allocated callback will be deleted in 418 // The newly allocated callback will be deleted in
391 // OnRequestNetworkProperties. 419 // OnRequestNetworkProperties.
392 chromeos::RequestNetworkManagerProperties( 420 chromeos::RequestNetworkManagerProperties(
393 &OnRequestNetworkProperties, 421 &OnRequestNetworkProperties,
394 new OnRequestNetworkPropertiesCallback(callback)); 422 new OnRequestNetworkPropertiesCallback(callback));
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 network_type, base::Bind(&DoNothing)); 616 network_type, base::Bind(&DoNothing));
589 } 617 }
590 } 618 }
591 } 619 }
592 620
593 void CrosRequestRequirePin(const std::string& device_path, 621 void CrosRequestRequirePin(const std::string& device_path,
594 const std::string& pin, 622 const std::string& pin,
595 bool enable, 623 bool enable,
596 NetworkActionCallback callback, 624 NetworkActionCallback callback,
597 void* object) { 625 void* object) {
598 chromeos::RequestRequirePin(device_path.c_str(), pin.c_str(), enable, 626 if (g_libcros_network_functions_enabled) {
599 callback, object); 627 chromeos::RequestRequirePin(device_path.c_str(), pin.c_str(), enable,
628 callback, object);
629 } else {
630 DBusThreadManager::Get()->GetFlimflamDeviceClient()->RequirePin(
631 dbus::ObjectPath(device_path), pin, enable,
632 base::Bind(&OnNetworkActionSuccess, device_path, callback, object),
633 base::Bind(&OnNetworkActionError, device_path, callback, object));
634 }
600 } 635 }
601 636
602 void CrosRequestEnterPin(const std::string& device_path, 637 void CrosRequestEnterPin(const std::string& device_path,
603 const std::string& pin, 638 const std::string& pin,
604 NetworkActionCallback callback, 639 NetworkActionCallback callback,
605 void* object) { 640 void* object) {
606 chromeos::RequestEnterPin(device_path.c_str(), pin.c_str(), callback, object); 641 if (g_libcros_network_functions_enabled) {
642 chromeos::RequestEnterPin(device_path.c_str(), pin.c_str(), callback,
643 object);
644 } else {
645 DBusThreadManager::Get()->GetFlimflamDeviceClient()->EnterPin(
646 dbus::ObjectPath(device_path), pin,
647 base::Bind(&OnNetworkActionSuccess, device_path, callback, object),
648 base::Bind(&OnNetworkActionError, device_path, callback, object));
649 }
607 } 650 }
608 651
609 void CrosRequestUnblockPin(const std::string& device_path, 652 void CrosRequestUnblockPin(const std::string& device_path,
610 const std::string& unblock_code, 653 const std::string& unblock_code,
611 const std::string& pin, 654 const std::string& pin,
612 NetworkActionCallback callback, 655 NetworkActionCallback callback,
613 void* object) { 656 void* object) {
614 chromeos::RequestUnblockPin(device_path.c_str(), unblock_code.c_str(), 657 if (g_libcros_network_functions_enabled) {
615 pin.c_str(), callback, object); 658 chromeos::RequestUnblockPin(device_path.c_str(), unblock_code.c_str(),
659 pin.c_str(), callback, object);
660 } else {
661 DBusThreadManager::Get()->GetFlimflamDeviceClient()->UnblockPin(
662 dbus::ObjectPath(device_path), unblock_code, pin,
663 base::Bind(&OnNetworkActionSuccess, device_path, callback, object),
664 base::Bind(&OnNetworkActionError, device_path, callback, object));
665 }
616 } 666 }
617 667
618 void CrosRequestChangePin(const std::string& device_path, 668 void CrosRequestChangePin(const std::string& device_path,
619 const std::string& old_pin, 669 const std::string& old_pin,
620 const std::string& new_pin, 670 const std::string& new_pin,
621 NetworkActionCallback callback, 671 NetworkActionCallback callback,
622 void* object) { 672 void* object) {
623 chromeos::RequestChangePin(device_path.c_str(), old_pin.c_str(), 673 if (g_libcros_network_functions_enabled) {
624 new_pin.c_str(), callback, object); 674 chromeos::RequestChangePin(device_path.c_str(), old_pin.c_str(),
675 new_pin.c_str(), callback, object);
676 } else {
677 DBusThreadManager::Get()->GetFlimflamDeviceClient()->ChangePin(
678 dbus::ObjectPath(device_path), old_pin, new_pin,
679 base::Bind(&OnNetworkActionSuccess, device_path, callback, object),
680 base::Bind(&OnNetworkActionError, device_path, callback, object));
681 }
625 } 682 }
626 683
627 void CrosProposeScan(const std::string& device_path) { 684 void CrosProposeScan(const std::string& device_path) {
628 chromeos::ProposeScan(device_path.c_str()); 685 chromeos::ProposeScan(device_path.c_str());
629 } 686 }
630 687
631 void CrosRequestCellularRegister(const std::string& device_path, 688 void CrosRequestCellularRegister(const std::string& device_path,
632 const std::string& network_id, 689 const std::string& network_id,
633 chromeos::NetworkActionCallback callback, 690 chromeos::NetworkActionCallback callback,
634 void* object) { 691 void* object) {
635 chromeos::RequestCellularRegister(device_path.c_str(), network_id.c_str(), 692 if (g_libcros_network_functions_enabled) {
636 callback, object); 693 chromeos::RequestCellularRegister(device_path.c_str(), network_id.c_str(),
694 callback, object);
695 } else {
696 DBusThreadManager::Get()->GetFlimflamDeviceClient()->Register(
697 dbus::ObjectPath(device_path), network_id,
698 base::Bind(&OnNetworkActionSuccess, device_path, callback, object),
699 base::Bind(&OnNetworkActionError, device_path, callback, object));
700 }
637 } 701 }
638 702
639 bool CrosSetOfflineMode(bool offline) { 703 bool CrosSetOfflineMode(bool offline) {
640 return chromeos::SetOfflineMode(offline); 704 return chromeos::SetOfflineMode(offline);
641 } 705 }
642 706
643 IPConfigStatus* CrosListIPConfigs(const std::string& device_path) { 707 IPConfigStatus* CrosListIPConfigs(const std::string& device_path) {
644 return chromeos::ListIPConfigs(device_path.c_str()); 708 return chromeos::ListIPConfigs(device_path.c_str());
645 } 709 }
646 710
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 ScopedGHashTable ghash( 790 ScopedGHashTable ghash(
727 ConvertDictionaryValueToStringValueGHashTable(properties)); 791 ConvertDictionaryValueToStringValueGHashTable(properties));
728 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); 792 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL);
729 } else { 793 } else {
730 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( 794 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService(
731 properties, base::Bind(&DoNothing)); 795 properties, base::Bind(&DoNothing));
732 } 796 }
733 } 797 }
734 798
735 } // namespace chromeos 799 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698