Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: extensions/browser/value_store/value_store_change.cc

Issue 1940133002: Use std::unique_ptr to transfer base::Value ownership in extensions::ValueStoreChange (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
8
7 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h"
9 12
10 // static 13 // static
11 std::string ValueStoreChange::ToJson( 14 std::string ValueStoreChange::ToJson(
12 const ValueStoreChangeList& changes) { 15 const ValueStoreChangeList& changes) {
13 base::DictionaryValue changes_value; 16 base::DictionaryValue changes_value;
14 for (ValueStoreChangeList::const_iterator it = changes.begin(); 17 for (ValueStoreChangeList::const_iterator it = changes.begin();
15 it != changes.end(); ++it) { 18 it != changes.end(); ++it) {
16 base::DictionaryValue* change_value = new base::DictionaryValue(); 19 base::DictionaryValue* change_value = new base::DictionaryValue();
17 if (it->old_value()) { 20 if (it->old_value()) {
18 change_value->Set("oldValue", it->old_value()->DeepCopy()); 21 change_value->Set("oldValue", it->old_value()->DeepCopy());
19 } 22 }
20 if (it->new_value()) { 23 if (it->new_value()) {
21 change_value->Set("newValue", it->new_value()->DeepCopy()); 24 change_value->Set("newValue", it->new_value()->DeepCopy());
22 } 25 }
23 changes_value.SetWithoutPathExpansion(it->key(), change_value); 26 changes_value.SetWithoutPathExpansion(it->key(), change_value);
24 } 27 }
25 std::string json; 28 std::string json;
26 base::JSONWriter::Write(changes_value, &json); 29 base::JSONWriter::Write(changes_value, &json);
27 return json; 30 return json;
28 } 31 }
29 32
30 ValueStoreChange::ValueStoreChange( 33 ValueStoreChange::ValueStoreChange(const std::string& key,
31 const std::string& key, base::Value* old_value, base::Value* new_value) 34 std::unique_ptr<base::Value> old_value,
32 : inner_(new Inner(key, old_value, new_value)) {} 35 std::unique_ptr<base::Value> new_value)
36 : inner_(new Inner(key, std::move(old_value), std::move(new_value))) {}
33 37
34 ValueStoreChange::ValueStoreChange(const ValueStoreChange& other) = default; 38 ValueStoreChange::ValueStoreChange(const ValueStoreChange& other) = default;
35 39
36 ValueStoreChange::~ValueStoreChange() {} 40 ValueStoreChange::~ValueStoreChange() {}
37 41
38 const std::string& ValueStoreChange::key() const { 42 const std::string& ValueStoreChange::key() const {
39 DCHECK(inner_.get()); 43 DCHECK(inner_.get());
40 return inner_->key_; 44 return inner_->key_;
41 } 45 }
42 46
43 const base::Value* ValueStoreChange::old_value() const { 47 const base::Value* ValueStoreChange::old_value() const {
44 DCHECK(inner_.get()); 48 DCHECK(inner_.get());
45 return inner_->old_value_.get(); 49 return inner_->old_value_.get();
46 } 50 }
47 51
48 const base::Value* ValueStoreChange::new_value() const { 52 const base::Value* ValueStoreChange::new_value() const {
49 DCHECK(inner_.get()); 53 DCHECK(inner_.get());
50 return inner_->new_value_.get(); 54 return inner_->new_value_.get();
51 } 55 }
52 56
53 ValueStoreChange::Inner::Inner( 57 ValueStoreChange::Inner::Inner(const std::string& key,
54 const std::string& key, base::Value* old_value, base::Value* new_value) 58 std::unique_ptr<base::Value> old_value,
55 : key_(key), old_value_(old_value), new_value_(new_value) {} 59 std::unique_ptr<base::Value> new_value)
60 : key_(key),
61 old_value_(std::move(old_value)),
62 new_value_(std::move(new_value)) {}
56 63
57 ValueStoreChange::Inner::~Inner() {} 64 ValueStoreChange::Inner::~Inner() {}
OLDNEW
« no previous file with comments | « extensions/browser/value_store/value_store_change.h ('k') | extensions/browser/value_store/value_store_change_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698