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 2012 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 | #include "SkTypes.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "SkThreadUtils.h" |
michael@0 | 11 | #include "SkThreadUtils_pthread.h" |
michael@0 | 12 | |
michael@0 | 13 | #include <pthread.h> |
michael@0 | 14 | #include <signal.h> |
michael@0 | 15 | |
michael@0 | 16 | PThreadEvent::PThreadEvent() : fConditionFlag(false) { |
michael@0 | 17 | pthread_cond_init(&fCondition, NULL); |
michael@0 | 18 | pthread_mutex_init(&fConditionMutex, NULL); |
michael@0 | 19 | } |
michael@0 | 20 | PThreadEvent::~PThreadEvent() { |
michael@0 | 21 | pthread_mutex_destroy(&fConditionMutex); |
michael@0 | 22 | pthread_cond_destroy(&fCondition); |
michael@0 | 23 | } |
michael@0 | 24 | void PThreadEvent::trigger() { |
michael@0 | 25 | pthread_mutex_lock(&fConditionMutex); |
michael@0 | 26 | fConditionFlag = true; |
michael@0 | 27 | pthread_cond_signal(&fCondition); |
michael@0 | 28 | pthread_mutex_unlock(&fConditionMutex); |
michael@0 | 29 | } |
michael@0 | 30 | void PThreadEvent::wait() { |
michael@0 | 31 | pthread_mutex_lock(&fConditionMutex); |
michael@0 | 32 | while (!fConditionFlag) { |
michael@0 | 33 | pthread_cond_wait(&fCondition, &fConditionMutex); |
michael@0 | 34 | } |
michael@0 | 35 | pthread_mutex_unlock(&fConditionMutex); |
michael@0 | 36 | } |
michael@0 | 37 | bool PThreadEvent::isTriggered() { |
michael@0 | 38 | bool currentFlag; |
michael@0 | 39 | pthread_mutex_lock(&fConditionMutex); |
michael@0 | 40 | currentFlag = fConditionFlag; |
michael@0 | 41 | pthread_mutex_unlock(&fConditionMutex); |
michael@0 | 42 | return currentFlag; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | SkThread_PThreadData::SkThread_PThreadData(SkThread::entryPointProc entryPoint, void* data) |
michael@0 | 46 | : fPThread() |
michael@0 | 47 | , fValidPThread(false) |
michael@0 | 48 | , fParam(data) |
michael@0 | 49 | , fEntryPoint(entryPoint) |
michael@0 | 50 | { |
michael@0 | 51 | pthread_attr_init(&fAttr); |
michael@0 | 52 | pthread_attr_setdetachstate(&fAttr, PTHREAD_CREATE_JOINABLE); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | SkThread_PThreadData::~SkThread_PThreadData() { |
michael@0 | 56 | pthread_attr_destroy(&fAttr); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | static void* thread_start(void* arg) { |
michael@0 | 60 | SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(arg); |
michael@0 | 61 | // Wait for start signal |
michael@0 | 62 | pthreadData->fStarted.wait(); |
michael@0 | 63 | |
michael@0 | 64 | // Call entry point only if thread was not canceled before starting. |
michael@0 | 65 | if (!pthreadData->fCanceled.isTriggered()) { |
michael@0 | 66 | pthreadData->fEntryPoint(pthreadData->fParam); |
michael@0 | 67 | } |
michael@0 | 68 | return NULL; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | SkThread::SkThread(entryPointProc entryPoint, void* data) { |
michael@0 | 72 | SkThread_PThreadData* pthreadData = new SkThread_PThreadData(entryPoint, data); |
michael@0 | 73 | fData = pthreadData; |
michael@0 | 74 | |
michael@0 | 75 | int ret = pthread_create(&(pthreadData->fPThread), |
michael@0 | 76 | &(pthreadData->fAttr), |
michael@0 | 77 | thread_start, |
michael@0 | 78 | pthreadData); |
michael@0 | 79 | |
michael@0 | 80 | pthreadData->fValidPThread = (0 == ret); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | SkThread::~SkThread() { |
michael@0 | 84 | if (fData != NULL) { |
michael@0 | 85 | SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData); |
michael@0 | 86 | // If created thread but start was never called, kill the thread. |
michael@0 | 87 | if (pthreadData->fValidPThread && !pthreadData->fStarted.isTriggered()) { |
michael@0 | 88 | pthreadData->fCanceled.trigger(); |
michael@0 | 89 | if (this->start()) { |
michael@0 | 90 | this->join(); |
michael@0 | 91 | } |
michael@0 | 92 | } |
michael@0 | 93 | delete pthreadData; |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | bool SkThread::start() { |
michael@0 | 98 | SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData); |
michael@0 | 99 | if (!pthreadData->fValidPThread) { |
michael@0 | 100 | return false; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | if (pthreadData->fStarted.isTriggered()) { |
michael@0 | 104 | return false; |
michael@0 | 105 | } |
michael@0 | 106 | pthreadData->fStarted.trigger(); |
michael@0 | 107 | return true; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | void SkThread::join() { |
michael@0 | 111 | SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData); |
michael@0 | 112 | if (!pthreadData->fValidPThread || !pthreadData->fStarted.isTriggered()) { |
michael@0 | 113 | return; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | pthread_join(pthreadData->fPThread, NULL); |
michael@0 | 117 | } |