Chromium Code Reviews| 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 { | |
|
akalin
2011/10/17 17:37:38
No need to make this an inner class. It could be
not at google - send to devlin
2011/10/17 23:05:44
I prefer it as an inner class.
| |
| 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 callingt this method. | |
| 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. | |
| 48 explicit ExtensionSettingChanges(const std::string& 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 explicit Inner(const std::string& changes) : changes_(changes) {} | |
|
akalin
2011/10/17 17:37:38
I think I still prefer passing around the ListValu
not at google - send to devlin
2011/10/17 23:05:44
It's much of a muchness from the perspective of a
| |
| 54 | |
| 55 const std::string changes_; | |
| 56 | |
| 57 private: | |
| 58 virtual ~Inner() {} | |
| 59 friend class base::RefCountedThreadSafe<Inner>; | |
| 60 }; | |
| 61 | |
| 62 scoped_refptr<Inner> inner_; | |
| 63 }; | |
| 64 | |
| 65 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_CHANGES_H_ | |
| OLD | NEW |