Bug 1708193 - Remove mozapps/extensions/internal/Content.js r=rpl
[gecko.git] / dom / storage / StorageActivityService.h
blob6202e0eb1dc92ef439f600ddea6cb53f87660556
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/. */
7 #ifndef mozilla_dom_StorageActivityService_h
8 #define mozilla_dom_StorageActivityService_h
10 #include "nsTHashMap.h"
11 #include "nsIObserver.h"
12 #include "nsIStorageActivityService.h"
13 #include "nsITimer.h"
14 #include "nsWeakReference.h"
16 namespace mozilla {
18 namespace ipc {
19 class PrincipalInfo;
20 } // namespace ipc
22 namespace dom {
24 class StorageActivityService final : public nsIStorageActivityService,
25 public nsIObserver,
26 public nsITimerCallback,
27 public nsINamed,
28 public nsSupportsWeakReference {
29 public:
30 NS_DECL_ISUPPORTS
31 NS_DECL_NSISTORAGEACTIVITYSERVICE
32 NS_DECL_NSIOBSERVER
33 NS_DECL_NSITIMERCALLBACK
34 NS_DECL_NSINAMED
36 // Main-thread only.
37 static void SendActivity(nsIPrincipal* aPrincipal);
39 // Thread-safe.
40 static void SendActivity(const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
42 // Thread-safe but for parent process only!
43 static void SendActivity(const nsACString& aOrigin);
45 // Used by XPCOM. Don't use it, use SendActivity() instead.
46 static already_AddRefed<StorageActivityService> GetOrCreate();
48 private:
49 StorageActivityService();
50 ~StorageActivityService();
52 void SendActivityInternal(nsIPrincipal* aPrincipal);
54 void SendActivityInternal(const nsACString& aOrigin);
56 void SendActivityToParent(nsIPrincipal* aPrincipal);
58 void MaybeStartTimer();
60 void MaybeStopTimer();
62 // Activities grouped by origin (+OriginAttributes).
63 nsTHashMap<nsCStringHashKey, PRTime> mActivities;
65 nsCOMPtr<nsITimer> mTimer;
68 } // namespace dom
69 } // namespace mozilla
71 #endif // mozilla_dom_StorageActivityService_h