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.

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

mercurial