Chromium Code Reviews| Index: chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc |
| diff --git a/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc b/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc |
| index 770b9e99533692577152f7fe31ba638987a2decb..fb5a13566a06f0441d2c6c769c542bfd840e7535 100644 |
| --- a/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc |
| +++ b/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc |
| @@ -5,7 +5,9 @@ |
| #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
| #include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| #include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| #include "base/location.h" |
| #include "base/logging.h" |
| #include "base/strings/string16.h" |
| @@ -15,6 +17,7 @@ |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| #include "components/security_state/security_state_model.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/mhtml_generation_params.h" |
| #include "net/base/filename_util.h" |
| @@ -29,6 +32,21 @@ const char kMHTMLFileNameExtension[] = ".mhtml"; |
| const char kFileNameComponentsSeparator[] = "-"; |
| const char kReplaceChars[] = " "; |
| const char kReplaceWith[] = "_"; |
| + |
| +void DeleteFileOnFileThread(const base::FilePath& file_path, |
| + const base::Closure& callback) { |
| + scoped_refptr<base::SequencedWorkerPool> worker_pool( |
| + content::BrowserThread::GetBlockingPool()); |
|
Dmitry Titov
2016/06/02 00:03:55
Isn't it what BrowserThread::FILE is for?
dewittj
2016/06/02 18:05:37
Done.
|
| + // Blocks shutdown because otherwise there would be leftover junk files. |
| + scoped_refptr<base::SequencedTaskRunner> task_runner( |
| + worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| + worker_pool->GetSequenceToken(), |
| + base::SequencedWorkerPool::BLOCK_SHUTDOWN)); |
| + task_runner->PostTaskAndReply( |
| + FROM_HERE, base::Bind(base::IgnoreResult(&base::DeleteFile), file_path, |
| + false /* recursive */), |
| + callback); |
| +} |
| } // namespace |
| // static |
| @@ -135,7 +153,10 @@ void OfflinePageMHTMLArchiver::OnGenerateMHTMLDone( |
| const base::FilePath& file_path, |
| int64_t file_size) { |
| if (file_size < 0) { |
| - ReportFailure(ArchiverResult::ERROR_ARCHIVE_CREATION_FAILED); |
| + DeleteFileOnFileThread( |
| + file_path, base::Bind(&OfflinePageMHTMLArchiver::ReportFailure, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + ArchiverResult::ERROR_ARCHIVE_CREATION_FAILED)); |
| } else { |
| base::ThreadTaskRunnerHandle::Get()->PostTask( |
| FROM_HERE, |