Revert 285173 "Removed InProcessBrowserTest::CleanUpOnMainThread()"
[chromium-blink-merge.git] / chrome / browser / extensions / api / browsing_data / browsing_data_api.h
blob42d1cad37edd11ed13773fc599d2d68af0eeabf1
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
3 // found in the LICENSE file.
5 // Defines the Chrome Extensions BrowsingData API functions, which entail
6 // clearing browsing data, and clearing the browser's cache (which, let's be
7 // honest, are the same thing), as specified in the extension API JSON.
9 #ifndef CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
10 #define CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
12 #include <string>
14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h"
17 class PluginPrefs;
19 namespace extension_browsing_data_api_constants {
21 // Parameter name keys.
22 extern const char kDataRemovalPermittedKey[];
23 extern const char kDataToRemoveKey[];
24 extern const char kOptionsKey[];
26 // Type keys.
27 extern const char kAppCacheKey[];
28 extern const char kCacheKey[];
29 extern const char kCookiesKey[];
30 extern const char kDownloadsKey[];
31 extern const char kFileSystemsKey[];
32 extern const char kFormDataKey[];
33 extern const char kHistoryKey[];
34 extern const char kIndexedDBKey[];
35 extern const char kPluginDataKey[];
36 extern const char kLocalStorageKey[];
37 extern const char kPasswordsKey[];
38 extern const char kWebSQLKey[];
40 // Option keys.
41 extern const char kExtensionsKey[];
42 extern const char kOriginTypesKey[];
43 extern const char kProtectedWebKey[];
44 extern const char kSinceKey[];
45 extern const char kUnprotectedWebKey[];
47 // Errors!
48 extern const char kBadDataTypeDetails[];
49 extern const char kDeleteProhibitedError[];
50 extern const char kOneAtATimeError[];
52 } // namespace extension_browsing_data_api_constants
54 class BrowsingDataSettingsFunction : public ChromeSyncExtensionFunction {
55 public:
56 DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS)
58 // ExtensionFunction:
59 virtual bool RunSync() OVERRIDE;
61 protected:
62 virtual ~BrowsingDataSettingsFunction() {}
64 private:
65 // Sets a boolean value in the |selected_dict| with the |data_type| as a key,
66 // indicating whether the data type is both selected and permitted to be
67 // removed; and a value in the |permitted_dict| with the |data_type| as a
68 // key, indicating only whether the data type is permitted to be removed.
69 void SetDetails(base::DictionaryValue* selected_dict,
70 base::DictionaryValue* permitted_dict,
71 const char* data_type,
72 bool is_selected);
75 // This serves as a base class from which the browsing data API removal
76 // functions will inherit. Each needs to be an observer of BrowsingDataRemover
77 // events, and each will handle those events in the same way (by calling the
78 // passed-in callback function).
80 // Each child class must implement GetRemovalMask(), which returns the bitmask
81 // of data types to remove.
82 class BrowsingDataRemoverFunction : public ChromeAsyncExtensionFunction,
83 public BrowsingDataRemover::Observer {
84 public:
85 // BrowsingDataRemover::Observer interface method.
86 virtual void OnBrowsingDataRemoverDone() OVERRIDE;
88 // ExtensionFunction:
89 virtual bool RunAsync() OVERRIDE;
91 protected:
92 virtual ~BrowsingDataRemoverFunction() {}
94 // Children should override this method to provide the proper removal mask
95 // based on the API call they represent.
96 virtual int GetRemovalMask() = 0;
98 private:
99 // Updates the removal bitmask according to whether removing plugin data is
100 // supported or not.
101 void CheckRemovingPluginDataSupported(
102 scoped_refptr<PluginPrefs> plugin_prefs);
104 // Parse the developer-provided |origin_types| object into an origin_set_mask
105 // that can be used with the BrowsingDataRemover.
106 int ParseOriginSetMask(const base::DictionaryValue& options);
108 // Called when we're ready to start removing data.
109 void StartRemoving();
111 base::Time remove_since_;
112 int removal_mask_;
113 int origin_set_mask_;
116 class BrowsingDataRemoveAppcacheFunction : public BrowsingDataRemoverFunction {
117 public:
118 DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
119 BROWSINGDATA_REMOVEAPPCACHE)
121 protected:
122 virtual ~BrowsingDataRemoveAppcacheFunction() {}
124 // BrowsingDataRemoverFunction:
125 virtual int GetRemovalMask() OVERRIDE;
128 class BrowsingDataRemoveFunction : public BrowsingDataRemoverFunction {
129 public:
130 DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE)
132 protected:
133 virtual ~BrowsingDataRemoveFunction() {}
135 // BrowsingDataRemoverFunction:
136 virtual int GetRemovalMask() OVERRIDE;
139 class BrowsingDataRemoveCacheFunction : public BrowsingDataRemoverFunction {
140 public:
141 DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
142 BROWSINGDATA_REMOVECACHE)
144 protected:
145 virtual ~BrowsingDataRemoveCacheFunction() {}
147 // BrowsingDataRemoverFunction:
148 virtual int GetRemovalMask() OVERRIDE;
151 class BrowsingDataRemoveCookiesFunction : public BrowsingDataRemoverFunction {
152 public:
153 DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
154 BROWSINGDATA_REMOVECOOKIES)
156 protected:
157 virtual ~BrowsingDataRemoveCookiesFunction() {}
159 // BrowsingDataRemoverFunction:
160 virtual int GetRemovalMask() OVERRIDE;
163 class BrowsingDataRemoveDownloadsFunction : public BrowsingDataRemoverFunction {
164 public:
165 DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
166 BROWSINGDATA_REMOVEDOWNLOADS)
168 protected:
169 virtual ~BrowsingDataRemoveDownloadsFunction() {}
171 // BrowsingDataRemoverFunction:
172 virtual int GetRemovalMask() OVERRIDE;
175 class BrowsingDataRemoveFileSystemsFunction
176 : public BrowsingDataRemoverFunction {
177 public:
178 DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
179 BROWSINGDATA_REMOVEFILESYSTEMS)
181 protected:
182 virtual ~BrowsingDataRemoveFileSystemsFunction() {}
184 // BrowsingDataRemoverFunction:
185 virtual int GetRemovalMask() OVERRIDE;
188 class BrowsingDataRemoveFormDataFunction : public BrowsingDataRemoverFunction {
189 public:
190 DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
191 BROWSINGDATA_REMOVEFORMDATA)
193 protected:
194 virtual ~BrowsingDataRemoveFormDataFunction() {}
196 // BrowsingDataRemoverFunction:
197 virtual int GetRemovalMask() OVERRIDE;
200 class BrowsingDataRemoveHistoryFunction : public BrowsingDataRemoverFunction {
201 public:
202 DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
203 BROWSINGDATA_REMOVEHISTORY)
205 protected:
206 virtual ~BrowsingDataRemoveHistoryFunction() {}
208 // BrowsingDataRemoverFunction:
209 virtual int GetRemovalMask() OVERRIDE;
212 class BrowsingDataRemoveIndexedDBFunction : public BrowsingDataRemoverFunction {
213 public:
214 DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
215 BROWSINGDATA_REMOVEINDEXEDDB)
217 protected:
218 virtual ~BrowsingDataRemoveIndexedDBFunction() {}
220 // BrowsingDataRemoverFunction:
221 virtual int GetRemovalMask() OVERRIDE;
224 class BrowsingDataRemoveLocalStorageFunction
225 : public BrowsingDataRemoverFunction {
226 public:
227 DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
228 BROWSINGDATA_REMOVELOCALSTORAGE)
230 protected:
231 virtual ~BrowsingDataRemoveLocalStorageFunction() {}
233 // BrowsingDataRemoverFunction:
234 virtual int GetRemovalMask() OVERRIDE;
237 class BrowsingDataRemovePluginDataFunction
238 : public BrowsingDataRemoverFunction {
239 public:
240 DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
241 BROWSINGDATA_REMOVEPLUGINDATA)
243 protected:
244 virtual ~BrowsingDataRemovePluginDataFunction() {}
246 // BrowsingDataRemoverFunction:
247 virtual int GetRemovalMask() OVERRIDE;
250 class BrowsingDataRemovePasswordsFunction : public BrowsingDataRemoverFunction {
251 public:
252 DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
253 BROWSINGDATA_REMOVEPASSWORDS)
255 protected:
256 virtual ~BrowsingDataRemovePasswordsFunction() {}
258 // BrowsingDataRemoverFunction:
259 virtual int GetRemovalMask() OVERRIDE;
262 class BrowsingDataRemoveWebSQLFunction : public BrowsingDataRemoverFunction {
263 public:
264 DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
265 BROWSINGDATA_REMOVEWEBSQL)
267 protected:
268 virtual ~BrowsingDataRemoveWebSQLFunction() {}
270 // BrowsingDataRemoverFunction:
271 virtual int GetRemovalMask() OVERRIDE;
274 #endif // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_