1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
6 
7 #ifndef mozilla_dom_PerformanceStorageWorker_h
8 #define mozilla_dom_PerformanceStorageWorker_h
9 
10 #include "PerformanceStorage.h"
11 
12 namespace mozilla {
13 namespace dom {
14 
15 class WorkerHolder;
16 class WorkerPrivate;
17 
18 class PerformanceProxyData;
19 
20 class PerformanceStorageWorker final : public PerformanceStorage {
21  public:
22   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PerformanceStorageWorker, override)
23 
24   static already_AddRefed<PerformanceStorageWorker> Create(
25       WorkerPrivate* aWorkerPrivate);
26 
27   void InitializeOnWorker();
28 
29   void ShutdownOnWorker();
30 
31   void AddEntry(nsIHttpChannel* aChannel,
32                 nsITimedChannel* aTimedChannel) override;
33 
34   void AddEntryOnWorker(UniquePtr<PerformanceProxyData>&& aData);
35 
36  private:
37   explicit PerformanceStorageWorker(WorkerPrivate* aWorkerPrivate);
38   ~PerformanceStorageWorker();
39 
40   Mutex mMutex;
41 
42   // Protected by mutex.
43   // This raw pointer is nullified when the WorkerHolder communicates the
44   // shutting down of the worker thread.
45   WorkerPrivate* mWorkerPrivate;
46 
47   // Protected by mutex.
48   enum {
49     eInitializing,
50     eReady,
51     eTerminated,
52   } mState;
53 
54   // Touched on worker-thread only.
55   UniquePtr<WorkerHolder> mWorkerHolder;
56 };
57 
58 }  // namespace dom
59 }  // namespace mozilla
60 
61 #endif  // mozilla_dom_PerformanceStorageWorker_h
62