Source code

Revision control

Other Tools

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_StorageActivityService_h
8
#define mozilla_dom_StorageActivityService_h
9
10
#include "nsDataHashtable.h"
11
#include "nsIStorageActivityService.h"
12
#include "nsITimer.h"
13
#include "nsWeakReference.h"
14
15
namespace mozilla {
16
17
namespace ipc {
18
class PrincipalInfo;
19
} // namespace ipc
20
21
namespace dom {
22
23
class StorageActivityService final : public nsIStorageActivityService,
24
public nsIObserver,
25
public nsITimerCallback,
26
public nsSupportsWeakReference {
27
public:
28
NS_DECL_ISUPPORTS
29
NS_DECL_NSISTORAGEACTIVITYSERVICE
30
NS_DECL_NSIOBSERVER
31
NS_DECL_NSITIMERCALLBACK
32
33
// Main-thread only.
34
static void SendActivity(nsIPrincipal* aPrincipal);
35
36
// Thread-safe.
37
static void SendActivity(const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
38
39
// Thread-safe but for parent process only!
40
static void SendActivity(const nsACString& aOrigin);
41
42
// Used by XPCOM. Don't use it, use SendActivity() instead.
43
static already_AddRefed<StorageActivityService> GetOrCreate();
44
45
private:
46
StorageActivityService();
47
~StorageActivityService();
48
49
void SendActivityInternal(nsIPrincipal* aPrincipal);
50
51
void SendActivityInternal(const nsACString& aOrigin);
52
53
void SendActivityToParent(nsIPrincipal* aPrincipal);
54
55
void MaybeStartTimer();
56
57
void MaybeStopTimer();
58
59
// Activities grouped by origin (+OriginAttributes).
60
nsDataHashtable<nsCStringHashKey, PRTime> mActivities;
61
62
nsCOMPtr<nsITimer> mTimer;
63
};
64
65
} // namespace dom
66
} // namespace mozilla
67
68
#endif // mozilla_dom_StorageActivityService_h