| 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_H_ | 5 #ifndef EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
| 6 #define EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_H_ | 6 #define EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <utility> | 12 #include <utility> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "extensions/browser/value_store/value_store_change.h" | 17 #include "extensions/browser/value_store/value_store_change.h" |
| 18 | 18 |
| 19 // Interface for a storage area for Value objects. | 19 // Interface for a storage area for Value objects. |
| 20 class ValueStore { | 20 class ValueStore { |
| 21 public: | 21 public: |
| 22 // Status codes returned from storage methods. | 22 // Status codes returned from storage methods. |
| 23 enum StatusCode { | 23 enum StatusCode { |
| 24 OK, | 24 OK, |
| 25 | 25 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 BackingStoreRestoreStatus restore_status; | 82 BackingStoreRestoreStatus restore_status; |
| 83 | 83 |
| 84 // Message associated with the status (error) if there is one. | 84 // Message associated with the status (error) if there is one. |
| 85 std::string message; | 85 std::string message; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 // The result of a read operation (Get). | 88 // The result of a read operation (Get). |
| 89 class ReadResultType { | 89 class ReadResultType { |
| 90 public: | 90 public: |
| 91 ReadResultType(scoped_ptr<base::DictionaryValue> settings, | 91 ReadResultType(std::unique_ptr<base::DictionaryValue> settings, |
| 92 const Status& status); | 92 const Status& status); |
| 93 explicit ReadResultType(const Status& status); | 93 explicit ReadResultType(const Status& status); |
| 94 ~ReadResultType(); | 94 ~ReadResultType(); |
| 95 | 95 |
| 96 // Gets the settings read from the storage. Note that this represents | 96 // Gets the settings read from the storage. Note that this represents |
| 97 // the root object. If you request the value for key "foo", that value will | 97 // the root object. If you request the value for key "foo", that value will |
| 98 // be in |settings|.|foo|. | 98 // be in |settings|.|foo|. |
| 99 // | 99 // |
| 100 // Must only be called if there is no error. | 100 // Must only be called if there is no error. |
| 101 base::DictionaryValue& settings() { return *settings_; } | 101 base::DictionaryValue& settings() { return *settings_; } |
| 102 scoped_ptr<base::DictionaryValue> PassSettings() { | 102 std::unique_ptr<base::DictionaryValue> PassSettings() { |
| 103 return std::move(settings_); | 103 return std::move(settings_); |
| 104 } | 104 } |
| 105 | 105 |
| 106 const Status& status() const { return status_; } | 106 const Status& status() const { return status_; } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 scoped_ptr<base::DictionaryValue> settings_; | 109 std::unique_ptr<base::DictionaryValue> settings_; |
| 110 Status status_; | 110 Status status_; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(ReadResultType); | 112 DISALLOW_COPY_AND_ASSIGN(ReadResultType); |
| 113 }; | 113 }; |
| 114 typedef scoped_ptr<ReadResultType> ReadResult; | 114 typedef std::unique_ptr<ReadResultType> ReadResult; |
| 115 | 115 |
| 116 // The result of a write operation (Set/Remove/Clear). | 116 // The result of a write operation (Set/Remove/Clear). |
| 117 class WriteResultType { | 117 class WriteResultType { |
| 118 public: | 118 public: |
| 119 WriteResultType(scoped_ptr<ValueStoreChangeList> changes, | 119 WriteResultType(std::unique_ptr<ValueStoreChangeList> changes, |
| 120 const Status& status); | 120 const Status& status); |
| 121 explicit WriteResultType(const Status& status); | 121 explicit WriteResultType(const Status& status); |
| 122 ~WriteResultType(); | 122 ~WriteResultType(); |
| 123 | 123 |
| 124 // Gets the list of changes to the settings which resulted from the write. | 124 // Gets the list of changes to the settings which resulted from the write. |
| 125 // Won't be present if the NO_GENERATE_CHANGES WriteOptions was given. | 125 // Won't be present if the NO_GENERATE_CHANGES WriteOptions was given. |
| 126 // Only call if no error. | 126 // Only call if no error. |
| 127 ValueStoreChangeList& changes() { return *changes_; } | 127 ValueStoreChangeList& changes() { return *changes_; } |
| 128 scoped_ptr<ValueStoreChangeList> PassChanges() { | 128 std::unique_ptr<ValueStoreChangeList> PassChanges() { |
| 129 return std::move(changes_); | 129 return std::move(changes_); |
| 130 } | 130 } |
| 131 | 131 |
| 132 const Status& status() const { return status_; } | 132 const Status& status() const { return status_; } |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 scoped_ptr<ValueStoreChangeList> changes_; | 135 std::unique_ptr<ValueStoreChangeList> changes_; |
| 136 Status status_; | 136 Status status_; |
| 137 | 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(WriteResultType); | 138 DISALLOW_COPY_AND_ASSIGN(WriteResultType); |
| 139 }; | 139 }; |
| 140 typedef scoped_ptr<WriteResultType> WriteResult; | 140 typedef std::unique_ptr<WriteResultType> WriteResult; |
| 141 | 141 |
| 142 // Options for write operations. | 142 // Options for write operations. |
| 143 enum WriteOptionsValues { | 143 enum WriteOptionsValues { |
| 144 // Callers should usually use this. | 144 // Callers should usually use this. |
| 145 DEFAULTS = 0, | 145 DEFAULTS = 0, |
| 146 | 146 |
| 147 // Ignore any quota restrictions. | 147 // Ignore any quota restrictions. |
| 148 IGNORE_QUOTA = 1<<1, | 148 IGNORE_QUOTA = 1<<1, |
| 149 | 149 |
| 150 // Don't generate the changes for a WriteResult. | 150 // Don't generate the changes for a WriteResult. |
| 151 NO_GENERATE_CHANGES = 1<<2, | 151 NO_GENERATE_CHANGES = 1<<2, |
| 152 }; | 152 }; |
| 153 typedef int WriteOptions; | 153 typedef int WriteOptions; |
| 154 | 154 |
| 155 virtual ~ValueStore() {} | 155 virtual ~ValueStore() {} |
| 156 | 156 |
| 157 // Helpers for making a Read/WriteResult. | 157 // Helpers for making a Read/WriteResult. |
| 158 template <typename T> | 158 template <typename T> |
| 159 static ReadResult MakeReadResult(scoped_ptr<T> arg, const Status& status) { | 159 static ReadResult MakeReadResult(std::unique_ptr<T> arg, |
| 160 const Status& status) { |
| 160 return ReadResult(new ReadResultType(std::move(arg), status)); | 161 return ReadResult(new ReadResultType(std::move(arg), status)); |
| 161 } | 162 } |
| 162 static ReadResult MakeReadResult(const Status& status) { | 163 static ReadResult MakeReadResult(const Status& status) { |
| 163 return ReadResult(new ReadResultType(status)); | 164 return ReadResult(new ReadResultType(status)); |
| 164 } | 165 } |
| 165 | 166 |
| 166 template <typename T> | 167 template <typename T> |
| 167 static WriteResult MakeWriteResult(scoped_ptr<T> arg, const Status& status) { | 168 static WriteResult MakeWriteResult(std::unique_ptr<T> arg, |
| 169 const Status& status) { |
| 168 return WriteResult(new WriteResultType(std::move(arg), status)); | 170 return WriteResult(new WriteResultType(std::move(arg), status)); |
| 169 } | 171 } |
| 170 static WriteResult MakeWriteResult(const Status& status) { | 172 static WriteResult MakeWriteResult(const Status& status) { |
| 171 return WriteResult(new WriteResultType(status)); | 173 return WriteResult(new WriteResultType(status)); |
| 172 } | 174 } |
| 173 | 175 |
| 174 // Gets the amount of space being used by a single value, in bytes. | 176 // Gets the amount of space being used by a single value, in bytes. |
| 175 // Note: The GetBytesInUse methods are only used by extension settings at the | 177 // Note: The GetBytesInUse methods are only used by extension settings at the |
| 176 // moment. If these become more generally useful, the | 178 // moment. If these become more generally useful, the |
| 177 // SettingsStorageQuotaEnforcer and WeakUnlimitedSettingsStorage classes | 179 // SettingsStorageQuotaEnforcer and WeakUnlimitedSettingsStorage classes |
| (...skipping 28 matching lines...) Expand all Loading... |
| 206 virtual WriteResult Remove(const std::string& key) = 0; | 208 virtual WriteResult Remove(const std::string& key) = 0; |
| 207 | 209 |
| 208 // Removes multiple keys from the storage. | 210 // Removes multiple keys from the storage. |
| 209 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; | 211 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; |
| 210 | 212 |
| 211 // Clears the storage. | 213 // Clears the storage. |
| 212 virtual WriteResult Clear() = 0; | 214 virtual WriteResult Clear() = 0; |
| 213 }; | 215 }; |
| 214 | 216 |
| 215 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_H_ | 217 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
| OLD | NEW |