| 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 "chromeos/network/onc/onc_translator.h" | 5 #include "chromeos/network/onc/onc_translator.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" | 
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 24 | 24 | 
| 25 namespace chromeos { | 25 namespace chromeos { | 
| 26 namespace onc { | 26 namespace onc { | 
| 27 | 27 | 
| 28 namespace { | 28 namespace { | 
| 29 | 29 | 
| 30 // Converts |str| to a base::Value of the given |type|. If the conversion fails, | 30 // Converts |str| to a base::Value of the given |type|. If the conversion fails, | 
| 31 // returns NULL. | 31 // returns NULL. | 
| 32 scoped_ptr<base::Value> ConvertStringToValue(const std::string& str, | 32 scoped_ptr<base::Value> ConvertStringToValue(const std::string& str, | 
| 33                                              base::Value::Type type) { | 33                                              base::Value::Type type) { | 
| 34   base::Value* value; | 34   scoped_ptr<base::Value> value; | 
| 35   if (type == base::Value::TYPE_STRING) { | 35   if (type == base::Value::TYPE_STRING) { | 
| 36     value = new base::StringValue(str); | 36     value.reset(new base::StringValue(str)); | 
| 37   } else { | 37   } else { | 
| 38     value = base::JSONReader::DeprecatedRead(str); | 38     value = base::JSONReader::Read(str); | 
| 39   } | 39   } | 
|  | 40   if (value && value->GetType() != type) | 
|  | 41     return nullptr; | 
| 40 | 42 | 
| 41   if (value == NULL || value->GetType() != type) { | 43   return value; | 
| 42     delete value; |  | 
| 43     value = NULL; |  | 
| 44   } |  | 
| 45   return make_scoped_ptr(value); |  | 
| 46 } | 44 } | 
| 47 | 45 | 
| 48 // This class implements the translation of properties from the given | 46 // This class implements the translation of properties from the given | 
| 49 // |shill_dictionary| to a new ONC object of signature |onc_signature|. Using | 47 // |shill_dictionary| to a new ONC object of signature |onc_signature|. Using | 
| 50 // recursive calls to CreateTranslatedONCObject of new instances, nested objects | 48 // recursive calls to CreateTranslatedONCObject of new instances, nested objects | 
| 51 // are translated. | 49 // are translated. | 
| 52 class ShillToONCTranslator { | 50 class ShillToONCTranslator { | 
| 53  public: | 51  public: | 
| 54   ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, | 52   ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, | 
| 55                        ::onc::ONCSource onc_source, | 53                        ::onc::ONCSource onc_source, | 
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 767     const NetworkState* network_state) { | 765     const NetworkState* network_state) { | 
| 768   CHECK(onc_signature != NULL); | 766   CHECK(onc_signature != NULL); | 
| 769 | 767 | 
| 770   ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, | 768   ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, | 
| 771                                   network_state); | 769                                   network_state); | 
| 772   return translator.CreateTranslatedONCObject(); | 770   return translator.CreateTranslatedONCObject(); | 
| 773 } | 771 } | 
| 774 | 772 | 
| 775 }  // namespace onc | 773 }  // namespace onc | 
| 776 }  // namespace chromeos | 774 }  // namespace chromeos | 
| OLD | NEW | 
|---|