Chromium Code Reviews| Index: chrome/browser/extensions/extension_setting_changes.h |
| diff --git a/chrome/browser/extensions/extension_setting_changes.h b/chrome/browser/extensions/extension_setting_changes.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1b31782bb438e4f92dbb3aa925995e8d24a77b7 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_setting_changes.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_CHANGES_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_CHANGES_H_ |
| +#pragma once |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/values.h" |
| + |
| +// A list of changes to extension settings. Create using the Builder class. |
| +// The Changes object is thread-safe and efficient to copy, while the Builder |
| +// object isn't. |
| +class ExtensionSettingChanges { |
| + public: |
| + // Non-thread-safe builder for ExtensionSettingChanges. |
| + 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.
|
| + public: |
| + Builder() {} |
| + |
| + // Appends a change for a setting. |
| + void AppendChange( |
| + const std::string& key, |
| + // Ownership taken. May be NULL to imply there is no old value. |
| + Value* old_value, |
| + // Ownership taken. May be NULL to imply there is no new value. |
| + Value* new_value); |
| + |
| + // Creates an ExtensionSettingChanges object. The Builder should not be |
| + // used after callingt this method. |
| + ExtensionSettingChanges Build(); |
| + |
| + private: |
| + ListValue changes_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Builder); |
| + }; |
| + |
| + ~ExtensionSettingChanges(); |
| + |
| + // Gets the JSON serialized form of the changes, for example: |
| + // [ { "key": "foo", "oldValue": "bar", "newValue": "baz" } ] |
| + std::string ToJson() const; |
| + |
| + private: |
| + // Create using the Builder class. |
| + explicit ExtensionSettingChanges(const std::string& changes); |
| + |
| + // Ref-counted inner class, a wrapper over a non-thread-safe string. |
| + class Inner : public base::RefCountedThreadSafe<Inner> { |
| + public: |
| + 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
|
| + |
| + const std::string changes_; |
| + |
| + private: |
| + virtual ~Inner() {} |
| + friend class base::RefCountedThreadSafe<Inner>; |
| + }; |
| + |
| + scoped_refptr<Inner> inner_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_CHANGES_H_ |