File: simple_util.h

package info (click to toggle)
qtwebengine-opensource-src 5.15.13%2Bdfsg-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,112,448 kB
  • sloc: cpp: 13,167,885; ansic: 4,228,702; javascript: 1,909,649; python: 554,805; asm: 529,966; xml: 496,619; java: 151,702; objc: 80,776; perl: 73,361; sh: 71,208; cs: 30,383; makefile: 20,779; yacc: 9,120; tcl: 8,394; php: 5,896; sql: 5,473; pascal: 4,510; lex: 2,884; lisp: 2,727; ruby: 559; awk: 200; sed: 40
file content (96 lines) | stat: -rw-r--r-- 3,632 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2013 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.

#ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_UTIL_H_
#define NET_DISK_CACHE_SIMPLE_SIMPLE_UTIL_H_

#include <stdint.h>

#include <string>

#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
#include "net/disk_cache/simple/simple_file_tracker.h"

namespace base {
class FilePath;
class Time;
}

namespace disk_cache {

namespace simple_util {

NET_EXPORT_PRIVATE std::string ConvertEntryHashKeyToHexString(
    uint64_t hash_key);

// |key| is the regular cache key, such as an URL.
// Returns the Hex ascii representation of the uint64_t hash_key.
NET_EXPORT_PRIVATE std::string GetEntryHashKeyAsHexString(
    const std::string& key);

// |key| is the regular HTTP Cache key, which is a URL.
// Returns the hash of the key as uint64_t.
NET_EXPORT_PRIVATE uint64_t GetEntryHashKey(const std::string& key);

// Parses the |hash_key| string into a uint64_t buffer.
// |hash_key| string must be of the form: FFFFFFFFFFFFFFFF .
NET_EXPORT_PRIVATE bool GetEntryHashKeyFromHexString(
    const base::StringPiece& hash_key,
    uint64_t* hash_key_out);

// Given a |key| for a (potential) entry in the simple backend and the |index|
// of a stream on that entry, returns the filename in which that stream would be
// stored.
NET_EXPORT_PRIVATE std::string GetFilenameFromKeyAndFileIndex(
    const std::string& key,
    int file_index);

// Same as |GetFilenameFromKeyAndIndex| above, but using a numeric key.
NET_EXPORT_PRIVATE std::string GetFilenameFromEntryFileKeyAndFileIndex(
    const SimpleFileTracker::EntryFileKey& key,
    int file_index);

// Given a |key| for an entry, returns the name of the sparse data file.
NET_EXPORT_PRIVATE std::string GetSparseFilenameFromEntryFileKey(
    const SimpleFileTracker::EntryFileKey& key);

// Given the size of a key, the size in bytes of the header at the beginning
// of a simple cache file.
size_t GetHeaderSize(size_t key_length);

// Given the size of a file holding a stream in the simple backend and the key
// to an entry, returns the number of bytes in the stream.
NET_EXPORT_PRIVATE int32_t GetDataSizeFromFileSize(size_t key_length,
                                                   int64_t file_size);

// Given the size of a stream in the simple backend and the key to an entry,
// returns the number of bytes in the file.
NET_EXPORT_PRIVATE int64_t GetFileSizeFromDataSize(size_t key_length,
                                                   int32_t data_size);

// Given the stream index, returns the number of the file the stream is stored
// in.
NET_EXPORT_PRIVATE int GetFileIndexFromStreamIndex(int stream_index);

// Fills |out_time| with the time the file last modified time. Unlike the
// functions in file.h, the time resolution is milliseconds.
NET_EXPORT_PRIVATE bool GetMTime(const base::FilePath& path,
                                 base::Time* out_mtime);

// Deletes a file, insuring POSIX semantics. Provided that all open handles to
// this file were opened with File::FLAG_SHARE_DELETE, it is possible to delete
// an open file and continue to use that file. After deleting an open file, it
// is possible to immediately create a new file with the same name.
NET_EXPORT_PRIVATE bool SimpleCacheDeleteFile(const base::FilePath& path);

uint32_t Crc32(const char* data, int length);

uint32_t IncrementalCrc32(uint32_t previous_crc, const char* data, int length);

}  // namespace simple_util

}  // namespace disk_cache

#endif  // NET_DISK_CACHE_SIMPLE_SIMPLE_UTIL_H_