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