| 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 #ifndef EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_CHANGE_H_ | 5 #ifndef EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_CHANGE_H_ |
| 6 #define EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_CHANGE_H_ | 6 #define EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_CHANGE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 | 14 |
| 15 class ValueStoreChange; | 15 class ValueStoreChange; |
| 16 typedef std::vector<ValueStoreChange> ValueStoreChangeList; | 16 typedef std::vector<ValueStoreChange> ValueStoreChangeList; |
| 17 | 17 |
| 18 // A change to a setting. Safe/efficient to copy. | 18 // A change to a setting. Safe/efficient to copy. |
| 19 class ValueStoreChange { | 19 class ValueStoreChange { |
| 20 public: | 20 public: |
| 21 // Converts an ValueStoreChangeList into JSON of the form: | 21 // Converts an ValueStoreChangeList into JSON of the form: |
| 22 // { "foo": { "key": "foo", "oldValue": "bar", "newValue": "baz" } } | 22 // { "foo": { "key": "foo", "oldValue": "bar", "newValue": "baz" } } |
| 23 static std::string ToJson(const ValueStoreChangeList& changes); | 23 static std::string ToJson(const ValueStoreChangeList& changes); |
| 24 | 24 |
| 25 // Ownership of |old_value| and |new_value| taken. | 25 ValueStoreChange(const std::string& key, |
| 26 ValueStoreChange( | 26 std::unique_ptr<base::Value> old_value, |
| 27 const std::string& key, base::Value* old_value, base::Value* new_value); | 27 std::unique_ptr<base::Value> new_value); |
| 28 | 28 |
| 29 ValueStoreChange(const ValueStoreChange& other); | 29 ValueStoreChange(const ValueStoreChange& other); |
| 30 | 30 |
| 31 ~ValueStoreChange(); | 31 ~ValueStoreChange(); |
| 32 | 32 |
| 33 // Gets the key of the setting which changed. | 33 // Gets the key of the setting which changed. |
| 34 const std::string& key() const; | 34 const std::string& key() const; |
| 35 | 35 |
| 36 // Gets the value of the setting before the change, or NULL if there was no | 36 // Gets the value of the setting before the change, or NULL if there was no |
| 37 // old value. | 37 // old value. |
| 38 const base::Value* old_value() const; | 38 const base::Value* old_value() const; |
| 39 | 39 |
| 40 // Gets the value of the setting after the change, or NULL if there is no new | 40 // Gets the value of the setting after the change, or NULL if there is no new |
| 41 // value. | 41 // value. |
| 42 const base::Value* new_value() const; | 42 const base::Value* new_value() const; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 class Inner : public base::RefCountedThreadSafe<Inner> { | 45 class Inner : public base::RefCountedThreadSafe<Inner> { |
| 46 public: | 46 public: |
| 47 Inner( | 47 Inner(const std::string& key, |
| 48 const std::string& key, base::Value* old_value, base::Value* new_value); | 48 std::unique_ptr<base::Value> old_value, |
| 49 std::unique_ptr<base::Value> new_value); |
| 49 | 50 |
| 50 const std::string key_; | 51 const std::string key_; |
| 51 const std::unique_ptr<base::Value> old_value_; | 52 const std::unique_ptr<base::Value> old_value_; |
| 52 const std::unique_ptr<base::Value> new_value_; | 53 const std::unique_ptr<base::Value> new_value_; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 friend class base::RefCountedThreadSafe<Inner>; | 56 friend class base::RefCountedThreadSafe<Inner>; |
| 56 virtual ~Inner(); | 57 virtual ~Inner(); |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 scoped_refptr<Inner> inner_; | 60 scoped_refptr<Inner> inner_; |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_CHANGE_H_ | 63 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_CHANGE_H_ |
| OLD | NEW |