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

Unified Diff: chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc

Issue 1843893002: Support resaving offline page right after it is being deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
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 73b820c7b4d1748e362133175efd9b18d4350fa5..2087eb84f3b8d274e07edaab8641200932c1da2a 100644
--- a/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc
+++ b/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc
@@ -4,12 +4,11 @@
#include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
-#include "base/base64.h"
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/logging.h"
-#include "base/sha1.h"
#include "base/strings/string16.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/web_contents.h"
@@ -35,13 +34,13 @@ std::string OfflinePageMHTMLArchiver::GetFileNameExtension() {
// static
base::FilePath OfflinePageMHTMLArchiver::GenerateFileName(
const GURL& url,
- const std::string& title) {
+ const std::string& title,
+ int64_t archive_id) {
std::string title_part(title.substr(0, kTitleLengthMax));
- std::string url_hash(base::SHA1HashString(url.spec()));
- base::Base64Encode(url_hash, &url_hash);
- std::string suggested_name(url.host() + kFileNameComponentsSeparator +
- title_part + kFileNameComponentsSeparator +
- url_hash);
+ std::string suggested_name(
+ url.host() + kFileNameComponentsSeparator +
+ title_part + kFileNameComponentsSeparator +
+ base::Int64ToString(archive_id));
// Substitute spaces out from title.
base::ReplaceChars(suggested_name, kReplaceChars, kReplaceWith,
@@ -73,16 +72,17 @@ OfflinePageMHTMLArchiver::~OfflinePageMHTMLArchiver() {
void OfflinePageMHTMLArchiver::CreateArchive(
const base::FilePath& archives_dir,
+ int64_t archive_id,
const CreateArchiveCallback& callback) {
DCHECK(callback_.is_null());
DCHECK(!callback.is_null());
callback_ = callback;
- GenerateMHTML(archives_dir);
+ GenerateMHTML(archives_dir, archive_id);
}
void OfflinePageMHTMLArchiver::GenerateMHTML(
- const base::FilePath& archives_dir) {
+ const base::FilePath& archives_dir, int64_t archive_id) {
if (archives_dir.empty()) {
DVLOG(1) << "Archive path was empty. Can't create archive.";
ReportFailure(ArchiverResult::ERROR_ARCHIVE_CREATION_FAILED);
@@ -107,7 +107,8 @@ void OfflinePageMHTMLArchiver::GenerateMHTML(
GURL url(web_contents_->GetLastCommittedURL());
base::string16 title(web_contents_->GetTitle());
base::FilePath file_path(
- archives_dir.Append(GenerateFileName(url, base::UTF16ToUTF8(title))));
+ archives_dir.Append(
+ GenerateFileName(url, base::UTF16ToUTF8(title), archive_id)));
web_contents_->GenerateMHTML(
file_path, base::Bind(&OfflinePageMHTMLArchiver::OnGenerateMHTMLDone,

Powered by Google App Engine
This is Rietveld 408576698