Changeset 181140 in webkit


Ignore:
Timestamp:
Mar 6, 2015 12:00:22 AM (9 years ago)
Author:
Antti Koivisto
Message:

Move disk cache classes to namespace
https://bugs.webkit.org/show_bug.cgi?id=142339

Reviewed by Anders Carlsson.

Move everything to NetworkCache namespace.

Location:
trunk/Source/WebKit2
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r181138 r181140  
     12015-03-05  Antti Koivisto  <antti@apple.com>
     2
     3        Move disk cache classes to namespace
     4        https://bugs.webkit.org/show_bug.cgi?id=142339
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Move everything to NetworkCache namespace.
     9
    1102015-03-05  Carlos Garcia Campos  <cgarcia@igalia.com>
    211
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp

    r181020 r181140  
    5050
    5151namespace WebKit {
    52 
    53 NetworkCache& NetworkCache::singleton()
    54 {
    55     static NeverDestroyed<NetworkCache> instance;
     52namespace NetworkCache {
     53
     54Cache& singleton()
     55{
     56    static NeverDestroyed<Cache> instance;
    5657    return instance;
    5758}
    5859
    59 bool NetworkCache::initialize(const String& cachePath, bool enableEfficacyLogging)
    60 {
    61     m_storage = NetworkCacheStorage::open(cachePath);
     60bool Cache::initialize(const String& cachePath, bool enableEfficacyLogging)
     61{
     62    m_storage = Storage::open(cachePath);
    6263
    6364    if (enableEfficacyLogging)
    64         m_statistics = NetworkCacheStatistics::open(cachePath);
     65        m_statistics = Statistics::open(cachePath);
    6566
    6667#if PLATFORM(COCOA)
     
    7879}
    7980
    80 void NetworkCache::setMaximumSize(size_t maximumSize)
     81void Cache::setMaximumSize(size_t maximumSize)
    8182{
    8283    if (!m_storage)
     
    8586}
    8687
    87 static NetworkCacheKey makeCacheKey(const WebCore::ResourceRequest& request)
     88static Key makeCacheKey(const WebCore::ResourceRequest& request)
    8889{
    8990#if ENABLE(CACHE_PARTITIONING)
     
    9798}
    9899
    99 static NetworkCacheStorage::Entry encodeStorageEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, PassRefPtr<WebCore::SharedBuffer> responseData)
    100 {
    101     NetworkCacheEncoder encoder;
     100static Storage::Entry encodeStorageEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, PassRefPtr<WebCore::SharedBuffer> responseData)
     101{
     102    Encoder encoder;
    102103    encoder << response;
    103104
     
    121122
    122123    auto timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
    123     NetworkCacheData header(encoder.buffer(), encoder.bufferSize());
    124     NetworkCacheData body;
     124    Data header(encoder.buffer(), encoder.bufferSize());
     125    Data body;
    125126    if (responseData)
    126127        body = { reinterpret_cast<const uint8_t*>(responseData->data()), responseData->size() };
     
    156157}
    157158
    158 static std::unique_ptr<NetworkCache::Entry> decodeStorageEntry(const NetworkCacheStorage::Entry& storageEntry, const WebCore::ResourceRequest& request, NetworkCache::CachedEntryReuseFailure& failure)
    159 {
    160     NetworkCacheDecoder decoder(storageEntry.header.data(), storageEntry.header.size());
     159static std::unique_ptr<Entry> decodeStorageEntry(const Storage::Entry& storageEntry, const WebCore::ResourceRequest& request, CachedEntryReuseFailure& failure)
     160{
     161    Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
    161162
    162163    WebCore::ResourceResponse cachedResponse;
    163164    if (!decoder.decode(cachedResponse)) {
    164165        LOG(NetworkCache, "(NetworkProcess) response decoding failed\n");
    165         failure = NetworkCache::CachedEntryReuseFailure::Other;
     166        failure = CachedEntryReuseFailure::Other;
    166167        return nullptr;
    167168    }
     
    169170    bool hasVaryingRequestHeaders;
    170171    if (!decoder.decode(hasVaryingRequestHeaders)) {
    171         failure = NetworkCache::CachedEntryReuseFailure::Other;
     172        failure = CachedEntryReuseFailure::Other;
    172173        return nullptr;
    173174    }
     
    176177        Vector<std::pair<String, String>> varyingRequestHeaders;
    177178        if (!decoder.decode(varyingRequestHeaders)) {
    178             failure = NetworkCache::CachedEntryReuseFailure::Other;
     179            failure = CachedEntryReuseFailure::Other;
    179180            return nullptr;
    180181        }
     
    182183        if (!verifyVaryingRequestHeaders(varyingRequestHeaders, request)) {
    183184            LOG(NetworkCache, "(NetworkProcess) varying header mismatch\n");
    184             failure = NetworkCache::CachedEntryReuseFailure::VaryingHeaderMismatch;
     185            failure = CachedEntryReuseFailure::VaryingHeaderMismatch;
    185186            return nullptr;
    186187        }
     
    188189    if (!decoder.verifyChecksum()) {
    189190        LOG(NetworkCache, "(NetworkProcess) checksum verification failure\n");
    190         failure = NetworkCache::CachedEntryReuseFailure::Other;
     191        failure = CachedEntryReuseFailure::Other;
    191192        return nullptr;
    192193    }
     
    203204        LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasValidatorFields=%d isExpired=%d age=%f lifetime=%f", isExpired, hasValidatorFields, age, lifetime);
    204205        if (!hasValidatorFields) {
    205             failure = NetworkCache::CachedEntryReuseFailure::MissingValidatorFields;
     206            failure = CachedEntryReuseFailure::MissingValidatorFields;
    206207            return nullptr;
    207208        }
    208209    }
    209210
    210     auto entry = std::make_unique<NetworkCache::Entry>();
     211    auto entry = std::make_unique<Entry>();
    211212    entry->storageEntry = storageEntry;
    212213    entry->needsRevalidation = needsRevalidation;
     
    228229}
    229230
    230 static NetworkCache::RetrieveDecision canRetrieve(const WebCore::ResourceRequest& request)
     231static RetrieveDecision canRetrieve(const WebCore::ResourceRequest& request)
    231232{
    232233    if (!request.url().protocolIsInHTTPFamily())
    233         return NetworkCache::RetrieveDecision::NoDueToProtocol;
     234        return RetrieveDecision::NoDueToProtocol;
    234235    // FIXME: Support HEAD and OPTIONS requests.
    235236    if (request.httpMethod() != "GET")
    236         return NetworkCache::RetrieveDecision::NoDueToHTTPMethod;
     237        return RetrieveDecision::NoDueToHTTPMethod;
    237238    // FIXME: We should be able to validate conditional requests using cache.
    238239    if (request.isConditional())
    239         return NetworkCache::RetrieveDecision::NoDueToConditionalRequest;
     240        return RetrieveDecision::NoDueToConditionalRequest;
    240241    if (request.cachePolicy() == WebCore::ReloadIgnoringCacheData)
    241         return NetworkCache::RetrieveDecision::NoDueToReloadIgnoringCache;
    242 
    243     return NetworkCache::RetrieveDecision::Yes;
    244 }
    245 
    246 void NetworkCache::retrieve(const WebCore::ResourceRequest& originalRequest, uint64_t webPageID, std::function<void (std::unique_ptr<Entry>)> completionHandler)
     242        return RetrieveDecision::NoDueToReloadIgnoringCache;
     243
     244    return RetrieveDecision::Yes;
     245}
     246
     247void Cache::retrieve(const WebCore::ResourceRequest& originalRequest, uint64_t webPageID, std::function<void (std::unique_ptr<Entry>)> completionHandler)
    247248{
    248249    ASSERT(isEnabled());
     
    250251    LOG(NetworkCache, "(NetworkProcess) retrieving %s priority %u", originalRequest.url().string().ascii().data(), originalRequest.priority());
    251252
    252     NetworkCacheKey storageKey = makeCacheKey(originalRequest);
     253    Key storageKey = makeCacheKey(originalRequest);
    253254    RetrieveDecision retrieveDecision = canRetrieve(originalRequest);
    254255    if (retrieveDecision != RetrieveDecision::Yes) {
     
    263264    unsigned priority = originalRequest.priority();
    264265
    265     m_storage->retrieve(storageKey, priority, [this, originalRequest, completionHandler, startTime, storageKey, webPageID](std::unique_ptr<NetworkCacheStorage::Entry> entry) {
     266    m_storage->retrieve(storageKey, priority, [this, originalRequest, completionHandler, startTime, storageKey, webPageID](std::unique_ptr<Storage::Entry> entry) {
    266267        if (!entry) {
    267268            LOG(NetworkCache, "(NetworkProcess) not found in storage");
     
    290291}
    291292
    292 static NetworkCache::StoreDecision canStore(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response)
     293static StoreDecision canStore(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response)
    293294{
    294295    if (!originalRequest.url().protocolIsInHTTPFamily() || !response.isHTTP()) {
    295296        LOG(NetworkCache, "(NetworkProcess) not HTTP");
    296         return NetworkCache::StoreDecision::NoDueToProtocol;
     297        return StoreDecision::NoDueToProtocol;
    297298    }
    298299    if (originalRequest.httpMethod() != "GET") {
    299300        LOG(NetworkCache, "(NetworkProcess) method %s", originalRequest.httpMethod().utf8().data());
    300         return NetworkCache::StoreDecision::NoDueToHTTPMethod;
     301        return StoreDecision::NoDueToHTTPMethod;
    301302    }
    302303    if (response.isAttachment()) {
    303304        LOG(NetworkCache, "(NetworkProcess) attachment");
    304         return NetworkCache::StoreDecision::NoDueToAttachmentResponse;
     305        return StoreDecision::NoDueToAttachmentResponse;
    305306    }
    306307
     
    315316        if (response.cacheControlContainsNoStore()) {
    316317            LOG(NetworkCache, "(NetworkProcess) Cache-control:no-store");
    317             return NetworkCache::StoreDecision::NoDueToNoStoreResponse;
    318         }
    319         return NetworkCache::StoreDecision::Yes;
     318            return StoreDecision::NoDueToNoStoreResponse;
     319        }
     320        return StoreDecision::Yes;
    320321    default:
    321322        LOG(NetworkCache, "(NetworkProcess) status code %d", response.httpStatusCode());
    322323    }
    323324
    324     return NetworkCache::StoreDecision::NoDueToHTTPStatusCode;
    325 }
    326 
    327 void NetworkCache::store(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData, std::function<void (MappedBody&)> completionHandler)
     325    return StoreDecision::NoDueToHTTPStatusCode;
     326}
     327
     328void Cache::store(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData, std::function<void (MappedBody&)> completionHandler)
    328329{
    329330    ASSERT(isEnabled());
     
    344345    auto storageEntry = encodeStorageEntry(originalRequest, response, WTF::move(responseData));
    345346
    346     m_storage->store(storageEntry, [completionHandler](bool success, const NetworkCacheData& bodyData) {
     347    m_storage->store(storageEntry, [completionHandler](bool success, const Data& bodyData) {
    347348        MappedBody mappedBody;
    348349#if ENABLE(SHAREABLE_RESOURCE)
     
    359360}
    360361
    361 void NetworkCache::update(const WebCore::ResourceRequest& originalRequest, const Entry& entry, const WebCore::ResourceResponse& validatingResponse)
     362void Cache::update(const WebCore::ResourceRequest& originalRequest, const Entry& entry, const WebCore::ResourceResponse& validatingResponse)
    362363{
    363364    LOG(NetworkCache, "(NetworkProcess) updating %s", originalRequest.url().string().latin1().data());
     
    368369    auto updateEntry = encodeStorageEntry(originalRequest, response, entry.buffer);
    369370
    370     m_storage->update(updateEntry, entry.storageEntry, [](bool success, const NetworkCacheData&) {
     371    m_storage->update(updateEntry, entry.storageEntry, [](bool success, const Data&) {
    371372        LOG(NetworkCache, "(NetworkProcess) updated, success=%d", success);
    372373    });
    373374}
    374375
    375 void NetworkCache::traverse(std::function<void (const Entry*)>&& traverseHandler)
     376void Cache::traverse(std::function<void (const Entry*)>&& traverseHandler)
    376377{
    377378    ASSERT(isEnabled());
    378379
    379     m_storage->traverse([traverseHandler](const NetworkCacheStorage::Entry* entry) {
     380    m_storage->traverse([traverseHandler](const Storage::Entry* entry) {
    380381        if (!entry) {
    381382            traverseHandler(nullptr);
     
    383384        }
    384385
    385         NetworkCache::Entry cacheEntry;
     386        Entry cacheEntry;
    386387        cacheEntry.storageEntry = *entry;
    387388
    388         NetworkCacheDecoder decoder(cacheEntry.storageEntry.header.data(), cacheEntry.storageEntry.header.size());
     389        Decoder decoder(cacheEntry.storageEntry.header.data(), cacheEntry.storageEntry.header.size());
    389390        if (!decoder.decode(cacheEntry.response))
    390391            return;
     
    394395}
    395396
    396 String NetworkCache::dumpFilePath() const
     397String Cache::dumpFilePath() const
    397398{
    398399    return WebCore::pathByAppendingComponent(m_storage->baseDirectoryPath(), "dump.json");
    399400}
    400401
    401 static bool entryAsJSON(StringBuilder& json, const NetworkCacheStorage::Entry& entry)
    402 {
    403     NetworkCacheDecoder decoder(entry.header.data(), entry.header.size());
     402static bool entryAsJSON(StringBuilder& json, const Storage::Entry& entry)
     403{
     404    Decoder decoder(entry.header.data(), entry.header.size());
    404405    WebCore::ResourceResponse cachedResponse;
    405406    if (!decoder.decode(cachedResponse))
     
    434435}
    435436
    436 void NetworkCache::dumpContentsToFile()
     437void Cache::dumpContentsToFile()
    437438{
    438439    if (!m_storage)
     
    442443        return;
    443444    WebCore::writeToFile(dumpFileHandle, "[\n", 2);
    444     m_storage->traverse([dumpFileHandle](const NetworkCacheStorage::Entry* entry) {
     445    m_storage->traverse([dumpFileHandle](const Storage::Entry* entry) {
    445446        if (!entry) {
    446447            WebCore::writeToFile(dumpFileHandle, "{}\n]\n", 5);
     
    458459}
    459460
    460 void NetworkCache::clear()
     461void Cache::clear()
    461462{
    462463    LOG(NetworkCache, "(NetworkProcess) clearing cache");
     
    474475}
    475476
    476 String NetworkCache::storagePath() const
     477String Cache::storagePath() const
    477478{
    478479    return m_storage ? m_storage->directoryPath() : String();
     
    480481
    481482}
    482 
    483 #endif
     483}
     484
     485#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h

    r180899 r181140  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4141
    4242namespace WebKit {
     43namespace NetworkCache {
    4344
    44 class NetworkCacheStatistics;
     45class Cache;
     46class Statistics;
    4547
    46 class NetworkCache {
    47     WTF_MAKE_NONCOPYABLE(NetworkCache);
    48     friend class WTF::NeverDestroyed<NetworkCache>;
     48Cache& singleton();
     49
     50struct MappedBody {
     51#if ENABLE(SHAREABLE_RESOURCE)
     52    RefPtr<ShareableResource> shareableResource;
     53    ShareableResource::Handle shareableResourceHandle;
     54#endif
     55};
     56
     57struct Entry {
     58    Storage::Entry storageEntry;
     59    WebCore::ResourceResponse response;
     60    RefPtr<WebCore::SharedBuffer> buffer;
     61#if ENABLE(SHAREABLE_RESOURCE)
     62    ShareableResource::Handle shareableResourceHandle;
     63#endif
     64    bool needsRevalidation;
     65};
     66
     67enum class RetrieveDecision {
     68    Yes,
     69    NoDueToProtocol,
     70    NoDueToHTTPMethod,
     71    NoDueToConditionalRequest,
     72    NoDueToReloadIgnoringCache
     73};
     74
     75enum class StoreDecision {
     76    Yes,
     77    NoDueToProtocol,
     78    NoDueToHTTPMethod,
     79    NoDueToAttachmentResponse,
     80    NoDueToNoStoreResponse,
     81    NoDueToHTTPStatusCode
     82};
     83
     84enum class CachedEntryReuseFailure {
     85    None,
     86    VaryingHeaderMismatch,
     87    MissingValidatorFields,
     88    Other,
     89};
     90
     91class Cache {
     92    WTF_MAKE_NONCOPYABLE(Cache);
     93    friend class WTF::NeverDestroyed<Cache>;
    4994public:
    50     enum class RetrieveDecision {
    51         Yes,
    52         NoDueToProtocol,
    53         NoDueToHTTPMethod,
    54         NoDueToConditionalRequest,
    55         NoDueToReloadIgnoringCache
    56     };
    57 
    58     enum class StoreDecision {
    59         Yes,
    60         NoDueToProtocol,
    61         NoDueToHTTPMethod,
    62         NoDueToAttachmentResponse,
    63         NoDueToNoStoreResponse,
    64         NoDueToHTTPStatusCode
    65     };
    66 
    67     enum class CachedEntryReuseFailure {
    68         None,
    69         VaryingHeaderMismatch,
    70         MissingValidatorFields,
    71         Other,
    72     };
    73 
    74     static NetworkCache& singleton();
    75 
    7695    bool initialize(const String& cachePath, bool enableEfficacyLogging);
    7796    void setMaximumSize(size_t);
     
    7998    bool isEnabled() const { return !!m_storage; }
    8099
    81     struct Entry {
    82         NetworkCacheStorage::Entry storageEntry;
    83         WebCore::ResourceResponse response;
    84         RefPtr<WebCore::SharedBuffer> buffer;
    85 #if ENABLE(SHAREABLE_RESOURCE)
    86         ShareableResource::Handle shareableResourceHandle;
    87 #endif
    88         bool needsRevalidation;
    89     };
    90100    // Completion handler may get called back synchronously on failure.
    91101    void retrieve(const WebCore::ResourceRequest&, uint64_t webPageID, std::function<void (std::unique_ptr<Entry>)>);
    92 
    93     struct MappedBody {
    94 #if ENABLE(SHAREABLE_RESOURCE)
    95         RefPtr<ShareableResource> shareableResource;
    96         ShareableResource::Handle shareableResourceHandle;
    97 #endif
    98     };
    99102    void store(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, RefPtr<WebCore::SharedBuffer>&&, std::function<void (MappedBody&)>);
    100103    void update(const WebCore::ResourceRequest&, const Entry&, const WebCore::ResourceResponse& validatingResponse);
     
    109112
    110113private:
    111     NetworkCache() = default;
    112     ~NetworkCache() = delete;
     114    Cache() = default;
     115    ~Cache() = delete;
    113116
    114117    String dumpFilePath() const;
    115118
    116     std::unique_ptr<NetworkCacheStorage> m_storage;
    117     std::unique_ptr<NetworkCacheStatistics> m_statistics;
     119    std::unique_ptr<Storage> m_storage;
     120    std::unique_ptr<Statistics> m_statistics;
    118121};
    119122
    120123}
     124}
    121125#endif
    122126#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h

    r175748 r181140  
    3030
    3131namespace WebKit {
     32namespace NetworkCache {
    3233
    33 class NetworkCacheDecoder;
    34 class NetworkCacheEncoder;
     34class Decoder;
     35class Encoder;
    3536   
    36 template<typename T> struct NetworkCacheCoder {
    37     static void encode(NetworkCacheEncoder& encoder, const T& t)
     37template<typename T> struct Coder {
     38    static void encode(Encoder& encoder, const T& t)
    3839    {
    3940        t.encode(encoder);
    4041    }
    4142
    42     static bool decode(NetworkCacheDecoder& decoder, T& t)
     43    static bool decode(Decoder& decoder, T& t)
    4344    {
    4445        return T::decode(decoder, t);
     
    4748
    4849}
     50}
    4951
    5052#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp

    r179779 r181140  
    3434
    3535namespace WebKit {
     36namespace NetworkCache {
    3637
    37 void NetworkCacheCoder<AtomicString>::encode(NetworkCacheEncoder& encoder, const AtomicString& atomicString)
     38void Coder<AtomicString>::encode(Encoder& encoder, const AtomicString& atomicString)
    3839{
    3940    encoder << atomicString.string();
    4041}
    4142
    42 bool NetworkCacheCoder<AtomicString>::decode(NetworkCacheDecoder& decoder, AtomicString& atomicString)
     43bool Coder<AtomicString>::decode(Decoder& decoder, AtomicString& atomicString)
    4344{
    4445    String string;
     
    5051}
    5152
    52 void NetworkCacheCoder<CString>::encode(NetworkCacheEncoder& encoder, const CString& string)
     53void Coder<CString>::encode(Encoder& encoder, const CString& string)
    5354{
    5455    // Special case the null string.
     
    6364}
    6465
    65 bool NetworkCacheCoder<CString>::decode(NetworkCacheDecoder& decoder, CString& result)
     66bool Coder<CString>::decode(Decoder& decoder, CString& result)
    6667{
    6768    uint32_t length;
     
    9192
    9293
    93 void NetworkCacheCoder<String>::encode(NetworkCacheEncoder& encoder, const String& string)
     94void Coder<String>::encode(Encoder& encoder, const String& string)
    9495{
    9596    // Special case the null string.
     
    111112
    112113template <typename CharacterType>
    113 static inline bool decodeStringText(NetworkCacheDecoder& decoder, uint32_t length, String& result)
     114static inline bool decodeStringText(Decoder& decoder, uint32_t length, String& result)
    114115{
    115116    // Before allocating the string, make sure that the decoder buffer is big enough.
     
    128129}
    129130
    130 bool NetworkCacheCoder<String>::decode(NetworkCacheDecoder& decoder, String& result)
     131bool Coder<String>::decode(Decoder& decoder, String& result)
    131132{
    132133    uint32_t length;
     
    149150}
    150151
    151 void NetworkCacheCoder<WebCore::CertificateInfo>::encode(NetworkCacheEncoder& encoder, const WebCore::CertificateInfo& certificateInfo)
     152void Coder<WebCore::CertificateInfo>::encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo)
    152153{
    153154    // FIXME: Cocoa CertificateInfo is a CF object tree. Generalize CF type coding so we don't need to use ArgumentCoder here.
     
    158159}
    159160
    160 bool NetworkCacheCoder<WebCore::CertificateInfo>::decode(NetworkCacheDecoder& decoder, WebCore::CertificateInfo& certificateInfo)
     161bool Coder<WebCore::CertificateInfo>::decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
    161162{
    162163    uint64_t certificateSize;
     
    174175}
    175176
    176 void NetworkCacheCoder<MD5::Digest>::encode(NetworkCacheEncoder& encoder, const MD5::Digest& digest)
     177void Coder<MD5::Digest>::encode(Encoder& encoder, const MD5::Digest& digest)
    177178{
    178179    encoder.encodeFixedLengthData(digest.data(), sizeof(digest));
    179180}
    180181
    181 bool NetworkCacheCoder<MD5::Digest>::decode(NetworkCacheDecoder& decoder, MD5::Digest& digest)
     182bool Coder<MD5::Digest>::decode(Decoder& decoder, MD5::Digest& digest)
    182183{
    183184    return decoder.decodeFixedLengthData(digest.data(), sizeof(digest));
     
    185186
    186187}
     188}
    187189
    188190#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h

    r179781 r181140  
    4040
    4141namespace WebKit {
    42 
    43 template<typename T, typename U> struct NetworkCacheCoder<std::pair<T, U>> {
    44     static void encode(NetworkCacheEncoder& encoder, const std::pair<T, U>& pair)
     42namespace NetworkCache {
     43
     44template<typename T, typename U> struct Coder<std::pair<T, U>> {
     45    static void encode(Encoder& encoder, const std::pair<T, U>& pair)
    4546    {
    4647        encoder << pair.first << pair.second;
    4748    }
    4849
    49     static bool decode(NetworkCacheDecoder& decoder, std::pair<T, U>& pair)
     50    static bool decode(Decoder& decoder, std::pair<T, U>& pair)
    5051    {
    5152        T first;
     
    6364};
    6465
    65 template<typename Rep, typename Period> struct NetworkCacheCoder<std::chrono::duration<Rep, Period>> {
    66     static void encode(NetworkCacheEncoder& encoder, const std::chrono::duration<Rep, Period>& duration)
     66template<typename Rep, typename Period> struct Coder<std::chrono::duration<Rep, Period>> {
     67    static void encode(Encoder& encoder, const std::chrono::duration<Rep, Period>& duration)
    6768    {
    6869        static_assert(std::is_integral<Rep>::value && std::is_signed<Rep>::value && sizeof(Rep) <= sizeof(int64_t), "Serialization of this Rep type is not supported yet. Only signed integer type which can be fit in an int64_t is currently supported.");
     
    7071    }
    7172
    72     static bool decode(NetworkCacheDecoder& decoder, std::chrono::duration<Rep, Period>& result)
     73    static bool decode(Decoder& decoder, std::chrono::duration<Rep, Period>& result)
    7374    {
    7475        int64_t count;
     
    8081};
    8182
    82 template<typename KeyType, typename ValueType> struct NetworkCacheCoder<WTF::KeyValuePair<KeyType, ValueType>> {
    83     static void encode(NetworkCacheEncoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair)
     83template<typename KeyType, typename ValueType> struct Coder<WTF::KeyValuePair<KeyType, ValueType>> {
     84    static void encode(Encoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair)
    8485    {
    8586        encoder << pair.key << pair.value;
    8687    }
    8788
    88     static bool decode(NetworkCacheDecoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)
     89    static bool decode(Decoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)
    8990    {
    9091        KeyType key;
     
    102103};
    103104
    104 template<bool fixedSizeElements, typename T, size_t inlineCapacity> struct VectorNetworkCacheCoder;
    105 
    106 template<typename T, size_t inlineCapacity> struct VectorNetworkCacheCoder<false, T, inlineCapacity> {
    107     static void encode(NetworkCacheEncoder& encoder, const Vector<T, inlineCapacity>& vector)
     105template<bool fixedSizeElements, typename T, size_t inlineCapacity> struct VectorCoder;
     106
     107template<typename T, size_t inlineCapacity> struct VectorCoder<false, T, inlineCapacity> {
     108    static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector)
    108109    {
    109110        encoder << static_cast<uint64_t>(vector.size());
     
    112113    }
    113114
    114     static bool decode(NetworkCacheDecoder& decoder, Vector<T, inlineCapacity>& vector)
     115    static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
    115116    {
    116117        uint64_t size;
     
    133134};
    134135
    135 template<typename T, size_t inlineCapacity> struct VectorNetworkCacheCoder<true, T, inlineCapacity> {
    136     static void encode(NetworkCacheEncoder& encoder, const Vector<T, inlineCapacity>& vector)
     136template<typename T, size_t inlineCapacity> struct VectorCoder<true, T, inlineCapacity> {
     137    static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector)
    137138    {
    138139        encoder << static_cast<uint64_t>(vector.size());
     
    140141    }
    141142   
    142     static bool decode(NetworkCacheDecoder& decoder, Vector<T, inlineCapacity>& vector)
     143    static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
    143144    {
    144145        uint64_t size;
     
    164165};
    165166
    166 template<typename T, size_t inlineCapacity> struct NetworkCacheCoder<Vector<T, inlineCapacity>> : VectorNetworkCacheCoder<std::is_arithmetic<T>::value, T, inlineCapacity> { };
    167 
    168 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> struct NetworkCacheCoder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> {
     167template<typename T, size_t inlineCapacity> struct Coder<Vector<T, inlineCapacity>> : VectorCoder<std::is_arithmetic<T>::value, T, inlineCapacity> { };
     168
     169template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> struct Coder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> {
    169170    typedef HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> HashMapType;
    170171
    171     static void encode(NetworkCacheEncoder& encoder, const HashMapType& hashMap)
     172    static void encode(Encoder& encoder, const HashMapType& hashMap)
    172173    {
    173174        encoder << static_cast<uint64_t>(hashMap.size());
     
    176177    }
    177178
    178     static bool decode(NetworkCacheDecoder& decoder, HashMapType& hashMap)
     179    static bool decode(Decoder& decoder, HashMapType& hashMap)
    179180    {
    180181        uint64_t hashMapSize;
     
    203204};
    204205
    205 template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct NetworkCacheCoder<HashSet<KeyArg, HashArg, KeyTraitsArg>> {
     206template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct Coder<HashSet<KeyArg, HashArg, KeyTraitsArg>> {
    206207    typedef HashSet<KeyArg, HashArg, KeyTraitsArg> HashSetType;
    207208
    208     static void encode(NetworkCacheEncoder& encoder, const HashSetType& hashSet)
     209    static void encode(Encoder& encoder, const HashSetType& hashSet)
    209210    {
    210211        encoder << static_cast<uint64_t>(hashSet.size());
     
    213214    }
    214215
    215     static bool decode(NetworkCacheDecoder& decoder, HashSetType& hashSet)
     216    static bool decode(Decoder& decoder, HashSetType& hashSet)
    216217    {
    217218        uint64_t hashSetSize;
     
    237238};
    238239
    239 template<> struct NetworkCacheCoder<AtomicString> {
    240     static void encode(NetworkCacheEncoder&, const AtomicString&);
    241     static bool decode(NetworkCacheDecoder&, AtomicString&);
    242 };
    243 
    244 template<> struct NetworkCacheCoder<CString> {
    245     static void encode(NetworkCacheEncoder&, const CString&);
    246     static bool decode(NetworkCacheDecoder&, CString&);
    247 };
    248 
    249 template<> struct NetworkCacheCoder<String> {
    250     static void encode(NetworkCacheEncoder&, const String&);
    251     static bool decode(NetworkCacheDecoder&, String&);
    252 };
    253 
    254 template<> struct NetworkCacheCoder<WebCore::CertificateInfo> {
    255     static void encode(NetworkCacheEncoder&, const WebCore::CertificateInfo&);
    256     static bool decode(NetworkCacheDecoder&, WebCore::CertificateInfo&);
    257 };
    258 
    259 template<> struct NetworkCacheCoder<MD5::Digest> {
    260     static void encode(NetworkCacheEncoder&, const MD5::Digest&);
    261     static bool decode(NetworkCacheDecoder&, MD5::Digest&);
     240template<> struct Coder<AtomicString> {
     241    static void encode(Encoder&, const AtomicString&);
     242    static bool decode(Decoder&, AtomicString&);
     243};
     244
     245template<> struct Coder<CString> {
     246    static void encode(Encoder&, const CString&);
     247    static bool decode(Decoder&, CString&);
     248};
     249
     250template<> struct Coder<String> {
     251    static void encode(Encoder&, const String&);
     252    static bool decode(Decoder&, String&);
     253};
     254
     255template<> struct Coder<WebCore::CertificateInfo> {
     256    static void encode(Encoder&, const WebCore::CertificateInfo&);
     257    static bool decode(Decoder&, WebCore::CertificateInfo&);
     258};
     259
     260template<> struct Coder<MD5::Digest> {
     261    static void encode(Encoder&, const MD5::Digest&);
     262    static bool decode(Decoder&, MD5::Digest&);
    262263};
    263264
    264265}
    265 
     266}
    266267#endif
    267268#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h

    r181020 r181140  
    3535
    3636namespace WebKit {
     37namespace NetworkCache {
    3738
    3839#if PLATFORM(COCOA)
     
    9394#endif
    9495
    95 class NetworkCacheData {
     96class Data {
    9697public:
    97     NetworkCacheData() { }
    98     NetworkCacheData(const uint8_t*, size_t);
     98    Data() { }
     99    Data(const uint8_t*, size_t);
    99100
    100101    enum class Backing { Buffer, Map };
    101102#if PLATFORM(COCOA)
    102     NetworkCacheData(DispatchPtr<dispatch_data_t>, Backing = Backing::Buffer);
     103    Data(DispatchPtr<dispatch_data_t>, Backing = Backing::Buffer);
    103104#endif
    104105    bool isNull() const;
     
    121122
    122123}
     124}
    123125
    124126#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm

    r181020 r181140  
    2525
    2626#include "config.h"
    27 #include "NetworkCachedata.h"
     27#include "NetworkCacheData.h"
    2828
    2929#if ENABLE(NETWORK_CACHE)
     
    3232
    3333namespace WebKit {
     34namespace NetworkCache {
    3435
    35 NetworkCacheData::NetworkCacheData(const uint8_t* data, size_t size)
     36Data::Data(const uint8_t* data, size_t size)
    3637    : m_dispatchData(adoptDispatch(dispatch_data_create(data, size, nullptr, DISPATCH_DATA_DESTRUCTOR_DEFAULT)))
    3738    , m_size(size)
     
    3940}
    4041
    41 NetworkCacheData::NetworkCacheData(DispatchPtr<dispatch_data_t> dispatchData, Backing backing)
     42Data::Data(DispatchPtr<dispatch_data_t> dispatchData, Backing backing)
    4243{
    4344    if (!dispatchData)
     
    4950}
    5051
    51 const uint8_t* NetworkCacheData::data() const
     52const uint8_t* Data::data() const
    5253{
    5354    if (!m_data) {
     
    6162}
    6263
    63 bool NetworkCacheData::isNull() const
     64bool Data::isNull() const
    6465{
    6566    return !m_dispatchData;
     
    6768
    6869}
     70}
    6971
    7072#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp

    r176398 r181140  
    3232
    3333namespace WebKit {
     34namespace NetworkCache {
    3435
    35 NetworkCacheDecoder::NetworkCacheDecoder(const uint8_t* buffer, size_t bufferSize)
     36Decoder::Decoder(const uint8_t* buffer, size_t bufferSize)
    3637    : m_buffer(buffer)
    3738    , m_bufferPosition(buffer)
     
    4142}
    4243
    43 NetworkCacheDecoder::~NetworkCacheDecoder()
     44Decoder::~Decoder()
    4445{
    4546}
    4647
    47 bool NetworkCacheDecoder::bufferIsLargeEnoughToContain(size_t size) const
     48bool Decoder::bufferIsLargeEnoughToContain(size_t size) const
    4849{
    4950    return m_bufferPosition + size <= m_bufferEnd;
    5051}
    5152
    52 bool NetworkCacheDecoder::decodeFixedLengthData(uint8_t* data, size_t size)
     53bool Decoder::decodeFixedLengthData(uint8_t* data, size_t size)
    5354{
    5455    if (!bufferIsLargeEnoughToContain(size))
     
    5859    m_bufferPosition += size;
    5960
    60     NetworkCacheEncoder::updateChecksumForData(m_checksum, data, size);
     61    Encoder::updateChecksumForData(m_checksum, data, size);
    6162    return true;
    6263}
    6364
    6465template<typename Type>
    65 bool NetworkCacheDecoder::decodeNumber(Type& value)
     66bool Decoder::decodeNumber(Type& value)
    6667{
    6768    if (!bufferIsLargeEnoughToContain(sizeof(value)))
     
    7172    m_bufferPosition += sizeof(Type);
    7273
    73     NetworkCacheEncoder::updateChecksumForNumber(m_checksum, value);
     74    Encoder::updateChecksumForNumber(m_checksum, value);
    7475    return true;
    7576}
    7677
    77 bool NetworkCacheDecoder::decode(bool& result)
     78bool Decoder::decode(bool& result)
    7879{
    7980    return decodeNumber(result);
    8081}
    8182
    82 bool NetworkCacheDecoder::decode(uint8_t& result)
     83bool Decoder::decode(uint8_t& result)
    8384{
    8485    return decodeNumber(result);
    8586}
    8687
    87 bool NetworkCacheDecoder::decode(uint16_t& result)
     88bool Decoder::decode(uint16_t& result)
    8889{
    8990    return decodeNumber(result);
    9091}
    9192
    92 bool NetworkCacheDecoder::decode(uint32_t& result)
     93bool Decoder::decode(uint32_t& result)
    9394{
    9495    return decodeNumber(result);
    9596}
    9697
    97 bool NetworkCacheDecoder::decode(uint64_t& result)
     98bool Decoder::decode(uint64_t& result)
    9899{
    99100    return decodeNumber(result);
    100101}
    101102
    102 bool NetworkCacheDecoder::decode(int32_t& result)
     103bool Decoder::decode(int32_t& result)
    103104{
    104105    return decodeNumber(result);
    105106}
    106107
    107 bool NetworkCacheDecoder::decode(int64_t& result)
     108bool Decoder::decode(int64_t& result)
    108109{
    109110    return decodeNumber(result);
    110111}
    111112
    112 bool NetworkCacheDecoder::decode(float& result)
     113bool Decoder::decode(float& result)
    113114{
    114115    return decodeNumber(result);
    115116}
    116117
    117 bool NetworkCacheDecoder::decode(double& result)
     118bool Decoder::decode(double& result)
    118119{
    119120    return decodeNumber(result);
    120121}
    121122
    122 bool NetworkCacheDecoder::verifyChecksum()
     123bool Decoder::verifyChecksum()
    123124{
    124125    unsigned computedChecksum = m_checksum;
     
    130131
    131132}
     133}
    132134
    133135#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h

    r176398 r181140  
    3232
    3333namespace WebKit {
     34namespace NetworkCache {
    3435
    35 class NetworkCacheDecoder {
     36class Decoder {
    3637    WTF_MAKE_FAST_ALLOCATED;
    3738public:
    38     NetworkCacheDecoder(const uint8_t* buffer, size_t bufferSize);
    39     virtual ~NetworkCacheDecoder();
     39    Decoder(const uint8_t* buffer, size_t bufferSize);
     40    virtual ~Decoder();
    4041
    4142    size_t length() const { return m_bufferEnd - m_buffer; }
     
    7374    template<typename T> bool decode(T& t)
    7475    {
    75         return NetworkCacheCoder<T>::decode(*this, t);
     76        return Coder<T>::decode(*this, t);
    7677    }
    7778
     
    99100
    100101}
     102}
    101103
    102104#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp

    r177294 r181140  
    3030
    3131namespace WebKit {
     32namespace NetworkCache {
    3233
    33 NetworkCacheEncoder::NetworkCacheEncoder()
     34Encoder::Encoder()
    3435    : m_checksum(0)
    3536{
    3637}
    3738
    38 NetworkCacheEncoder::~NetworkCacheEncoder()
     39Encoder::~Encoder()
    3940{
    4041}
    4142
    42 uint8_t* NetworkCacheEncoder::grow(size_t size)
     43uint8_t* Encoder::grow(size_t size)
    4344{
    4445    size_t newPosition = m_buffer.size();
     
    4748}
    4849
    49 void NetworkCacheEncoder::updateChecksumForData(unsigned& checksum, const uint8_t* data, size_t size)
     50void Encoder::updateChecksumForData(unsigned& checksum, const uint8_t* data, size_t size)
    5051{
    5152    // FIXME: hashMemory should not require alignment.
    5253    size_t hashSize = size - size % 2;
    53     unsigned hash = StringHasher::hashMemory(data, hashSize) ^ NetworkCacheEncoder::Salt<uint8_t*>::value;
     54    unsigned hash = StringHasher::hashMemory(data, hashSize) ^ Encoder::Salt<uint8_t*>::value;
    5455    checksum = WTF::pairIntHash(checksum, hash);
    5556}
    5657
    57 void NetworkCacheEncoder::encodeFixedLengthData(const uint8_t* data, size_t size)
     58void Encoder::encodeFixedLengthData(const uint8_t* data, size_t size)
    5859{
    5960    updateChecksumForData(m_checksum, data, size);
     
    6465
    6566template<typename Type>
    66 void NetworkCacheEncoder::encodeNumber(Type value)
     67void Encoder::encodeNumber(Type value)
    6768{
    68     NetworkCacheEncoder::updateChecksumForNumber(m_checksum, value);
     69    Encoder::updateChecksumForNumber(m_checksum, value);
    6970
    7071    uint8_t* buffer = grow(sizeof(Type));
     
    7273}
    7374
    74 void NetworkCacheEncoder::encode(bool value)
     75void Encoder::encode(bool value)
    7576{
    7677    encodeNumber(value);
    7778}
    7879
    79 void NetworkCacheEncoder::encode(uint8_t value)
     80void Encoder::encode(uint8_t value)
    8081{
    8182    encodeNumber(value);
    8283}
    8384
    84 void NetworkCacheEncoder::encode(uint16_t value)
     85void Encoder::encode(uint16_t value)
    8586{
    8687    encodeNumber(value);
    8788}
    8889
    89 void NetworkCacheEncoder::encode(uint32_t value)
     90void Encoder::encode(uint32_t value)
    9091{
    9192    encodeNumber(value);
    9293}
    9394
    94 void NetworkCacheEncoder::encode(uint64_t value)
     95void Encoder::encode(uint64_t value)
    9596{
    9697    encodeNumber(value);
    9798}
    9899
    99 void NetworkCacheEncoder::encode(int32_t value)
     100void Encoder::encode(int32_t value)
    100101{
    101102    encodeNumber(value);
    102103}
    103104
    104 void NetworkCacheEncoder::encode(int64_t value)
     105void Encoder::encode(int64_t value)
    105106{
    106107    encodeNumber(value);
    107108}
    108109
    109 void NetworkCacheEncoder::encode(float value)
     110void Encoder::encode(float value)
    110111{
    111112    encodeNumber(value);
    112113}
    113114
    114 void NetworkCacheEncoder::encode(double value)
     115void Encoder::encode(double value)
    115116{
    116117    encodeNumber(value);
    117118}
    118119
    119 void NetworkCacheEncoder::encodeChecksum()
     120void Encoder::encodeChecksum()
    120121{
    121122    encodeNumber(m_checksum);
     
    123124
    124125}
     126}
    125127
    126128#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h

    r176398 r181140  
    3535
    3636namespace WebKit {
     37namespace NetworkCache {
    3738
    38 class NetworkCacheEncoder;
     39class Encoder;
    3940class DataReference;
    4041
    41 class NetworkCacheEncoder {
     42class Encoder {
    4243    WTF_MAKE_FAST_ALLOCATED;
    4344public:
    44     NetworkCacheEncoder();
    45     virtual ~NetworkCacheEncoder();
     45    Encoder();
     46    virtual ~Encoder();
    4647
    4748    void encodeChecksum();
     
    5758    template<typename T> void encode(const T& t)
    5859    {
    59         NetworkCacheCoder<T>::encode(*this, t);
     60        Coder<T>::encode(*this, t);
    6061    }
    6162
    62     template<typename T> NetworkCacheEncoder& operator<<(const T& t)
     63    template<typename T> Encoder& operator<<(const T& t)
    6364    {
    6465        encode(t);
     
    9394};
    9495
    95 template <> struct NetworkCacheEncoder::Salt<bool> { static const unsigned value = 3; };
    96 template <> struct NetworkCacheEncoder::Salt<uint8_t> { static const  unsigned value = 5; };
    97 template <> struct NetworkCacheEncoder::Salt<uint16_t> { static const unsigned value = 7; };
    98 template <> struct NetworkCacheEncoder::Salt<uint32_t> { static const unsigned value = 11; };
    99 template <> struct NetworkCacheEncoder::Salt<uint64_t> { static const unsigned value = 13; };
    100 template <> struct NetworkCacheEncoder::Salt<int32_t> { static const unsigned value = 17; };
    101 template <> struct NetworkCacheEncoder::Salt<int64_t> { static const unsigned value = 19; };
    102 template <> struct NetworkCacheEncoder::Salt<float> { static const unsigned value = 23; };
    103 template <> struct NetworkCacheEncoder::Salt<double> { static const unsigned value = 29; };
    104 template <> struct NetworkCacheEncoder::Salt<uint8_t*> { static const unsigned value = 101; };
     96template <> struct Encoder::Salt<bool> { static const unsigned value = 3; };
     97template <> struct Encoder::Salt<uint8_t> { static const  unsigned value = 5; };
     98template <> struct Encoder::Salt<uint16_t> { static const unsigned value = 7; };
     99template <> struct Encoder::Salt<uint32_t> { static const unsigned value = 11; };
     100template <> struct Encoder::Salt<uint64_t> { static const unsigned value = 13; };
     101template <> struct Encoder::Salt<int32_t> { static const unsigned value = 17; };
     102template <> struct Encoder::Salt<int64_t> { static const unsigned value = 19; };
     103template <> struct Encoder::Salt<float> { static const unsigned value = 23; };
     104template <> struct Encoder::Salt<double> { static const unsigned value = 29; };
     105template <> struct Encoder::Salt<uint8_t*> { static const unsigned value = 101; };
    105106
    106107template <typename Type>
    107 void NetworkCacheEncoder::updateChecksumForNumber(unsigned& checksum, Type value)
     108void Encoder::updateChecksumForNumber(unsigned& checksum, Type value)
    108109{
    109     unsigned hash = WTF::intHash(static_cast<uint64_t>(value)) ^ NetworkCacheEncoder::Salt<Type>::value;
     110    unsigned hash = WTF::intHash(static_cast<uint64_t>(value)) ^ Encoder::Salt<Type>::value;
    110111    checksum = WTF::pairIntHash(checksum, hash);
    111112}
    112113
    113114}
     115}
    114116
    115117#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h

    r180947 r181140  
    3535
    3636namespace WebKit {
     37namespace NetworkCache {
    3738
    3839template <typename Function>
     
    6061        String partitionPath = WebCore::pathByAppendingComponent(cachePath, subdirName);
    6162        traverseDirectory(partitionPath, DT_REG, [&function, &partitionPath](const String& fileName) {
    62             if (fileName.length() != NetworkCacheKey::hashStringLength())
     63            if (fileName.length() != Key::hashStringLength())
    6364                return;
    6465            function(fileName, partitionPath);
     
    6768}
    6869
    69 } // namespace WebKit
     70}
     71}
    7072
    7173#endif // ENABLE(NETWORK_CACHE)
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannel.h

    r181020 r181140  
    3535
    3636namespace WebKit {
     37namespace NetworkCache {
    3738
    38 class NetworkCacheIOChannel : public ThreadSafeRefCounted<NetworkCacheIOChannel> {
     39class IOChannel : public ThreadSafeRefCounted<IOChannel> {
    3940public:
    4041    enum class Type { Read, Write, Create };
    41     static Ref<NetworkCacheIOChannel> open(const String& file, Type);
     42    static Ref<IOChannel> open(const String& file, Type);
    4243
    43     void read(size_t offset, size_t, std::function<void (NetworkCacheData&, int error)>);
    44     void write(size_t offset, const NetworkCacheData&, std::function<void (int error)>);
     44    void read(size_t offset, size_t, std::function<void (Data&, int error)>);
     45    void write(size_t offset, const Data&, std::function<void (int error)>);
    4546
    4647    int fileDescriptor() const { return m_fileDescriptor; }
    4748
    4849private:
    49     NetworkCacheIOChannel(int fd);
     50    IOChannel(int fd);
    5051
    5152#if PLATFORM(COCOA)
     
    5657
    5758}
     59}
    5860
    5961#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm

    r181020 r181140  
    3838
    3939namespace WebKit {
     40namespace NetworkCache {
    4041
    41 NetworkCacheIOChannel::NetworkCacheIOChannel(int fd)
     42IOChannel::IOChannel(int fd)
    4243    : m_fileDescriptor(fd)
    4344{
     
    5051}
    5152
    52 Ref<NetworkCacheIOChannel> NetworkCacheIOChannel::open(const String& filePath, NetworkCacheIOChannel::Type type)
     53Ref<IOChannel> IOChannel::open(const String& filePath, IOChannel::Type type)
    5354{
    5455    int oflag;
     
    7273    int fd = ::open(path.data(), oflag, mode);
    7374
    74     return adoptRef(*new NetworkCacheIOChannel(fd));
     75    return adoptRef(*new IOChannel(fd));
    7576}
    7677
    77 void NetworkCacheIOChannel::read(size_t offset, size_t size, std::function<void ( NetworkCacheData&, int error)> completionHandler)
     78void IOChannel::read(size_t offset, size_t size, std::function<void ( Data&, int error)> completionHandler)
    7879{
    79     RefPtr<NetworkCacheIOChannel> channel(this);
     80    RefPtr<IOChannel> channel(this);
    8081    bool didCallCompletionHandler = false;
    8182    dispatch_io_read(m_dispatchIO.get(), offset, size, dispatch_get_main_queue(), [channel, completionHandler, didCallCompletionHandler](bool done, dispatch_data_t fileData, int error) mutable {
    8283        if (done) {
    8384            if (!didCallCompletionHandler) {
    84                 NetworkCacheData nullData;
     85                Data nullData;
    8586                completionHandler(nullData, error);
    8687            }
     
    8889        }
    8990        ASSERT(!didCallCompletionHandler);
    90         NetworkCacheData data(fileData);
     91        Data data(fileData);
    9192        completionHandler(data, error);
    9293        didCallCompletionHandler = true;
     
    9495}
    9596
    96 void NetworkCacheIOChannel::write(size_t offset, const NetworkCacheData& data, std::function<void (int error)> completionHandler)
     97void IOChannel::write(size_t offset, const Data& data, std::function<void (int error)> completionHandler)
    9798{
    98     RefPtr<NetworkCacheIOChannel> channel(this);
     99    RefPtr<IOChannel> channel(this);
    99100    auto dispatchData = data.dispatchData();
    100101    dispatch_io_write(m_dispatchIO.get(), offset, dispatchData, dispatch_get_main_queue(), [channel, completionHandler](bool done, dispatch_data_t fileData, int error) {
     
    105106
    106107}
     108}
     109
    107110#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp

    r180949 r181140  
    3535
    3636namespace WebKit {
     37namespace NetworkCache {
    3738
    38 NetworkCacheKey::NetworkCacheKey(const NetworkCacheKey& o)
     39Key::Key(const Key& o)
    3940    : m_method(o.m_method.isolatedCopy())
    4041    , m_partition(o.m_partition.isolatedCopy())
     
    4445}
    4546
    46 NetworkCacheKey::NetworkCacheKey(NetworkCacheKey&& o)
     47Key::Key(Key&& o)
    4748    : m_method(WTF::move(o.m_method))
    4849    , m_partition(WTF::move(o.m_partition))
     
    5253}
    5354
    54 NetworkCacheKey::NetworkCacheKey(const String& method, const String& partition, const String& identifier)
     55Key::Key(const String& method, const String& partition, const String& identifier)
    5556    : m_method(method.isolatedCopy())
    5657    , m_partition(partition.isolatedCopy())
     
    6061}
    6162
    62 NetworkCacheKey& NetworkCacheKey::operator=(const NetworkCacheKey& other)
     63Key& Key::operator=(const Key& other)
    6364{
    6465    m_method = other.m_method.isolatedCopy();
     
    8283}
    8384
    84 NetworkCacheKey::HashType NetworkCacheKey::computeHash() const
     85Key::HashType Key::computeHash() const
    8586{
    8687    // We don't really need a cryptographic hash. The key is always verified against the entry header.
     
    9596}
    9697
    97 String NetworkCacheKey::hashAsString() const
     98String Key::hashAsString() const
    9899{
    99100    StringBuilder builder;
     
    106107}
    107108
    108 template <typename CharType> bool hexDigitsToHash(CharType* characters, NetworkCacheKey::HashType& hash)
     109template <typename CharType> bool hexDigitsToHash(CharType* characters, Key::HashType& hash)
    109110{
    110111    for (unsigned i = 0; i < sizeof(hash); ++i) {
     
    118119}
    119120
    120 bool NetworkCacheKey::stringToHash(const String& string, HashType& hash)
     121bool Key::stringToHash(const String& string, HashType& hash)
    121122{
    122123    if (string.length() != hashStringLength())
     
    127128}
    128129
    129 bool NetworkCacheKey::operator==(const NetworkCacheKey& other) const
     130bool Key::operator==(const Key& other) const
    130131{
    131132    return m_hash == other.m_hash && m_method == other.m_method && m_partition == other.m_partition && m_identifier == other.m_identifier;
    132133}
    133134
    134 void NetworkCacheKey::encode(NetworkCacheEncoder& encoder) const
     135void Key::encode(Encoder& encoder) const
    135136{
    136137    encoder << m_method;
     
    140141}
    141142
    142 bool NetworkCacheKey::decode(NetworkCacheDecoder& decoder, NetworkCacheKey& key)
     143bool Key::decode(Decoder& decoder, Key& key)
    143144{
    144145    return decoder.decode(key.m_method) && decoder.decode(key.m_partition) && decoder.decode(key.m_identifier) && decoder.decode(key.m_hash);
     
    146147
    147148}
     149}
    148150
    149151#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h

    r180949 r181140  
    3333
    3434namespace WebKit {
     35namespace NetworkCache {
    3536
    36 class NetworkCacheEncoder;
    37 class NetworkCacheDecoder;
     37class Encoder;
     38class Decoder;
    3839
    39 class NetworkCacheKey {
     40class Key {
    4041public:
    4142    typedef MD5::Digest HashType;
    4243
    43     NetworkCacheKey() { }
    44     NetworkCacheKey(const NetworkCacheKey&);
    45     NetworkCacheKey(NetworkCacheKey&&);
    46     NetworkCacheKey(const String& method, const String& partition, const String& identifier);
     44    Key() { }
     45    Key(const Key&);
     46    Key(Key&&);
     47    Key(const String& method, const String& partition, const String& identifier);
    4748
    48     NetworkCacheKey& operator=(const NetworkCacheKey&);
     49    Key& operator=(const Key&);
    4950
    5051    bool isNull() const { return m_identifier.isNull(); }
     
    6364    String hashAsString() const;
    6465
    65     void encode(NetworkCacheEncoder&) const;
    66     static bool decode(NetworkCacheDecoder&, NetworkCacheKey&);
     66    void encode(Encoder&) const;
     67    static bool decode(Decoder&, Key&);
    6768
    68     bool operator==(const NetworkCacheKey&) const;
    69     bool operator!=(const NetworkCacheKey& other) const { return !(*this == other); }
     69    bool operator==(const Key&) const;
     70    bool operator!=(const Key& other) const { return !(*this == other); }
    7071
    7172private:
     
    7980
    8081}
     82}
    8183
    8284#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h

    r181086 r181140  
    4040
    4141namespace WebKit {
     42namespace NetworkCache {
    4243
    43 class NetworkCacheStatistics {
     44class Statistics {
    4445public:
    45     static std::unique_ptr<NetworkCacheStatistics> open(const String& cachePath);
     46    static std::unique_ptr<Statistics> open(const String& cachePath);
    4647
    4748    void clear();
    4849
    49     void recordNotCachingResponse(const NetworkCacheKey&, NetworkCache::StoreDecision);
    50     void recordNotUsingCacheForRequest(uint64_t webPageID, const NetworkCacheKey&, const WebCore::ResourceRequest&, NetworkCache::RetrieveDecision);
    51     void recordRetrievalFailure(uint64_t webPageID, const NetworkCacheKey&, const WebCore::ResourceRequest&);
    52     void recordRetrievedCachedEntry(uint64_t webPageID, const NetworkCacheKey&, const WebCore::ResourceRequest&, NetworkCache::CachedEntryReuseFailure);
     50    void recordNotCachingResponse(const Key&, StoreDecision);
     51    void recordNotUsingCacheForRequest(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&, RetrieveDecision);
     52    void recordRetrievalFailure(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&);
     53    void recordRetrievedCachedEntry(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&, CachedEntryReuseFailure);
    5354
    5455private:
    55     explicit NetworkCacheStatistics(const String& databasePath);
     56    explicit Statistics(const String& databasePath);
    5657
    5758    void initialize(const String& databasePath);
     
    6364    void writeTimerFired();
    6465
    65     typedef std::function<void (bool wasEverRequested, const Optional<NetworkCache::StoreDecision>&)> RequestedCompletionHandler;
     66    typedef std::function<void (bool wasEverRequested, const Optional<StoreDecision>&)> RequestedCompletionHandler;
    6667    enum class NeedUncachedReason { No, Yes };
    6768    void queryWasEverRequested(const String&, NeedUncachedReason, const RequestedCompletionHandler&);
     
    8687};
    8788
    88 } // namespace WebKit
     89}
     90}
    8991
    9092#endif // ENABLE(NETWORK_CACHE)
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm

    r181086 r181140  
    4242
    4343namespace WebKit {
    44 
    45 static const char* networkCacheStatisticsDatabaseName = "WebKitCacheStatistics.db";
     44namespace NetworkCache {
     45
     46static const char* StatisticsDatabaseName = "WebKitCacheStatistics.db";
    4647static const std::chrono::milliseconds mininumWriteInterval = std::chrono::milliseconds(10000);
    4748
     
    7374}
    7475
    75 std::unique_ptr<NetworkCacheStatistics> NetworkCacheStatistics::open(const String& cachePath)
    76 {
    77     ASSERT(RunLoop::isMain());
    78 
    79     String databasePath = WebCore::pathByAppendingComponent(cachePath, networkCacheStatisticsDatabaseName);
    80     return std::unique_ptr<NetworkCacheStatistics>(new NetworkCacheStatistics(databasePath));
    81 }
    82 
    83 NetworkCacheStatistics::NetworkCacheStatistics(const String& databasePath)
     76std::unique_ptr<Statistics> Statistics::open(const String& cachePath)
     77{
     78    ASSERT(RunLoop::isMain());
     79
     80    String databasePath = WebCore::pathByAppendingComponent(cachePath, StatisticsDatabaseName);
     81    return std::unique_ptr<Statistics>(new Statistics(databasePath));
     82}
     83
     84Statistics::Statistics(const String& databasePath)
    8485    : m_backgroundIOQueue(adoptDispatch(dispatch_queue_create("com.apple.WebKit.Cache.Statistics.Background", DISPATCH_QUEUE_SERIAL)))
    85     , m_writeTimer(*this, &NetworkCacheStatistics::writeTimerFired)
     86    , m_writeTimer(*this, &Statistics::writeTimerFired)
    8687{
    8788    dispatch_set_target_queue(m_backgroundIOQueue.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
     
    9091}
    9192
    92 void NetworkCacheStatistics::initialize(const String& databasePath)
     93void Statistics::initialize(const String& databasePath)
    9394{
    9495    ASSERT(RunLoop::isMain());
     
    9798
    9899    StringCapture databasePathCapture(databasePath);
    99     StringCapture networkCachePathCapture(NetworkCache::singleton().storagePath());
     100    StringCapture networkCachePathCapture(singleton().storagePath());
    100101    dispatch_async(m_backgroundIOQueue.get(), [this, databasePathCapture, networkCachePathCapture, startTime] {
    101102        WebCore::SQLiteTransactionInProgressAutoCounter transactionCounter;
     
    139140}
    140141
    141 void NetworkCacheStatistics::bootstrapFromNetworkCache(const String& networkCachePath)
     142void Statistics::bootstrapFromNetworkCache(const String& networkCachePath)
    142143{
    143144    ASSERT(!RunLoop::isMain());
     
    159160}
    160161
    161 void NetworkCacheStatistics::shrinkIfNeeded()
     162void Statistics::shrinkIfNeeded()
    162163{
    163164    ASSERT(RunLoop::isMain());
     
    171172    clear();
    172173
    173     StringCapture networkCachePathCapture(NetworkCache::singleton().storagePath());
     174    StringCapture networkCachePathCapture(singleton().storagePath());
    174175    dispatch_async(m_backgroundIOQueue.get(), [this, networkCachePathCapture] {
    175176        bootstrapFromNetworkCache(networkCachePathCapture.string());
     
    178179}
    179180
    180 void NetworkCacheStatistics::recordNotCachingResponse(const NetworkCacheKey& key, NetworkCache::StoreDecision storeDecision)
    181 {
    182     ASSERT(storeDecision != NetworkCache::StoreDecision::Yes);
     181void Statistics::recordNotCachingResponse(const Key& key, StoreDecision storeDecision)
     182{
     183    ASSERT(storeDecision != StoreDecision::Yes);
    183184
    184185    m_storeDecisionsToAdd.set(key.hashAsString(), storeDecision);
     
    187188}
    188189
    189 static String retrieveDecisionToDiagnosticKey(NetworkCache::RetrieveDecision retrieveDecision)
     190static String retrieveDecisionToDiagnosticKey(RetrieveDecision retrieveDecision)
    190191{
    191192    switch (retrieveDecision) {
    192     case NetworkCache::RetrieveDecision::NoDueToProtocol:
     193    case RetrieveDecision::NoDueToProtocol:
    193194        return WebCore::DiagnosticLoggingKeys::notHTTPFamilyKey();
    194     case NetworkCache::RetrieveDecision::NoDueToHTTPMethod:
     195    case RetrieveDecision::NoDueToHTTPMethod:
    195196        return WebCore::DiagnosticLoggingKeys::unsupportedHTTPMethodKey();
    196     case NetworkCache::RetrieveDecision::NoDueToConditionalRequest:
     197    case RetrieveDecision::NoDueToConditionalRequest:
    197198        return WebCore::DiagnosticLoggingKeys::isConditionalRequestKey();
    198     case NetworkCache::RetrieveDecision::NoDueToReloadIgnoringCache:
     199    case RetrieveDecision::NoDueToReloadIgnoringCache:
    199200        return WebCore::DiagnosticLoggingKeys::isReloadIgnoringCacheDataKey();
    200     case NetworkCache::RetrieveDecision::Yes:
     201    case RetrieveDecision::Yes:
    201202        ASSERT_NOT_REACHED();
    202203        break;
     
    205206}
    206207
    207 void NetworkCacheStatistics::recordNotUsingCacheForRequest(uint64_t webPageID, const NetworkCacheKey& key, const WebCore::ResourceRequest& request, NetworkCache::RetrieveDecision retrieveDecision)
    208 {
    209     ASSERT(retrieveDecision != NetworkCache::RetrieveDecision::Yes);
     208void Statistics::recordNotUsingCacheForRequest(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request, RetrieveDecision retrieveDecision)
     209{
     210    ASSERT(retrieveDecision != RetrieveDecision::Yes);
    210211
    211212    String hash = key.hashAsString();
    212213    WebCore::URL requestURL = request.url();
    213     queryWasEverRequested(hash, NeedUncachedReason::No, [this, hash, requestURL, webPageID, retrieveDecision](bool wasEverRequested, const Optional<NetworkCache::StoreDecision>&) {
     214    queryWasEverRequested(hash, NeedUncachedReason::No, [this, hash, requestURL, webPageID, retrieveDecision](bool wasEverRequested, const Optional<StoreDecision>&) {
    214215        if (wasEverRequested) {
    215216            String diagnosticKey = retrieveDecisionToDiagnosticKey(retrieveDecision);
     
    221222}
    222223
    223 static String storeDecisionToDiagnosticKey(NetworkCache::StoreDecision storeDecision)
     224static String storeDecisionToDiagnosticKey(StoreDecision storeDecision)
    224225{
    225226    switch (storeDecision) {
    226     case NetworkCache::StoreDecision::NoDueToProtocol:
     227    case StoreDecision::NoDueToProtocol:
    227228        return WebCore::DiagnosticLoggingKeys::notHTTPFamilyKey();
    228     case NetworkCache::StoreDecision::NoDueToHTTPMethod:
     229    case StoreDecision::NoDueToHTTPMethod:
    229230        return WebCore::DiagnosticLoggingKeys::unsupportedHTTPMethodKey();
    230     case NetworkCache::StoreDecision::NoDueToAttachmentResponse:
     231    case StoreDecision::NoDueToAttachmentResponse:
    231232        return WebCore::DiagnosticLoggingKeys::isAttachmentKey();
    232     case NetworkCache::StoreDecision::NoDueToNoStoreResponse:
     233    case StoreDecision::NoDueToNoStoreResponse:
    233234        return WebCore::DiagnosticLoggingKeys::cacheControlNoStoreKey();
    234     case NetworkCache::StoreDecision::NoDueToHTTPStatusCode:
     235    case StoreDecision::NoDueToHTTPStatusCode:
    235236        return WebCore::DiagnosticLoggingKeys::uncacheableStatusCodeKey();
    236     case NetworkCache::StoreDecision::Yes:
     237    case StoreDecision::Yes:
    237238        // It was stored but could not be retrieved so it must have been pruned from the cache.
    238239        return WebCore::DiagnosticLoggingKeys::noLongerInCacheKey();
     
    241242}
    242243
    243 void NetworkCacheStatistics::recordRetrievalFailure(uint64_t webPageID, const NetworkCacheKey& key, const WebCore::ResourceRequest& request)
     244void Statistics::recordRetrievalFailure(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request)
    244245{
    245246    String hash = key.hashAsString();
    246247    WebCore::URL requestURL = request.url();
    247     queryWasEverRequested(hash, NeedUncachedReason::Yes, [this, hash, requestURL, webPageID](bool wasPreviouslyRequested, const Optional<NetworkCache::StoreDecision>& storeDecision) {
     248    queryWasEverRequested(hash, NeedUncachedReason::Yes, [this, hash, requestURL, webPageID](bool wasPreviouslyRequested, const Optional<StoreDecision>& storeDecision) {
    248249        if (wasPreviouslyRequested) {
    249250            String diagnosticKey = storeDecisionToDiagnosticKey(storeDecision.value());
     
    255256}
    256257
    257 static String cachedEntryReuseFailureToDiagnosticKey(NetworkCache::CachedEntryReuseFailure failure)
     258static String cachedEntryReuseFailureToDiagnosticKey(CachedEntryReuseFailure failure)
    258259{
    259260    switch (failure) {
    260     case NetworkCache::CachedEntryReuseFailure::VaryingHeaderMismatch:
     261    case CachedEntryReuseFailure::VaryingHeaderMismatch:
    261262        return WebCore::DiagnosticLoggingKeys::varyingHeaderMismatchKey();
    262     case NetworkCache::CachedEntryReuseFailure::MissingValidatorFields:
     263    case CachedEntryReuseFailure::MissingValidatorFields:
    263264        return WebCore::DiagnosticLoggingKeys::missingValidatorFieldsKey();
    264     case NetworkCache::CachedEntryReuseFailure::Other:
     265    case CachedEntryReuseFailure::Other:
    265266        return WebCore::DiagnosticLoggingKeys::otherKey();
    266     case NetworkCache::CachedEntryReuseFailure::None:
     267    case CachedEntryReuseFailure::None:
    267268        ASSERT_NOT_REACHED();
    268269        break;
     
    271272}
    272273
    273 void NetworkCacheStatistics::recordRetrievedCachedEntry(uint64_t webPageID, const NetworkCacheKey& key, const WebCore::ResourceRequest& request, NetworkCache::CachedEntryReuseFailure failure)
     274void Statistics::recordRetrievedCachedEntry(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request, CachedEntryReuseFailure failure)
    274275{
    275276    WebCore::URL requestURL = request.url();
    276     if (failure == NetworkCache::CachedEntryReuseFailure::None) {
     277    if (failure == CachedEntryReuseFailure::None) {
    277278        LOG(NetworkCache, "(NetworkProcess) webPageID %llu: %s is in the cache and is used", webPageID, requestURL.string().ascii().data());
    278279        NetworkProcess::singleton().logDiagnosticMessageWithResult(webPageID, WebCore::DiagnosticLoggingKeys::networkCacheKey(), WebCore::DiagnosticLoggingKeys::retrievalKey(), WebCore::DiagnosticLoggingResultPass, WebCore::ShouldSample::Yes);
     
    285286}
    286287
    287 void NetworkCacheStatistics::markAsRequested(const String& hash)
     288void Statistics::markAsRequested(const String& hash)
    288289{
    289290    ASSERT(RunLoop::isMain());
     
    294295}
    295296
    296 void NetworkCacheStatistics::writeTimerFired()
     297void Statistics::writeTimerFired()
    297298{
    298299    ASSERT(RunLoop::isMain());
     
    302303    m_hashesToAdd.clear();
    303304
    304     Vector<std::pair<StringCapture, NetworkCache::StoreDecision>> storeDecisionsToAdd;
     305    Vector<std::pair<StringCapture, StoreDecision>> storeDecisionsToAdd;
    305306    copyToVector(m_storeDecisionsToAdd, storeDecisionsToAdd);
    306307    m_storeDecisionsToAdd.clear();
     
    323324}
    324325
    325 void NetworkCacheStatistics::queryWasEverRequested(const String& hash, NeedUncachedReason needUncachedReason, const RequestedCompletionHandler& completionHandler)
     326void Statistics::queryWasEverRequested(const String& hash, NeedUncachedReason needUncachedReason, const RequestedCompletionHandler& completionHandler)
    326327{
    327328    ASSERT(RunLoop::isMain());
     
    344345    dispatch_async(m_backgroundIOQueue.get(), [this, wasAlreadyRequested, &query] () mutable {
    345346        WebCore::SQLiteTransactionInProgressAutoCounter transactionCounter;
    346         Optional<NetworkCache::StoreDecision> storeDecision;
     347        Optional<StoreDecision> storeDecision;
    347348        if (m_database.isOpen()) {
    348349            if (!wasAlreadyRequested) {
     
    355356            if (wasAlreadyRequested && query.needUncachedReason) {
    356357                WebCore::SQLiteStatement statement(m_database, ASCIILiteral("SELECT reason FROM UncachedReason WHERE hash=?"));
    357                 storeDecision = NetworkCache::StoreDecision::Yes;
     358                storeDecision = StoreDecision::Yes;
    358359                if (statement.prepare() == WebCore::SQLResultOk) {
    359360                    statement.bindText(1, query.hash);
    360361                    if (statement.step() == WebCore::SQLResultRow)
    361                         storeDecision = static_cast<NetworkCache::StoreDecision>(statement.getColumnInt(0));
     362                        storeDecision = static_cast<StoreDecision>(statement.getColumnInt(0));
    362363                }
    363364            }
     
    370371}
    371372
    372 void NetworkCacheStatistics::clear()
     373void Statistics::clear()
    373374{
    374375    ASSERT(RunLoop::isMain());
     
    387388}
    388389
    389 void NetworkCacheStatistics::addHashesToDatabase(const Vector<StringCapture>& hashes)
     390void Statistics::addHashesToDatabase(const Vector<StringCapture>& hashes)
    390391{
    391392    ASSERT(!RunLoop::isMain());
     
    405406}
    406407
    407 void NetworkCacheStatistics::addStoreDecisionsToDatabase(const Vector<std::pair<StringCapture, NetworkCache::StoreDecision>>& storeDecisions)
     408void Statistics::addStoreDecisionsToDatabase(const Vector<std::pair<StringCapture, StoreDecision>>& storeDecisions)
    408409{
    409410    ASSERT(!RunLoop::isMain());
     
    423424}
    424425
    425 } // namespace WebKit
     426}
     427}
    426428
    427429#endif // ENABLE(NETWORK_CACHE)
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h

    r181079 r181140  
    3838#include <wtf/text/WTFString.h>
    3939
    40 namespace WebCore {
    41 class SharedBuffer;
    42 }
     40namespace WebKit {
     41namespace NetworkCache {
    4342
    44 namespace IPC {
    45 class ArgumentEncoder;
    46 class ArgumentDecoder;
    47 }
    48 
    49 namespace WebKit {
    50 
    51 class NetworkCacheStorage {
    52     WTF_MAKE_NONCOPYABLE(NetworkCacheStorage);
     43class Storage {
     44    WTF_MAKE_NONCOPYABLE(Storage);
    5345public:
    54     static std::unique_ptr<NetworkCacheStorage> open(const String& cachePath);
     46    static std::unique_ptr<Storage> open(const String& cachePath);
    5547
    5648    struct Entry {
    57         NetworkCacheKey key;
     49        Key key;
    5850        std::chrono::milliseconds timeStamp;
    59         NetworkCacheData header;
    60         NetworkCacheData body;
     51        Data header;
     52        Data body;
    6153    };
    6254    // This may call completion handler synchronously on failure.
    6355    typedef std::function<bool (std::unique_ptr<Entry>)> RetrieveCompletionHandler;
    64     void retrieve(const NetworkCacheKey&, unsigned priority, RetrieveCompletionHandler&&);
     56    void retrieve(const Key&, unsigned priority, RetrieveCompletionHandler&&);
    6557
    66     typedef std::function<void (bool success, const NetworkCacheData& mappedBody)> StoreCompletionHandler;
     58    typedef std::function<void (bool success, const Data& mappedBody)> StoreCompletionHandler;
    6759    void store(const Entry&, StoreCompletionHandler&&);
    6860    void update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&&);
     
    8072
    8173private:
    82     NetworkCacheStorage(const String& directoryPath);
     74    Storage(const String& directoryPath);
    8375
    8476    void initialize();
     
    8678    void shrinkIfNeeded();
    8779
    88     void removeEntry(const NetworkCacheKey&);
     80    void removeEntry(const Key&);
    8981
    9082    struct ReadOperation {
    91         NetworkCacheKey key;
     83        Key key;
    9284        RetrieveCompletionHandler completionHandler;
    9385    };
     
    128120
    129121}
     122}
    130123#endif
    131124#endif
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorageCocoa.mm

    r181079 r181140  
    4747
    4848namespace WebKit {
     49namespace NetworkCache {
    4950
    5051static const char networkCacheSubdirectory[] = "WebKitCache";
    5152static const char versionDirectoryPrefix[] = "Version ";
    5253
    53 std::unique_ptr<NetworkCacheStorage> NetworkCacheStorage::open(const String& cachePath)
     54std::unique_ptr<Storage> Storage::open(const String& cachePath)
    5455{
    5556    ASSERT(RunLoop::isMain());
     
    5859    if (!WebCore::makeAllDirectories(networkCachePath))
    5960        return nullptr;
    60     return std::unique_ptr<NetworkCacheStorage>(new NetworkCacheStorage(networkCachePath));
     61    return std::unique_ptr<Storage>(new Storage(networkCachePath));
    6162}
    6263
    6364static String makeVersionedDirectoryPath(const String& baseDirectoryPath)
    6465{
    65     String versionSubdirectory = versionDirectoryPrefix + String::number(NetworkCacheStorage::version);
     66    String versionSubdirectory = versionDirectoryPrefix + String::number(Storage::version);
    6667    return WebCore::pathByAppendingComponent(baseDirectoryPath, versionSubdirectory);
    6768}
    6869
    69 NetworkCacheStorage::NetworkCacheStorage(const String& baseDirectoryPath)
     70Storage::Storage(const String& baseDirectoryPath)
    7071    : m_baseDirectoryPath(baseDirectoryPath)
    7172    , m_directoryPath(makeVersionedDirectoryPath(baseDirectoryPath))
     
    7778}
    7879
    79 void NetworkCacheStorage::initialize()
     80void Storage::initialize()
    8081{
    8182    ASSERT(RunLoop::isMain());
     
    8687        String cachePath = cachePathCapture.string();
    8788        traverseCacheFiles(cachePath, [this](const String& fileName, const String& partitionPath) {
    88             NetworkCacheKey::HashType hash;
    89             if (!NetworkCacheKey::stringToHash(fileName, hash))
     89            Key::HashType hash;
     90            if (!Key::stringToHash(fileName, hash))
    9091                return;
    91             unsigned shortHash = NetworkCacheKey::toShortHash(hash);
     92            unsigned shortHash = Key::toShortHash(hash);
    9293            RunLoop::main().dispatch([this, shortHash] {
    9394                m_contentsFilter.add(shortHash);
     
    101102}
    102103
    103 static String directoryPathForKey(const NetworkCacheKey& key, const String& cachePath)
     104static String directoryPathForKey(const Key& key, const String& cachePath)
    104105{
    105106    ASSERT(!key.partition().isEmpty());
     
    107108}
    108109
    109 static String fileNameForKey(const NetworkCacheKey& key)
     110static String fileNameForKey(const Key& key)
    110111{
    111112    return key.hashAsString();
    112113}
    113114
    114 static String filePathForKey(const NetworkCacheKey& key, const String& cachePath)
     115static String filePathForKey(const Key& key, const String& cachePath)
    115116{
    116117    return WebCore::pathByAppendingComponent(directoryPathForKey(key, cachePath), fileNameForKey(key));
    117118}
    118119
    119 static Ref<NetworkCacheIOChannel> openFileForKey(const NetworkCacheKey& key, NetworkCacheIOChannel::Type type, const String& cachePath)
     120static Ref<IOChannel> openFileForKey(const Key& key, IOChannel::Type type, const String& cachePath)
    120121{
    121122    auto directoryPath = directoryPathForKey(key, cachePath);
    122123    auto filePath = WebCore::pathByAppendingComponent(directoryPath, fileNameForKey(key));
    123     if (type == NetworkCacheIOChannel::Type::Create)
     124    if (type == IOChannel::Type::Create)
    124125        WebCore::makeAllDirectories(directoryPath);
    125     return NetworkCacheIOChannel::open(filePath, type);
     126    return IOChannel::open(filePath, type);
    126127}
    127128
     
    140141struct EntryMetaData {
    141142    EntryMetaData() { }
    142     explicit EntryMetaData(const NetworkCacheKey& key) : cacheStorageVersion(NetworkCacheStorage::version), key(key) { }
     143    explicit EntryMetaData(const Key& key)
     144        : cacheStorageVersion(Storage::version)
     145        , key(key)
     146    { }
    143147
    144148    unsigned cacheStorageVersion;
    145     NetworkCacheKey key;
     149    Key key;
    146150    std::chrono::milliseconds timeStamp;
    147151    unsigned headerChecksum;
     
    153157};
    154158
    155 static bool decodeEntryMetaData(EntryMetaData& metaData, const NetworkCacheData& fileData)
     159static bool decodeEntryMetaData(EntryMetaData& metaData, const Data& fileData)
    156160{
    157161    bool success = false;
    158162    dispatch_data_apply(fileData.dispatchData(), [&metaData, &success](dispatch_data_t, size_t, const void* data, size_t size) {
    159         NetworkCacheDecoder decoder(reinterpret_cast<const uint8_t*>(data), size);
     163        Decoder decoder(reinterpret_cast<const uint8_t*>(data), size);
    160164        if (!decoder.decode(metaData.cacheStorageVersion))
    161165            return false;
     
    193197}
    194198
    195 static bool decodeEntryHeader(const NetworkCacheData& fileData, EntryMetaData& metaData, NetworkCacheData& data)
     199static bool decodeEntryHeader(const Data& fileData, EntryMetaData& metaData, Data& data)
    196200{
    197201    if (!decodeEntryMetaData(metaData, fileData))
    198202        return false;
    199     if (metaData.cacheStorageVersion != NetworkCacheStorage::version)
     203    if (metaData.cacheStorageVersion != Storage::version)
    200204        return false;
    201205    if (metaData.headerOffset + metaData.headerSize > metaData.bodyOffset)
     
    211215}
    212216
    213 static std::unique_ptr<NetworkCacheStorage::Entry> decodeEntry(const NetworkCacheData& fileData, int fd, const NetworkCacheKey& key)
     217static std::unique_ptr<Storage::Entry> decodeEntry(const Data& fileData, int fd, const Key& key)
    214218{
    215219    EntryMetaData metaData;
    216     NetworkCacheData headerData;
     220    Data headerData;
    217221    if (!decodeEntryHeader(fileData, metaData, headerData))
    218222        return nullptr;
     
    234238    }
    235239
    236     return std::unique_ptr<NetworkCacheStorage::Entry>(new NetworkCacheStorage::Entry {
     240    return std::unique_ptr<Storage::Entry>(new Storage::Entry {
    237241        metaData.key,
    238242        metaData.timeStamp,
    239243        headerData,
    240         { bodyData, NetworkCacheData::Backing::Map }
     244        { bodyData, Data::Backing::Map }
    241245    });
    242246}
     
    244248static DispatchPtr<dispatch_data_t> encodeEntryMetaData(const EntryMetaData& entry)
    245249{
    246     NetworkCacheEncoder encoder;
     250    Encoder encoder;
    247251
    248252    encoder << entry.cacheStorageVersion;
     
    259263}
    260264
    261 static NetworkCacheData encodeEntryHeader(const NetworkCacheStorage::Entry& entry)
     265static Data encodeEntryHeader(const Storage::Entry& entry)
    262266{
    263267    EntryMetaData metaData(entry.key);
     
    280284}
    281285
    282 void NetworkCacheStorage::removeEntry(const NetworkCacheKey& key)
     286void Storage::removeEntry(const Key& key)
    283287{
    284288    ASSERT(RunLoop::isMain());
     
    296300}
    297301
    298 void NetworkCacheStorage::dispatchReadOperation(const ReadOperation& read)
     302void Storage::dispatchReadOperation(const ReadOperation& read)
    299303{
    300304    ASSERT(RunLoop::isMain());
     
    303307    StringCapture cachePathCapture(m_directoryPath);
    304308    ioQueue().dispatch([this, &read, cachePathCapture] {
    305         auto channel = openFileForKey(read.key, NetworkCacheIOChannel::Type::Read, cachePathCapture.string());
     309        auto channel = openFileForKey(read.key, IOChannel::Type::Read, cachePathCapture.string());
    306310        int fd = channel->fileDescriptor();
    307         channel->read(0, std::numeric_limits<size_t>::max(), [this, &read, fd](NetworkCacheData& fileData, int error) {
     311        channel->read(0, std::numeric_limits<size_t>::max(), [this, &read, fd](Data& fileData, int error) {
    308312            if (error) {
    309313                removeEntry(read.key);
     
    325329}
    326330
    327 void NetworkCacheStorage::dispatchPendingReadOperations()
     331void Storage::dispatchPendingReadOperations()
    328332{
    329333    ASSERT(RunLoop::isMain());
     
    346350}
    347351
    348 template <class T> bool retrieveFromMemory(const T& operations, const NetworkCacheKey& key, NetworkCacheStorage::RetrieveCompletionHandler& completionHandler)
     352template <class T> bool retrieveFromMemory(const T& operations, const Key& key, Storage::RetrieveCompletionHandler& completionHandler)
    349353{
    350354    for (auto& operation : operations) {
     
    353357            auto entry = operation->entry;
    354358            RunLoop::main().dispatch([entry, completionHandler] {
    355                 completionHandler(std::make_unique<NetworkCacheStorage::Entry>(entry));
     359                completionHandler(std::make_unique<Storage::Entry>(entry));
    356360            });
    357361            return true;
     
    361365}
    362366
    363 void NetworkCacheStorage::retrieve(const NetworkCacheKey& key, unsigned priority, RetrieveCompletionHandler&& completionHandler)
     367void Storage::retrieve(const Key& key, unsigned priority, RetrieveCompletionHandler&& completionHandler)
    364368{
    365369    ASSERT(RunLoop::isMain());
     
    386390}
    387391
    388 void NetworkCacheStorage::store(const Entry& entry, StoreCompletionHandler&& completionHandler)
     392void Storage::store(const Entry& entry, StoreCompletionHandler&& completionHandler)
    389393{
    390394    ASSERT(RunLoop::isMain());
     
    404408}
    405409
    406 void NetworkCacheStorage::update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&& completionHandler)
     410void Storage::update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&& completionHandler)
    407411{
    408412    ASSERT(RunLoop::isMain());
     
    420424}
    421425
    422 void NetworkCacheStorage::traverse(std::function<void (const Entry*)>&& traverseHandler)
     426void Storage::traverse(std::function<void (const Entry*)>&& traverseHandler)
    423427{
    424428    StringCapture cachePathCapture(m_directoryPath);
     
    428432        traverseCacheFiles(cachePath, [this, &semaphore, &traverseHandler](const String& fileName, const String& partitionPath) {
    429433            auto filePath = WebCore::pathByAppendingComponent(partitionPath, fileName);
    430             auto channel = NetworkCacheIOChannel::open(filePath, NetworkCacheIOChannel::Type::Read);
     434            auto channel = IOChannel::open(filePath, IOChannel::Type::Read);
    431435            const size_t headerReadSize = 16 << 10;
    432             channel->read(0, headerReadSize, [this, &semaphore, &traverseHandler](NetworkCacheData& fileData, int) {
     436            channel->read(0, headerReadSize, [this, &semaphore, &traverseHandler](Data& fileData, int) {
    433437                EntryMetaData metaData;
    434                 NetworkCacheData headerData;
     438                Data headerData;
    435439                if (decodeEntryHeader(fileData, metaData, headerData)) {
    436440                    Entry entry { metaData.key, metaData.timeStamp, headerData, { } };
     
    447451}
    448452
    449 void NetworkCacheStorage::dispatchPendingWriteOperations()
     453void Storage::dispatchPendingWriteOperations()
    450454{
    451455    ASSERT(RunLoop::isMain());
     
    470474}
    471475
    472 void NetworkCacheStorage::dispatchFullWriteOperation(const WriteOperation& write)
     476void Storage::dispatchFullWriteOperation(const WriteOperation& write)
    473477{
    474478    ASSERT(RunLoop::isMain());
     
    483487        auto headerAndBodyData = adoptDispatch(dispatch_data_create_concat(encodedHeader.dispatchData(), write.entry.body.dispatchData()));
    484488
    485         NetworkCacheData writeData(headerAndBodyData);
    486 
    487         auto channel = openFileForKey(write.entry.key, NetworkCacheIOChannel::Type::Create, cachePathCapture.string());
     489        Data writeData(headerAndBodyData);
     490
     491        auto channel = openFileForKey(write.entry.key, IOChannel::Type::Create, cachePathCapture.string());
    488492        int fd = channel->fileDescriptor();
    489493        size_t bodyOffset = encodedHeader.size();
     
    503507            auto bodyMap = shouldMapBody ? mapFile(fd, bodyOffset, bodySize) : nullptr;
    504508
    505             NetworkCacheData bodyData(bodyMap, NetworkCacheData::Backing::Map);
     509            Data bodyData(bodyMap, Data::Backing::Map);
    506510            write.completionHandler(!error, bodyData);
    507511
     
    515519}
    516520
    517 void NetworkCacheStorage::dispatchHeaderWriteOperation(const WriteOperation& write)
     521void Storage::dispatchHeaderWriteOperation(const WriteOperation& write)
    518522{
    519523    ASSERT(RunLoop::isMain());
     
    537541        }
    538542
    539         auto channel = openFileForKey(write.entry.key, NetworkCacheIOChannel::Type::Write, cachePathCapture.string());
     543        auto channel = openFileForKey(write.entry.key, IOChannel::Type::Write, cachePathCapture.string());
    540544        channel->write(0, headerData, [this, &write](int error) {
    541545            LOG(NetworkCacheStorage, "(NetworkProcess) update complete error=%d", error);
     
    553557}
    554558
    555 void NetworkCacheStorage::setMaximumSize(size_t size)
     559void Storage::setMaximumSize(size_t size)
    556560{
    557561    ASSERT(RunLoop::isMain());
     
    561565}
    562566
    563 void NetworkCacheStorage::clear()
     567void Storage::clear()
    564568{
    565569    ASSERT(RunLoop::isMain());
     
    583587}
    584588
    585 void NetworkCacheStorage::shrinkIfNeeded()
     589void Storage::shrinkIfNeeded()
    586590{
    587591    ASSERT(RunLoop::isMain());
     
    614618
    615619            WebCore::deleteFile(filePath);
    616             NetworkCacheKey::HashType hash;
    617             if (!NetworkCacheKey::stringToHash(fileName, hash))
     620            Key::HashType hash;
     621            if (!Key::stringToHash(fileName, hash))
    618622                return;
    619             unsigned shortHash = NetworkCacheKey::toShortHash(hash);
     623            unsigned shortHash = Key::toShortHash(hash);
    620624            RunLoop::main().dispatch([this, shortHash] {
    621625                if (m_contentsFilter.mayContain(shortHash))
     
    636640}
    637641
    638 void NetworkCacheStorage::deleteOldVersions()
     642void Storage::deleteOldVersions()
    639643{
    640644    // Delete V1 cache.
     
    655659
    656660}
     661}
    657662
    658663#endif
Note: See TracChangeset for help on using the changeset viewer.