OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSING_DATA_REMOVER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_BROWSING_DATA_REMOVER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | |
9 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" | 14 #include "content/common/content_export.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 15 #include "content/public/browser/browsing_data_remover_delegate.h" |
jam
2017/04/20 00:39:48
nit: just forward declare
msramek
2017/04/21 15:22:12
Done. Also added a few more forward declarations t
| |
15 | 16 |
16 namespace content { | 17 namespace content { |
18 | |
17 class BrowsingDataFilterBuilder; | 19 class BrowsingDataFilterBuilder; |
18 } | |
19 | 20 |
20 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
21 // BrowsingDataRemover is responsible for removing data related to browsing: | 22 // BrowsingDataRemover is responsible for removing data related to browsing: |
22 // visits in url database, downloads, cookies ... | 23 // visits in url database, downloads, cookies ... |
23 // | 24 // |
24 // USAGE: | 25 // USAGE: |
25 // | 26 // |
26 // 0. Instantiation. | 27 // 0. Instantiation. |
27 // | 28 // |
28 // BrowsingDataRemover* remover = | 29 // content::BrowsingDataRemover* remover = |
29 // BrowsingDataRemoverFactory::GetForBrowserContext(browser_context); | 30 // content::BrowserContext::GetBrowsingDataRemover(browser_context); |
30 // | 31 // |
31 // 1. No observer. | 32 // 1. No observer. |
32 // | 33 // |
33 // remover->Remove(base::Time(), base::Time::Max(), REMOVE_COOKIES, ALL); | 34 // remover->Remove(base::Time(), base::Time::Max(), REMOVE_COOKIES, ALL); |
34 // | 35 // |
35 // 2. Using an observer to report when one's own removal task is finished. | 36 // 2. Using an observer to report when one's own removal task is finished. |
36 // | 37 // |
37 // class CookiesDeleter : public BrowsingDataRemover::Observer { | 38 // class CookiesDeleter : public content::BrowsingDataRemover::Observer { |
38 // CookiesDeleter() { remover->AddObserver(this); } | 39 // CookiesDeleter() { remover->AddObserver(this); } |
39 // ~CookiesDeleter() { remover->RemoveObserver(this); } | 40 // ~CookiesDeleter() { remover->RemoveObserver(this); } |
40 // | 41 // |
41 // void DeleteCookies() { | 42 // void DeleteCookies() { |
42 // remover->RemoveAndReply(base::Time(), base::Time::Max(), | 43 // remover->RemoveAndReply(base::Time(), base::Time::Max(), |
43 // REMOVE_COOKIES, ALL, this); | 44 // REMOVE_COOKIES, ALL, this); |
44 // } | 45 // } |
45 // | 46 // |
46 // void OnBrowsingDataRemoverDone() { | 47 // void OnBrowsingDataRemoverDone() { |
47 // LOG(INFO) << "Cookies were deleted."; | 48 // LOG(INFO) << "Cookies were deleted."; |
48 // } | 49 // } |
49 // } | 50 // } |
50 // | 51 // |
51 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
52 // | 53 // |
53 // TODO(crbug.com/668114): BrowsingDataRemover does not currently support plugin | 54 // TODO(crbug.com/668114): BrowsingDataRemover does not currently support plugin |
54 // data deletion. Use PluginDataRemover instead. | 55 // data deletion. Use PluginDataRemover instead. |
55 class BrowsingDataRemover : public KeyedService { | 56 class CONTENT_EXPORT BrowsingDataRemover { |
jam
2017/04/20 00:39:48
nit: not needed on interfaces, so remove along wit
msramek
2017/04/21 15:22:12
Done.
| |
56 public: | 57 public: |
57 // Mask used for Remove. | 58 // Mask used for Remove. |
58 enum DataType { | 59 enum DataType { |
59 // Storage datatypes. | 60 // Storage datatypes. |
60 DATA_TYPE_APP_CACHE = 1 << 0, | 61 DATA_TYPE_APP_CACHE = 1 << 0, |
61 DATA_TYPE_FILE_SYSTEMS = 1 << 1, | 62 DATA_TYPE_FILE_SYSTEMS = 1 << 1, |
62 DATA_TYPE_INDEXED_DB = 1 << 2, | 63 DATA_TYPE_INDEXED_DB = 1 << 2, |
63 DATA_TYPE_LOCAL_STORAGE = 1 << 3, | 64 DATA_TYPE_LOCAL_STORAGE = 1 << 3, |
64 DATA_TYPE_WEB_SQL = 1 << 4, | 65 DATA_TYPE_WEB_SQL = 1 << 4, |
65 DATA_TYPE_SERVICE_WORKERS = 1 << 5, | 66 DATA_TYPE_SERVICE_WORKERS = 1 << 5, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 // reorder the entries, as this enum is passed to UMA. | 112 // reorder the entries, as this enum is passed to UMA. |
112 enum CookieOrCacheDeletionChoice { | 113 enum CookieOrCacheDeletionChoice { |
113 NEITHER_COOKIES_NOR_CACHE, | 114 NEITHER_COOKIES_NOR_CACHE, |
114 ONLY_COOKIES, | 115 ONLY_COOKIES, |
115 ONLY_CACHE, | 116 ONLY_CACHE, |
116 BOTH_COOKIES_AND_CACHE, | 117 BOTH_COOKIES_AND_CACHE, |
117 MAX_CHOICE_VALUE | 118 MAX_CHOICE_VALUE |
118 }; | 119 }; |
119 | 120 |
120 // Observer is notified when its own removal task is done. | 121 // Observer is notified when its own removal task is done. |
121 class Observer { | 122 class Observer { |
jam
2017/04/20 00:39:48
for this class and the next one, can we just use c
msramek
2017/04/21 15:22:12
The second class (CompletionInhibitor) can be remo
jam
2017/04/21 22:58:30
Thanks, I read the discussion above. The major poi
msramek
2017/04/25 01:29:09
Alright! I'll send you a followup to convert them
| |
122 public: | 123 public: |
123 // Called when a removal task is finished. Note that every removal task can | 124 // 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 // only have one observer attached to it, and only that one is called. |
125 virtual void OnBrowsingDataRemoverDone() = 0; | 126 virtual void OnBrowsingDataRemoverDone() = 0; |
126 | 127 |
127 protected: | 128 protected: |
128 virtual ~Observer() {} | 129 virtual ~Observer() {} |
129 }; | 130 }; |
130 | 131 |
131 // Called by the embedder to provide the delegate that will take care of | 132 // The completion inhibitor can artificially delay completion of the browsing |
132 // deleting embedder-specific data. | 133 // data removal process. It is used during testing to simulate scenarios in |
134 // which the deletion stalls or takes a very long time. | |
135 class CompletionInhibitor { | |
136 public: | |
137 // Invoked when a |remover| is just about to complete clearing browser data, | |
138 // and will be prevented from completing until after the callback | |
139 // |continue_to_completion| is run. | |
140 virtual void OnBrowsingDataRemoverWouldComplete( | |
141 BrowsingDataRemover* remover, | |
142 const base::Closure& continue_to_completion) = 0; | |
143 | |
144 protected: | |
145 virtual ~CompletionInhibitor() {} | |
146 }; | |
147 | |
148 // A delegate that will take care of deleting embedder-specific data. | |
133 virtual void SetEmbedderDelegate( | 149 virtual void SetEmbedderDelegate( |
134 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) = 0; | 150 BrowsingDataRemoverDelegate* embedder_delegate) = 0; |
135 virtual BrowsingDataRemoverDelegate* GetEmbedderDelegate() const = 0; | 151 virtual BrowsingDataRemoverDelegate* GetEmbedderDelegate() const = 0; |
jam
2017/04/20 00:39:48
it's a bit odd that the embedder sets the delegate
msramek
2017/04/21 15:22:12
We don't, and removing it really made the code a b
| |
136 | 152 |
137 // Determines whether |origin| matches the |origin_type_mask| according to | 153 // Determines whether |origin| matches the |origin_type_mask| according to |
138 // the |special_storage_policy|. | 154 // the |special_storage_policy|. |
139 virtual bool DoesOriginMatchMask( | 155 virtual bool DoesOriginMatchMask( |
140 int origin_type_mask, | 156 int origin_type_mask, |
141 const GURL& origin, | 157 const GURL& origin, |
142 storage::SpecialStoragePolicy* special_storage_policy) const = 0; | 158 storage::SpecialStoragePolicy* special_storage_policy) const = 0; |
143 | 159 |
144 // Removes browsing data within the given |time_range|, with datatypes being | 160 // Removes browsing data within the given |time_range|, with datatypes being |
145 // specified by |remove_mask| and origin types by |origin_type_mask|. | 161 // specified by |remove_mask| and origin types by |origin_type_mask|. |
(...skipping 11 matching lines...) Expand all Loading... | |
157 Observer* observer) = 0; | 173 Observer* observer) = 0; |
158 | 174 |
159 // Like Remove(), but in case of URL-keyed only removes data whose URL match | 175 // 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). | 176 // |filter_builder| (e.g. are on certain origin or domain). |
161 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES. | 177 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES. |
162 virtual void RemoveWithFilter( | 178 virtual void RemoveWithFilter( |
163 const base::Time& delete_begin, | 179 const base::Time& delete_begin, |
164 const base::Time& delete_end, | 180 const base::Time& delete_end, |
165 int remove_mask, | 181 int remove_mask, |
166 int origin_type_mask, | 182 int origin_type_mask, |
167 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder) = 0; | 183 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) = 0; |
168 | 184 |
169 // A version of the above that in addition informs the |observer| when the | 185 // A version of the above that in addition informs the |observer| when the |
170 // removal task is finished. | 186 // removal task is finished. |
171 virtual void RemoveWithFilterAndReply( | 187 virtual void RemoveWithFilterAndReply( |
172 const base::Time& delete_begin, | 188 const base::Time& delete_begin, |
173 const base::Time& delete_end, | 189 const base::Time& delete_end, |
174 int remove_mask, | 190 int remove_mask, |
175 int origin_type_mask, | 191 int origin_type_mask, |
176 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, | 192 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, |
177 Observer* observer) = 0; | 193 Observer* observer) = 0; |
178 | 194 |
179 // Observers. | 195 // Observers. |
180 virtual void AddObserver(Observer* observer) = 0; | 196 virtual void AddObserver(Observer* observer) = 0; |
181 virtual void RemoveObserver(Observer* observer) = 0; | 197 virtual void RemoveObserver(Observer* observer) = 0; |
182 | 198 |
183 // A |callback| that will be called just before a deletion task is completed | 199 // A |callback| that will be called just before a deletion task is completed |
184 // and observers are notified. The receiver must respond by calling | 200 // and observers are notified. The receiver must respond by calling |
185 // |continue_to_completion| to finish the task. Used in tests to artificially | 201 // |continue_to_completion| to finish the task. Used in tests to artificially |
186 // prolong execution. | 202 // prolong execution. |
187 virtual void SetWouldCompleteCallbackForTesting( | 203 virtual void SetWouldCompleteCallbackForTesting( |
188 const base::Callback<void(const base::Closure& continue_to_completion)>& | 204 const base::Callback<void(const base::Closure& continue_to_completion)>& |
189 callback) = 0; | 205 callback) = 0; |
190 | 206 |
191 // Parameters of the last call are exposed to be used by tests. Removal and | 207 // 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. | 208 // 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, | 209 // TODO(msramek): If other consumers than tests are interested in this, |
194 // consider returning them in OnBrowsingDataRemoverDone() callback. If not, | 210 // consider returning them in OnBrowsingDataRemoverDone() callback. If not, |
195 // consider simplifying this interface by removing these methods and changing | 211 // consider simplifying this interface by removing these methods and changing |
196 // the tests to record the parameters using GMock instead. | 212 // the tests to record the parameters using GMock instead. |
197 virtual const base::Time& GetLastUsedBeginTime() = 0; | 213 virtual const base::Time& GetLastUsedBeginTime() = 0; |
198 virtual const base::Time& GetLastUsedEndTime() = 0; | 214 virtual const base::Time& GetLastUsedEndTime() = 0; |
199 virtual int GetLastUsedRemovalMask() = 0; | 215 virtual int GetLastUsedRemovalMask() = 0; |
200 virtual int GetLastUsedOriginTypeMask() = 0; | 216 virtual int GetLastUsedOriginTypeMask() = 0; |
201 }; | 217 }; |
202 | 218 |
203 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 219 } // namespace content |
220 | |
221 #endif // CONTENT_PUBLIC_BROWSER_BROWSING_DATA_REMOVER_H_ | |
OLD | NEW |