| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cpp/src/util/json.h" | 5 #include "cpp/src/util/json.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // of the standalone library use char* rather than std::string. | 28 // of the standalone library use char* rather than std::string. |
| 29 scoped_ptr<base::Value> parsed(base::JSONReader::Read(json.c_str())); | 29 scoped_ptr<base::Value> parsed(base::JSONReader::Read(json.c_str())); |
| 30 if (parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) | 30 if (parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) |
| 31 dict_.reset(static_cast<base::DictionaryValue*>(parsed.release())); | 31 dict_.reset(static_cast<base::DictionaryValue*>(parsed.release())); |
| 32 | 32 |
| 33 return !!dict_; | 33 return !!dict_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 virtual bool GetStringValueForKey(const std::string& key, std::string* value) | 36 virtual bool GetStringValueForKey(const std::string& key, std::string* value) |
| 37 const OVERRIDE { | 37 const OVERRIDE { |
| 38 DCHECK(dict_); |
| 38 return dict_->GetStringWithoutPathExpansion(key, value); | 39 return dict_->GetStringWithoutPathExpansion(key, value); |
| 39 } | 40 } |
| 40 | 41 |
| 42 virtual bool GetJsonValueForKey(const std::string& key, |
| 43 scoped_ptr<Json>* value) const OVERRIDE { |
| 44 DCHECK(dict_); |
| 45 base::DictionaryValue* sub_dict = NULL; // Owned by |dict_|. |
| 46 if (!dict_->GetDictionaryWithoutPathExpansion(key, &sub_dict) || !sub_dict) |
| 47 return false; |
| 48 |
| 49 if (value) { |
| 50 value->reset(new ChromeJson( |
| 51 scoped_ptr<base::DictionaryValue>(sub_dict->DeepCopy()))); |
| 52 } |
| 53 |
| 54 return true; |
| 55 } |
| 56 |
| 41 private: | 57 private: |
| 58 explicit ChromeJson(scoped_ptr<base::DictionaryValue> dict) |
| 59 : dict_(dict.Pass()) {} |
| 60 |
| 42 scoped_ptr<base::DictionaryValue> dict_; | 61 scoped_ptr<base::DictionaryValue> dict_; |
| 43 | 62 |
| 44 DISALLOW_COPY_AND_ASSIGN(ChromeJson); | 63 DISALLOW_COPY_AND_ASSIGN(ChromeJson); |
| 45 }; | 64 }; |
| 46 | 65 |
| 47 } // namespace | 66 } // namespace |
| 48 | 67 |
| 49 Json::~Json() {} | 68 Json::~Json() {} |
| 50 | 69 |
| 51 // static | 70 // static |
| 52 scoped_ptr<Json> Json::Build() { | 71 scoped_ptr<Json> Json::Build() { |
| 53 return scoped_ptr<Json>(new ChromeJson); | 72 return scoped_ptr<Json>(new ChromeJson); |
| 54 } | 73 } |
| 55 | 74 |
| 56 Json::Json() {} | 75 Json::Json() {} |
| 57 | 76 |
| 58 } // namespace addressinput | 77 } // namespace addressinput |
| 59 } // namespace i18n | 78 } // namespace i18n |
| OLD | NEW |