2013-03-26 15:13:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-03-26 15:13:17 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
#ifndef mozilla_dom_quota_usageinfo_h__
|
|
|
|
#define mozilla_dom_quota_usageinfo_h__
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/quota/QuotaCommon.h"
|
|
|
|
|
2013-08-12 13:51:49 +04:00
|
|
|
#include "mozilla/Atomics.h"
|
2015-11-22 12:43:23 +03:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
BEGIN_QUOTA_NAMESPACE
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
class UsageInfo
|
2013-03-26 15:13:17 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-09-11 08:18:36 +04:00
|
|
|
UsageInfo()
|
2017-03-22 14:13:54 +03:00
|
|
|
: mDatabaseUsage(0)
|
|
|
|
, mFileUsage(0)
|
|
|
|
, mLimit(0)
|
2013-03-26 15:13:17 +04:00
|
|
|
{ }
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
virtual ~UsageInfo()
|
2013-03-26 15:13:17 +04:00
|
|
|
{ }
|
|
|
|
|
2017-03-22 14:13:58 +03:00
|
|
|
void
|
|
|
|
Append(const UsageInfo& aUsageInfo)
|
|
|
|
{
|
|
|
|
IncrementUsage(&mDatabaseUsage, aUsageInfo.mDatabaseUsage);
|
|
|
|
IncrementUsage(&mFileUsage, aUsageInfo.mFileUsage);
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
void
|
|
|
|
AppendToDatabaseUsage(uint64_t aUsage)
|
|
|
|
{
|
|
|
|
IncrementUsage(&mDatabaseUsage, aUsage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AppendToFileUsage(uint64_t aUsage)
|
|
|
|
{
|
|
|
|
IncrementUsage(&mFileUsage, aUsage);
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:24:06 +03:00
|
|
|
void
|
|
|
|
SetLimit(uint64_t aLimit)
|
|
|
|
{
|
|
|
|
mLimit = aLimit;
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
uint64_t
|
|
|
|
DatabaseUsage()
|
|
|
|
{
|
|
|
|
return mDatabaseUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
FileUsage()
|
|
|
|
{
|
|
|
|
return mFileUsage;
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:24:06 +03:00
|
|
|
uint64_t
|
|
|
|
Limit()
|
|
|
|
{
|
|
|
|
return mLimit;
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
uint64_t
|
|
|
|
TotalUsage()
|
|
|
|
{
|
|
|
|
uint64_t totalUsage = mDatabaseUsage;
|
|
|
|
IncrementUsage(&totalUsage, mFileUsage);
|
|
|
|
return totalUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ResetUsage()
|
|
|
|
{
|
|
|
|
mDatabaseUsage = 0;
|
|
|
|
mFileUsage = 0;
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:43:23 +03:00
|
|
|
static void
|
|
|
|
IncrementUsage(uint64_t* aUsage, uint64_t aDelta)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aUsage);
|
|
|
|
CheckedUint64 value = *aUsage;
|
|
|
|
value += aDelta;
|
|
|
|
if (value.isValid()) {
|
|
|
|
*aUsage = value.value();
|
|
|
|
} else {
|
|
|
|
*aUsage = UINT64_MAX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
private:
|
|
|
|
uint64_t mDatabaseUsage;
|
|
|
|
uint64_t mFileUsage;
|
2016-06-24 05:24:06 +03:00
|
|
|
uint64_t mLimit;
|
2013-03-26 15:13:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_QUOTA_NAMESPACE
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
#endif // mozilla_dom_quota_usageinfo_h__
|