1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsReadableUtils.h"
9 #include "nsDependentSubstring.h"
11 #include "mozilla/IntegerPrintfMacros.h"
14 * Cache Service Utility Functions
17 mozilla::LazyLogModule
gCacheLog("cache");
19 void CacheLogPrintPath(mozilla::LogLevel level
, const char* format
,
21 MOZ_LOG(gCacheLog
, level
, (format
, item
->HumanReadablePath().get()));
24 uint32_t SecondsFromPRTime(PRTime prTime
) {
25 int64_t microSecondsPerSecond
= PR_USEC_PER_SEC
;
26 return uint32_t(prTime
/ microSecondsPerSecond
);
29 PRTime
PRTimeFromSeconds(uint32_t seconds
) {
30 int64_t intermediateResult
= seconds
;
31 PRTime prTime
= intermediateResult
* PR_USEC_PER_SEC
;
35 nsresult
ClientIDFromCacheKey(const nsACString
& key
, nsACString
& result
) {
36 nsReadingIterator
<char> colon
;
37 key
.BeginReading(colon
);
39 nsReadingIterator
<char> start
;
40 key
.BeginReading(start
);
42 nsReadingIterator
<char> end
;
45 if (FindCharInReadable(':', colon
, end
)) {
46 result
.Assign(Substring(start
, colon
));
50 NS_ASSERTION(false, "FindCharInRead failed to find ':'");
51 return NS_ERROR_UNEXPECTED
;
54 nsresult
ClientKeyFromCacheKey(const nsCString
& key
, nsACString
& result
) {
55 nsReadingIterator
<char> start
;
56 key
.BeginReading(start
);
58 nsReadingIterator
<char> end
;
61 if (FindCharInReadable(':', start
, end
)) {
62 ++start
; // advance past clientID ':' delimiter
63 result
.Assign(Substring(start
, end
));
67 NS_ASSERTION(false, "FindCharInRead failed to find ':'");
69 return NS_ERROR_UNEXPECTED
;