gfx/skia/trunk/src/gpu/GrTemplates.h

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.

     1 /*
     2  * Copyright 2010 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  */
     8 #ifndef GrTemplates_DEFINED
     9 #define GrTemplates_DEFINED
    11 #include "SkTypes.h"
    13 /**
    14  *  Use to cast a ptr to a different type, and maintain strict-aliasing
    15  */
    16 template <typename Dst, typename Src> Dst GrTCast(Src src) {
    17     union {
    18         Src src;
    19         Dst dst;
    20     } data;
    21     data.src = src;
    22     return data.dst;
    23 }
    25 /**
    26  * takes a T*, saves the value it points to,  in and restores the value in the
    27  * destructor
    28  * e.g.:
    29  * {
    30  *      GrAutoTRestore<int*> autoCountRestore;
    31  *      if (useExtra) {
    32  *          autoCountRestore.reset(&fCount);
    33  *          fCount += fExtraCount;
    34  *      }
    35  *      ...
    36  * }  // fCount is restored
    37  */
    38 template <typename T> class GrAutoTRestore : public SkNoncopyable {
    39 public:
    40     GrAutoTRestore() : fPtr(NULL), fVal() {}
    42     GrAutoTRestore(T* ptr) {
    43         fPtr = ptr;
    44         if (NULL != ptr) {
    45             fVal = *ptr;
    46         }
    47     }
    49     ~GrAutoTRestore() {
    50         if (NULL != fPtr) {
    51             *fPtr = fVal;
    52         }
    53     }
    55     // restores previously saved value (if any) and saves value for passed T*
    56     void reset(T* ptr) {
    57         if (NULL != fPtr) {
    58             *fPtr = fVal;
    59         }
    60         fPtr = ptr;
    61         fVal = *ptr;
    62     }
    63 private:
    64     T* fPtr;
    65     T  fVal;
    66 };
    68 #endif

mercurial