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 // Handles the |result| of a read function. | 33 // Sets error_ or result_ depending on the value of a storage ReadResult, and |
34 // - If the result succeeded, this will set |result_| and return. | 34 // returns whether the result implies success (i.e. !error). |
35 // - If |result| failed with a ValueStore::CORRUPTION error, this will call | 35 bool UseReadResult(ValueStore::ReadResult result); |
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); | |
40 | 36 |
41 // Handles the |result| of a write function. | 37 // Sets error_ depending on the value of a storage WriteResult, sends a |
42 // - If the result succeeded, this will set |result_| and return. | 38 // change notification if needed, and returns whether the result implies |
43 // - If |result| failed with a ValueStore::CORRUPTION error, this will call | 39 // success (i.e. !error). |
44 // RestoreStorageAndRetry(), and return that result. | 40 bool UseWriteResult(ValueStore::WriteResult 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); | |
49 | 41 |
50 private: | 42 private: |
51 // Called via PostTask from RunImpl. Calls RunWithStorage and then | 43 // Called via PostTask from RunImpl. Calls RunWithStorage and then |
52 // SendResponse with its success value. | 44 // SendResponse with its success value. |
53 void AsyncRunWithStorage(ValueStore* storage); | 45 void AsyncRunWithStorage(ValueStore* storage); |
54 | 46 |
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 | |
62 // The settings namespace the call was for. For example, SYNC if the API | 47 // The settings namespace the call was for. For example, SYNC if the API |
63 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. | 48 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. |
64 settings_namespace::Namespace settings_namespace_; | 49 settings_namespace::Namespace settings_namespace_; |
65 | 50 |
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 | |
70 // Observers, cached so that it's only grabbed from the UI thread. | 51 // Observers, cached so that it's only grabbed from the UI thread. |
71 scoped_refptr<SettingsObserverList> observers_; | 52 scoped_refptr<SettingsObserverList> observers_; |
72 }; | 53 }; |
73 | 54 |
74 class StorageStorageAreaGetFunction : public SettingsFunction { | 55 class StorageStorageAreaGetFunction : public SettingsFunction { |
75 public: | 56 public: |
76 DECLARE_EXTENSION_FUNCTION("storage.get", STORAGE_GET) | 57 DECLARE_EXTENSION_FUNCTION("storage.get", STORAGE_GET) |
77 | 58 |
78 protected: | 59 protected: |
79 virtual ~StorageStorageAreaGetFunction() {} | 60 virtual ~StorageStorageAreaGetFunction() {} |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 protected: | 115 protected: |
135 virtual ~StorageStorageAreaGetBytesInUseFunction() {} | 116 virtual ~StorageStorageAreaGetBytesInUseFunction() {} |
136 | 117 |
137 // SettingsFunction: | 118 // SettingsFunction: |
138 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | 119 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; |
139 }; | 120 }; |
140 | 121 |
141 } // namespace extensions | 122 } // namespace extensions |
142 | 123 |
143 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ | 124 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ |
OLD | NEW |