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 | // SkTLS.h |
michael@0 | 3 | // |
michael@0 | 4 | // |
michael@0 | 5 | // Created by Mike Reed on 4/21/12. |
michael@0 | 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. |
michael@0 | 7 | // |
michael@0 | 8 | |
michael@0 | 9 | #ifndef SkTLS_DEFINED |
michael@0 | 10 | #define SkTLS_DEFINED |
michael@0 | 11 | |
michael@0 | 12 | #include "SkTypes.h" |
michael@0 | 13 | |
michael@0 | 14 | /** |
michael@0 | 15 | * Maintains a per-thread cache, using a CreateProc as the key into that cache. |
michael@0 | 16 | */ |
michael@0 | 17 | class SkTLS { |
michael@0 | 18 | public: |
michael@0 | 19 | typedef void* (*CreateProc)(); |
michael@0 | 20 | typedef void (*DeleteProc)(void*); |
michael@0 | 21 | |
michael@0 | 22 | /** |
michael@0 | 23 | * If Get() has previously been called with this CreateProc, then this |
michael@0 | 24 | * returns its cached data, otherwise it returns NULL. The CreateProc is |
michael@0 | 25 | * never invoked in Find, it is only used as a key for searching the |
michael@0 | 26 | * cache. |
michael@0 | 27 | */ |
michael@0 | 28 | static void* Find(CreateProc); |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Return the cached data that was returned by the CreateProc. This proc |
michael@0 | 32 | * is only called the first time Get is called, and there after it is |
michael@0 | 33 | * cached (per-thread), using the CreateProc as a key to look it up. |
michael@0 | 34 | * |
michael@0 | 35 | * When this thread, or Delete is called, the cached data is removed, and |
michael@0 | 36 | * if a DeleteProc was specified, it is passed the pointer to the cached |
michael@0 | 37 | * data. |
michael@0 | 38 | */ |
michael@0 | 39 | static void* Get(CreateProc, DeleteProc); |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * Remove (optionally calling the DeleteProc if it was specificed in Get) |
michael@0 | 43 | * the cached data associated with this CreateProc. If no associated cached |
michael@0 | 44 | * data is found, do nothing. |
michael@0 | 45 | */ |
michael@0 | 46 | static void Delete(CreateProc); |
michael@0 | 47 | |
michael@0 | 48 | private: |
michael@0 | 49 | // Our implementation requires only 1 TLS slot, as we manage multiple values |
michael@0 | 50 | // ourselves in a list, with the platform specific value as our head. |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Implemented by the platform, to return the value of our (one) slot per-thread |
michael@0 | 54 | * |
michael@0 | 55 | * If forceCreateTheSlot is true, then we must have created the "slot" for |
michael@0 | 56 | * our TLS, even though we know that the return value will be NULL in that |
michael@0 | 57 | * case (i.e. no-slot and first-time-slot both return NULL). This ensures |
michael@0 | 58 | * that after calling GetSpecific, we know that we can legally call |
michael@0 | 59 | * SetSpecific. |
michael@0 | 60 | * |
michael@0 | 61 | * If forceCreateTheSlot is false, then the impl can either create the |
michael@0 | 62 | * slot or not. |
michael@0 | 63 | */ |
michael@0 | 64 | static void* PlatformGetSpecific(bool forceCreateTheSlot); |
michael@0 | 65 | |
michael@0 | 66 | /** |
michael@0 | 67 | * Implemented by the platform, to set the value for our (one) slot per-thread |
michael@0 | 68 | * |
michael@0 | 69 | * The implementation can rely on GetSpecific(true) having been previously |
michael@0 | 70 | * called before SetSpecific is called. |
michael@0 | 71 | */ |
michael@0 | 72 | static void PlatformSetSpecific(void*); |
michael@0 | 73 | |
michael@0 | 74 | public: |
michael@0 | 75 | /** |
michael@0 | 76 | * Will delete our internal list. To be called by the platform if/when its |
michael@0 | 77 | * TLS slot is deleted (often at thread shutdown). |
michael@0 | 78 | * |
michael@0 | 79 | * Public *only* for the platform's use, not to be called by a client. |
michael@0 | 80 | */ |
michael@0 | 81 | static void Destructor(void* ptr); |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | #endif |