gfx/skia/trunk/src/core/SkRefDict.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkRefDict.h"
michael@0 11 #include "SkString.h"
michael@0 12
michael@0 13 struct SkRefDict::Impl {
michael@0 14 Impl* fNext;
michael@0 15 SkString fName;
michael@0 16 SkRefCnt* fData;
michael@0 17 };
michael@0 18
michael@0 19 SkRefDict::SkRefDict() : fImpl(NULL) {}
michael@0 20
michael@0 21 SkRefDict::~SkRefDict() {
michael@0 22 this->removeAll();
michael@0 23 }
michael@0 24
michael@0 25 SkRefCnt* SkRefDict::find(const char name[]) const {
michael@0 26 if (NULL == name) {
michael@0 27 return NULL;
michael@0 28 }
michael@0 29
michael@0 30 Impl* rec = fImpl;
michael@0 31 while (rec) {
michael@0 32 if (rec->fName.equals(name)) {
michael@0 33 return rec->fData;
michael@0 34 }
michael@0 35 rec = rec->fNext;
michael@0 36 }
michael@0 37 return NULL;
michael@0 38 }
michael@0 39
michael@0 40 void SkRefDict::set(const char name[], SkRefCnt* data) {
michael@0 41 if (NULL == name) {
michael@0 42 return;
michael@0 43 }
michael@0 44
michael@0 45 Impl* rec = fImpl;
michael@0 46 Impl* prev = NULL;
michael@0 47 while (rec) {
michael@0 48 if (rec->fName.equals(name)) {
michael@0 49 if (data) {
michael@0 50 // replace
michael@0 51 data->ref();
michael@0 52 rec->fData->unref();
michael@0 53 rec->fData = data;
michael@0 54 } else {
michael@0 55 // remove
michael@0 56 rec->fData->unref();
michael@0 57 if (prev) {
michael@0 58 prev->fNext = rec->fNext;
michael@0 59 } else {
michael@0 60 fImpl = rec->fNext;
michael@0 61 }
michael@0 62 delete rec;
michael@0 63 }
michael@0 64 return;
michael@0 65 }
michael@0 66 prev = rec;
michael@0 67 rec = rec->fNext;
michael@0 68 }
michael@0 69
michael@0 70 // if get here, name was not found, so add it
michael@0 71 data->ref();
michael@0 72 rec = new Impl;
michael@0 73 rec->fName.set(name);
michael@0 74 rec->fData = data;
michael@0 75 // prepend to the head of our list
michael@0 76 rec->fNext = fImpl;
michael@0 77 fImpl = rec;
michael@0 78 }
michael@0 79
michael@0 80 void SkRefDict::removeAll() {
michael@0 81 Impl* rec = fImpl;
michael@0 82 while (rec) {
michael@0 83 Impl* next = rec->fNext;
michael@0 84 rec->fData->unref();
michael@0 85 delete rec;
michael@0 86 rec = next;
michael@0 87 }
michael@0 88 fImpl = NULL;
michael@0 89 }

mercurial