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

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: 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..8fa8aae8355cfe961e20c4af5b70c2adf2b50f03 100644
--- a/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc
+++ b/chrome/browser/android/offline_pages/offline_page_mhtml_archiver.cc
@@ -10,6 +10,7 @@
#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 +36,16 @@ std::string OfflinePageMHTMLArchiver::GetFileNameExtension() {
// static
base::FilePath OfflinePageMHTMLArchiver::GenerateFileName(
const GURL& url,
- const std::string& title) {
+ const std::string& title,
+ int64_t id) {
std::string title_part(title.substr(0, kTitleLengthMax));
std::string url_hash(base::SHA1HashString(url.spec()));
base::Base64Encode(url_hash, &url_hash);
fgorski 2016/03/30 01:43:29 if we are adding offline_id here, do we still need
jianli 2016/03/31 21:02:42 Done.
- std::string suggested_name(url.host() + kFileNameComponentsSeparator +
- title_part + kFileNameComponentsSeparator +
- url_hash);
+ std::string suggested_name(
+ url.host() + kFileNameComponentsSeparator +
+ title_part + kFileNameComponentsSeparator +
+ base::Int64ToString(id) + kFileNameComponentsSeparator +
+ url_hash);
// Substitute spaces out from title.
base::ReplaceChars(suggested_name, kReplaceChars, kReplaceWith,
@@ -73,16 +77,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 +112,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