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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageStorageSpacePolicy.java

Issue 1894703002: [Offline pages] Removing offline pages from Bookmarks UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marking more methods as visible for testing Created 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.offlinepages;
6
7 import org.chromium.base.Callback;
8
9 import java.util.List;
10
11 /**
12 * Manages the storage space policy for offline pages.
13 *
14 * When created, it records the size on disk that is being used, this value neve r changes after
15 * creation so make a new OfflinePageStorageSpacePolicy whenever a new measureme nt is desired.
16 */
17 public class OfflinePageStorageSpacePolicy {
18 /**
19 * Minimal total size of all pages, before a header will be shown to offer f reeing up space.
20 */
21 private static final long MINIMUM_TOTAL_SIZE_BYTES = 10 * (1 << 20); // 10MB
22 /**
23 * Minimal size of pages to clean up, before a header will be shown to offer freeing up space.
24 */
25 private static final long MINIMUM_CLEANUP_SIZE_BYTES = 5 * (1 << 20); // 5MB
26
27 private long mSizeOfAllPages;
28 private long mSizeOfPagesToCleanUp;
29
30 /**
31 * Asynchronously creates an OffinePageStorageSpacePolicy which is prefilled with information
32 * about the state of the disk usage of Offline Pages.
33 */
34 public static void create(final OfflinePageBridge offlinePageBridge,
35 final Callback<OfflinePageStorageSpacePolicy> callback) {
36 assert offlinePageBridge != null;
37 offlinePageBridge.getAllPages(new OfflinePageBridge.MultipleOfflinePageI temCallback() {
38 @Override
39 public void onResult(List<OfflinePageItem> allPages) {
40 callback.onResult(new OfflinePageStorageSpacePolicy(offlinePageB ridge, allPages));
41 }
42 });
43 }
44
45 /**
46 * Creates a policy object with the given list of offline pages.
47 *
48 * @param offlinePageBridge An object to access offline page functionality.
49 * @param offlinePages The list of all offline pages.
50 */
51 private OfflinePageStorageSpacePolicy(
52 OfflinePageBridge offlinePageBridge, List<OfflinePageItem> offlinePa ges) {
53 mSizeOfAllPages = getTotalSize(offlinePages);
54 mSizeOfPagesToCleanUp = getTotalSize(offlinePageBridge.getPagesToCleanUp ());
55 }
56
57 /** @return Whether there exists offline pages that could be cleaned up to m ake space. */
58 public boolean hasPagesToCleanUp() {
59 return mSizeOfPagesToCleanUp > 0;
60 }
61
62 /**
63 * @return Whether the header should be shown in saved pages view to inform user of total used
64 * storage and offer freeing up space.
65 */
66 public boolean shouldShowStorageSpaceHeader() {
67 return getSizeOfAllPages() > MINIMUM_TOTAL_SIZE_BYTES
68 && getSizeOfPagesToCleanUp() > MINIMUM_CLEANUP_SIZE_BYTES;
69 }
70
71 /** @return Total size, in bytes, of all saved pages. */
72 public long getSizeOfAllPages() {
73 return mSizeOfAllPages;
74 }
75
76 private long getSizeOfPagesToCleanUp() {
77 return mSizeOfPagesToCleanUp;
78 }
79
80 private long getTotalSize(List<OfflinePageItem> offlinePages) {
81 long totalSize = 0;
82 for (OfflinePageItem page : offlinePages) {
83 totalSize += page.getFileSize();
84 }
85 return totalSize;
86 }
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698