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

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

Issue 2860573004: [Offline Pages] Add cached offline page utils and show usage in settings. (Closed)
Patch Set: comments from carlosk@. Created 3 years, 8 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/cached_offline_page_utils.cc
diff --git a/components/offline_pages/core/cached_offline_page_utils.cc b/components/offline_pages/core/cached_offline_page_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3c5981d4bb99a173263f00ea5fdaff46744ef269
--- /dev/null
+++ b/components/offline_pages/core/cached_offline_page_utils.cc
@@ -0,0 +1,47 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// 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/cached_offline_page_utils.h"
+
+#include <stdint.h>
+
+#include "base/bind.h"
+#include "base/time/time.h"
+#include "components/offline_pages/core/offline_page_item.h"
+#include "components/offline_pages/core/offline_page_model.h"
+#include "components/offline_pages/core/offline_page_types.h"
+
+namespace {
+
+void DoCalculateSizeBetween(
+ const offline_pages::SizeCalculatedCallback& callback,
+ const base::Time& begin_time,
+ const base::Time& end_time,
+ const offline_pages::MultipleOfflinePageItemResult& result) {
+ int64_t total_size = 0;
+ for (auto& page : result) {
+ if (begin_time < page.creation_time && page.creation_time < end_time)
+ total_size += page.file_size;
+ }
+ callback.Run(total_size);
+}
+
+} // namespace
+
+namespace offline_pages {
+
+void GetCachedOfflinePageSizeBetween(OfflinePageModel* model,
+ const SizeCalculatedCallback& callback,
+ const base::Time& begin_time,
+ const base::Time& end_time) {
+ DCHECK(model);
+ OfflinePageModelQueryBuilder builder;
+ builder.RequireRemovedOnCacheReset(
+ OfflinePageModelQuery::Requirement::INCLUDE_MATCHING);
+ model->GetPagesMatchingQuery(
+ builder.Build(model->GetPolicyController()),
+ base::Bind(&DoCalculateSizeBetween, callback, begin_time, end_time));
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698