gfx/2d/DrawEventRecorder.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef MOZILLA_GFX_DRAWEVENTRECORDER_H_
     7 #define MOZILLA_GFX_DRAWEVENTRECORDER_H_
     9 #include "2D.h"
    10 #include "RecordedEvent.h"
    11 #include <ostream>
    12 #include <fstream>
    14 #if defined(_MSC_VER)
    15 #include <hash_set>
    16 #else
    17 #include <set>
    18 #endif
    20 namespace mozilla {
    21 namespace gfx {
    23 class PathRecording;
    25 class DrawEventRecorderPrivate : public DrawEventRecorder
    26 {
    27 public:
    28   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderPrivate)
    29   DrawEventRecorderPrivate(std::ostream *aStream);
    30   virtual ~DrawEventRecorderPrivate() { }
    32   void RecordEvent(const RecordedEvent &aEvent);
    33   void WritePath(const PathRecording *aPath);
    35   void AddStoredPath(const ReferencePtr aPath) {
    36     mStoredPaths.insert(aPath);
    37   }
    39   void RemoveStoredPath(const ReferencePtr aPath) {
    40     mStoredPaths.erase(aPath);
    41   }
    43   bool HasStoredPath(const ReferencePtr aPath) {
    44     if (mStoredPaths.find(aPath) != mStoredPaths.end()) {
    45       return true;
    46     }
    47     return false;
    48   }
    50 protected:
    51   std::ostream *mOutputStream;
    53   virtual void Flush() = 0;
    55 #if defined(_MSC_VER)
    56   typedef stdext::hash_set<const void*> ObjectSet;
    57 #else
    58   typedef std::set<const void*> ObjectSet;
    59 #endif
    61   ObjectSet mStoredPaths;
    62   ObjectSet mStoredScaledFonts;
    63 };
    65 class DrawEventRecorderFile : public DrawEventRecorderPrivate
    66 {
    67 public:
    68   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderFile)
    69   DrawEventRecorderFile(const char *aFilename);
    70   ~DrawEventRecorderFile();
    72 private:
    73   virtual void Flush();
    75   std::ofstream mOutputFile;
    76 };
    78 }
    79 }
    81 #endif /* MOZILLA_GFX_DRAWEVENTRECORDER_H_ */

mercurial