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

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: 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>
(...skipping 15 matching lines...) Expand all
26 class BrowsingDataRemoverFactory; 26 class BrowsingDataRemoverFactory;
27 27
28 namespace content { 28 namespace content {
29 class BrowserContext; 29 class BrowserContext;
30 class BrowsingDataFilterBuilder; 30 class BrowsingDataFilterBuilder;
31 class StoragePartition; 31 class StoragePartition;
32 } 32 }
33 33
34 class BrowsingDataRemoverImpl : public BrowsingDataRemover { 34 class BrowsingDataRemoverImpl : public BrowsingDataRemover {
35 public: 35 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. 36 // Used to track the deletion of a single data storage backend.
53 class SubTask { 37 class SubTask {
54 public: 38 public:
55 // Creates a SubTask that calls |forward_callback| when completed. 39 // Creates a SubTask that calls |forward_callback| when completed.
56 // |forward_callback| is only kept as a reference and must outlive SubTask. 40 // |forward_callback| is only kept as a reference and must outlive SubTask.
57 explicit SubTask(const base::Closure& forward_callback); 41 explicit SubTask(const base::Closure& forward_callback);
58 ~SubTask(); 42 ~SubTask();
59 43
60 // Indicate that the task is in progress and we're waiting. 44 // Indicate that the task is in progress and we're waiting.
61 void Start(); 45 void Start();
62 46
63 // Returns a callback that should be called to indicate that the task 47 // Returns a callback that should be called to indicate that the task
64 // has been finished. 48 // has been finished.
65 base::Closure GetCompletionCallback(); 49 base::Closure GetCompletionCallback();
66 50
67 // Whether the task is still in progress. 51 // Whether the task is still in progress.
68 bool is_pending() const { return is_pending_; } 52 bool is_pending() const { return is_pending_; }
69 53
70 private: 54 private:
71 void CompletionCallback(); 55 void CompletionCallback();
72 56
73 bool is_pending_; 57 bool is_pending_;
74 const base::Closure& forward_callback_; 58 const base::Closure& forward_callback_;
75 base::WeakPtrFactory<SubTask> weak_ptr_factory_; 59 base::WeakPtrFactory<SubTask> weak_ptr_factory_;
76 }; 60 };
77 61
78 // Is the BrowsingDataRemoverImpl currently in the process of removing data? 62 // Is the BrowsingDataRemoverImpl currently in the process of removing data?
79 bool is_removing() { return is_removing_; } 63 bool is_removing() { return is_removing_; }
80 64
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: 65 // BrowsingDataRemover implementation:
91 void SetEmbedderDelegate( 66 void SetEmbedderDelegate(
92 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) override; 67 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) override;
93 BrowsingDataRemoverDelegate* GetEmbedderDelegate() const override; 68 BrowsingDataRemoverDelegate* GetEmbedderDelegate() const override;
94 bool DoesOriginMatchMask( 69 bool DoesOriginMatchMask(
95 int origin_type_mask, 70 int origin_type_mask,
96 const GURL& origin, 71 const GURL& origin,
97 storage::SpecialStoragePolicy* special_storage_policy) const override; 72 storage::SpecialStoragePolicy* special_storage_policy) const override;
98 void Remove(const base::Time& delete_begin, 73 void Remove(const base::Time& delete_begin,
99 const base::Time& delete_end, 74 const base::Time& delete_end,
(...skipping 15 matching lines...) Expand all
115 const base::Time& delete_begin, 90 const base::Time& delete_begin,
116 const base::Time& delete_end, 91 const base::Time& delete_end,
117 int remove_mask, 92 int remove_mask,
118 int origin_type_mask, 93 int origin_type_mask,
119 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, 94 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder,
120 Observer* observer) override; 95 Observer* observer) override;
121 96
122 void AddObserver(Observer* observer) override; 97 void AddObserver(Observer* observer) override;
123 void RemoveObserver(Observer* observer) override; 98 void RemoveObserver(Observer* observer) override;
124 99
100 void SetCompletionInhibitorForTesting(
101 CompletionInhibitor* inhibitor) 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 203
226 // True if Remove has been invoked. 204 // True if Remove has been invoked.
227 bool is_removing_; 205 bool is_removing_;
228 206
229 // Removal tasks to be processed. 207 // Removal tasks to be processed.
230 std::queue<RemovalTask> task_queue_; 208 std::queue<RemovalTask> task_queue_;
231 209
232 // If non-NULL, the |completion_inhibitor_| is notified each time an instance 210 // If non-NULL, the |completion_inhibitor_| is notified each time an instance
233 // is about to complete a browsing data removal process, and has the ability 211 // is about to complete a browsing data removal process, and has the ability
234 // to artificially delay completion. Used for testing. 212 // to artificially delay completion. Used for testing.
235 static CompletionInhibitor* completion_inhibitor_; 213 CompletionInhibitor* completion_inhibitor_;
236 214
237 // A callback to NotifyIfDone() used by SubTasks instances. 215 // A callback to NotifyIfDone() used by SubTasks instances.
238 const base::Closure sub_task_forward_callback_; 216 const base::Closure sub_task_forward_callback_;
239 217
240 // Keeping track of various subtasks to be completed. 218 // Keeping track of various subtasks to be completed.
241 // These may only be accessed from UI thread in order to avoid races! 219 // These may only be accessed from UI thread in order to avoid races!
242 SubTask synchronous_clear_operations_; 220 SubTask synchronous_clear_operations_;
243 SubTask clear_embedder_data_; 221 SubTask clear_embedder_data_;
244 SubTask clear_cache_; 222 SubTask clear_cache_;
245 SubTask clear_channel_ids_; 223 SubTask clear_channel_ids_;
246 SubTask clear_http_auth_cache_; 224 SubTask clear_http_auth_cache_;
247 SubTask clear_storage_partition_data_; 225 SubTask clear_storage_partition_data_;
248 226
249 // Observers of the global state and individual tasks. 227 // Observers of the global state and individual tasks.
250 base::ObserverList<Observer, true> observer_list_; 228 base::ObserverList<Observer, true> observer_list_;
251 229
252 // We do not own this. 230 // We do not own this.
253 content::StoragePartition* storage_partition_for_testing_ = nullptr; 231 content::StoragePartition* storage_partition_for_testing_;
254 232
255 base::WeakPtrFactory<BrowsingDataRemoverImpl> weak_ptr_factory_; 233 base::WeakPtrFactory<BrowsingDataRemoverImpl> weak_ptr_factory_;
256 234
257 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImpl); 235 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImpl);
258 }; 236 };
259 237
260 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_ 238 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698