OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_CHANGES_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_CHANGES_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/values.h" |
| 11 |
| 12 // A list of changes to extension settings. Create using the Builder class. |
| 13 // The Changes object is thread-safe and efficient to copy, while the Builder |
| 14 // object isn't. |
| 15 class ExtensionSettingChanges { |
| 16 public: |
| 17 // Non-thread-safe builder for ExtensionSettingChanges. |
| 18 class Builder { |
| 19 public: |
| 20 Builder() {} |
| 21 |
| 22 // Appends a change for a setting. |
| 23 void AppendChange( |
| 24 const std::string& key, |
| 25 // Ownership taken. May be NULL to imply there is no old value. |
| 26 Value* old_value, |
| 27 // Ownership taken. May be NULL to imply there is no new value. |
| 28 Value* new_value); |
| 29 |
| 30 // Creates an ExtensionSettingChanges object. The Builder should not be |
| 31 // used after calling this. |
| 32 ExtensionSettingChanges Build(); |
| 33 |
| 34 private: |
| 35 ListValue changes_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 38 }; |
| 39 |
| 40 ~ExtensionSettingChanges(); |
| 41 |
| 42 // Gets the JSON serialized form of the changes, for example: |
| 43 // [ { "key": "foo", "oldValue": "bar", "newValue": "baz" } ] |
| 44 std::string ToJson() const; |
| 45 |
| 46 private: |
| 47 // Create using the Builder class. |changes| will be cleared. |
| 48 explicit ExtensionSettingChanges(ListValue* changes); |
| 49 |
| 50 // Ref-counted inner class, a wrapper over a non-thread-safe string. |
| 51 class Inner : public base::RefCountedThreadSafe<Inner> { |
| 52 public: |
| 53 Inner() {} |
| 54 |
| 55 // swap() this with the changes from the Builder after construction. |
| 56 ListValue changes_; |
| 57 |
| 58 private: |
| 59 virtual ~Inner() {} |
| 60 friend class base::RefCountedThreadSafe<Inner>; |
| 61 }; |
| 62 |
| 63 scoped_refptr<Inner> inner_; |
| 64 }; |
| 65 |
| 66 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_CHANGES_H_ |
OLD | NEW |