Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionDataUseItem.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionDataUseItem.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionDataUseItem.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d440baccebc2d27bf7eb7bb337e14d4b69d79852 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionDataUseItem.java |
| @@ -0,0 +1,87 @@ |
| +// 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. |
| + |
| +package org.chromium.chrome.browser.preferences.datareduction; |
| + |
| +import android.content.Context; |
| +import android.text.format.Formatter; |
| + |
| +/** |
| + * Stores the data used and saved by a hostname. |
| + */ |
| +public class DataReductionDataUseItem implements Comparable<DataReductionDataUseItem> { |
| + private String mHostname; |
| + private long mDataUsed; |
| + private long mOriginalSize; |
| + |
| + /** |
| + * Constructor for a DataReductionDataUseItem which associates a hostname with it's data usage |
|
Theresa
2017/04/03 15:05:21
nit: s/it's/its
megjablon
2017/04/03 20:33:45
Done.
|
| + * and savings. |
| + * |
| + * @param hostname The hostname associated with this data usage. |
| + * @param dataUsed The amount of data used by the host. |
| + * @param originalSize The original size of the data. |
| + */ |
| + public DataReductionDataUseItem(String hostname, long dataUsed, long originalSize) { |
| + mHostname = hostname; |
| + mDataUsed = dataUsed; |
| + mOriginalSize = originalSize; |
| + } |
| + |
| + /** |
| + * Returns the hostname for this data usage. |
|
Theresa
2017/04/03 15:05:20
nit: s/data usage/data use item
megjablon
2017/04/03 20:33:45
Done.
|
| + * @return The hostname. |
| + */ |
| + public String getHostname() { |
| + return mHostname; |
| + } |
| + |
| + /** |
| + * Returns the amount of data used by the associated hostname. |
| + * @return The data used. |
| + */ |
| + public long getDataUsed() { |
| + return mDataUsed; |
| + } |
| + |
| + /** |
| + * Returns the amount of data saved by the associated hostname. |
| + * @return The data saved. |
| + */ |
| + public long getDataSaved() { |
| + return mOriginalSize - mDataUsed; |
| + } |
| + |
| + /** |
| + * Returns a formatted String of the data used by the associated hostname. |
| + * @param context An Android context. |
| + * @return A formatted string of the data used. |
| + */ |
| + public String getFormattedDataUsed(Context context) { |
| + return Formatter.formatFileSize(context, mDataUsed); |
| + } |
| + |
| + /** |
| + * Returns a formatted String of the data saved by the associated hostname. |
| + * @param context An Android context. |
| + * @return A formatted string of the data saved. |
| + */ |
| + public String getFormattedDataSaved(Context context) { |
| + return Formatter.formatFileSize(context, mOriginalSize - mDataUsed); |
| + } |
| + |
| + /** |
| + * Sorts the DataReductionDataUseItems by most to least data used. |
| + */ |
| + @Override |
| + public int compareTo(DataReductionDataUseItem another) { |
| + if (mDataUsed < another.getDataUsed()) { |
| + return 1; |
| + } else if (mDataUsed > another.getDataUsed()) { |
| + return -1; |
| + } else { |
| + return 0; |
| + } |
| + } |
| +} |