Sat, 03 Jan 2015 20:18:00 +0100
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 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SkMutex_pthread_DEFINED |
michael@0 | 9 | #define SkMutex_pthread_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | /** Posix pthread_mutex based mutex. */ |
michael@0 | 12 | |
michael@0 | 13 | #ifdef SK_DEBUG_PTHREAD_MUTEX |
michael@0 | 14 | #include "SkTypes.h" |
michael@0 | 15 | #define SkDEBUGCODE_PTHREAD_MUTEX(code) code |
michael@0 | 16 | #else |
michael@0 | 17 | #define SkDEBUGCODE_PTHREAD_MUTEX(code) |
michael@0 | 18 | #ifndef SkDebugf |
michael@0 | 19 | void SkDebugf(const char format[], ...); |
michael@0 | 20 | #endif |
michael@0 | 21 | #endif |
michael@0 | 22 | |
michael@0 | 23 | #include <errno.h> |
michael@0 | 24 | #include <pthread.h> |
michael@0 | 25 | |
michael@0 | 26 | // A SkBaseMutex is a POD structure that can be directly initialized |
michael@0 | 27 | // at declaration time with SK_DECLARE_STATIC/GLOBAL_MUTEX. This avoids the |
michael@0 | 28 | // generation of a static initializer in the final machine code (and |
michael@0 | 29 | // a corresponding static finalizer). |
michael@0 | 30 | struct SkBaseMutex { |
michael@0 | 31 | void acquire() { pthread_mutex_lock(&fMutex); } |
michael@0 | 32 | void release() { pthread_mutex_unlock(&fMutex); } |
michael@0 | 33 | pthread_mutex_t fMutex; |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | // A normal mutex that requires to be initialized through normal C++ construction, |
michael@0 | 37 | // i.e. when it's a member of another class, or allocated on the heap. |
michael@0 | 38 | class SkMutex : public SkBaseMutex { |
michael@0 | 39 | public: |
michael@0 | 40 | SkMutex() { |
michael@0 | 41 | SkDEBUGCODE_PTHREAD_MUTEX(int status = )pthread_mutex_init(&fMutex, NULL); |
michael@0 | 42 | SkDEBUGCODE_PTHREAD_MUTEX( |
michael@0 | 43 | if (status != 0) { |
michael@0 | 44 | print_pthread_error(status); |
michael@0 | 45 | SkASSERT(0 == status); |
michael@0 | 46 | } |
michael@0 | 47 | ) |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | ~SkMutex() { |
michael@0 | 51 | SkDEBUGCODE_PTHREAD_MUTEX(int status = )pthread_mutex_destroy(&fMutex); |
michael@0 | 52 | SkDEBUGCODE_PTHREAD_MUTEX( |
michael@0 | 53 | if (status != 0) { |
michael@0 | 54 | print_pthread_error(status); |
michael@0 | 55 | SkASSERT(0 == status); |
michael@0 | 56 | } |
michael@0 | 57 | ) |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | private: |
michael@0 | 61 | SkMutex(const SkMutex&); |
michael@0 | 62 | SkMutex& operator=(const SkMutex&); |
michael@0 | 63 | |
michael@0 | 64 | static void print_pthread_error(int status) { |
michael@0 | 65 | switch (status) { |
michael@0 | 66 | case 0: // success |
michael@0 | 67 | break; |
michael@0 | 68 | case EINVAL: |
michael@0 | 69 | SkDebugf("pthread error [%d] EINVAL\n", status); |
michael@0 | 70 | break; |
michael@0 | 71 | case EBUSY: |
michael@0 | 72 | SkDebugf("pthread error [%d] EBUSY\n", status); |
michael@0 | 73 | break; |
michael@0 | 74 | default: |
michael@0 | 75 | SkDebugf("pthread error [%d] unknown\n", status); |
michael@0 | 76 | break; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | // Using POD-style initialization prevents the generation of a static initializer. |
michael@0 | 82 | #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = { PTHREAD_MUTEX_INITIALIZER } |
michael@0 | 83 | |
michael@0 | 84 | // Special case used when the static mutex must be available globally. |
michael@0 | 85 | #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = { PTHREAD_MUTEX_INITIALIZER } |
michael@0 | 86 | |
michael@0 | 87 | #endif |