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 CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
| 9 #include <set> |
| 10 |
9 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
10 #include "base/time/time.h" | 12 #include "base/time/time.h" |
11 #include "build/build_config.h" | |
12 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" | 13 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" |
| 14 #include "content/public/browser/browsing_data_types.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 class BrowsingDataFilterBuilder; | 17 class BrowsingDataFilterBuilder; |
| 18 struct BrowsingDataType; |
16 } | 19 } |
17 | 20 |
18 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
19 // BrowsingDataRemover is responsible for removing data related to browsing: | 22 // BrowsingDataRemover is responsible for removing data related to browsing: |
20 // visits in url database, downloads, cookies ... | 23 // visits in url database, downloads, cookies ... |
21 // | 24 // |
22 // USAGE: | 25 // USAGE: |
23 // | 26 // |
24 // 0. Instantiation. | 27 // 0. Instantiation. |
25 // | 28 // |
(...skipping 19 matching lines...) Expand all Loading... |
45 // LOG(INFO) << "Cookies were deleted."; | 48 // LOG(INFO) << "Cookies were deleted."; |
46 // } | 49 // } |
47 // } | 50 // } |
48 // | 51 // |
49 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
50 // | 53 // |
51 // TODO(crbug.com/668114): BrowsingDataRemover does not currently support plugin | 54 // TODO(crbug.com/668114): BrowsingDataRemover does not currently support plugin |
52 // data deletion. Use PluginDataRemover instead. | 55 // data deletion. Use PluginDataRemover instead. |
53 class BrowsingDataRemover { | 56 class BrowsingDataRemover { |
54 public: | 57 public: |
55 // Mask used for Remove. | |
56 enum RemoveDataMask { | |
57 REMOVE_APPCACHE = 1 << 0, | |
58 REMOVE_CACHE = 1 << 1, | |
59 REMOVE_COOKIES = 1 << 2, | |
60 REMOVE_DOWNLOADS = 1 << 3, | |
61 REMOVE_FILE_SYSTEMS = 1 << 4, | |
62 REMOVE_FORM_DATA = 1 << 5, | |
63 // In addition to visits, REMOVE_HISTORY removes keywords, last session and | |
64 // passwords UI statistics. | |
65 REMOVE_HISTORY = 1 << 6, | |
66 REMOVE_INDEXEDDB = 1 << 7, | |
67 REMOVE_LOCAL_STORAGE = 1 << 8, | |
68 REMOVE_PLUGIN_DATA = 1 << 9, | |
69 REMOVE_PASSWORDS = 1 << 10, | |
70 REMOVE_WEBSQL = 1 << 11, | |
71 REMOVE_CHANNEL_IDS = 1 << 12, | |
72 REMOVE_MEDIA_LICENSES = 1 << 13, | |
73 REMOVE_SERVICE_WORKERS = 1 << 14, | |
74 REMOVE_SITE_USAGE_DATA = 1 << 15, | |
75 // REMOVE_NOCHECKS intentionally does not check if the browser context is | |
76 // prohibited from deleting history or downloads. | |
77 REMOVE_NOCHECKS = 1 << 16, | |
78 REMOVE_CACHE_STORAGE = 1 << 17, | |
79 #if defined(OS_ANDROID) | |
80 REMOVE_WEBAPP_DATA = 1 << 18, | |
81 #endif | |
82 REMOVE_DURABLE_PERMISSION = 1 << 19, | |
83 | |
84 // The following flag is used only in tests. In normal usage, hosted app | |
85 // data is controlled by the REMOVE_COOKIES flag, applied to the | |
86 // protected-web origin. | |
87 REMOVE_HOSTED_APP_DATA_TESTONLY = 1 << 31, | |
88 | |
89 // "Site data" includes cookies, appcache, file systems, indexedDBs, local | |
90 // storage, webSQL, service workers, cache storage, plugin data, web app | |
91 // data (on Android) and statistics about passwords. | |
92 REMOVE_SITE_DATA = REMOVE_APPCACHE | REMOVE_COOKIES | REMOVE_FILE_SYSTEMS | | |
93 REMOVE_INDEXEDDB | | |
94 REMOVE_LOCAL_STORAGE | | |
95 REMOVE_PLUGIN_DATA | | |
96 REMOVE_SERVICE_WORKERS | | |
97 REMOVE_CACHE_STORAGE | | |
98 REMOVE_WEBSQL | | |
99 REMOVE_CHANNEL_IDS | | |
100 #if defined(OS_ANDROID) | |
101 REMOVE_WEBAPP_DATA | | |
102 #endif | |
103 REMOVE_SITE_USAGE_DATA | | |
104 REMOVE_DURABLE_PERMISSION, | |
105 | |
106 // Datatypes protected by Important Sites. | |
107 IMPORTANT_SITES_DATATYPES = REMOVE_SITE_DATA | REMOVE_CACHE, | |
108 | |
109 // Datatypes that can be deleted partially per URL / origin / domain, | |
110 // whichever makes sense. | |
111 FILTERABLE_DATATYPES = REMOVE_SITE_DATA | REMOVE_CACHE | REMOVE_DOWNLOADS, | |
112 | |
113 // Includes all the available remove options. Meant to be used by clients | |
114 // that wish to wipe as much data as possible from a Profile, to make it | |
115 // look like a new Profile. | |
116 REMOVE_ALL = REMOVE_SITE_DATA | REMOVE_CACHE | REMOVE_DOWNLOADS | | |
117 REMOVE_FORM_DATA | | |
118 REMOVE_HISTORY | | |
119 REMOVE_PASSWORDS | | |
120 REMOVE_MEDIA_LICENSES, | |
121 | |
122 // Includes all available remove options. Meant to be used when the Profile | |
123 // is scheduled to be deleted, and all possible data should be wiped from | |
124 // disk as soon as possible. | |
125 REMOVE_WIPE_PROFILE = REMOVE_ALL | REMOVE_NOCHECKS, | |
126 }; | |
127 | |
128 // Important sites protect a small set of sites from the deletion of certain | |
129 // datatypes. Therefore, those datatypes must be filterable by | |
130 // url/origin/domain. | |
131 static_assert(0 == (IMPORTANT_SITES_DATATYPES & ~FILTERABLE_DATATYPES), | |
132 "All important sites datatypes must be filterable."); | |
133 | |
134 // A helper enum to report the deletion of cookies and/or cache. Do not | 58 // A helper enum to report the deletion of cookies and/or cache. Do not |
135 // reorder the entries, as this enum is passed to UMA. | 59 // reorder the entries, as this enum is passed to UMA. |
136 enum CookieOrCacheDeletionChoice { | 60 enum CookieOrCacheDeletionChoice { |
137 NEITHER_COOKIES_NOR_CACHE, | 61 NEITHER_COOKIES_NOR_CACHE, |
138 ONLY_COOKIES, | 62 ONLY_COOKIES, |
139 ONLY_CACHE, | 63 ONLY_CACHE, |
140 BOTH_COOKIES_AND_CACHE, | 64 BOTH_COOKIES_AND_CACHE, |
141 MAX_CHOICE_VALUE | 65 MAX_CHOICE_VALUE |
142 }; | 66 }; |
143 | 67 |
144 // Observer is notified when its own removal task is done. | 68 // Observer is notified when its own removal task is done. |
145 class Observer { | 69 class Observer { |
146 public: | 70 public: |
147 // Called when a removal task is finished. Note that every removal task can | 71 // Called when a removal task is finished. Note that every removal task can |
148 // only have one observer attached to it, and only that one is called. | 72 // only have one observer attached to it, and only that one is called. |
149 virtual void OnBrowsingDataRemoverDone() = 0; | 73 virtual void OnBrowsingDataRemoverDone() = 0; |
150 | 74 |
151 protected: | 75 protected: |
152 virtual ~Observer() {} | 76 virtual ~Observer() {} |
153 }; | 77 }; |
154 | 78 |
155 // Called by the embedder to provide the delegate that will take care of | 79 // Called by the embedder to provide the delegate that will take care of |
156 // deleting embedder-specific data. | 80 // deleting embedder-specific data. |
157 virtual void SetEmbedderDelegate( | 81 virtual void SetEmbedderDelegate( |
158 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) = 0; | 82 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) = 0; |
159 virtual BrowsingDataRemoverDelegate* GetEmbedderDelegate() const = 0; | 83 virtual BrowsingDataRemoverDelegate* GetEmbedderDelegate() const = 0; |
160 | 84 |
161 // Removes browsing data within the given |time_range|, with datatypes being | 85 // Removes browsing data within the given |time_range|, with datatypes being |
162 // specified by |remove_mask| and origin types by |origin_type_mask|. | 86 // specified by |remove_mask| and origin types by |origin_type_mask|. |
163 virtual void Remove(const base::Time& delete_begin, | 87 virtual void Remove( |
164 const base::Time& delete_end, | 88 const base::Time& delete_begin, |
165 int remove_mask, | 89 const base::Time& delete_end, |
166 int origin_type_mask) = 0; | 90 const std::set<const content::BrowsingDataType*>& remove_mask, |
| 91 int origin_type_mask) = 0; |
167 | 92 |
168 // A version of the above that in addition informs the |observer| when the | 93 // A version of the above that in addition informs the |observer| when the |
169 // removal task is finished. | 94 // removal task is finished. |
170 virtual void RemoveAndReply(const base::Time& delete_begin, | 95 virtual void RemoveAndReply( |
171 const base::Time& delete_end, | 96 const base::Time& delete_begin, |
172 int remove_mask, | 97 const base::Time& delete_end, |
173 int origin_type_mask, | 98 const std::set<const content::BrowsingDataType*>& remove_mask, |
174 Observer* observer) = 0; | 99 int origin_type_mask, |
| 100 Observer* observer) = 0; |
175 | 101 |
176 // Like Remove(), but in case of URL-keyed only removes data whose URL match | 102 // Like Remove(), but in case of URL-keyed only removes data whose URL match |
177 // |filter_builder| (e.g. are on certain origin or domain). | 103 // |filter_builder| (e.g. are on certain origin or domain). |
178 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES. | 104 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES. |
179 virtual void RemoveWithFilter( | 105 virtual void RemoveWithFilter( |
180 const base::Time& delete_begin, | 106 const base::Time& delete_begin, |
181 const base::Time& delete_end, | 107 const base::Time& delete_end, |
182 int remove_mask, | 108 const std::set<const content::BrowsingDataType*>& remove_mask, |
183 int origin_type_mask, | 109 int origin_type_mask, |
184 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder) = 0; | 110 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder) = 0; |
185 | 111 |
186 // A version of the above that in addition informs the |observer| when the | 112 // A version of the above that in addition informs the |observer| when the |
187 // removal task is finished. | 113 // removal task is finished. |
188 virtual void RemoveWithFilterAndReply( | 114 virtual void RemoveWithFilterAndReply( |
189 const base::Time& delete_begin, | 115 const base::Time& delete_begin, |
190 const base::Time& delete_end, | 116 const base::Time& delete_end, |
191 int remove_mask, | 117 const std::set<const content::BrowsingDataType*>& remove_mask, |
192 int origin_type_mask, | 118 int origin_type_mask, |
193 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, | 119 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, |
194 Observer* observer) = 0; | 120 Observer* observer) = 0; |
195 | 121 |
196 // Observers. | 122 // Observers. |
197 virtual void AddObserver(Observer* observer) = 0; | 123 virtual void AddObserver(Observer* observer) = 0; |
198 virtual void RemoveObserver(Observer* observer) = 0; | 124 virtual void RemoveObserver(Observer* observer) = 0; |
199 | 125 |
200 // Parameters of the last call are exposed to be used by tests. Removal and | 126 // Parameters of the last call are exposed to be used by tests. Removal and |
201 // origin type masks equal to -1 mean that no removal has ever been executed. | 127 // origin type masks equal to -1 mean that no removal has ever been executed. |
202 // TODO(msramek): If other consumers than tests are interested in this, | 128 // TODO(msramek): If other consumers than tests are interested in this, |
203 // consider returning them in OnBrowsingDataRemoverDone() callback. If not, | 129 // consider returning them in OnBrowsingDataRemoverDone() callback. If not, |
204 // consider simplifying this interface by removing these methods and changing | 130 // consider simplifying this interface by removing these methods and changing |
205 // the tests to record the parameters using GMock instead. | 131 // the tests to record the parameters using GMock instead. |
206 virtual const base::Time& GetLastUsedBeginTime() = 0; | 132 virtual const base::Time& GetLastUsedBeginTime() = 0; |
207 virtual const base::Time& GetLastUsedEndTime() = 0; | 133 virtual const base::Time& GetLastUsedEndTime() = 0; |
208 virtual int GetLastUsedRemovalMask() = 0; | 134 virtual const std::set<const content::BrowsingDataType*>& |
| 135 GetLastUsedRemovalMask() = 0; |
209 virtual int GetLastUsedOriginTypeMask() = 0; | 136 virtual int GetLastUsedOriginTypeMask() = 0; |
210 }; | 137 }; |
211 | 138 |
212 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 139 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
OLD | NEW |