Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1607)

Side by Side Diff: tools/UrlDataManager.cpp

Issue 1670153005: Create image cache for use by json canvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/UrlDataManager.h ('k') | tools/skiaserve/skiaserve.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "UrlDataManager.h"
9
10 bool operator==(const SkData& a, const SkData& b) {
11 return a.equals(&b);
12 }
13
14 UrlDataManager::UrlDataManager(SkString rootUrl) : fRootUrl(rootUrl), fDataId(0) {}
15
16 SkString UrlDataManager::addData(SkData* data, const char* contentType) {
17 UrlData* urlData = fCache.find(*data);
18 if (fCache.find(*data)) {
19 SkASSERT(data->equals(urlData->fData.get()));
20 return urlData->fUrl;
21 }
22
23 urlData = new UrlData;
24 urlData->fData.reset(SkRef(data));
25 urlData->fContentType.set(contentType);
26 urlData->fUrl.appendf("%s/%d", fRootUrl.c_str(), fDataId++);
27
28 fCache.add(urlData);
29
30 SkASSERT(!fUrlLookup.find(urlData->fUrl));
31 fUrlLookup.add(urlData);
32 return urlData->fUrl;
33 }
34
35 void UrlDataManager::reset() {
36 SkTDynamicHash<UrlData, SkData, LookupTrait>::Iter iter(&fCache);
37 while (!iter.done()) {
38 UrlData* urlData = &(*iter);
39 urlData->unref();
40 ++iter;
41 }
42
43 fCache.rewind();
44 }
OLDNEW
« no previous file with comments | « tools/UrlDataManager.h ('k') | tools/skiaserve/skiaserve.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698