OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkUrlDataManager_DEFINED | |
9 #define SkUrlDataManager_DEFINED | |
10 | |
11 #include "SkChecksum.h" | |
12 #include "SkData.h" | |
13 #include "SkString.h" | |
14 #include "SkTDynamicHash.h" | |
15 | |
16 /* | |
17 * A simple class which allows clients to add opaque data types, and returns a u rl where this data | |
18 * will be hosted. Its up to the owner of this class to actually serve the data . | |
19 */ | |
20 bool operator==(const SkData& a, const SkData& b); | |
21 | |
22 class UrlDataManager { | |
23 public: | |
24 UrlDataManager(SkString rootUrl); | |
25 ~UrlDataManager() { this->reset(); } | |
26 | |
27 SkString addData(SkData*, const char* contentType); | |
ethannicholas
2016/02/08 14:26:35
Can we get some documentation on this method, e.g.
| |
28 | |
29 struct UrlData : public SkRefCnt { | |
30 SkString fUrl; | |
31 SkString fContentType; | |
32 SkAutoTUnref<SkData> fData; | |
33 }; | |
34 | |
35 UrlData* getDataFromUrl(SkString url) { | |
36 return fUrlLookup.find(url); | |
37 } | |
38 void reset(); | |
39 | |
40 private: | |
41 struct LookupTrait { | |
42 // We use the data as a hash, this is not really optimal but is fine unt il proven otherwise | |
43 static const SkData& GetKey(const UrlData& data) { | |
44 return *data.fData.get(); | |
45 } | |
46 | |
47 static uint32_t Hash(const SkData& key) { | |
48 return SkChecksum::Murmur3(key.bytes(), key.size()); | |
49 } | |
50 }; | |
51 | |
52 struct ReverseLookupTrait { | |
53 static const SkString& GetKey(const UrlData& data) { | |
54 return data.fUrl; | |
55 } | |
56 | |
57 static uint32_t Hash(const SkString& key) { | |
58 return SkChecksum::Murmur3(key.c_str(), strlen(key.c_str())); | |
59 } | |
60 }; | |
61 | |
62 | |
63 SkString fRootUrl; | |
64 SkTDynamicHash<UrlData, SkData, LookupTrait> fCache; | |
65 SkTDynamicHash<UrlData, SkString, ReverseLookupTrait> fUrlLookup; | |
66 uint32_t fDataId; | |
67 }; | |
68 | |
69 #endif | |
OLD | NEW |