Tue, 06 Jan 2015 21:39:09 +0100
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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_LATENCY_H
8 #define MOZILLA_LATENCY_H
10 #include "mozilla/TimeStamp.h"
11 #include "prlog.h"
12 #include "nsCOMPtr.h"
13 #include "nsIThread.h"
14 #include "mozilla/Monitor.h"
15 #include "nsISupportsImpl.h"
16 #include "nsIObserver.h"
18 class AsyncLatencyLogger;
19 class LogEvent;
21 PRLogModuleInfo* GetLatencyLog();
23 // This class is a singleton. It is refcounted.
24 class AsyncLatencyLogger : public nsIObserver
25 {
26 NS_DECL_THREADSAFE_ISUPPORTS
27 NS_DECL_NSIOBSERVER
29 public:
31 enum LatencyLogIndex {
32 AudioMediaStreamTrack = 0,
33 VideoMediaStreamTrack,
34 Cubeb,
35 AudioStream,
36 NetEQ,
37 AudioCaptureBase, // base time for capturing an audio stream
38 AudioCapture, // records number of samples captured and the time
39 AudioTrackInsertion, // # of samples inserted into a mediastreamtrack and the time
40 MediaPipelineAudioInsertion, // Timestamp and time of timestamp
41 AudioTransmit, // Timestamp and socket send time
42 AudioReceive, // Timestamp and receive time
43 MediaPipelineAudioPlayout, // Timestamp and playout into MST time
44 MediaStreamCreate, // Source and TrackUnion streams
45 AudioStreamCreate, // TrackUnion stream and AudioStream
46 AudioSendRTP,
47 AudioRecvRTP,
48 _MAX_INDEX
49 };
50 // Log with a null timestamp
51 void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue);
52 // Log with a timestamp
53 void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue,
54 mozilla::TimeStamp &aTime);
55 // Write a log message to NSPR
56 void WriteLog(LatencyLogIndex index, uint64_t aID, int64_t aValue,
57 mozilla::TimeStamp timestamp);
58 // Get the base time used by the logger for delta calculations
59 void GetStartTime(mozilla::TimeStamp &aStart);
61 static AsyncLatencyLogger* Get(bool aStartTimer = false);
62 static void InitializeStatics();
63 // After this is called, the global log object may go away
64 static void ShutdownLogger();
65 private:
66 AsyncLatencyLogger();
67 virtual ~AsyncLatencyLogger();
68 int64_t GetTimeStamp();
69 void Init();
70 // Shut down the thread associated with this, and make sure it doesn't
71 // start up again.
72 void Shutdown();
73 // The thread on which the IO happens
74 nsCOMPtr<nsIThread> mThread;
75 // This can be initialized on multiple threads, but is protected by a
76 // monitor. After the initialization phase, it is accessed on the log
77 // thread only.
78 mozilla::TimeStamp mStart;
79 // This monitor protects mStart and mMediaLatencyLog for the
80 // initialization sequence. It is initialized at layout startup, and
81 // destroyed at layout shutdown.
82 mozilla::Mutex mMutex;
83 };
85 // need uint32_t versions for access from webrtc/trunk code
86 // Log without a time delta
87 void LogLatency(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue);
88 void LogLatency(uint32_t index, uint64_t aID, int64_t aValue);
89 // Log TimeStamp::Now() (as delta)
90 void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue);
91 void LogTime(uint32_t index, uint64_t aID, int64_t aValue);
92 // Log the specified time (as delta)
93 void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue,
94 mozilla::TimeStamp &aTime);
96 // For generating unique-ish ids for logged sources
97 #define LATENCY_STREAM_ID(source, trackID) \
98 ((((uint64_t) (source)) & ~0x0F) | (trackID))
100 #endif