| 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_API_STORAGE_STORAGE_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ | 6 #define EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "extensions/browser/api/storage/settings_namespace.h" | 10 #include "extensions/browser/api/storage/settings_namespace.h" |
| 11 #include "extensions/browser/api/storage/settings_observer.h" | 11 #include "extensions/browser/api/storage/settings_observer.h" |
| 12 #include "extensions/browser/extension_function.h" | 12 #include "extensions/browser/extension_function.h" |
| 13 #include "extensions/browser/value_store/value_store.h" | 13 #include "extensions/browser/value_store/value_store.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 // Superclass of all settings functions. | 17 // Superclass of all settings functions. |
| 18 class SettingsFunction : public UIThreadExtensionFunction { | 18 class SettingsFunction : public UIThreadExtensionFunction { |
| 19 protected: | 19 protected: |
| 20 SettingsFunction(); | 20 SettingsFunction(); |
| 21 virtual ~SettingsFunction(); | 21 virtual ~SettingsFunction(); |
| 22 | 22 |
| 23 // ExtensionFunction: | 23 // ExtensionFunction: |
| 24 virtual bool ShouldSkipQuotaLimiting() const OVERRIDE; | 24 virtual bool ShouldSkipQuotaLimiting() const OVERRIDE; |
| 25 virtual ResponseAction RunImplTypesafe() OVERRIDE; | 25 virtual ResponseAction Run() OVERRIDE; |
| 26 | 26 |
| 27 // Extension settings function implementations should do their work here. | 27 // Extension settings function implementations should do their work here. |
| 28 // The StorageFrontend makes sure this is posted to the appropriate thread. | 28 // The StorageFrontend makes sure this is posted to the appropriate thread. |
| 29 virtual ResponseValue RunWithStorage(ValueStore* storage) = 0; | 29 virtual ResponseValue RunWithStorage(ValueStore* storage) = 0; |
| 30 | 30 |
| 31 // Handles the |result| of a read function. | 31 // Handles the |result| of a read function. |
| 32 // - If the result succeeded, this will set |result_| and return. | 32 // - If the result succeeded, this will set |result_| and return. |
| 33 // - If |result| failed with a ValueStore::CORRUPTION error, this will call | 33 // - If |result| failed with a ValueStore::CORRUPTION error, this will call |
| 34 // RestoreStorageAndRetry(), and return that result. | 34 // RestoreStorageAndRetry(), and return that result. |
| 35 // - If the |result| failed with a different error, this will set |error_| | 35 // - If the |result| failed with a different error, this will set |error_| |
| 36 // and return. | 36 // and return. |
| 37 ResponseValue UseReadResult(ValueStore::ReadResult result, | 37 ResponseValue UseReadResult(ValueStore::ReadResult result, |
| 38 ValueStore* storage); | 38 ValueStore* storage); |
| 39 | 39 |
| 40 // Handles the |result| of a write function. | 40 // Handles the |result| of a write function. |
| 41 // - If the result succeeded, this will set |result_| and return. | 41 // - If the result succeeded, this will set |result_| and return. |
| 42 // - If |result| failed with a ValueStore::CORRUPTION error, this will call | 42 // - If |result| failed with a ValueStore::CORRUPTION error, this will call |
| 43 // RestoreStorageAndRetry(), and return that result. | 43 // RestoreStorageAndRetry(), and return that result. |
| 44 // - If the |result| failed with a different error, this will set |error_| | 44 // - If the |result| failed with a different error, this will set |error_| |
| 45 // and return. | 45 // and return. |
| 46 // This will also send out a change notification, if appropriate. | 46 // This will also send out a change notification, if appropriate. |
| 47 ResponseValue UseWriteResult(ValueStore::WriteResult result, | 47 ResponseValue UseWriteResult(ValueStore::WriteResult result, |
| 48 ValueStore* storage); | 48 ValueStore* storage); |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // Called via PostTask from RunImplTypesafe. Calls RunWithStorage and then | 51 // Called via PostTask from Run. Calls RunWithStorage and then |
| 52 // SendResponse with its success value. | 52 // SendResponse with its success value. |
| 53 void AsyncRunWithStorage(ValueStore* storage); | 53 void AsyncRunWithStorage(ValueStore* storage); |
| 54 | 54 |
| 55 // Called if we encounter a ValueStore error. If the error is due to | 55 // Called if we encounter a ValueStore error. If the error is due to |
| 56 // corruption, tries to restore the ValueStore and re-run the API function. | 56 // corruption, tries to restore the ValueStore and re-run the API function. |
| 57 // If the storage cannot be restored or was due to some other error, then sets | 57 // If the storage cannot be restored or was due to some other error, then sets |
| 58 // error and returns. This also sets the |tried_restoring_storage_| flag to | 58 // error and returns. This also sets the |tried_restoring_storage_| flag to |
| 59 // ensure we don't enter a loop. | 59 // ensure we don't enter a loop. |
| 60 ResponseValue HandleError(const ValueStore::Error& error, | 60 ResponseValue HandleError(const ValueStore::Error& error, |
| 61 ValueStore* storage); | 61 ValueStore* storage); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 protected: | 135 protected: |
| 136 virtual ~StorageStorageAreaGetBytesInUseFunction() {} | 136 virtual ~StorageStorageAreaGetBytesInUseFunction() {} |
| 137 | 137 |
| 138 // SettingsFunction: | 138 // SettingsFunction: |
| 139 virtual ResponseValue RunWithStorage(ValueStore* storage) OVERRIDE; | 139 virtual ResponseValue RunWithStorage(ValueStore* storage) OVERRIDE; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace extensions | 142 } // namespace extensions |
| 143 | 143 |
| 144 #endif // EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ | 144 #endif // EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ |
| OLD | NEW |