| 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 "extensions/common/value_builder.h" | 5 #include "extensions/common/value_builder.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 | 12 |
| 12 namespace extensions { | 13 namespace extensions { |
| 13 | 14 |
| 14 // DictionaryBuilder | 15 // DictionaryBuilder |
| 15 | 16 |
| 16 DictionaryBuilder::DictionaryBuilder() : dict_(new base::DictionaryValue) {} | 17 DictionaryBuilder::DictionaryBuilder() : dict_(new base::DictionaryValue) {} |
| 17 | 18 |
| 18 DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue& init) | 19 DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue& init) |
| 19 : dict_(init.DeepCopy()) {} | 20 : dict_(init.DeepCopy()) {} |
| 20 | 21 |
| 21 DictionaryBuilder::~DictionaryBuilder() {} | 22 DictionaryBuilder::~DictionaryBuilder() {} |
| 22 | 23 |
| 23 std::string DictionaryBuilder::ToJSON() const { | 24 std::string DictionaryBuilder::ToJSON() const { |
| 24 std::string json; | 25 std::string json; |
| 25 base::JSONWriter::WriteWithOptions( | 26 base::JSONWriter::WriteWithOptions( |
| 26 *dict_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); | 27 *dict_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
| 27 return json; | 28 return json; |
| 28 } | 29 } |
| 29 | 30 |
| 30 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, | 31 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, |
| 31 int in_value) { | 32 int in_value) { |
| 32 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value)); | 33 dict_->SetWithoutPathExpansion( |
| 34 path, base::MakeUnique<base::FundamentalValue>(in_value)); |
| 33 return *this; | 35 return *this; |
| 34 } | 36 } |
| 35 | 37 |
| 36 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, | 38 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, |
| 37 double in_value) { | 39 double in_value) { |
| 38 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value)); | 40 dict_->SetWithoutPathExpansion( |
| 41 path, base::MakeUnique<base::FundamentalValue>(in_value)); |
| 39 return *this; | 42 return *this; |
| 40 } | 43 } |
| 41 | 44 |
| 42 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, | 45 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, |
| 43 const std::string& in_value) { | 46 const std::string& in_value) { |
| 44 dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value)); | 47 dict_->SetWithoutPathExpansion(path, |
| 48 base::MakeUnique<base::StringValue>(in_value)); |
| 45 return *this; | 49 return *this; |
| 46 } | 50 } |
| 47 | 51 |
| 48 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, | 52 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, |
| 49 const base::string16& in_value) { | 53 const base::string16& in_value) { |
| 50 dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value)); | 54 dict_->SetWithoutPathExpansion(path, |
| 55 base::MakeUnique<base::StringValue>(in_value)); |
| 51 return *this; | 56 return *this; |
| 52 } | 57 } |
| 53 | 58 |
| 54 DictionaryBuilder& DictionaryBuilder::Set( | 59 DictionaryBuilder& DictionaryBuilder::Set( |
| 55 const std::string& path, | 60 const std::string& path, |
| 56 std::unique_ptr<base::Value> in_value) { | 61 std::unique_ptr<base::Value> in_value) { |
| 57 dict_->SetWithoutPathExpansion(path, std::move(in_value)); | 62 dict_->SetWithoutPathExpansion(path, std::move(in_value)); |
| 58 return *this; | 63 return *this; |
| 59 } | 64 } |
| 60 | 65 |
| 61 DictionaryBuilder& DictionaryBuilder::SetBoolean( | 66 DictionaryBuilder& DictionaryBuilder::SetBoolean( |
| 62 const std::string& path, bool in_value) { | 67 const std::string& path, bool in_value) { |
| 63 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value)); | 68 dict_->SetWithoutPathExpansion( |
| 69 path, base::MakeUnique<base::FundamentalValue>(in_value)); |
| 64 return *this; | 70 return *this; |
| 65 } | 71 } |
| 66 | 72 |
| 67 // ListBuilder | 73 // ListBuilder |
| 68 | 74 |
| 69 ListBuilder::ListBuilder() : list_(new base::ListValue) {} | 75 ListBuilder::ListBuilder() : list_(new base::ListValue) {} |
| 70 ListBuilder::ListBuilder(const base::ListValue& init) : list_(init.DeepCopy()) { | 76 ListBuilder::ListBuilder(const base::ListValue& init) : list_(init.DeepCopy()) { |
| 71 } | 77 } |
| 72 ListBuilder::~ListBuilder() {} | 78 ListBuilder::~ListBuilder() {} |
| 73 | 79 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 95 list_->Append(std::move(in_value)); | 101 list_->Append(std::move(in_value)); |
| 96 return *this; | 102 return *this; |
| 97 } | 103 } |
| 98 | 104 |
| 99 ListBuilder& ListBuilder::AppendBoolean(bool in_value) { | 105 ListBuilder& ListBuilder::AppendBoolean(bool in_value) { |
| 100 list_->AppendBoolean(in_value); | 106 list_->AppendBoolean(in_value); |
| 101 return *this; | 107 return *this; |
| 102 } | 108 } |
| 103 | 109 |
| 104 } // namespace extensions | 110 } // namespace extensions |
| OLD | NEW |