| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_API_STORAGE_STORAGE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_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 "chrome/browser/extensions/api/storage/settings_namespace.h" | 10 #include "chrome/browser/extensions/api/storage/settings_namespace.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // ExtensionFunction: | 23 // ExtensionFunction: |
| 24 virtual bool ShouldSkipQuotaLimiting() const OVERRIDE; | 24 virtual bool ShouldSkipQuotaLimiting() const OVERRIDE; |
| 25 virtual bool RunImpl() OVERRIDE; | 25 virtual bool RunImpl() 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 SettingsFrontend makes sure this is posted to the appropriate thread. | 28 // The SettingsFrontend makes sure this is posted to the appropriate thread. |
| 29 // Implementations should fill in args themselves, though (like RunImpl) | 29 // Implementations should fill in args themselves, though (like RunImpl) |
| 30 // may return false to imply failure. | 30 // may return false to imply failure. |
| 31 virtual bool RunWithStorage(ValueStore* storage) = 0; | 31 virtual bool RunWithStorage(ValueStore* storage) = 0; |
| 32 | 32 |
| 33 // Sets error_ or result_ depending on the value of a storage ReadResult, and | 33 // Handles the |result| of a read function. |
| 34 // returns whether the result implies success (i.e. !error). | 34 // - If the result succeeded, this will set |result_| and return. |
| 35 bool UseReadResult(ValueStore::ReadResult result); | 35 // - If |result| failed with a ValueStore::CORRUPTION error, this will call |
| 36 // RestoreStorageAndRetry(), and return that result. |
| 37 // - If the |result| failed with a different error, this will set |error_| |
| 38 // and return. |
| 39 bool UseReadResult(ValueStore::ReadResult result, ValueStore* storage); |
| 36 | 40 |
| 37 // Sets error_ depending on the value of a storage WriteResult, sends a | 41 // Handles the |result| of a write function. |
| 38 // change notification if needed, and returns whether the result implies | 42 // - If the result succeeded, this will set |result_| and return. |
| 39 // success (i.e. !error). | 43 // - If |result| failed with a ValueStore::CORRUPTION error, this will call |
| 40 bool UseWriteResult(ValueStore::WriteResult result); | 44 // RestoreStorageAndRetry(), and return that result. |
| 45 // - If the |result| failed with a different error, this will set |error_| |
| 46 // and return. |
| 47 // This will also send out a change notification, if appropriate. |
| 48 bool UseWriteResult(ValueStore::WriteResult result, ValueStore* storage); |
| 41 | 49 |
| 42 private: | 50 private: |
| 43 // Called via PostTask from RunImpl. Calls RunWithStorage and then | 51 // Called via PostTask from RunImpl. Calls RunWithStorage and then |
| 44 // SendResponse with its success value. | 52 // SendResponse with its success value. |
| 45 void AsyncRunWithStorage(ValueStore* storage); | 53 void AsyncRunWithStorage(ValueStore* storage); |
| 46 | 54 |
| 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. |
| 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 |
| 59 // ensure we don't enter a loop. |
| 60 bool HandleError(const ValueStore::Error& error, ValueStore* storage); |
| 61 |
| 47 // The settings namespace the call was for. For example, SYNC if the API | 62 // The settings namespace the call was for. For example, SYNC if the API |
| 48 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. | 63 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. |
| 49 settings_namespace::Namespace settings_namespace_; | 64 settings_namespace::Namespace settings_namespace_; |
| 50 | 65 |
| 66 // A flag indicating whether or not we have tried to restore storage. We |
| 67 // should only ever try once (per API call) in order to avoid entering a loop. |
| 68 bool tried_restoring_storage_; |
| 69 |
| 51 // Observers, cached so that it's only grabbed from the UI thread. | 70 // Observers, cached so that it's only grabbed from the UI thread. |
| 52 scoped_refptr<SettingsObserverList> observers_; | 71 scoped_refptr<SettingsObserverList> observers_; |
| 53 }; | 72 }; |
| 54 | 73 |
| 55 class StorageStorageAreaGetFunction : public SettingsFunction { | 74 class StorageStorageAreaGetFunction : public SettingsFunction { |
| 56 public: | 75 public: |
| 57 DECLARE_EXTENSION_FUNCTION("storage.get", STORAGE_GET) | 76 DECLARE_EXTENSION_FUNCTION("storage.get", STORAGE_GET) |
| 58 | 77 |
| 59 protected: | 78 protected: |
| 60 virtual ~StorageStorageAreaGetFunction() {} | 79 virtual ~StorageStorageAreaGetFunction() {} |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 protected: | 134 protected: |
| 116 virtual ~StorageStorageAreaGetBytesInUseFunction() {} | 135 virtual ~StorageStorageAreaGetBytesInUseFunction() {} |
| 117 | 136 |
| 118 // SettingsFunction: | 137 // SettingsFunction: |
| 119 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | 138 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; |
| 120 }; | 139 }; |
| 121 | 140 |
| 122 } // namespace extensions | 141 } // namespace extensions |
| 123 | 142 |
| 124 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ | 143 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ |
| OLD | NEW |