Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/base/IOActivityMonitor.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 *
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 IOActivityMonitor_h___
8
#define IOActivityMonitor_h___
9
10
#include "mozilla/dom/ChromeUtilsBinding.h"
11
#include "nsCOMPtr.h"
12
#include "nscore.h"
13
#include "nsClassHashtable.h"
14
#include "nsDataHashtable.h"
15
#include "nsHashKeys.h"
16
#include "nsISupports.h"
17
#include "prinrval.h"
18
#include "prio.h"
19
#include "private/pprio.h"
20
#include <stdint.h>
21
22
namespace mozilla {
23
24
namespace dom {
25
  class Promise;
26
}
27
28
namespace net {
29
30
0
#define IO_ACTIVITY_ENABLED_PREF "io.activity.enabled"
31
32
typedef nsDataHashtable<nsCStringHashKey, dom::IOActivityDataDictionary> Activities;
33
34
35
// IOActivityMonitor has several roles:
36
// - maintains an IOActivity per resource and updates it
37
// - sends a dump of the activities to a promise via RequestActivities
38
class IOActivityMonitor final
39
    : public nsINamed
40
{
41
public:
42
  IOActivityMonitor();
43
44
  NS_DECL_THREADSAFE_ISUPPORTS
45
  NS_DECL_NSINAMED
46
47
  // initializes and destroys the singleton
48
  static nsresult Init();
49
  static nsresult Shutdown();
50
51
  // collect amounts of data that are written/read by location
52
  static nsresult Read(const nsACString& location, uint32_t aAmount);
53
  static nsresult Write(const nsACString& location, uint32_t aAmount);
54
55
  static nsresult MonitorFile(PRFileDesc *aFd, const char* aPath);
56
  static nsresult MonitorSocket(PRFileDesc *aFd);
57
  static nsresult Read(PRFileDesc *fd, uint32_t aAmount);
58
  static nsresult Write(PRFileDesc *fd, uint32_t aAmount);
59
60
  static bool IsActive();
61
  static void RequestActivities(dom::Promise* aPromise);
62
private:
63
0
  ~IOActivityMonitor() = default;
64
  nsresult InitInternal();
65
  nsresult ShutdownInternal();
66
  bool IncrementActivity(const nsACString& location, uint32_t aRx, uint32_t aTx);
67
  nsresult WriteInternal(const nsACString& location, uint32_t aAmount);
68
  nsresult ReadInternal(const nsACString& location, uint32_t aAmount);
69
  void RequestActivitiesInternal(dom::Promise* aPromise);
70
71
  Activities mActivities;
72
  // protects mActivities accesses
73
  Mutex mLock;
74
};
75
76
} // namespace net
77
} // namespace mozilla
78
79
#endif /* IOActivityMonitor_h___ */