OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_remover.h" | 5 #include "chrome/browser/browsing_data_remover.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
| 10 #include "base/logging.h" |
| 11 |
10 #include "base/callback.h" | 12 #include "base/callback.h" |
11 #include "base/file_util.h" | 13 #include "base/file_util.h" |
12 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
13 #include "chrome/browser/autofill/personal_data_manager.h" | 15 #include "chrome/browser/autofill/personal_data_manager.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/download/download_manager.h" | 17 #include "chrome/browser/download/download_manager.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 19 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
18 #include "chrome/browser/history/history.h" | 20 #include "chrome/browser/history/history.h" |
19 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 main_context_getter_->GetURLRequestContext()); | 555 main_context_getter_->GetURLRequestContext()); |
554 return request_context ? request_context->appcache_service() | 556 return request_context ? request_context->appcache_service() |
555 : NULL; | 557 : NULL; |
556 } | 558 } |
557 | 559 |
558 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { | 560 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { |
559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
560 DCHECK(waiting_for_clear_file_systems_); | 562 DCHECK(waiting_for_clear_file_systems_); |
561 scoped_refptr<fileapi::FileSystemContext> | 563 scoped_refptr<fileapi::FileSystemContext> |
562 fs_context(profile_->GetFileSystemContext()); | 564 fs_context(profile_->GetFileSystemContext()); |
| 565 |
| 566 // As long as the FileSystemContext is refcounted, we can use a raw pointer |
| 567 // here, and let the FileSystemContext delete the FileSystemFileUtil when |
| 568 // it's destroyed. |
| 569 fileapi::FileSystemFileUtil* file_util = fs_context->path_manager()-> |
| 570 sandbox_provider()->GetFileSystemFileUtil(); |
| 571 |
| 572 scoped_ptr<fileapi::FileSystemOperationContext> |
| 573 op_context(new fileapi::FileSystemOperationContext( |
| 574 fs_context.get(), file_util)); |
| 575 |
| 576 // We own the reference to the OriginEnumerator, so we wrap it in a scoped_ptr |
| 577 // to ensure that it's destroyed when we leave the FILE thread. |
563 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> | 578 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> |
564 origin_enumerator(fs_context->path_manager()->sandbox_provider()-> | 579 origins(fs_context->path_manager()->sandbox_provider()-> |
565 CreateOriginEnumerator()); | 580 CreateOriginEnumerator()); |
566 | 581 |
567 GURL origin; | 582 GURL origin; |
568 while (!(origin = origin_enumerator->Next()).is_empty()) { | 583 while (!(origin = origins->Next()).is_empty()) { |
569 if (special_storage_policy_->IsStorageProtected(origin)) | 584 if (special_storage_policy_->IsStorageProtected(origin)) |
570 continue; | 585 continue; |
571 if (delete_begin_ == base::Time()) { | 586 if (delete_begin_ == base::Time()) { |
572 // If the user chooses to delete browsing data "since the beginning of | 587 // If the user chooses to delete browsing data "since the beginning of |
573 // time" remove both temporary and persistent file systems entirely. | 588 // time" remove both temporary and persistent file systems entirely. |
574 fs_context->DeleteDataForOriginAndTypeOnFileThread(origin, | 589 fs_context->DeleteDataForOriginOnFileThread(origin); |
575 fileapi::kFileSystemTypeTemporary); | 590 } else { |
576 fs_context->DeleteDataForOriginAndTypeOnFileThread(origin, | 591 // Else, walk through the origin's temporary filesystem. If any file has |
577 fileapi::kFileSystemTypePersistent); | 592 // been modified in the timeframe, remove the entire filesystem. |
| 593 if (origins->HasFileSystemType(fileapi::kFileSystemTypeTemporary)) { |
| 594 op_context->set_src_origin_url(origin); |
| 595 op_context->set_src_type(fileapi::kFileSystemTypeTemporary); |
| 596 |
| 597 // TODO(mkwst): Replace the FileEnumerator with a check against the |
| 598 // quota system, once last_modified dates are available. |
| 599 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> files( |
| 600 file_util->CreateFileEnumerator(op_context.get(), |
| 601 FilePath(FILE_PATH_LITERAL("/")))); |
| 602 |
| 603 FilePath current; |
| 604 bool was_modified = false; |
| 605 while (!(current = files->Next()).empty()) { |
| 606 base::PlatformFileInfo file_info; |
| 607 FilePath platform_file_path; |
| 608 base::PlatformFileError error_code; |
| 609 error_code = file_util->GetFileInfo(op_context.get(), current, |
| 610 &file_info, &platform_file_path); |
| 611 if (error_code == base::PLATFORM_FILE_OK && |
| 612 file_info.last_modified >= delete_begin_) { |
| 613 was_modified = true; |
| 614 break; |
| 615 } |
| 616 } |
| 617 if (was_modified) { |
| 618 fs_context->DeleteDataForOriginAndTypeOnFileThread(origin, |
| 619 fileapi::kFileSystemTypeTemporary); |
| 620 } |
| 621 } |
578 } | 622 } |
579 // TODO(mkwst): Else? Decide what to do for time-based deletion: crbug/63700 | |
580 } | 623 } |
581 | 624 |
582 BrowserThread::PostTask( | 625 BrowserThread::PostTask( |
583 BrowserThread::UI, FROM_HERE, | 626 BrowserThread::UI, FROM_HERE, |
584 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems)); | 627 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems)); |
585 } | 628 } |
586 | 629 |
587 void BrowsingDataRemover::OnClearedFileSystems() { | 630 void BrowsingDataRemover::OnClearedFileSystems() { |
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
589 waiting_for_clear_file_systems_ = false; | 632 waiting_for_clear_file_systems_ = false; |
(...skipping 26 matching lines...) Expand all Loading... |
616 | 659 |
617 ClearGearsData(profile_dir); | 660 ClearGearsData(profile_dir); |
618 OnClearedGearsData(); | 661 OnClearedGearsData(); |
619 } | 662 } |
620 | 663 |
621 void BrowsingDataRemover::OnWaitableEventSignaled( | 664 void BrowsingDataRemover::OnWaitableEventSignaled( |
622 base::WaitableEvent* waitable_event) { | 665 base::WaitableEvent* waitable_event) { |
623 waiting_for_clear_lso_data_ = false; | 666 waiting_for_clear_lso_data_ = false; |
624 NotifyAndDeleteIfDone(); | 667 NotifyAndDeleteIfDone(); |
625 } | 668 } |
OLD | NEW |