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

Unified Diff: components/offline_pages/core/archive_manager.cc

Issue 2889663004: [DO NOT COMMIT][Offline Pages] Moving Offline Page Cache to cache directory.
Patch Set: again? Created 3 years, 7 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: components/offline_pages/core/archive_manager.cc
diff --git a/components/offline_pages/core/archive_manager.cc b/components/offline_pages/core/archive_manager.cc
index cd81776772c40d2423d97473a1add2c88aba6e3f..688c3293b63d881fe825851598f2b30e599e2e6e 100644
--- a/components/offline_pages/core/archive_manager.cc
+++ b/components/offline_pages/core/archive_manager.cc
@@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "components/offline_pages/core/archive_manager.h"
+
+#include <set>
+#include <vector>
+
#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_enumerator.h"
@@ -12,17 +17,20 @@
#include "base/sequenced_task_runner.h"
#include "base/sys_info.h"
#include "base/threading/thread_task_runner_handle.h"
-#include "components/offline_pages/core/archive_manager.h"
namespace offline_pages {
+using LifetimeType = LifetimePolicy::LifetimeType;
+
namespace {
using StorageStatsCallback =
base::Callback<void(const ArchiveManager::StorageStats& storage_stats)>;
-void EnsureArchivesDirCreatedImpl(const base::FilePath& archives_dir) {
- CHECK(base::CreateDirectory(archives_dir));
+void EnsureArchivesDirCreatedImpl(const ArchiveDirectories& archive_dirs) {
+ for (const auto& archive_dir : archive_dirs) {
+ CHECK(base::CreateDirectory(archive_dir.second));
+ }
}
void ExistsArchiveImpl(const base::FilePath& file_path,
@@ -44,26 +52,37 @@ void DeleteArchivesImpl(const std::vector<base::FilePath>& file_paths,
}
void GetAllArchivesImpl(
- const base::FilePath& archive_dir,
+ const std::vector<base::FilePath>& archive_dirs,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::Callback<void(const std::set<base::FilePath>&)>& callback) {
std::set<base::FilePath> archive_paths;
- base::FileEnumerator file_enumerator(archive_dir, false,
- base::FileEnumerator::FILES);
- for (base::FilePath archive_path = file_enumerator.Next();
- !archive_path.empty(); archive_path = file_enumerator.Next()) {
- archive_paths.insert(archive_path);
+ // Iterate through all the archive directories.
+ for (const auto& archive_dir : archive_dirs) {
+ base::FileEnumerator file_enumerator(archive_dir, false,
+ base::FileEnumerator::FILES);
+ for (base::FilePath archive_path = file_enumerator.Next();
+ !archive_path.empty(); archive_path = file_enumerator.Next()) {
+ archive_paths.insert(archive_path);
+ }
}
task_runner->PostTask(FROM_HERE, base::Bind(callback, archive_paths));
}
-void GetStorageStatsImpl(const base::FilePath& archive_dir,
+void GetStorageStatsImpl(const std::vector<base::FilePath>& archive_dirs,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const StorageStatsCallback& callback) {
ArchiveManager::StorageStats storage_stats;
- storage_stats.free_disk_space =
- base::SysInfo::AmountOfFreeDiskSpace(archive_dir);
- storage_stats.total_archives_size = base::ComputeDirectorySize(archive_dir);
+ storage_stats.free_disk_space = 0;
+ storage_stats.total_archives_size = 0;
+ // Since currently both types of pages are still saved on the same disk, we
+ // should divide the free disk space by the number of places we save pages.
+ for (const auto& archive_dir : archive_dirs) {
+ storage_stats.free_disk_space +=
+ base::SysInfo::AmountOfFreeDiskSpace(archive_dir);
+ storage_stats.total_archives_size +=
+ base::ComputeDirectorySize(archive_dir);
+ }
+ storage_stats.free_disk_space /= archive_dirs.size();
task_runner->PostTask(FROM_HERE, base::Bind(callback, storage_stats));
}
@@ -73,15 +92,15 @@ void GetStorageStatsImpl(const base::FilePath& archive_dir,
ArchiveManager::ArchiveManager() {}
ArchiveManager::ArchiveManager(
- const base::FilePath& archives_dir,
+ const ArchiveDirectories& archive_dirs,
const scoped_refptr<base::SequencedTaskRunner>& task_runner)
- : archives_dir_(archives_dir), task_runner_(task_runner) {}
+ : archive_dirs_(archive_dirs), task_runner_(task_runner) {}
ArchiveManager::~ArchiveManager() {}
void ArchiveManager::EnsureArchivesDirCreated(const base::Closure& callback) {
task_runner_->PostTaskAndReply(
- FROM_HERE, base::Bind(EnsureArchivesDirCreatedImpl, archives_dir_),
+ FROM_HERE, base::Bind(EnsureArchivesDirCreatedImpl, archive_dirs_),
callback);
}
@@ -109,15 +128,23 @@ void ArchiveManager::DeleteMultipleArchives(
void ArchiveManager::GetAllArchives(
const base::Callback<void(const std::set<base::FilePath>&)>& callback)
const {
+ std::vector<base::FilePath> archive_dirs;
+ for (const auto& iter : archive_dirs_)
+ archive_dirs.push_back(iter.second);
task_runner_->PostTask(
- FROM_HERE, base::Bind(GetAllArchivesImpl, archives_dir_,
+ FROM_HERE, base::Bind(GetAllArchivesImpl, archive_dirs,
base::ThreadTaskRunnerHandle::Get(), callback));
}
void ArchiveManager::GetStorageStats(
+ const std::set<LifetimeType>& lifetime_types,
const StorageStatsCallback& callback) const {
+ std::vector<base::FilePath> archive_dirs;
+ for (const auto& type : lifetime_types)
+ archive_dirs.push_back(archive_dirs_.at(type));
+ DCHECK(archive_dirs.size());
task_runner_->PostTask(
- FROM_HERE, base::Bind(GetStorageStatsImpl, archives_dir_,
+ FROM_HERE, base::Bind(GetStorageStatsImpl, archive_dirs,
base::ThreadTaskRunnerHandle::Get(), callback));
}
« no previous file with comments | « components/offline_pages/core/archive_manager.h ('k') | components/offline_pages/core/archive_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698