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

Side by Side Diff: chrome/browser/extensions/extension_settings_storage.h

Issue 8361027: Re-commit 106660 with the crashing test disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 14
15 // Interface for extension settings storage classes. 15 // Interface for extension settings storage classes.
16 // 16 //
17 // All methods *must* be run on the FILE thread, inclusing construction and 17 // All methods *must* be run on the FILE thread, inclusing construction and
18 // destructions. 18 // destructions.
19 class ExtensionSettingsStorage { 19 class ExtensionSettingsStorage {
20 public: 20 public:
21 // The result of an operation. 21 // The result of an operation.
22 // 22 //
23 // Supports lightweight copying. 23 // Supports lightweight copying.
24 class Result { 24 class Result {
25 public: 25 public:
26 // Ownership of |settings| and |changed_keys| taken. 26 // Ownership of all arguments are taken.
27 // |settings| may be NULL when the result is for an operation which 27 // |settings| may be NULL when the result is for an operation which
28 // generates no setting values (e.g. Remove(), Clear()). 28 // generates no setting values (e.g. Remove(), Clear()).
29 // |changed_keys| may be NULL when the result is for an operation which 29 // |changed_keys| and |old_settings| may be NULL when the result is for an
30 // cannot change settings (e.g. Get()). 30 // operation which cannot change settings (e.g. Get()).
31 Result(DictionaryValue* settings, std::set<std::string>* changed_keys); 31 Result(
32 DictionaryValue* settings,
33 DictionaryValue* old_settings,
34 std::set<std::string>* changed_keys);
32 explicit Result(const std::string& error); 35 explicit Result(const std::string& error);
33 ~Result(); 36 ~Result();
34 37
35 // The dictionary result of the computation. NULL does not imply invalid; 38 // The dictionary result of the computation. NULL does not imply invalid;
36 // HasError() should be used to test this. 39 // HasError() should be used to test this.
37 // Ownership remains with with the Result. 40 // Ownership remains with this.
38 DictionaryValue* GetSettings() const; 41 const DictionaryValue* GetSettings() const;
39 42
40 // Gets the list of setting keys which changed as a result of the 43 // Gets the set of setting keys which changed as a result of the
41 // computation. This includes all settings that existed and removed, all 44 // computation. This includes all settings that existed and removed, all
42 // settings which changed when set, and all setting keys cleared. 45 // settings which changed when set, and all setting keys cleared. May be
43 // May be NULL for operations which cannot change settings, such as Get(). 46 // NULL for operations which cannot change settings, such as Get().
44 std::set<std::string>* GetChangedKeys() const; 47 const std::set<std::string>* GetChangedKeys() const;
48
49 // Gets the value of a setting prior to the operation which generated
50 // this Result, or NULL if the setting had no original value or this Result
51 // is from an operation that didn't modify the settings (such as Get()).
52 // Ownerships remains with this.
53 const Value* GetOldValue(const std::string& key) const;
54
55 // Like GetOldValue, but gets the new value.
56 const Value* GetNewValue(const std::string& key) const;
45 57
46 // Whether there was an error in the computation. If so, the results of 58 // Whether there was an error in the computation. If so, the results of
47 // GetSettings and ReleaseSettings are not valid. 59 // GetSettings and ReleaseSettings are not valid.
48 bool HasError() const; 60 bool HasError() const;
49 61
50 // Gets the error message, if any. 62 // Gets the error message, if any.
51 const std::string& GetError() const; 63 const std::string& GetError() const;
52 64
53 private: 65 private:
54 struct Inner : public base::RefCountedThreadSafe<Inner> { 66 struct Inner : public base::RefCountedThreadSafe<Inner> {
55 // Empty error implies no error. 67 // Empty error implies no error.
56 Inner( 68 Inner(
57 DictionaryValue* settings, 69 DictionaryValue* settings,
70 DictionaryValue* old_settings,
58 std::set<std::string>* changed_keys, 71 std::set<std::string>* changed_keys,
59 const std::string& error); 72 const std::string& error);
60 ~Inner(); 73 ~Inner();
61 74
62 const scoped_ptr<DictionaryValue> settings_; 75 const scoped_ptr<DictionaryValue> settings_;
76 const scoped_ptr<DictionaryValue> old_settings_;
63 const scoped_ptr<std::set<std::string> > changed_keys_; 77 const scoped_ptr<std::set<std::string> > changed_keys_;
64 const std::string error_; 78 const std::string error_;
65 }; 79 };
66 80
67 scoped_refptr<Inner> inner_; 81 scoped_refptr<Inner> inner_;
68 }; 82 };
69 83
70 virtual ~ExtensionSettingsStorage() {} 84 virtual ~ExtensionSettingsStorage() {}
71 85
72 // Gets a single value from storage. 86 // Gets a single value from storage.
(...skipping 23 matching lines...) Expand all
96 // Removes multiple keys from the storage. 110 // Removes multiple keys from the storage.
97 // If successful, result value is NULL. 111 // If successful, result value is NULL.
98 virtual Result Remove(const std::vector<std::string>& keys) = 0; 112 virtual Result Remove(const std::vector<std::string>& keys) = 0;
99 113
100 // Clears the storage. 114 // Clears the storage.
101 // If successful, result value is NULL. 115 // If successful, result value is NULL.
102 virtual Result Clear() = 0; 116 virtual Result Clear() = 0;
103 }; 117 };
104 118
105 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ 119 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_settings_observer.cc ('k') | chrome/browser/extensions/extension_settings_storage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698