| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 // A callback used to implement CrosRequest*Properties functions. | 206 // A callback used to implement CrosRequest*Properties functions. |
| 207 void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback, | 207 void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback, |
| 208 const std::string& path, | 208 const std::string& path, |
| 209 DBusMethodCallStatus call_status, | 209 DBusMethodCallStatus call_status, |
| 210 const base::DictionaryValue& value) { | 210 const base::DictionaryValue& value) { |
| 211 callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL); | 211 callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Used as a callback for FlimflamManagerClient::GetService |
| 215 void OnGetService(const NetworkPropertiesCallback& callback, |
| 216 DBusMethodCallStatus call_status, |
| 217 const dbus::ObjectPath& service_path) { |
| 218 if (call_status == DBUS_METHOD_CALL_SUCCESS) { |
| 219 DBusThreadManager::Get()->GetFlimflamServiceClient()->GetProperties( |
| 220 service_path, base::Bind(&RunCallbackWithDictionaryValue, |
| 221 callback, |
| 222 service_path.value())); |
| 223 } |
| 224 } |
| 225 |
| 214 // Used as a callback for chromeos::ConfigureService. | 226 // Used as a callback for chromeos::ConfigureService. |
| 215 void OnConfigureService(void* object, | 227 void OnConfigureService(void* object, |
| 216 const char* service_path, | 228 const char* service_path, |
| 217 NetworkMethodErrorType error, | 229 NetworkMethodErrorType error, |
| 218 const char* error_message) { | 230 const char* error_message) { |
| 219 if (error != NETWORK_METHOD_ERROR_NONE) { | 231 if (error != NETWORK_METHOD_ERROR_NONE) { |
| 220 LOG(WARNING) << "Error from ConfigureService callback: " | 232 LOG(WARNING) << "Error from ConfigureService callback: " |
| 221 << " Error: " << error << " Message: " << error_message; | 233 << " Error: " << error << " Message: " << error_message; |
| 222 } | 234 } |
| 223 } | 235 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 base::Bind(&RunCallbackWithDictionaryValue, | 470 base::Bind(&RunCallbackWithDictionaryValue, |
| 459 callback, | 471 callback, |
| 460 profile_entry_path)); | 472 profile_entry_path)); |
| 461 } | 473 } |
| 462 } | 474 } |
| 463 | 475 |
| 464 void CrosRequestHiddenWifiNetworkProperties( | 476 void CrosRequestHiddenWifiNetworkProperties( |
| 465 const std::string& ssid, | 477 const std::string& ssid, |
| 466 const std::string& security, | 478 const std::string& security, |
| 467 const NetworkPropertiesCallback& callback) { | 479 const NetworkPropertiesCallback& callback) { |
| 468 // The newly allocated callback will be deleted in OnRequestNetworkProperties. | 480 if (g_libcros_network_functions_enabled) { |
| 469 chromeos::RequestHiddenWifiNetworkProperties( | 481 // The newly allocated callback will be deleted in |
| 470 ssid.c_str(), | 482 // OnRequestNetworkProperties. |
| 471 security.c_str(), | 483 chromeos::RequestHiddenWifiNetworkProperties( |
| 472 &OnRequestNetworkProperties, | 484 ssid.c_str(), |
| 473 new OnRequestNetworkPropertiesCallback(callback)); | 485 security.c_str(), |
| 486 &OnRequestNetworkProperties, |
| 487 new OnRequestNetworkPropertiesCallback(callback)); |
| 488 } else { |
| 489 base::DictionaryValue properties; |
| 490 properties.SetWithoutPathExpansion( |
| 491 flimflam::kModeProperty, |
| 492 base::Value::CreateStringValue(flimflam::kModeManaged)); |
| 493 properties.SetWithoutPathExpansion( |
| 494 flimflam::kTypeProperty, |
| 495 base::Value::CreateStringValue(flimflam::kTypeWifi)); |
| 496 properties.SetWithoutPathExpansion( |
| 497 flimflam::kSSIDProperty, |
| 498 base::Value::CreateStringValue(ssid)); |
| 499 properties.SetWithoutPathExpansion( |
| 500 flimflam::kSecurityProperty, |
| 501 base::Value::CreateStringValue(security)); |
| 502 // flimflam.Manger.GetService() will apply the property changes in |
| 503 // |properties| and return a new or existing service to OnGetService(). |
| 504 // OnGetService will then call GetProperties which will then call callback. |
| 505 DBusThreadManager::Get()->GetFlimflamManagerClient()->GetService( |
| 506 properties, base::Bind(&OnGetService, callback)); |
| 507 } |
| 474 } | 508 } |
| 475 | 509 |
| 476 void CrosRequestVirtualNetworkProperties( | 510 void CrosRequestVirtualNetworkProperties( |
| 477 const std::string& service_name, | 511 const std::string& service_name, |
| 478 const std::string& server_hostname, | 512 const std::string& server_hostname, |
| 479 const std::string& provider_type, | 513 const std::string& provider_type, |
| 480 const NetworkPropertiesCallback& callback) { | 514 const NetworkPropertiesCallback& callback) { |
| 481 // The newly allocated callback will be deleted in OnRequestNetworkProperties. | 515 if (g_libcros_network_functions_enabled) { |
| 482 chromeos::RequestVirtualNetworkProperties( | 516 // The newly allocated callback will be deleted in |
| 483 service_name.c_str(), | 517 // OnRequestNetworkProperties. |
| 484 server_hostname.c_str(), | 518 chromeos::RequestVirtualNetworkProperties( |
| 485 provider_type.c_str(), | 519 service_name.c_str(), |
| 486 &OnRequestNetworkProperties, | 520 server_hostname.c_str(), |
| 487 new OnRequestNetworkPropertiesCallback(callback)); | 521 provider_type.c_str(), |
| 522 &OnRequestNetworkProperties, |
| 523 new OnRequestNetworkPropertiesCallback(callback)); |
| 524 } else { |
| 525 base::DictionaryValue properties; |
| 526 properties.SetWithoutPathExpansion( |
| 527 flimflam::kTypeProperty, |
| 528 base::Value::CreateStringValue(flimflam::kTypeVPN)); |
| 529 properties.SetWithoutPathExpansion( |
| 530 flimflam::kProviderNameProperty, |
| 531 base::Value::CreateStringValue(service_name)); |
| 532 properties.SetWithoutPathExpansion( |
| 533 flimflam::kProviderHostProperty, |
| 534 base::Value::CreateStringValue(server_hostname)); |
| 535 properties.SetWithoutPathExpansion( |
| 536 flimflam::kProviderTypeProperty, |
| 537 base::Value::CreateStringValue(provider_type)); |
| 538 // The actual value of Domain does not matter, so just use service_name. |
| 539 properties.SetWithoutPathExpansion( |
| 540 flimflam::kVPNDomainProperty, |
| 541 base::Value::CreateStringValue(service_name)); |
| 542 |
| 543 // flimflam.Manger.GetService() will apply the property changes in |
| 544 // |properties| and pass a new or existing service to OnGetService(). |
| 545 // OnGetService will then call GetProperties which will then call callback. |
| 546 DBusThreadManager::Get()->GetFlimflamManagerClient()->GetService( |
| 547 properties, base::Bind(&OnGetService, callback)); |
| 548 } |
| 488 } | 549 } |
| 489 | 550 |
| 490 void CrosRequestNetworkServiceDisconnect(const std::string& service_path) { | 551 void CrosRequestNetworkServiceDisconnect(const std::string& service_path) { |
| 491 if (g_libcros_network_functions_enabled) { | 552 if (g_libcros_network_functions_enabled) { |
| 492 chromeos::RequestNetworkServiceDisconnect(service_path.c_str()); | 553 chromeos::RequestNetworkServiceDisconnect(service_path.c_str()); |
| 493 } else { | 554 } else { |
| 494 DBusThreadManager::Get()->GetFlimflamServiceClient()->Disconnect( | 555 DBusThreadManager::Get()->GetFlimflamServiceClient()->Disconnect( |
| 495 dbus::ObjectPath(service_path), base::Bind(&DoNothing)); | 556 dbus::ObjectPath(service_path), base::Bind(&DoNothing)); |
| 496 } | 557 } |
| 497 } | 558 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 ScopedGHashTable ghash( | 726 ScopedGHashTable ghash( |
| 666 ConvertDictionaryValueToStringValueGHashTable(properties)); | 727 ConvertDictionaryValueToStringValueGHashTable(properties)); |
| 667 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); | 728 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); |
| 668 } else { | 729 } else { |
| 669 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( | 730 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( |
| 670 properties, base::Bind(&DoNothing)); | 731 properties, base::Bind(&DoNothing)); |
| 671 } | 732 } |
| 672 } | 733 } |
| 673 | 734 |
| 674 } // namespace chromeos | 735 } // namespace chromeos |
| OLD | NEW |