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

Unified Diff: components/offline_pages/core/offline_page_model_impl.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/offline_page_model_impl.cc
diff --git a/components/offline_pages/core/offline_page_model_impl.cc b/components/offline_pages/core/offline_page_model_impl.cc
index 596892d6171acbfba7f5d5bd205f01f10c151b64..5bcaad204e0390ff4d1677a1546974ca7dd0e234 100644
--- a/components/offline_pages/core/offline_page_model_impl.cc
+++ b/components/offline_pages/core/offline_page_model_impl.cc
@@ -27,14 +27,13 @@
#include "components/offline_pages/core/offline_page_storage_manager.h"
#include "url/gurl.h"
-using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult;
-using ClearStorageCallback =
- offline_pages::OfflinePageStorageManager::ClearStorageCallback;
-using ClearStorageResult =
- offline_pages::OfflinePageStorageManager::ClearStorageResult;
-
namespace offline_pages {
+using ArchiverResult = OfflinePageArchiver::ArchiverResult;
+using ClearStorageCallback = OfflinePageStorageManager::ClearStorageCallback;
+using ClearStorageResult = OfflinePageStorageManager::ClearStorageResult;
+using LifetimeType = LifetimePolicy::LifetimeType;
+
namespace {
// The delay used to schedule the first clear storage request for storage
@@ -42,15 +41,19 @@ namespace {
const base::TimeDelta kStorageManagerStartingDelay =
base::TimeDelta::FromSeconds(20);
-int64_t GenerateOfflineId() {
- return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1;
-}
-
// The maximum histogram size for the metrics that measure time between views of
// a given page.
const base::TimeDelta kMaxOpenedPageHistogramBucket =
base::TimeDelta::FromDays(90);
+// The const set representing all LifetimeTypes.
+const std::set<LifetimeType> kAllLifetimeTypes({LifetimeType::TEMPORARY,
+ LifetimeType::PERSISTENT});
+
+int64_t GenerateOfflineId() {
+ return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1;
+}
+
SavePageResult ToSavePageResult(ArchiverResult archiver_result) {
SavePageResult result;
switch (archiver_result) {
@@ -316,13 +319,13 @@ OfflinePageModelImpl::OfflinePageModelImpl()
OfflinePageModelImpl::OfflinePageModelImpl(
std::unique_ptr<OfflinePageMetadataStore> store,
- const base::FilePath& archives_dir,
+ const ArchiveDirectories& archive_dirs,
const scoped_refptr<base::SequencedTaskRunner>& task_runner)
: store_(std::move(store)),
- archives_dir_(archives_dir),
+ archive_dirs_(archive_dirs),
is_loaded_(false),
policy_controller_(new ClientPolicyController()),
- archive_manager_(new ArchiveManager(archives_dir, task_runner)),
+ archive_manager_(new ArchiveManager(archive_dirs, task_runner)),
testing_clock_(nullptr),
weak_ptr_factory_(this) {
archive_manager_->EnsureArchivesDirCreated(
@@ -371,7 +374,8 @@ void OfflinePageModelImpl::SavePage(
// popup overlay that obstructs viewing the normal content.
create_archive_params.remove_popup_overlay = save_page_params.is_background;
archiver->CreateArchive(
- archives_dir_, create_archive_params,
+ GetArchiveDirectory(save_page_params.client_id.name_space),
+ create_archive_params,
base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone,
weak_ptr_factory_.GetWeakPtr(), save_page_params, offline_id,
GetCurrentTime(), callback));
@@ -861,7 +865,7 @@ void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback,
int64_t offline_id) {
ReportSavePageResultHistogramAfterSave(client_id, result);
archive_manager_->GetStorageStats(
- base::Bind(&ReportStorageHistogramsAfterSave));
+ kAllLifetimeTypes, base::Bind(&ReportStorageHistogramsAfterSave));
callback.Run(result, offline_id);
}
@@ -975,7 +979,7 @@ void OfflinePageModelImpl::InformDeletePageDone(
static_cast<int>(result),
static_cast<int>(DeletePageResult::RESULT_COUNT));
archive_manager_->GetStorageStats(
- base::Bind(&ReportStorageHistogramsAfterDelete));
+ kAllLifetimeTypes, base::Bind(&ReportStorageHistogramsAfterDelete));
if (!callback.is_null())
callback.Run(result);
}
@@ -1087,6 +1091,12 @@ bool OfflinePageModelImpl::IsRemovedOnCacheReset(
offline_page.client_id.name_space);
}
+const base::FilePath& OfflinePageModelImpl::GetArchiveDirectory(
+ const std::string& name_space) const {
+ return archive_dirs_.at(
+ policy_controller_->GetPolicy(name_space).lifetime_policy.lifetime_type);
+}
+
void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) {
if (!is_loaded_) {
delayed_tasks_.push_back(task);

Powered by Google App Engine
This is Rietveld 408576698