Chromium Code Reviews| 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, base::Value::CreateStringValue("vpn")); | |
|
stevenjb
2012/04/23 21:37:26
Use kTypeVPN
hashimoto
2012/04/24 03:53:11
Done.
| |
| 528 properties.SetWithoutPathExpansion( | |
| 529 flimflam::kProviderNameProperty, | |
| 530 base::Value::CreateStringValue(service_name)); | |
| 531 properties.SetWithoutPathExpansion( | |
| 532 flimflam::kProviderHostProperty, | |
| 533 base::Value::CreateStringValue(server_hostname)); | |
| 534 properties.SetWithoutPathExpansion( | |
| 535 flimflam::kProviderTypeProperty, | |
| 536 base::Value::CreateStringValue(provider_type)); | |
| 537 // The actual value of Domain does not matter, so just use service_name. | |
| 538 properties.SetWithoutPathExpansion( | |
| 539 flimflam::kVPNDomainProperty, | |
| 540 base::Value::CreateStringValue(service_name)); | |
| 541 | |
| 542 // flimflam.Manger.GetService() will apply the property changes in | |
| 543 // |properties| and pass a new or existing service to OnGetService(). | |
| 544 // OnGetService will then call GetProperties which will then call callback. | |
| 545 DBusThreadManager::Get()->GetFlimflamManagerClient()->GetService( | |
| 546 properties, base::Bind(&OnGetService, callback)); | |
| 547 } | |
| 488 } | 548 } |
| 489 | 549 |
| 490 void CrosRequestNetworkServiceDisconnect(const std::string& service_path) { | 550 void CrosRequestNetworkServiceDisconnect(const std::string& service_path) { |
| 491 if (g_libcros_network_functions_enabled) { | 551 if (g_libcros_network_functions_enabled) { |
| 492 chromeos::RequestNetworkServiceDisconnect(service_path.c_str()); | 552 chromeos::RequestNetworkServiceDisconnect(service_path.c_str()); |
| 493 } else { | 553 } else { |
| 494 DBusThreadManager::Get()->GetFlimflamServiceClient()->Disconnect( | 554 DBusThreadManager::Get()->GetFlimflamServiceClient()->Disconnect( |
| 495 dbus::ObjectPath(service_path), base::Bind(&DoNothing)); | 555 dbus::ObjectPath(service_path), base::Bind(&DoNothing)); |
| 496 } | 556 } |
| 497 } | 557 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 ScopedGHashTable ghash( | 725 ScopedGHashTable ghash( |
| 666 ConvertDictionaryValueToStringValueGHashTable(properties)); | 726 ConvertDictionaryValueToStringValueGHashTable(properties)); |
| 667 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); | 727 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); |
| 668 } else { | 728 } else { |
| 669 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( | 729 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( |
| 670 properties, base::Bind(&DoNothing)); | 730 properties, base::Bind(&DoNothing)); |
| 671 } | 731 } |
| 672 } | 732 } |
| 673 | 733 |
| 674 } // namespace chromeos | 734 } // namespace chromeos |
| OLD | NEW |