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

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

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

Powered by Google App Engine
This is Rietveld 408576698