| Index: ios/chrome/browser/reading_list/url_downloader.cc
|
| diff --git a/ios/chrome/browser/reading_list/url_downloader.cc b/ios/chrome/browser/reading_list/url_downloader.cc
|
| index b986c7fa12749119db6321267e7e130486470f58..b49bdad9a803fd10d276ffdcbd5caf1127e926ab 100644
|
| --- a/ios/chrome/browser/reading_list/url_downloader.cc
|
| +++ b/ios/chrome/browser/reading_list/url_downloader.cc
|
| @@ -9,17 +9,15 @@
|
|
|
| #include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| -#include "base/md5.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/path_service.h"
|
| #include "ios/chrome/browser/chrome_paths.h"
|
| #include "ios/chrome/browser/dom_distiller/distiller_viewer.h"
|
| +#include "ios/chrome/browser/reading_list/offline_url_utils.h"
|
| #include "ios/web/public/web_thread.h"
|
| #include "net/base/escape.h"
|
| #include "url/gurl.h"
|
|
|
| -const char kReadingListOfflineDirectory[] = "Offline";
|
| -
|
| // URLDownloader
|
|
|
| URLDownloader::URLDownloader(
|
| @@ -44,7 +42,9 @@ void URLDownloader::OfflineURLExists(const GURL& url,
|
| base::Callback<void(bool)> callback) {
|
| task_tracker_.PostTaskAndReplyWithResult(
|
| web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE).get(),
|
| - FROM_HERE, base::Bind(&base::PathExists, OfflinePageAbsolutePath(url)),
|
| + FROM_HERE,
|
| + base::Bind(&base::PathExists,
|
| + reading_list::OfflinePageAbsolutePath(base_directory_, url)),
|
| callback);
|
| }
|
|
|
| @@ -73,8 +73,8 @@ void URLDownloader::DownloadCompletionHandler(const GURL& url,
|
| auto post_delete = base::Bind(
|
| [](URLDownloader* _this, const GURL& url, const std::string& title,
|
| SuccessState success) {
|
| - _this->download_completion_.Run(url, success,
|
| - _this->OfflinePagePath(url), title);
|
| + _this->download_completion_.Run(
|
| + url, success, reading_list::OfflinePagePath(url), title);
|
| _this->distiller_.reset();
|
| _this->working_ = false;
|
| _this->HandleNextTask();
|
| @@ -89,7 +89,8 @@ void URLDownloader::DownloadCompletionHandler(const GURL& url,
|
| [](const base::FilePath& offline_directory_path) {
|
| base::DeleteFile(offline_directory_path, true);
|
| },
|
| - OfflineURLDirectoryAbsolutePath(url)),
|
| + reading_list::OfflineURLDirectoryAbsolutePath(
|
| + base_directory_, url)),
|
| post_delete);
|
| } else {
|
| post_delete.Run();
|
| @@ -117,7 +118,9 @@ void URLDownloader::HandleNextTask() {
|
| task_tracker_.PostTaskAndReplyWithResult(
|
| web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE).get(),
|
| FROM_HERE, base::Bind(&base::DeleteFile,
|
| - OfflineURLDirectoryAbsolutePath(url), true),
|
| + reading_list::OfflineURLDirectoryAbsolutePath(
|
| + base_directory_, url),
|
| + true),
|
| base::Bind(&URLDownloader::DeleteCompletionHandler,
|
| base::Unretained(this), url));
|
| } else if (task.first == DOWNLOAD) {
|
| @@ -173,30 +176,9 @@ URLDownloader::SuccessState URLDownloader::SaveDistilledHTML(
|
| return ERROR_PERMANENT;
|
| }
|
|
|
| -base::FilePath URLDownloader::OfflineRootDirectoryPath() {
|
| - return base_directory_.Append(
|
| - FILE_PATH_LITERAL(kReadingListOfflineDirectory));
|
| -}
|
| -
|
| -std::string URLDownloader::OfflineURLDirectoryID(const GURL& url) {
|
| - return base::MD5String(url.spec());
|
| -}
|
| -
|
| -base::FilePath URLDownloader::OfflinePagePath(const GURL& url) {
|
| - base::FilePath directory(OfflineURLDirectoryID(url));
|
| - return directory.Append(FILE_PATH_LITERAL("page.html"));
|
| -}
|
| -
|
| -base::FilePath URLDownloader::OfflineURLDirectoryAbsolutePath(const GURL& url) {
|
| - return OfflineRootDirectoryPath().Append(OfflineURLDirectoryID(url));
|
| -}
|
| -
|
| -base::FilePath URLDownloader::OfflinePageAbsolutePath(const GURL& url) {
|
| - return OfflineRootDirectoryPath().Append(OfflinePagePath(url));
|
| -}
|
| -
|
| bool URLDownloader::CreateOfflineURLDirectory(const GURL& url) {
|
| - base::FilePath path = OfflineURLDirectoryAbsolutePath(url);
|
| + base::FilePath path =
|
| + reading_list::OfflineURLDirectoryAbsolutePath(base_directory_, url);
|
| if (!DirectoryExists(path)) {
|
| return CreateDirectoryAndGetError(path, nil);
|
| }
|
| @@ -209,7 +191,9 @@ bool URLDownloader::SaveImage(const GURL& url,
|
| std::string* image_name) {
|
| std::string image_hash = base::MD5String(image_url.spec());
|
| *image_name = image_hash;
|
| - base::FilePath path = OfflineURLDirectoryAbsolutePath(url).Append(image_hash);
|
| + base::FilePath path =
|
| + reading_list::OfflineURLDirectoryAbsolutePath(base_directory_, url)
|
| + .Append(image_hash);
|
| if (!base::PathExists(path)) {
|
| return base::WriteFile(path, data.c_str(), data.length()) > 0;
|
| }
|
| @@ -243,6 +227,7 @@ bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) {
|
| if (html.empty()) {
|
| return false;
|
| }
|
| - base::FilePath path = OfflinePageAbsolutePath(url);
|
| + base::FilePath path =
|
| + reading_list::OfflinePageAbsolutePath(base_directory_, url);
|
| return base::WriteFile(path, html.c_str(), html.length()) > 0;
|
| }
|
|
|