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

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

Issue 2802013002: Move BrowsingDataRemoverImpl:: CompletionInhibitor to the public interface (Closed)
Patch Set: Finishing after shutdown is still OK. Created 3 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_IMPL_H_ 5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_ 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
11 #include <set> 11 #include <set>
12 12
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 15 #include "base/observer_list.h"
17 #include "base/synchronization/waitable_event_watcher.h" 16 #include "base/synchronization/waitable_event_watcher.h"
18 #include "base/time/time.h" 17 #include "base/time/time.h"
19 #include "build/build_config.h" 18 #include "build/build_config.h"
20 #include "chrome/browser/browsing_data/browsing_data_remover.h" 19 #include "chrome/browser/browsing_data/browsing_data_remover.h"
21 #include "chrome/common/features.h" 20 #include "chrome/common/features.h"
22 #include "ppapi/features/features.h" 21 #include "ppapi/features/features.h"
23 #include "storage/common/quota/quota_types.h" 22 #include "storage/common/quota/quota_types.h"
24 #include "url/gurl.h" 23 #include "url/gurl.h"
25 24
26 class BrowsingDataRemoverFactory; 25 class BrowsingDataRemoverFactory;
27 26
28 namespace content { 27 namespace content {
29 class BrowserContext; 28 class BrowserContext;
30 class BrowsingDataFilterBuilder; 29 class BrowsingDataFilterBuilder;
31 class StoragePartition; 30 class StoragePartition;
32 } 31 }
33 32
34 class BrowsingDataRemoverImpl : public BrowsingDataRemover { 33 class BrowsingDataRemoverImpl : public BrowsingDataRemover {
35 public: 34 public:
36 // The completion inhibitor can artificially delay completion of the browsing
37 // data removal process. It is used during testing to simulate scenarios in
38 // which the deletion stalls or takes a very long time.
39 class CompletionInhibitor {
40 public:
41 // Invoked when a |remover| is just about to complete clearing browser data,
42 // and will be prevented from completing until after the callback
43 // |continue_to_completion| is run.
44 virtual void OnBrowsingDataRemoverWouldComplete(
45 BrowsingDataRemoverImpl* remover,
46 const base::Closure& continue_to_completion) = 0;
47
48 protected:
49 virtual ~CompletionInhibitor() {}
50 };
51
52 // Used to track the deletion of a single data storage backend. 35 // Used to track the deletion of a single data storage backend.
53 class SubTask { 36 class SubTask {
54 public: 37 public:
55 // Creates a SubTask that calls |forward_callback| when completed. 38 // Creates a SubTask that calls |forward_callback| when completed.
56 // |forward_callback| is only kept as a reference and must outlive SubTask. 39 // |forward_callback| is only kept as a reference and must outlive SubTask.
57 explicit SubTask(const base::Closure& forward_callback); 40 explicit SubTask(const base::Closure& forward_callback);
58 ~SubTask(); 41 ~SubTask();
59 42
60 // Indicate that the task is in progress and we're waiting. 43 // Indicate that the task is in progress and we're waiting.
61 void Start(); 44 void Start();
62 45
63 // Returns a callback that should be called to indicate that the task 46 // Returns a callback that should be called to indicate that the task
64 // has been finished. 47 // has been finished.
65 base::Closure GetCompletionCallback(); 48 base::Closure GetCompletionCallback();
66 49
67 // Whether the task is still in progress. 50 // Whether the task is still in progress.
68 bool is_pending() const { return is_pending_; } 51 bool is_pending() const { return is_pending_; }
69 52
70 private: 53 private:
71 void CompletionCallback(); 54 void CompletionCallback();
72 55
73 bool is_pending_; 56 bool is_pending_;
74 const base::Closure& forward_callback_; 57 const base::Closure& forward_callback_;
75 base::WeakPtrFactory<SubTask> weak_ptr_factory_; 58 base::WeakPtrFactory<SubTask> weak_ptr_factory_;
76 }; 59 };
77 60
78 // Is the BrowsingDataRemoverImpl currently in the process of removing data? 61 // Is the BrowsingDataRemoverImpl currently in the process of removing data?
79 bool is_removing() { return is_removing_; } 62 bool is_removing() { return is_removing_; }
80 63
81 // Sets a CompletionInhibitor, which will be notified each time an instance is
82 // about to complete a browsing data removal process, and will be able to
83 // artificially delay the completion.
84 // TODO(crbug.com/483528): Make this non-static.
85 static void set_completion_inhibitor_for_testing(
86 CompletionInhibitor* inhibitor) {
87 completion_inhibitor_ = inhibitor;
88 }
89
90 // BrowsingDataRemover implementation: 64 // BrowsingDataRemover implementation:
91 void SetEmbedderDelegate( 65 void SetEmbedderDelegate(
92 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) override; 66 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) override;
93 BrowsingDataRemoverDelegate* GetEmbedderDelegate() const override; 67 BrowsingDataRemoverDelegate* GetEmbedderDelegate() const override;
94 bool DoesOriginMatchMask( 68 bool DoesOriginMatchMask(
95 int origin_type_mask, 69 int origin_type_mask,
96 const GURL& origin, 70 const GURL& origin,
97 storage::SpecialStoragePolicy* special_storage_policy) const override; 71 storage::SpecialStoragePolicy* special_storage_policy) const override;
98 void Remove(const base::Time& delete_begin, 72 void Remove(const base::Time& delete_begin,
99 const base::Time& delete_end, 73 const base::Time& delete_end,
(...skipping 15 matching lines...) Expand all
115 const base::Time& delete_begin, 89 const base::Time& delete_begin,
116 const base::Time& delete_end, 90 const base::Time& delete_end,
117 int remove_mask, 91 int remove_mask,
118 int origin_type_mask, 92 int origin_type_mask,
119 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, 93 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder,
120 Observer* observer) override; 94 Observer* observer) override;
121 95
122 void AddObserver(Observer* observer) override; 96 void AddObserver(Observer* observer) override;
123 void RemoveObserver(Observer* observer) override; 97 void RemoveObserver(Observer* observer) override;
124 98
99 void SetWouldCompleteCallbackForTesting(
100 const base::Callback<void(const base::Closure& continue_to_completion)>&
101 callback) override;
102
125 const base::Time& GetLastUsedBeginTime() override; 103 const base::Time& GetLastUsedBeginTime() override;
126 const base::Time& GetLastUsedEndTime() override; 104 const base::Time& GetLastUsedEndTime() override;
127 int GetLastUsedRemovalMask() override; 105 int GetLastUsedRemovalMask() override;
128 int GetLastUsedOriginTypeMask() override; 106 int GetLastUsedOriginTypeMask() override;
129 107
130 // Used for testing. 108 // Used for testing.
131 void OverrideStoragePartitionForTesting( 109 void OverrideStoragePartitionForTesting(
132 content::StoragePartition* storage_partition); 110 content::StoragePartition* storage_partition);
133 111
134 protected: 112 protected:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 176
199 // Notifies observers and transitions to the idle state. 177 // Notifies observers and transitions to the idle state.
200 void Notify(); 178 void Notify();
201 179
202 // Checks if we are all done, and if so, calls Notify(). 180 // Checks if we are all done, and if so, calls Notify().
203 void NotifyIfDone(); 181 void NotifyIfDone();
204 182
205 // Returns true if we're all done. 183 // Returns true if we're all done.
206 bool AllDone(); 184 bool AllDone();
207 185
208 // Retrieve a UI thread-bound weak pointer to this BrowsingDataRemoverImpl. 186 // Like GetWeakPtr(), but returns a weak pointer to BrowsingDataRemoverImpl
187 // for internal purposes.
209 base::WeakPtr<BrowsingDataRemoverImpl> GetWeakPtr(); 188 base::WeakPtr<BrowsingDataRemoverImpl> GetWeakPtr();
210 189
211 // The browser context we're to remove from. 190 // The browser context we're to remove from.
212 content::BrowserContext* browser_context_; 191 content::BrowserContext* browser_context_;
213 192
214 // A delegate to delete the embedder-specific data. 193 // A delegate to delete the embedder-specific data.
215 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate_; 194 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate_;
216 195
217 // Start time to delete from. 196 // Start time to delete from.
218 base::Time delete_begin_; 197 base::Time delete_begin_;
219 198
220 // End time to delete to. 199 // End time to delete to.
221 base::Time delete_end_; 200 base::Time delete_end_;
222 201
223 // The removal mask for the current removal operation. 202 // The removal mask for the current removal operation.
224 int remove_mask_ = 0; 203 int remove_mask_ = 0;
225 204
226 // From which types of origins should we remove data? 205 // From which types of origins should we remove data?
227 int origin_type_mask_ = 0; 206 int origin_type_mask_ = 0;
228 207
229 // True if Remove has been invoked. 208 // True if Remove has been invoked.
230 bool is_removing_; 209 bool is_removing_;
231 210
232 // Removal tasks to be processed. 211 // Removal tasks to be processed.
233 std::queue<RemovalTask> task_queue_; 212 std::queue<RemovalTask> task_queue_;
234 213
235 // If non-NULL, the |completion_inhibitor_| is notified each time an instance 214 // If non-null, the |would_complete_callback_| is called each time an instance
236 // is about to complete a browsing data removal process, and has the ability 215 // is about to complete a browsing data removal process, and has the ability
237 // to artificially delay completion. Used for testing. 216 // to artificially delay completion. Used for testing.
238 static CompletionInhibitor* completion_inhibitor_; 217 base::Callback<void(const base::Closure& continue_to_completion)>
218 would_complete_callback_;
239 219
240 // A callback to NotifyIfDone() used by SubTasks instances. 220 // A callback to NotifyIfDone() used by SubTasks instances.
241 const base::Closure sub_task_forward_callback_; 221 const base::Closure sub_task_forward_callback_;
242 222
243 // Keeping track of various subtasks to be completed. 223 // Keeping track of various subtasks to be completed.
244 // These may only be accessed from UI thread in order to avoid races! 224 // These may only be accessed from UI thread in order to avoid races!
245 SubTask synchronous_clear_operations_; 225 SubTask synchronous_clear_operations_;
246 SubTask clear_embedder_data_; 226 SubTask clear_embedder_data_;
247 SubTask clear_cache_; 227 SubTask clear_cache_;
248 SubTask clear_channel_ids_; 228 SubTask clear_channel_ids_;
249 SubTask clear_http_auth_cache_; 229 SubTask clear_http_auth_cache_;
250 SubTask clear_storage_partition_data_; 230 SubTask clear_storage_partition_data_;
251 231
252 // Observers of the global state and individual tasks. 232 // Observers of the global state and individual tasks.
253 base::ObserverList<Observer, true> observer_list_; 233 base::ObserverList<Observer, true> observer_list_;
254 234
255 // We do not own this. 235 // We do not own this.
256 content::StoragePartition* storage_partition_for_testing_ = nullptr; 236 content::StoragePartition* storage_partition_for_testing_;
257 237
258 base::WeakPtrFactory<BrowsingDataRemoverImpl> weak_ptr_factory_; 238 base::WeakPtrFactory<BrowsingDataRemoverImpl> weak_ptr_factory_;
259 239
260 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImpl); 240 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImpl);
261 }; 241 };
262 242
263 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_ 243 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover.h ('k') | chrome/browser/browsing_data/browsing_data_remover_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698