| 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 20 matching lines...) Expand all Loading... |
| 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 return dict_->GetStringWithoutPathExpansion(key, value); | 38 return dict_->GetStringWithoutPathExpansion(key, value); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual bool GetJsonValueForKey(const std::string& key, Json** value) |
| 42 const OVERRIDE { |
| 43 base::DictionaryValue* sub_dict = NULL; // Owned by dict_. |
| 44 |
| 45 if (!dict_->GetDictionaryWithoutPathExpansion(key, &sub_dict) || !sub_dict) |
| 46 return false; |
| 47 |
| 48 if (value) { |
| 49 *value = new ChromeJson( |
| 50 scoped_ptr<base::DictionaryValue>(sub_dict->DeepCopy())); |
| 51 } |
| 52 |
| 53 return true; |
| 54 } |
| 55 |
| 41 private: | 56 private: |
| 57 explicit ChromeJson(scoped_ptr<base::DictionaryValue> dict) |
| 58 : dict_(dict.Pass()) {} |
| 59 |
| 42 scoped_ptr<base::DictionaryValue> dict_; | 60 scoped_ptr<base::DictionaryValue> dict_; |
| 43 | 61 |
| 44 DISALLOW_COPY_AND_ASSIGN(ChromeJson); | 62 DISALLOW_COPY_AND_ASSIGN(ChromeJson); |
| 45 }; | 63 }; |
| 46 | 64 |
| 47 } // namespace | 65 } // namespace |
| 48 | 66 |
| 49 Json::~Json() {} | 67 Json::~Json() {} |
| 50 | 68 |
| 51 // static | 69 // static |
| 52 scoped_ptr<Json> Json::Build() { | 70 scoped_ptr<Json> Json::Build() { |
| 53 return scoped_ptr<Json>(new ChromeJson); | 71 return scoped_ptr<Json>(new ChromeJson); |
| 54 } | 72 } |
| 55 | 73 |
| 56 Json::Json() {} | 74 Json::Json() {} |
| 57 | 75 |
| 58 } // namespace addressinput | 76 } // namespace addressinput |
| 59 } // namespace i18n | 77 } // namespace i18n |
| OLD | NEW |