2001-03-21 01:42:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +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/. */
|
2001-03-21 01:42:03 +03:00
|
|
|
|
|
|
|
#include "nsCache.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2002-03-24 00:35:01 +03:00
|
|
|
#include "nsDependentSubstring.h"
|
2003-03-11 02:19:05 +03:00
|
|
|
#include "nsString.h"
|
2016-12-16 06:16:31 +03:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2001-04-04 07:30:45 +04:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
/**
|
|
|
|
* Cache Service Utility Functions
|
|
|
|
*/
|
|
|
|
|
2015-11-03 07:35:29 +03:00
|
|
|
mozilla::LazyLogModule gCacheLog("cache");
|
2003-03-11 02:19:05 +03:00
|
|
|
|
|
|
|
void
|
2015-06-04 01:25:57 +03:00
|
|
|
CacheLogPrintPath(mozilla::LogLevel level, const char * format, nsIFile * item)
|
2003-03-11 02:19:05 +03:00
|
|
|
{
|
2017-12-15 14:21:19 +03:00
|
|
|
MOZ_LOG(gCacheLog, level, (format, item->HumanReadablePath().get()));
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
2003-03-11 02:19:05 +03:00
|
|
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2001-03-21 01:42:03 +03:00
|
|
|
SecondsFromPRTime(PRTime prTime)
|
|
|
|
{
|
2012-10-12 21:29:11 +04:00
|
|
|
int64_t microSecondsPerSecond = PR_USEC_PER_SEC;
|
2012-10-12 21:29:11 +04:00
|
|
|
return uint32_t(prTime / microSecondsPerSecond);
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRTime
|
2012-08-22 19:56:38 +04:00
|
|
|
PRTimeFromSeconds(uint32_t seconds)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2012-10-26 03:25:57 +04:00
|
|
|
int64_t intermediateResult = seconds;
|
2012-10-12 21:29:11 +04:00
|
|
|
PRTime prTime = intermediateResult * PR_USEC_PER_SEC;
|
2001-03-21 01:42:03 +03:00
|
|
|
return prTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2017-10-29 14:19:48 +03:00
|
|
|
ClientIDFromCacheKey(const nsACString& key, nsACString& result)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
|
|
|
nsReadingIterator<char> colon;
|
|
|
|
key.BeginReading(colon);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
nsReadingIterator<char> start;
|
|
|
|
key.BeginReading(start);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
nsReadingIterator<char> end;
|
|
|
|
key.EndReading(end);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
if (FindCharInReadable(':', colon, end)) {
|
2017-10-29 14:19:48 +03:00
|
|
|
result.Assign(Substring(start, colon));
|
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
2017-10-29 14:19:48 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(false, "FindCharInRead failed to find ':'");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2005-01-13 06:25:28 +03:00
|
|
|
ClientKeyFromCacheKey(const nsCString& key, nsACString &result)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
|
|
|
nsReadingIterator<char> start;
|
|
|
|
key.BeginReading(start);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
nsReadingIterator<char> end;
|
|
|
|
key.EndReading(end);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
if (FindCharInReadable(':', start, end)) {
|
|
|
|
++start; // advance past clientID ':' delimiter
|
2005-01-13 06:25:28 +03:00
|
|
|
result.Assign(Substring(start, end));
|
2017-10-29 14:19:48 +03:00
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
2017-10-29 14:19:48 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(false, "FindCharInRead failed to find ':'");
|
|
|
|
result.Truncate(0);
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|