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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover.cc

Issue 2578723002: Reduce BrowsingDataRemover's dependencies on Chrome (Closed)
Patch Set: A new callsite appeared through rebase - fixed the compilation error. Created 3 years, 11 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 #include "chrome/browser/browsing_data/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" 18 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
19 #include "chrome/browser/browsing_data/browsing_data_helper.h" 19 #include "chrome/browser/browsing_data/browsing_data_helper.h"
20 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" 20 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
21 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" 21 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
22 #include "chrome/browser/download/download_prefs.h"
23 #include "chrome/browser/io_thread.h"
24 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
26 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h" 24 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h"
27 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
28 #include "components/web_cache/browser/web_cache_manager.h" 26 #include "components/web_cache/browser/web_cache_manager.h"
27 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/content_browser_client.h"
30 #include "content/public/browser/download_manager.h" 30 #include "content/public/browser/download_manager.h"
31 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/plugin_data_remover.h" 32 #include "content/public/browser/plugin_data_remover.h"
33 #include "content/public/browser/ssl_host_state_delegate.h" 33 #include "content/public/browser/ssl_host_state_delegate.h"
34 #include "content/public/browser/storage_partition.h" 34 #include "content/public/browser/storage_partition.h"
35 #include "content/public/browser/user_metrics.h" 35 #include "content/public/browser/user_metrics.h"
36 #include "extensions/features/features.h" 36 #include "extensions/features/features.h"
37 #include "media/media_features.h" 37 #include "media/media_features.h"
38 #include "net/base/net_errors.h" 38 #include "net/base/net_errors.h"
39 #include "net/cookies/cookie_store.h" 39 #include "net/cookies/cookie_store.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 weak_ptr_factory_.GetWeakPtr()); 150 weak_ptr_factory_.GetWeakPtr());
151 } 151 }
152 152
153 void BrowsingDataRemover::SubTask::CompletionCallback() { 153 void BrowsingDataRemover::SubTask::CompletionCallback() {
154 DCHECK_CURRENTLY_ON(BrowserThread::UI); 154 DCHECK_CURRENTLY_ON(BrowserThread::UI);
155 DCHECK(is_pending_); 155 DCHECK(is_pending_);
156 is_pending_ = false; 156 is_pending_ = false;
157 forward_callback_.Run(); 157 forward_callback_.Run();
158 } 158 }
159 159
160 bool BrowsingDataRemover::TimeRange::operator==(
161 const BrowsingDataRemover::TimeRange& other) const {
162 return begin == other.begin && end == other.end;
163 }
164
165 // static
166 BrowsingDataRemover::TimeRange BrowsingDataRemover::Unbounded() {
167 return TimeRange(base::Time(), base::Time::Max());
168 }
169
170 // static
171 BrowsingDataRemover::TimeRange BrowsingDataRemover::Period(
172 browsing_data::TimePeriod period) {
173 switch (period) {
174 case browsing_data::LAST_HOUR:
175 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastHour"));
176 break;
177 case browsing_data::LAST_DAY:
178 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastDay"));
179 break;
180 case browsing_data::LAST_WEEK:
181 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastWeek"));
182 break;
183 case browsing_data::FOUR_WEEKS:
184 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastMonth"));
185 break;
186 case browsing_data::ALL_TIME:
187 content::RecordAction(UserMetricsAction("ClearBrowsingData_Everything"));
188 break;
189 }
190 return TimeRange(CalculateBeginDeleteTime(period), base::Time::Max());
191 }
192
193 BrowsingDataRemover::BrowsingDataRemover( 160 BrowsingDataRemover::BrowsingDataRemover(
194 content::BrowserContext* browser_context) 161 content::BrowserContext* browser_context)
195 : profile_(Profile::FromBrowserContext(browser_context)), 162 : browser_context_(browser_context),
196 remove_mask_(-1), 163 remove_mask_(-1),
197 origin_type_mask_(-1), 164 origin_type_mask_(-1),
198 is_removing_(false), 165 is_removing_(false),
199 #if BUILDFLAG(ENABLE_PLUGINS) 166 #if BUILDFLAG(ENABLE_PLUGINS)
200 flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(profile_)), 167 flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(browser_context_)),
201 #endif 168 #endif
202 sub_task_forward_callback_( 169 sub_task_forward_callback_(
203 base::Bind(&BrowsingDataRemover::NotifyIfDone, 170 base::Bind(&BrowsingDataRemover::NotifyIfDone,
204 base::Unretained(this))), 171 base::Unretained(this))),
205 synchronous_clear_operations_(sub_task_forward_callback_), 172 synchronous_clear_operations_(sub_task_forward_callback_),
206 clear_embedder_data_(sub_task_forward_callback_), 173 clear_embedder_data_(sub_task_forward_callback_),
207 clear_cache_(sub_task_forward_callback_), 174 clear_cache_(sub_task_forward_callback_),
208 clear_channel_ids_(sub_task_forward_callback_), 175 clear_channel_ids_(sub_task_forward_callback_),
209 clear_http_auth_cache_(sub_task_forward_callback_), 176 clear_http_auth_cache_(sub_task_forward_callback_),
210 clear_storage_partition_data_(sub_task_forward_callback_), 177 clear_storage_partition_data_(sub_task_forward_callback_),
211 weak_ptr_factory_(this) { 178 weak_ptr_factory_(this) {
212 DCHECK(browser_context); 179 DCHECK(browser_context_);
213 } 180 }
214 181
215 BrowsingDataRemover::~BrowsingDataRemover() { 182 BrowsingDataRemover::~BrowsingDataRemover() {
216 if (!task_queue_.empty()) { 183 if (!task_queue_.empty()) {
217 VLOG(1) << "BrowsingDataRemover shuts down with " << task_queue_.size() 184 VLOG(1) << "BrowsingDataRemover shuts down with " << task_queue_.size()
218 << " pending tasks"; 185 << " pending tasks";
219 } 186 }
220 187
221 // If we are still removing data, notify observers that their task has been 188 // If we are still removing data, notify observers that their task has been
222 // (albeit unsucessfuly) processed, so they can unregister themselves. 189 // (albeit unsucessfuly) processed, so they can unregister themselves.
223 // TODO(bauerb): If it becomes a problem that browsing data might not actually 190 // TODO(bauerb): If it becomes a problem that browsing data might not actually
224 // be fully cleared when an observer is notified, add a success flag. 191 // be fully cleared when an observer is notified, add a success flag.
225 while (!task_queue_.empty()) { 192 while (!task_queue_.empty()) {
226 if (observer_list_.HasObserver(task_queue_.front().observer)) 193 if (observer_list_.HasObserver(task_queue_.front().observer))
227 task_queue_.front().observer->OnBrowsingDataRemoverDone(); 194 task_queue_.front().observer->OnBrowsingDataRemoverDone();
228 task_queue_.pop(); 195 task_queue_.pop();
229 } 196 }
230 } 197 }
231 198
232 void BrowsingDataRemover::Shutdown() { 199 void BrowsingDataRemover::Shutdown() {
233 embedder_delegate_.reset(); 200 embedder_delegate_.reset();
234 } 201 }
235 202
236 void BrowsingDataRemover::SetRemoving(bool is_removing) { 203 void BrowsingDataRemover::SetRemoving(bool is_removing) {
237 DCHECK_NE(is_removing_, is_removing); 204 DCHECK_NE(is_removing_, is_removing);
238 is_removing_ = is_removing; 205 is_removing_ = is_removing;
239 } 206 }
240 207
241 void BrowsingDataRemover::Remove(const TimeRange& time_range, 208 void BrowsingDataRemover::Remove(const base::Time& delete_begin,
209 const base::Time& delete_end,
242 int remove_mask, 210 int remove_mask,
243 int origin_type_mask) { 211 int origin_type_mask) {
244 RemoveInternal(time_range, remove_mask, origin_type_mask, 212 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
245 std::unique_ptr<RegistrableDomainFilterBuilder>(), nullptr); 213 std::unique_ptr<RegistrableDomainFilterBuilder>(), nullptr);
246 } 214 }
247 215
248 void BrowsingDataRemover::RemoveAndReply( 216 void BrowsingDataRemover::RemoveAndReply(
249 const TimeRange& time_range, 217 const base::Time& delete_begin,
218 const base::Time& delete_end,
250 int remove_mask, 219 int remove_mask,
251 int origin_type_mask, 220 int origin_type_mask,
252 Observer* observer) { 221 Observer* observer) {
253 DCHECK(observer); 222 DCHECK(observer);
254 RemoveInternal(time_range, remove_mask, origin_type_mask, 223 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
255 std::unique_ptr<RegistrableDomainFilterBuilder>(), observer); 224 std::unique_ptr<RegistrableDomainFilterBuilder>(), observer);
256 } 225 }
257 226
258 void BrowsingDataRemover::RemoveWithFilter( 227 void BrowsingDataRemover::RemoveWithFilter(
259 const TimeRange& time_range, 228 const base::Time& delete_begin,
229 const base::Time& delete_end,
260 int remove_mask, 230 int remove_mask,
261 int origin_type_mask, 231 int origin_type_mask,
262 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { 232 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
263 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES); 233 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES);
264 DCHECK(filter_builder); 234 DCHECK(filter_builder);
265 RemoveInternal(time_range, remove_mask, origin_type_mask, 235 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
266 std::move(filter_builder), nullptr); 236 std::move(filter_builder), nullptr);
267 } 237 }
268 238
269 void BrowsingDataRemover::RemoveWithFilterAndReply( 239 void BrowsingDataRemover::RemoveWithFilterAndReply(
270 const TimeRange& time_range, 240 const base::Time& delete_begin,
241 const base::Time& delete_end,
271 int remove_mask, 242 int remove_mask,
272 int origin_type_mask, 243 int origin_type_mask,
273 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 244 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
274 Observer* observer) { 245 Observer* observer) {
275 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES); 246 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES);
276 DCHECK(filter_builder); 247 DCHECK(filter_builder);
277 DCHECK(observer); 248 DCHECK(observer);
278 RemoveInternal(time_range, remove_mask, origin_type_mask, 249 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
279 std::move(filter_builder), observer); 250 std::move(filter_builder), observer);
280 } 251 }
281 252
282 void BrowsingDataRemover::RemoveInternal( 253 void BrowsingDataRemover::RemoveInternal(
283 const TimeRange& time_range, 254 const base::Time& delete_begin,
255 const base::Time& delete_end,
284 int remove_mask, 256 int remove_mask,
285 int origin_type_mask, 257 int origin_type_mask,
286 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 258 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
287 Observer* observer) { 259 Observer* observer) {
288 DCHECK(!observer || observer_list_.HasObserver(observer)) 260 DCHECK(!observer || observer_list_.HasObserver(observer))
289 << "Every observer must register itself (by calling AddObserver()) " 261 << "Every observer must register itself (by calling AddObserver()) "
290 << "before observing a removal task."; 262 << "before observing a removal task.";
291 263
292 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter. 264 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter.
293 // No filter is equivalent to one that |IsEmptyBlacklist()|. 265 // No filter is equivalent to one that |IsEmptyBlacklist()|.
294 if (!filter_builder) { 266 if (!filter_builder) {
295 filter_builder = base::MakeUnique<RegistrableDomainFilterBuilder>( 267 filter_builder = base::MakeUnique<RegistrableDomainFilterBuilder>(
296 RegistrableDomainFilterBuilder::BLACKLIST); 268 RegistrableDomainFilterBuilder::BLACKLIST);
297 DCHECK(filter_builder->IsEmptyBlacklist()); 269 DCHECK(filter_builder->IsEmptyBlacklist());
298 } 270 }
299 271
300 task_queue_.emplace( 272 task_queue_.emplace(
301 time_range, 273 delete_begin,
274 delete_end,
302 remove_mask, 275 remove_mask,
303 origin_type_mask, 276 origin_type_mask,
304 std::move(filter_builder), 277 std::move(filter_builder),
305 observer); 278 observer);
306 279
307 // If this is the only scheduled task, execute it immediately. Otherwise, 280 // If this is the only scheduled task, execute it immediately. Otherwise,
308 // it will be automatically executed when all tasks scheduled before it 281 // it will be automatically executed when all tasks scheduled before it
309 // finish. 282 // finish.
310 if (task_queue_.size() == 1) { 283 if (task_queue_.size() == 1) {
311 SetRemoving(true); 284 SetRemoving(true);
312 RunNextTask(); 285 RunNextTask();
313 } 286 }
314 } 287 }
315 288
316 void BrowsingDataRemover::RunNextTask() { 289 void BrowsingDataRemover::RunNextTask() {
317 DCHECK(!task_queue_.empty()); 290 DCHECK(!task_queue_.empty());
318 const RemovalTask& removal_task = task_queue_.front(); 291 const RemovalTask& removal_task = task_queue_.front();
319 292
320 RemoveImpl(removal_task.time_range, 293 RemoveImpl(removal_task.delete_begin,
294 removal_task.delete_end,
321 removal_task.remove_mask, 295 removal_task.remove_mask,
322 *removal_task.filter_builder, 296 *removal_task.filter_builder,
323 removal_task.origin_type_mask); 297 removal_task.origin_type_mask);
324 } 298 }
325 299
326 void BrowsingDataRemover::RemoveImpl( 300 void BrowsingDataRemover::RemoveImpl(
327 const TimeRange& time_range, 301 const base::Time& delete_begin,
302 const base::Time& delete_end,
328 int remove_mask, 303 int remove_mask,
329 const BrowsingDataFilterBuilder& filter_builder, 304 const BrowsingDataFilterBuilder& filter_builder,
330 int origin_type_mask) { 305 int origin_type_mask) {
331 // =============== README before adding more storage backends =============== 306 // =============== README before adding more storage backends ===============
332 // 307 //
333 // If you're adding a data storage backend that is included among 308 // If you're adding a data storage backend that is included among
334 // RemoveDataMask::FILTERABLE_DATATYPES, you must do one of the following: 309 // RemoveDataMask::FILTERABLE_DATATYPES, you must do one of the following:
335 // 1. Support one of the filters generated by |filter_builder|. 310 // 1. Support one of the filters generated by |filter_builder|.
336 // 2. Add a comment explaining why is it acceptable in your case to delete all 311 // 2. Add a comment explaining why is it acceptable in your case to delete all
337 // data without filtering URLs / origins / domains. 312 // data without filtering URLs / origins / domains.
338 // 3. Do not support partial deletion, i.e. only delete your data if 313 // 3. Do not support partial deletion, i.e. only delete your data if
339 // |filter_builder.IsEmptyBlacklist()|. Add a comment explaining why this 314 // |filter_builder.IsEmptyBlacklist()|. Add a comment explaining why this
340 // is acceptable. 315 // is acceptable.
341 synchronous_clear_operations_.Start(); 316 synchronous_clear_operations_.Start();
342 317
343 // crbug.com/140910: Many places were calling this with base::Time() as 318 // crbug.com/140910: Many places were calling this with base::Time() as
344 // delete_end, even though they should've used base::Time::Max(). 319 // delete_end, even though they should've used base::Time::Max().
345 DCHECK_NE(base::Time(), time_range.end); 320 DCHECK_NE(base::Time(), delete_end);
346 321
347 delete_begin_ = time_range.begin; 322 delete_begin_ = delete_begin;
348 delete_end_ = time_range.end; 323 delete_end_ = delete_end;
349 remove_mask_ = remove_mask; 324 remove_mask_ = remove_mask;
350 origin_type_mask_ = origin_type_mask; 325 origin_type_mask_ = origin_type_mask;
351 326
352 if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 327 if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
353 content::RecordAction( 328 content::RecordAction(
354 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); 329 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
355 } 330 }
356 if (origin_type_mask_ & BrowsingDataHelper::PROTECTED_WEB) { 331 if (origin_type_mask_ & BrowsingDataHelper::PROTECTED_WEB) {
357 content::RecordAction( 332 content::RecordAction(
358 UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb")); 333 UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb"));
(...skipping 19 matching lines...) Expand all
378 } else if (remove_mask & REMOVE_CACHE) { 353 } else if (remove_mask & REMOVE_CACHE) {
379 choice = ONLY_CACHE; 354 choice = ONLY_CACHE;
380 } 355 }
381 356
382 UMA_HISTOGRAM_ENUMERATION( 357 UMA_HISTOGRAM_ENUMERATION(
383 "History.ClearBrowsingData.UserDeletedCookieOrCache", 358 "History.ClearBrowsingData.UserDeletedCookieOrCache",
384 choice, MAX_CHOICE_VALUE); 359 choice, MAX_CHOICE_VALUE);
385 360
386 // Managed devices and supervised users can have restrictions on history 361 // Managed devices and supervised users can have restrictions on history
387 // deletion. 362 // deletion.
388 PrefService* prefs = profile_->GetPrefs(); 363 // TODO(crbug.com/668114): This should be provided via ContentBrowserClient
389 bool may_delete_history = prefs->GetBoolean( 364 // once BrowsingDataRemover moves to content.
390 prefs::kAllowDeletingBrowserHistory); 365 PrefService* prefs =
366 Profile::FromBrowserContext(browser_context_)->GetPrefs();
367 bool may_delete_history =
368 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
391 369
392 // All the UI entry points into the BrowsingDataRemover should be disabled, 370 // All the UI entry points into the BrowsingDataRemover should be disabled,
393 // but this will fire if something was missed or added. 371 // but this will fire if something was missed or added.
394 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || 372 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
395 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); 373 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
396 374
397 ////////////////////////////////////////////////////////////////////////////// 375 //////////////////////////////////////////////////////////////////////////////
398 // INITIALIZATION 376 // INITIALIZATION
399 base::Callback<bool(const GURL& url)> filter = 377 base::Callback<bool(const GURL& url)> filter =
400 filter_builder.BuildGeneralFilter(); 378 filter_builder.BuildGeneralFilter();
401 379
402 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { 380 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
403 // The SSL Host State that tracks SSL interstitial "proceed" decisions may 381 // The SSL Host State that tracks SSL interstitial "proceed" decisions may
404 // include origins that the user has visited, so it must be cleared. 382 // include origins that the user has visited, so it must be cleared.
405 // TODO(msramek): We can reuse the plugin filter here, since both plugins 383 // TODO(msramek): We can reuse the plugin filter here, since both plugins
406 // and SSL host state are scoped to hosts and represent them as std::string. 384 // and SSL host state are scoped to hosts and represent them as std::string.
407 // Rename the method to indicate its more general usage. 385 // Rename the method to indicate its more general usage.
408 if (profile_->GetSSLHostStateDelegate()) { 386 if (browser_context_->GetSSLHostStateDelegate()) {
409 profile_->GetSSLHostStateDelegate()->Clear( 387 browser_context_->GetSSLHostStateDelegate()->Clear(
410 filter_builder.IsEmptyBlacklist() 388 filter_builder.IsEmptyBlacklist()
411 ? base::Callback<bool(const std::string&)>() 389 ? base::Callback<bool(const std::string&)>()
412 : filter_builder.BuildPluginFilter()); 390 : filter_builder.BuildPluginFilter());
413 } 391 }
414 } 392 }
415 393
416 ////////////////////////////////////////////////////////////////////////////// 394 //////////////////////////////////////////////////////////////////////////////
417 // REMOVE_DOWNLOADS 395 // REMOVE_DOWNLOADS
418 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { 396 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
419 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); 397 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
420 content::DownloadManager* download_manager = 398 content::DownloadManager* download_manager =
421 BrowserContext::GetDownloadManager(profile_); 399 BrowserContext::GetDownloadManager(browser_context_);
422 download_manager->RemoveDownloadsByURLAndTime(filter, 400 download_manager->RemoveDownloadsByURLAndTime(filter,
423 delete_begin_, delete_end_); 401 delete_begin_, delete_end_);
424 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager(
425 download_manager);
426 download_prefs->SetSaveFilePath(download_prefs->DownloadPath());
427 } 402 }
428 403
429 ////////////////////////////////////////////////////////////////////////////// 404 //////////////////////////////////////////////////////////////////////////////
430 // REMOVE_CHANNEL_IDS 405 // REMOVE_CHANNEL_IDS
431 // Channel IDs are not separated for protected and unprotected web 406 // Channel IDs are not separated for protected and unprotected web
432 // origins. We check the origin_type_mask_ to prevent unintended deletion. 407 // origins. We check the origin_type_mask_ to prevent unintended deletion.
433 if (remove_mask & REMOVE_CHANNEL_IDS && 408 if (remove_mask & REMOVE_CHANNEL_IDS &&
434 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 409 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
435 content::RecordAction( 410 content::RecordAction(
436 UserMetricsAction("ClearBrowsingData_ChannelIDs")); 411 UserMetricsAction("ClearBrowsingData_ChannelIDs"));
437 // Since we are running on the UI thread don't call GetURLRequestContext(). 412 // Since we are running on the UI thread don't call GetURLRequestContext().
438 scoped_refptr<net::URLRequestContextGetter> rq_context = 413 scoped_refptr<net::URLRequestContextGetter> rq_context =
439 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 414 content::BrowserContext::GetDefaultStoragePartition(browser_context_)->
440 GetURLRequestContext(); 415 GetURLRequestContext();
441 clear_channel_ids_.Start(); 416 clear_channel_ids_.Start();
442 BrowserThread::PostTask( 417 BrowserThread::PostTask(
443 BrowserThread::IO, FROM_HERE, 418 BrowserThread::IO, FROM_HERE,
444 base::Bind(&ClearChannelIDsOnIOThread, 419 base::Bind(&ClearChannelIDsOnIOThread,
445 filter_builder.BuildChannelIDFilter(), 420 filter_builder.BuildChannelIDFilter(),
446 delete_begin_, delete_end_, std::move(rq_context), 421 delete_begin_, delete_end_, std::move(rq_context),
447 clear_channel_ids_.GetCompletionCallback())); 422 clear_channel_ids_.GetCompletionCallback()));
448 } 423 }
449 424
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 // Flash (which are deleted father down in this method). 470 // Flash (which are deleted father down in this method).
496 if (remove_mask & REMOVE_MEDIA_LICENSES) { 471 if (remove_mask & REMOVE_MEDIA_LICENSES) {
497 storage_partition_remove_mask |= 472 storage_partition_remove_mask |=
498 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA; 473 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA;
499 } 474 }
500 475
501 if (storage_partition_remove_mask) { 476 if (storage_partition_remove_mask) {
502 clear_storage_partition_data_.Start(); 477 clear_storage_partition_data_.Start();
503 478
504 content::StoragePartition* storage_partition; 479 content::StoragePartition* storage_partition;
505 if (storage_partition_for_testing_) 480 if (storage_partition_for_testing_) {
506 storage_partition = storage_partition_for_testing_; 481 storage_partition = storage_partition_for_testing_;
507 else 482 } else {
508 storage_partition = BrowserContext::GetDefaultStoragePartition(profile_); 483 storage_partition =
484 BrowserContext::GetDefaultStoragePartition(browser_context_);
485 }
509 486
510 uint32_t quota_storage_remove_mask = 487 uint32_t quota_storage_remove_mask =
511 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 488 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
512 489
513 if (delete_begin_ == base::Time() || 490 if (delete_begin_ == base::Time() ||
514 origin_type_mask_ & 491 origin_type_mask_ &
515 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { 492 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
516 // If we're deleting since the beginning of time, or we're removing 493 // If we're deleting since the beginning of time, or we're removing
517 // protected origins, then remove persistent quota data. 494 // protected origins, then remove persistent quota data.
518 quota_storage_remove_mask |= 495 quota_storage_remove_mask |=
(...skipping 21 matching lines...) Expand all
540 #if BUILDFLAG(ENABLE_PLUGINS) 517 #if BUILDFLAG(ENABLE_PLUGINS)
541 // Plugin is data not separated for protected and unprotected web origins. We 518 // Plugin is data not separated for protected and unprotected web origins. We
542 // check the origin_type_mask_ to prevent unintended deletion. 519 // check the origin_type_mask_ to prevent unintended deletion.
543 if (remove_mask & REMOVE_PLUGIN_DATA && 520 if (remove_mask & REMOVE_PLUGIN_DATA &&
544 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 521 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
545 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); 522 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
546 clear_plugin_data_count_ = 1; 523 clear_plugin_data_count_ = 1;
547 524
548 if (filter_builder.IsEmptyBlacklist()) { 525 if (filter_builder.IsEmptyBlacklist()) {
549 DCHECK(!plugin_data_remover_); 526 DCHECK(!plugin_data_remover_);
550 plugin_data_remover_.reset(content::PluginDataRemover::Create(profile_)); 527 plugin_data_remover_.reset(
528 content::PluginDataRemover::Create(browser_context_));
551 base::WaitableEvent* event = 529 base::WaitableEvent* event =
552 plugin_data_remover_->StartRemoving(delete_begin_); 530 plugin_data_remover_->StartRemoving(delete_begin_);
553 531
554 base::WaitableEventWatcher::EventCallback watcher_callback = 532 base::WaitableEventWatcher::EventCallback watcher_callback =
555 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, 533 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
556 weak_ptr_factory_.GetWeakPtr()); 534 weak_ptr_factory_.GetWeakPtr());
557 watcher_.StartWatching(event, watcher_callback); 535 watcher_.StartWatching(event, watcher_callback);
558 } else { 536 } else {
559 // TODO(msramek): Store filters from the currently executed task on the 537 // TODO(msramek): Store filters from the currently executed task on the
560 // object to avoid having to copy them to callback methods. 538 // object to avoid having to copy them to callback methods.
(...skipping 10 matching lines...) Expand all
571 if (remove_mask & REMOVE_CACHE) { 549 if (remove_mask & REMOVE_CACHE) {
572 // Tell the renderers to clear their cache. 550 // Tell the renderers to clear their cache.
573 web_cache::WebCacheManager::GetInstance()->ClearCache(); 551 web_cache::WebCacheManager::GetInstance()->ClearCache();
574 552
575 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); 553 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
576 554
577 clear_cache_.Start(); 555 clear_cache_.Start();
578 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. 556 // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
579 if (filter_builder.IsEmptyBlacklist()) { 557 if (filter_builder.IsEmptyBlacklist()) {
580 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( 558 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
581 BrowserContext::GetDefaultStoragePartition(profile_), 559 BrowserContext::GetDefaultStoragePartition(browser_context_),
582 delete_begin_, delete_end_) 560 delete_begin_, delete_end_)
583 ->Remove(clear_cache_.GetCompletionCallback()); 561 ->Remove(clear_cache_.GetCompletionCallback());
584 } else { 562 } else {
585 browsing_data::StoragePartitionHttpCacheDataRemover:: 563 browsing_data::StoragePartitionHttpCacheDataRemover::
586 CreateForURLsAndRange( 564 CreateForURLsAndRange(
587 BrowserContext::GetDefaultStoragePartition(profile_), 565 BrowserContext::GetDefaultStoragePartition(browser_context_),
588 filter, delete_begin_, delete_end_) 566 filter, delete_begin_, delete_end_)
589 ->Remove(clear_cache_.GetCompletionCallback()); 567 ->Remove(clear_cache_.GetCompletionCallback());
590 } 568 }
591 569
592 // Tell the shader disk cache to clear. 570 // Tell the shader disk cache to clear.
593 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); 571 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache"));
594 storage_partition_remove_mask |= 572 storage_partition_remove_mask |=
595 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; 573 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
596 } 574 }
597 575
598 ////////////////////////////////////////////////////////////////////////////// 576 //////////////////////////////////////////////////////////////////////////////
599 // Auth cache. 577 // Auth cache.
600 if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) { 578 if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) {
601 scoped_refptr<net::URLRequestContextGetter> request_context = 579 scoped_refptr<net::URLRequestContextGetter> request_context =
602 profile_->GetRequestContext(); 580 BrowserContext::GetDefaultStoragePartition(browser_context_)
581 ->GetURLRequestContext();
603 clear_http_auth_cache_.Start(); 582 clear_http_auth_cache_.Start();
604 BrowserThread::PostTaskAndReply( 583 BrowserThread::PostTaskAndReply(
605 BrowserThread::IO, FROM_HERE, 584 BrowserThread::IO, FROM_HERE,
606 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context), 585 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context),
607 delete_begin_), 586 delete_begin_),
608 clear_http_auth_cache_.GetCompletionCallback()); 587 clear_http_auth_cache_.GetCompletionCallback());
609 } 588 }
610 589
611 ////////////////////////////////////////////////////////////////////////////// 590 //////////////////////////////////////////////////////////////////////////////
612 // Embedder data. 591 // Embedder data.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 634
656 int BrowsingDataRemover::GetLastUsedRemovalMask() { 635 int BrowsingDataRemover::GetLastUsedRemovalMask() {
657 return remove_mask_; 636 return remove_mask_;
658 } 637 }
659 638
660 int BrowsingDataRemover::GetLastUsedOriginTypeMask() { 639 int BrowsingDataRemover::GetLastUsedOriginTypeMask() {
661 return origin_type_mask_; 640 return origin_type_mask_;
662 } 641 }
663 642
664 BrowsingDataRemover::RemovalTask::RemovalTask( 643 BrowsingDataRemover::RemovalTask::RemovalTask(
665 const TimeRange& time_range, 644 const base::Time& delete_begin,
645 const base::Time& delete_end,
666 int remove_mask, 646 int remove_mask,
667 int origin_type_mask, 647 int origin_type_mask,
668 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 648 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
669 Observer* observer) 649 Observer* observer)
670 : time_range(time_range), 650 : delete_begin(delete_begin),
651 delete_end(delete_end),
671 remove_mask(remove_mask), 652 remove_mask(remove_mask),
672 origin_type_mask(origin_type_mask), 653 origin_type_mask(origin_type_mask),
673 filter_builder(std::move(filter_builder)), 654 filter_builder(std::move(filter_builder)),
674 observer(observer) {} 655 observer(observer) {}
675 656
676 BrowsingDataRemover::RemovalTask::~RemovalTask() {} 657 BrowsingDataRemover::RemovalTask::~RemovalTask() {}
677 658
678 bool BrowsingDataRemover::AllDone() { 659 bool BrowsingDataRemover::AllDone() {
679 return !synchronous_clear_operations_.is_pending() && 660 return !synchronous_clear_operations_.is_pending() &&
680 !clear_embedder_data_.is_pending() && 661 !clear_embedder_data_.is_pending() &&
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 } 756 }
776 757
777 NotifyIfDone(); 758 NotifyIfDone();
778 } 759 }
779 760
780 void BrowsingDataRemover::OnFlashDataDeleted() { 761 void BrowsingDataRemover::OnFlashDataDeleted() {
781 clear_plugin_data_count_--; 762 clear_plugin_data_count_--;
782 NotifyIfDone(); 763 NotifyIfDone();
783 } 764 }
784 #endif 765 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698