Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover.h

Issue 2827523003: Move BrowsingDataRemover to content/ (Closed)
Patch Set: Rebase over codereview.chromium.org/2815913005 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_
7
8 #include <memory>
9 #include "base/callback_forward.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h"
12 #include "build/build_config.h"
13 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
14 #include "components/keyed_service/core/keyed_service.h"
15
16 namespace content {
17 class BrowsingDataFilterBuilder;
18 }
19
20 ////////////////////////////////////////////////////////////////////////////////
21 // BrowsingDataRemover is responsible for removing data related to browsing:
22 // visits in url database, downloads, cookies ...
23 //
24 // USAGE:
25 //
26 // 0. Instantiation.
27 //
28 // BrowsingDataRemover* remover =
29 // BrowsingDataRemoverFactory::GetForBrowserContext(browser_context);
30 //
31 // 1. No observer.
32 //
33 // remover->Remove(base::Time(), base::Time::Max(), REMOVE_COOKIES, ALL);
34 //
35 // 2. Using an observer to report when one's own removal task is finished.
36 //
37 // class CookiesDeleter : public BrowsingDataRemover::Observer {
38 // CookiesDeleter() { remover->AddObserver(this); }
39 // ~CookiesDeleter() { remover->RemoveObserver(this); }
40 //
41 // void DeleteCookies() {
42 // remover->RemoveAndReply(base::Time(), base::Time::Max(),
43 // REMOVE_COOKIES, ALL, this);
44 // }
45 //
46 // void OnBrowsingDataRemoverDone() {
47 // LOG(INFO) << "Cookies were deleted.";
48 // }
49 // }
50 //
51 ////////////////////////////////////////////////////////////////////////////////
52 //
53 // TODO(crbug.com/668114): BrowsingDataRemover does not currently support plugin
54 // data deletion. Use PluginDataRemover instead.
55 class BrowsingDataRemover : public KeyedService {
56 public:
57 // Mask used for Remove.
58 enum DataType {
59 // Storage datatypes.
60 DATA_TYPE_APP_CACHE = 1 << 0,
61 DATA_TYPE_FILE_SYSTEMS = 1 << 1,
62 DATA_TYPE_INDEXED_DB = 1 << 2,
63 DATA_TYPE_LOCAL_STORAGE = 1 << 3,
64 DATA_TYPE_WEB_SQL = 1 << 4,
65 DATA_TYPE_SERVICE_WORKERS = 1 << 5,
66 DATA_TYPE_CACHE_STORAGE = 1 << 6,
67
68 // Used to request the deletion of embedder-specific storage datatypes.
69 DATA_TYPE_EMBEDDER_DOM_STORAGE = 1 << 7,
70
71 // DOM-accessible storage (https://www.w3.org/TR/clear-site-data/#storage).
72 // Has the same effect as selecting all storage datatypes listed above
73 // and ones defined by the embedder.
74 DATA_TYPE_DOM_STORAGE = DATA_TYPE_APP_CACHE | DATA_TYPE_FILE_SYSTEMS |
75 DATA_TYPE_INDEXED_DB |
76 DATA_TYPE_LOCAL_STORAGE |
77 DATA_TYPE_WEB_SQL |
78 DATA_TYPE_SERVICE_WORKERS |
79 DATA_TYPE_CACHE_STORAGE |
80 DATA_TYPE_EMBEDDER_DOM_STORAGE,
81
82 // Other datatypes.
83 DATA_TYPE_COOKIES = 1 << 8,
84 DATA_TYPE_CHANNEL_IDS = 1 << 9,
85 DATA_TYPE_CACHE = 1 << 10,
86 DATA_TYPE_DOWNLOADS = 1 << 11,
87 DATA_TYPE_MEDIA_LICENSES = 1 << 12,
88
89 // REMOVE_NOCHECKS intentionally does not check if the browser context is
90 // prohibited from deleting history or downloads.
91 DATA_TYPE_NO_CHECKS = 1 << 13,
92
93 // Embedders can add more datatypes beyond this point.
94 DATA_TYPE_CONTENT_END = DATA_TYPE_NO_CHECKS,
95 };
96
97 enum OriginType {
98 // Web storage origins that StoragePartition recognizes as NOT protected
99 // according to its special storage policy.
100 ORIGIN_TYPE_UNPROTECTED_WEB = 1 << 0,
101
102 // Web storage origins that StoragePartition recognizes as protected
103 // according to its special storage policy.
104 ORIGIN_TYPE_PROTECTED_WEB = 1 << 1,
105
106 // Embedders can add more origin types beyond this point.
107 ORIGIN_TYPE_CONTENT_END = ORIGIN_TYPE_PROTECTED_WEB,
108 };
109
110 // A helper enum to report the deletion of cookies and/or cache. Do not
111 // reorder the entries, as this enum is passed to UMA.
112 enum CookieOrCacheDeletionChoice {
113 NEITHER_COOKIES_NOR_CACHE,
114 ONLY_COOKIES,
115 ONLY_CACHE,
116 BOTH_COOKIES_AND_CACHE,
117 MAX_CHOICE_VALUE
118 };
119
120 // Observer is notified when its own removal task is done.
121 class Observer {
122 public:
123 // Called when a removal task is finished. Note that every removal task can
124 // only have one observer attached to it, and only that one is called.
125 virtual void OnBrowsingDataRemoverDone() = 0;
126
127 protected:
128 virtual ~Observer() {}
129 };
130
131 // Called by the embedder to provide the delegate that will take care of
132 // deleting embedder-specific data.
133 virtual void SetEmbedderDelegate(
134 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) = 0;
135 virtual BrowsingDataRemoverDelegate* GetEmbedderDelegate() const = 0;
136
137 // Determines whether |origin| matches the |origin_type_mask| according to
138 // the |special_storage_policy|.
139 virtual bool DoesOriginMatchMask(
140 int origin_type_mask,
141 const GURL& origin,
142 storage::SpecialStoragePolicy* special_storage_policy) const = 0;
143
144 // Removes browsing data within the given |time_range|, with datatypes being
145 // specified by |remove_mask| and origin types by |origin_type_mask|.
146 virtual void Remove(const base::Time& delete_begin,
147 const base::Time& delete_end,
148 int remove_mask,
149 int origin_type_mask) = 0;
150
151 // A version of the above that in addition informs the |observer| when the
152 // removal task is finished.
153 virtual void RemoveAndReply(const base::Time& delete_begin,
154 const base::Time& delete_end,
155 int remove_mask,
156 int origin_type_mask,
157 Observer* observer) = 0;
158
159 // Like Remove(), but in case of URL-keyed only removes data whose URL match
160 // |filter_builder| (e.g. are on certain origin or domain).
161 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES.
162 virtual void RemoveWithFilter(
163 const base::Time& delete_begin,
164 const base::Time& delete_end,
165 int remove_mask,
166 int origin_type_mask,
167 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder) = 0;
168
169 // A version of the above that in addition informs the |observer| when the
170 // removal task is finished.
171 virtual void RemoveWithFilterAndReply(
172 const base::Time& delete_begin,
173 const base::Time& delete_end,
174 int remove_mask,
175 int origin_type_mask,
176 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder,
177 Observer* observer) = 0;
178
179 // Observers.
180 virtual void AddObserver(Observer* observer) = 0;
181 virtual void RemoveObserver(Observer* observer) = 0;
182
183 // A |callback| that will be called just before a deletion task is completed
184 // and observers are notified. The receiver must respond by calling
185 // |continue_to_completion| to finish the task. Used in tests to artificially
186 // prolong execution.
187 virtual void SetWouldCompleteCallbackForTesting(
188 const base::Callback<void(const base::Closure& continue_to_completion)>&
189 callback) = 0;
190
191 // Parameters of the last call are exposed to be used by tests. Removal and
192 // origin type masks equal to -1 mean that no removal has ever been executed.
193 // TODO(msramek): If other consumers than tests are interested in this,
194 // consider returning them in OnBrowsingDataRemoverDone() callback. If not,
195 // consider simplifying this interface by removing these methods and changing
196 // the tests to record the parameters using GMock instead.
197 virtual const base::Time& GetLastUsedBeginTime() = 0;
198 virtual const base::Time& GetLastUsedEndTime() = 0;
199 virtual int GetLastUsedRemovalMask() = 0;
200 virtual int GetLastUsedOriginTypeMask() = 0;
201 };
202
203 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698