Commit 6371c94c authored by dewittj's avatar dewittj Committed by Commit bot

Offline Pages: Remove leftover file if MHTML generation error occurred.

BUG=613761

Review-Url: https://codereview.chromium.org/2028263003
Cr-Commit-Position: refs/heads/master@{#397726}
parent d00f0b24
......@@ -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,15 @@ const char kMHTMLFileNameExtension[] = ".mhtml";
const char kFileNameComponentsSeparator[] = "-";
const char kReplaceChars[] = " ";
const char kReplaceWith[] = "_";
void DeleteFileOnFileThread(const base::FilePath& file_path,
const base::Closure& callback) {
content::BrowserThread::PostTaskAndReply(
content::BrowserThread::FILE, FROM_HERE,
base::Bind(base::IgnoreResult(&base::DeleteFile), file_path,
false /* recursive */),
callback);
}
} // namespace
// static
......@@ -135,7 +147,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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment