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 |