OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_ | |
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <queue> | |
11 #include <set> | |
12 | |
13 #include "base/gtest_prod_util.h" | |
14 #include "base/macros.h" | |
15 #include "base/observer_list.h" | |
16 #include "base/synchronization/waitable_event_watcher.h" | |
17 #include "base/time/time.h" | |
18 #include "build/build_config.h" | |
19 #include "chrome/browser/browsing_data/browsing_data_remover.h" | |
20 #include "chrome/common/features.h" | |
21 #include "ppapi/features/features.h" | |
22 #include "storage/common/quota/quota_types.h" | |
23 #include "url/gurl.h" | |
24 | |
25 class BrowsingDataRemoverFactory; | |
26 | |
27 namespace content { | |
28 class BrowserContext; | |
29 class BrowsingDataFilterBuilder; | |
30 class StoragePartition; | |
31 } | |
32 | |
33 class BrowsingDataRemoverImpl : public BrowsingDataRemover { | |
34 public: | |
35 // Used to track the deletion of a single data storage backend. | |
36 class SubTask { | |
37 public: | |
38 // Creates a SubTask that calls |forward_callback| when completed. | |
39 // |forward_callback| is only kept as a reference and must outlive SubTask. | |
40 explicit SubTask(const base::Closure& forward_callback); | |
41 ~SubTask(); | |
42 | |
43 // Indicate that the task is in progress and we're waiting. | |
44 void Start(); | |
45 | |
46 // Returns a callback that should be called to indicate that the task | |
47 // has been finished. | |
48 base::Closure GetCompletionCallback(); | |
49 | |
50 // Whether the task is still in progress. | |
51 bool is_pending() const { return is_pending_; } | |
52 | |
53 private: | |
54 void CompletionCallback(); | |
55 | |
56 bool is_pending_; | |
57 const base::Closure& forward_callback_; | |
58 base::WeakPtrFactory<SubTask> weak_ptr_factory_; | |
59 }; | |
60 | |
61 // Is the BrowsingDataRemoverImpl currently in the process of removing data? | |
62 bool is_removing() { return is_removing_; } | |
63 | |
64 // BrowsingDataRemover implementation: | |
65 void SetEmbedderDelegate( | |
66 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) override; | |
67 BrowsingDataRemoverDelegate* GetEmbedderDelegate() const override; | |
68 bool DoesOriginMatchMask( | |
69 int origin_type_mask, | |
70 const GURL& origin, | |
71 storage::SpecialStoragePolicy* special_storage_policy) const override; | |
72 void Remove(const base::Time& delete_begin, | |
73 const base::Time& delete_end, | |
74 int remove_mask, | |
75 int origin_type_mask) override; | |
76 void RemoveAndReply(const base::Time& delete_begin, | |
77 const base::Time& delete_end, | |
78 int remove_mask, | |
79 int origin_type_mask, | |
80 Observer* observer) override; | |
81 void RemoveWithFilter( | |
82 const base::Time& delete_begin, | |
83 const base::Time& delete_end, | |
84 int remove_mask, | |
85 int origin_type_mask, | |
86 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder) | |
87 override; | |
88 void RemoveWithFilterAndReply( | |
89 const base::Time& delete_begin, | |
90 const base::Time& delete_end, | |
91 int remove_mask, | |
92 int origin_type_mask, | |
93 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, | |
94 Observer* observer) override; | |
95 | |
96 void AddObserver(Observer* observer) override; | |
97 void RemoveObserver(Observer* observer) override; | |
98 | |
99 void SetWouldCompleteCallbackForTesting( | |
100 const base::Callback<void(const base::Closure& continue_to_completion)>& | |
101 callback) override; | |
102 | |
103 const base::Time& GetLastUsedBeginTime() override; | |
104 const base::Time& GetLastUsedEndTime() override; | |
105 int GetLastUsedRemovalMask() override; | |
106 int GetLastUsedOriginTypeMask() override; | |
107 | |
108 // Used for testing. | |
109 void OverrideStoragePartitionForTesting( | |
110 content::StoragePartition* storage_partition); | |
111 | |
112 protected: | |
113 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of | |
114 // this class. The constructor is protected so that the class is mockable. | |
115 explicit BrowsingDataRemoverImpl(content::BrowserContext* browser_context); | |
116 ~BrowsingDataRemoverImpl() override; | |
117 | |
118 // A common reduction of all public Remove[WithFilter][AndReply] methods. | |
119 virtual void RemoveInternal( | |
120 const base::Time& delete_begin, | |
121 const base::Time& delete_end, | |
122 int remove_mask, | |
123 int origin_type_mask, | |
124 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, | |
125 Observer* observer); | |
126 | |
127 private: | |
128 // Testing the private RemovalTask. | |
129 FRIEND_TEST_ALL_PREFIXES(BrowsingDataRemoverImplTest, MultipleTasks); | |
130 | |
131 friend class BrowsingDataRemoverFactory; | |
132 | |
133 // Represents a single removal task. Contains all parameters needed to execute | |
134 // it and a pointer to the observer that added it. | |
135 struct RemovalTask { | |
136 RemovalTask( | |
137 const base::Time& delete_begin, | |
138 const base::Time& delete_end, | |
139 int remove_mask, | |
140 int origin_type_mask, | |
141 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, | |
142 Observer* observer); | |
143 ~RemovalTask(); | |
144 | |
145 base::Time delete_begin; | |
146 base::Time delete_end; | |
147 int remove_mask; | |
148 int origin_type_mask; | |
149 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder; | |
150 Observer* observer; | |
151 }; | |
152 | |
153 void Shutdown() override; | |
154 | |
155 // Setter for |is_removing_|; DCHECKs that we can only start removing if we're | |
156 // not already removing, and vice-versa. | |
157 void SetRemoving(bool is_removing); | |
158 | |
159 // Executes the next removal task. Called after the previous task was finished | |
160 // or directly from Remove() if the task queue was empty. | |
161 void RunNextTask(); | |
162 | |
163 // Removes the specified items related to browsing for a specific host. If the | |
164 // provided |remove_url| is empty, data is removed for all origins; otherwise, | |
165 // it is restricted by the origin filter origin (where implemented yet). The | |
166 // |origin_type_mask| parameter defines the set of origins from which data | |
167 // should be removed (protected, unprotected, or both). | |
168 // TODO(ttr314): Remove "(where implemented yet)" constraint above once | |
169 // crbug.com/113621 is done. | |
170 // TODO(crbug.com/589586): Support all backends w/ origin filter. | |
171 void RemoveImpl(const base::Time& delete_begin, | |
172 const base::Time& delete_end, | |
173 int remove_mask, | |
174 const content::BrowsingDataFilterBuilder& filter_builder, | |
175 int origin_type_mask); | |
176 | |
177 // Notifies observers and transitions to the idle state. | |
178 void Notify(); | |
179 | |
180 // Checks if we are all done, and if so, calls Notify(). | |
181 void NotifyIfDone(); | |
182 | |
183 // Returns true if we're all done. | |
184 bool AllDone(); | |
185 | |
186 // Like GetWeakPtr(), but returns a weak pointer to BrowsingDataRemoverImpl | |
187 // for internal purposes. | |
188 base::WeakPtr<BrowsingDataRemoverImpl> GetWeakPtr(); | |
189 | |
190 // The browser context we're to remove from. | |
191 content::BrowserContext* browser_context_; | |
192 | |
193 // A delegate to delete the embedder-specific data. | |
194 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate_; | |
195 | |
196 // Start time to delete from. | |
197 base::Time delete_begin_; | |
198 | |
199 // End time to delete to. | |
200 base::Time delete_end_; | |
201 | |
202 // The removal mask for the current removal operation. | |
203 int remove_mask_ = 0; | |
204 | |
205 // From which types of origins should we remove data? | |
206 int origin_type_mask_ = 0; | |
207 | |
208 // True if Remove has been invoked. | |
209 bool is_removing_; | |
210 | |
211 // Removal tasks to be processed. | |
212 std::queue<RemovalTask> task_queue_; | |
213 | |
214 // If non-null, the |would_complete_callback_| is called each time an instance | |
215 // is about to complete a browsing data removal process, and has the ability | |
216 // to artificially delay completion. Used for testing. | |
217 base::Callback<void(const base::Closure& continue_to_completion)> | |
218 would_complete_callback_; | |
219 | |
220 // A callback to NotifyIfDone() used by SubTasks instances. | |
221 const base::Closure sub_task_forward_callback_; | |
222 | |
223 // Keeping track of various subtasks to be completed. | |
224 // These may only be accessed from UI thread in order to avoid races! | |
225 SubTask synchronous_clear_operations_; | |
226 SubTask clear_embedder_data_; | |
227 SubTask clear_cache_; | |
228 SubTask clear_channel_ids_; | |
229 SubTask clear_http_auth_cache_; | |
230 SubTask clear_storage_partition_data_; | |
231 | |
232 // Observers of the global state and individual tasks. | |
233 base::ObserverList<Observer, true> observer_list_; | |
234 | |
235 // We do not own this. | |
236 content::StoragePartition* storage_partition_for_testing_; | |
237 | |
238 base::WeakPtrFactory<BrowsingDataRemoverImpl> weak_ptr_factory_; | |
239 | |
240 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImpl); | |
241 }; | |
242 | |
243 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_ | |
OLD | NEW |