| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
| 6 | 6 |
| 7 #include <dbus/dbus-glib.h> | 7 #include <dbus/dbus-glib.h> |
| 8 #include <dbus/dbus-gtype-specialized.h> | 8 #include <dbus/dbus-gtype-specialized.h> |
| 9 #include <glib-object.h> | 9 #include <glib-object.h> |
| 10 | 10 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 return new GValue(); | 317 return new GValue(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 GHashTable* ConvertDictionaryValueToGValueMap(const DictionaryValue* dict) { | 320 GHashTable* ConvertDictionaryValueToGValueMap(const DictionaryValue* dict) { |
| 321 GHashTable* ghash = | 321 GHashTable* ghash = |
| 322 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | 322 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
| 323 for (DictionaryValue::key_iterator it = dict->begin_keys(); | 323 for (DictionaryValue::key_iterator it = dict->begin_keys(); |
| 324 it != dict->end_keys(); ++it) { | 324 it != dict->end_keys(); ++it) { |
| 325 std::string key = *it; | 325 std::string key = *it; |
| 326 Value* val = NULL; | 326 Value* val = NULL; |
| 327 if (dict->Get(key, &val)) { | 327 if (dict->GetWithoutPathExpansion(key, &val)) { |
| 328 g_hash_table_insert(ghash, | 328 g_hash_table_insert(ghash, |
| 329 g_strdup(const_cast<char*>(key.c_str())), | 329 g_strdup(const_cast<char*>(key.c_str())), |
| 330 ConvertValueToGValue(val)); | 330 ConvertValueToGValue(val)); |
| 331 } else { |
| 332 VLOG(2) << "Could not insert key " << key << " into hash"; |
| 331 } | 333 } |
| 332 } | 334 } |
| 333 return ghash; | 335 return ghash; |
| 334 } | 336 } |
| 335 | 337 |
| 336 } // namespace | 338 } // namespace |
| 337 | 339 |
| 338 //////////////////////////////////////////////////////////////////////////////// | 340 //////////////////////////////////////////////////////////////////////////////// |
| 339 // FoundCellularNetwork | 341 // FoundCellularNetwork |
| 340 | 342 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 delete entry; | 417 delete entry; |
| 416 entry = value.DeepCopy(); | 418 entry = value.DeepCopy(); |
| 417 if (VLOG_IS_ON(2)) { | 419 if (VLOG_IS_ON(2)) { |
| 418 std::string value_json; | 420 std::string value_json; |
| 419 base::JSONWriter::Write(&value, true, &value_json); | 421 base::JSONWriter::Write(&value, true, &value_json); |
| 420 VLOG(2) << "Updated property map on network: " | 422 VLOG(2) << "Updated property map on network: " |
| 421 << unique_id() << "[" << index << "] = " << value_json; | 423 << unique_id() << "[" << index << "] = " << value_json; |
| 422 } | 424 } |
| 423 } | 425 } |
| 424 | 426 |
| 427 bool Network::GetProperty(PropertyIndex index, |
| 428 const base::Value** value) const { |
| 429 PropertyMap::const_iterator i = property_map_.find(index); |
| 430 if (i == property_map_.end()) |
| 431 return false; |
| 432 if (value != NULL) |
| 433 *value = i->second; |
| 434 return true; |
| 435 } |
| 436 |
| 425 void Network::SetState(ConnectionState new_state) { | 437 void Network::SetState(ConnectionState new_state) { |
| 426 if (new_state == state_) | 438 if (new_state == state_) |
| 427 return; | 439 return; |
| 428 ConnectionState old_state = state_; | 440 ConnectionState old_state = state_; |
| 429 state_ = new_state; | 441 state_ = new_state; |
| 430 if (!IsConnectingState(new_state)) | 442 if (!IsConnectingState(new_state)) |
| 431 set_connection_started(false); | 443 set_connection_started(false); |
| 432 if (new_state == STATE_FAILURE) { | 444 if (new_state == STATE_FAILURE) { |
| 433 if (old_state != STATE_UNKNOWN && | 445 if (old_state != STATE_UNKNOWN && |
| 434 old_state != STATE_IDLE) { | 446 old_state != STATE_IDLE) { |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 user_passphrase, &user_passphrase_); | 812 user_passphrase, &user_passphrase_); |
| 801 SetStringProperty(flimflam::kL2tpIpsecGroupNameProperty, | 813 SetStringProperty(flimflam::kL2tpIpsecGroupNameProperty, |
| 802 group_name, &group_name_); | 814 group_name, &group_name_); |
| 803 } | 815 } |
| 804 | 816 |
| 805 void VirtualNetwork::SetOpenVPNCredentials( | 817 void VirtualNetwork::SetOpenVPNCredentials( |
| 806 const std::string& client_cert_id, | 818 const std::string& client_cert_id, |
| 807 const std::string& username, | 819 const std::string& username, |
| 808 const std::string& user_passphrase, | 820 const std::string& user_passphrase, |
| 809 const std::string& otp) { | 821 const std::string& otp) { |
| 822 // TODO(kmixter): Are we missing setting the CaCert property? |
| 810 SetStringProperty(flimflam::kOpenVPNClientCertIdProperty, | 823 SetStringProperty(flimflam::kOpenVPNClientCertIdProperty, |
| 811 client_cert_id, &client_cert_id_); | 824 client_cert_id, &client_cert_id_); |
| 812 SetStringProperty(flimflam::kOpenVPNUserProperty, username, &username_); | 825 SetStringProperty(flimflam::kOpenVPNUserProperty, username, &username_); |
| 813 SetStringProperty(flimflam::kOpenVPNPasswordProperty, | 826 SetStringProperty(flimflam::kOpenVPNPasswordProperty, |
| 814 user_passphrase, &user_passphrase_); | 827 user_passphrase, &user_passphrase_); |
| 815 SetStringProperty(flimflam::kOpenVPNOTPProperty, otp, NULL); | 828 SetStringProperty(flimflam::kOpenVPNOTPProperty, otp, NULL); |
| 816 } | 829 } |
| 817 | 830 |
| 818 void VirtualNetwork::SetCertificateSlotAndPin( | 831 void VirtualNetwork::SetCertificateSlotAndPin( |
| 819 const std::string& slot, const std::string& pin) { | 832 const std::string& slot, const std::string& pin) { |
| (...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2829 if (!parser.ParseCertificate(i)) { | 2842 if (!parser.ParseCertificate(i)) { |
| 2830 DLOG(WARNING) << "Cannot parse certificate in ONC file"; | 2843 DLOG(WARNING) << "Cannot parse certificate in ONC file"; |
| 2831 return false; | 2844 return false; |
| 2832 } | 2845 } |
| 2833 } | 2846 } |
| 2834 | 2847 |
| 2835 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 2848 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
| 2836 // Parse Open Network Configuration blob into a temporary Network object. | 2849 // Parse Open Network Configuration blob into a temporary Network object. |
| 2837 scoped_ptr<Network> network(parser.ParseNetwork(i)); | 2850 scoped_ptr<Network> network(parser.ParseNetwork(i)); |
| 2838 if (!network.get()) { | 2851 if (!network.get()) { |
| 2839 DLOG(WARNING) << "Cannot parse networks in ONC file"; | 2852 DLOG(WARNING) << "Cannot parse network in ONC file"; |
| 2840 return false; | 2853 return false; |
| 2841 } | 2854 } |
| 2842 | 2855 |
| 2843 DictionaryValue dict; | 2856 DictionaryValue dict; |
| 2844 for (Network::PropertyMap::const_iterator props = | 2857 for (Network::PropertyMap::const_iterator props = |
| 2845 network->property_map_.begin(); | 2858 network->property_map_.begin(); |
| 2846 props != network->property_map_.end(); ++props) { | 2859 props != network->property_map_.end(); ++props) { |
| 2847 std::string key = | 2860 std::string key = |
| 2848 NativeNetworkParser::property_mapper()->GetKey(props->first); | 2861 NativeNetworkParser::property_mapper()->GetKey(props->first); |
| 2849 if (!key.empty()) | 2862 if (!key.empty()) |
| 2850 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); | 2863 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); |
| 2864 else |
| 2865 VLOG(2) << "Property " << props->first << " will not be sent"; |
| 2851 } | 2866 } |
| 2852 | 2867 |
| 2853 CallConfigureService(network->unique_id(), &dict); | 2868 CallConfigureService(network->unique_id(), &dict); |
| 2854 } | 2869 } |
| 2855 return parser.GetNetworkConfigsSize() != 0; | 2870 return parser.GetNetworkConfigsSize() != 0; |
| 2856 } | 2871 } |
| 2857 | 2872 |
| 2858 //////////////////////////////////////////////////////////////////////////// | 2873 //////////////////////////////////////////////////////////////////////////// |
| 2859 // Testing functions. | 2874 // Testing functions. |
| 2860 | 2875 |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3685 if (error != NETWORK_METHOD_ERROR_NONE) { | 3700 if (error != NETWORK_METHOD_ERROR_NONE) { |
| 3686 LOG(WARNING) << "Error from ConfigureService callback for: " | 3701 LOG(WARNING) << "Error from ConfigureService callback for: " |
| 3687 << service_path | 3702 << service_path |
| 3688 << " Error: " << error << " Message: " << error_message; | 3703 << " Error: " << error << " Message: " << error_message; |
| 3689 } | 3704 } |
| 3690 } | 3705 } |
| 3691 | 3706 |
| 3692 void NetworkLibraryImplCros::CallConfigureService(const std::string& identifier, | 3707 void NetworkLibraryImplCros::CallConfigureService(const std::string& identifier, |
| 3693 const DictionaryValue* info) { | 3708 const DictionaryValue* info) { |
| 3694 GHashTable* ghash = ConvertDictionaryValueToGValueMap(info); | 3709 GHashTable* ghash = ConvertDictionaryValueToGValueMap(info); |
| 3710 if (VLOG_IS_ON(2)) { |
| 3711 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
| 3712 std::string dict_json; |
| 3713 base::JSONWriter::Write(static_cast<Value*>(dict.get()), true, &dict_json); |
| 3714 VLOG(2) << "ConfigureService will be called on:" << dict_json; |
| 3715 } |
| 3695 chromeos::ConfigureService(identifier.c_str(), ghash, | 3716 chromeos::ConfigureService(identifier.c_str(), ghash, |
| 3696 ConfigureServiceCallback, this); | 3717 ConfigureServiceCallback, this); |
| 3697 } | 3718 } |
| 3698 | 3719 |
| 3699 // static callback | 3720 // static callback |
| 3700 void NetworkLibraryImplCros::NetworkConnectCallback( | 3721 void NetworkLibraryImplCros::NetworkConnectCallback( |
| 3701 void* object, | 3722 void* object, |
| 3702 const char* service_path, | 3723 const char* service_path, |
| 3703 NetworkMethodErrorType error, | 3724 NetworkMethodErrorType error, |
| 3704 const char* error_message) { | 3725 const char* error_message) { |
| (...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5320 return impl; | 5341 return impl; |
| 5321 } | 5342 } |
| 5322 | 5343 |
| 5323 ///////////////////////////////////////////////////////////////////////////// | 5344 ///////////////////////////////////////////////////////////////////////////// |
| 5324 | 5345 |
| 5325 } // namespace chromeos | 5346 } // namespace chromeos |
| 5326 | 5347 |
| 5327 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 5348 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 5328 // won't be deleted until its last InvokeLater is run. | 5349 // won't be deleted until its last InvokeLater is run. |
| 5329 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 5350 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
| OLD | NEW |