OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/value_store/value_store_change.h" | 5 #include "extensions/browser/value_store/value_store_change.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/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 | 12 |
13 // static | 13 // static |
14 std::string ValueStoreChange::ToJson( | 14 std::string ValueStoreChange::ToJson( |
15 const ValueStoreChangeList& changes) { | 15 const ValueStoreChangeList& changes) { |
16 base::DictionaryValue changes_value; | 16 base::DictionaryValue changes_value; |
17 for (ValueStoreChangeList::const_iterator it = changes.begin(); | 17 for (ValueStoreChangeList::const_iterator it = changes.begin(); |
18 it != changes.end(); ++it) { | 18 it != changes.end(); ++it) { |
19 base::DictionaryValue* change_value = new base::DictionaryValue(); | 19 std::unique_ptr<base::DictionaryValue> change_value = |
| 20 base::MakeUnique<base::DictionaryValue>(); |
20 if (it->old_value()) { | 21 if (it->old_value()) { |
21 change_value->Set("oldValue", it->old_value()->DeepCopy()); | 22 change_value->Set("oldValue", it->old_value()->DeepCopy()); |
22 } | 23 } |
23 if (it->new_value()) { | 24 if (it->new_value()) { |
24 change_value->Set("newValue", it->new_value()->DeepCopy()); | 25 change_value->Set("newValue", it->new_value()->DeepCopy()); |
25 } | 26 } |
26 changes_value.SetWithoutPathExpansion(it->key(), change_value); | 27 changes_value.SetWithoutPathExpansion(it->key(), std::move(change_value)); |
27 } | 28 } |
28 std::string json; | 29 std::string json; |
29 bool success = base::JSONWriter::Write(changes_value, &json); | 30 bool success = base::JSONWriter::Write(changes_value, &json); |
30 DCHECK(success); | 31 DCHECK(success); |
31 return json; | 32 return json; |
32 } | 33 } |
33 | 34 |
34 ValueStoreChange::ValueStoreChange(const std::string& key, | 35 ValueStoreChange::ValueStoreChange(const std::string& key, |
35 std::unique_ptr<base::Value> old_value, | 36 std::unique_ptr<base::Value> old_value, |
36 std::unique_ptr<base::Value> new_value) | 37 std::unique_ptr<base::Value> new_value) |
(...skipping 19 matching lines...) Expand all Loading... |
56 } | 57 } |
57 | 58 |
58 ValueStoreChange::Inner::Inner(const std::string& key, | 59 ValueStoreChange::Inner::Inner(const std::string& key, |
59 std::unique_ptr<base::Value> old_value, | 60 std::unique_ptr<base::Value> old_value, |
60 std::unique_ptr<base::Value> new_value) | 61 std::unique_ptr<base::Value> new_value) |
61 : key_(key), | 62 : key_(key), |
62 old_value_(std::move(old_value)), | 63 old_value_(std::move(old_value)), |
63 new_value_(std::move(new_value)) {} | 64 new_value_(std::move(new_value)) {} |
64 | 65 |
65 ValueStoreChange::Inner::~Inner() {} | 66 ValueStoreChange::Inner::~Inner() {} |
OLD | NEW |