Merge autoland to mozilla-central. a=merge
[gecko.git] / netwerk / base / nsLoadGroup.h
blob04becdfa3ac3c5e064830155e6fdb3563d30f9f2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsLoadGroup_h__
7 #define nsLoadGroup_h__
9 #include "nsILoadGroup.h"
10 #include "nsILoadGroupChild.h"
11 #include "nsIObserver.h"
12 #include "nsCOMPtr.h"
13 #include "nsWeakReference.h"
14 #include "nsISupportsPriority.h"
15 #include "PLDHashTable.h"
16 #include "mozilla/TimeStamp.h"
18 class nsIRequestContext;
19 class nsIRequestContextService;
20 class nsITimedChannel;
22 namespace mozilla {
23 namespace net {
25 class nsLoadGroup : public nsILoadGroup,
26 public nsILoadGroupChild,
27 public nsIObserver,
28 public nsISupportsPriority,
29 public nsSupportsWeakReference {
30 public:
31 NS_DECL_ISUPPORTS
33 ////////////////////////////////////////////////////////////////////////////
34 // nsIRequest methods:
35 NS_DECL_NSIREQUEST
37 ////////////////////////////////////////////////////////////////////////////
38 // nsILoadGroup methods:
39 NS_DECL_NSILOADGROUP
41 ////////////////////////////////////////////////////////////////////////////
42 // nsILoadGroupChild methods:
43 NS_DECL_NSILOADGROUPCHILD
45 ////////////////////////////////////////////////////////////////////////////
46 // nsISupportsPriority methods:
47 NS_DECL_NSISUPPORTSPRIORITY
49 ////////////////////////////////////////////////////////////////////////////
50 // nsIObserver methods:
51 NS_DECL_NSIOBSERVER
53 ////////////////////////////////////////////////////////////////////////////
54 // nsLoadGroup methods:
56 nsLoadGroup();
58 nsresult Init();
59 nsresult InitWithRequestContextId(const uint64_t& aRequestContextId);
61 void SetGroupObserver(nsIRequestObserver* aObserver,
62 bool aIncludeBackgroundRequests);
64 /**
65 * Flags inherited from the default request in the load group onto other loads
66 * added to the load group.
68 * NOTE(emilio): If modifying these, be aware that we allow these flags to be
69 * effectively set from the content process on a document navigation, and
70 * thus nothing security-critical should be allowed here.
72 static constexpr nsLoadFlags kInheritedLoadFlags =
73 LOAD_BACKGROUND | LOAD_BYPASS_CACHE | LOAD_FROM_CACHE | VALIDATE_ALWAYS |
74 VALIDATE_ONCE_PER_SESSION | VALIDATE_NEVER;
76 protected:
77 virtual ~nsLoadGroup();
79 nsresult MergeLoadFlags(nsIRequest* aRequest, nsLoadFlags& flags);
80 nsresult MergeDefaultLoadFlags(nsIRequest* aRequest, nsLoadFlags& flags);
82 private:
83 void TelemetryReport();
84 void TelemetryReportChannel(nsITimedChannel* timedChannel,
85 bool defaultRequest);
87 nsresult RemoveRequestFromHashtable(nsIRequest* aRequest, nsresult aStatus);
88 nsresult NotifyRemovalObservers(nsIRequest* aRequest, nsresult aStatus);
90 protected:
91 uint32_t mForegroundCount{0};
92 uint32_t mLoadFlags{LOAD_NORMAL};
93 uint32_t mDefaultLoadFlags{0};
94 int32_t mPriority{PRIORITY_NORMAL};
96 nsCOMPtr<nsILoadGroup> mLoadGroup; // load groups can contain load groups
97 nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
98 nsCOMPtr<nsIRequestContext> mRequestContext;
99 nsCOMPtr<nsIRequestContextService> mRequestContextService;
101 nsCOMPtr<nsIRequest> mDefaultLoadRequest;
102 PLDHashTable mRequests;
104 nsWeakPtr mObserver;
105 nsWeakPtr mParentLoadGroup;
107 nsresult mStatus{NS_OK};
108 bool mIsCanceling{false};
109 bool mDefaultLoadIsTimed{false};
110 bool mBrowsingContextDiscarded{false};
111 bool mExternalRequestContext{false};
112 bool mNotifyObserverAboutBackgroundRequests{false};
114 // size of requests with keepalive flag for this load group
115 uint64_t mPendingKeepaliveRequestSize{0};
117 /* Telemetry */
118 mozilla::TimeStamp mDefaultRequestCreationTime;
119 uint32_t mTimedRequests{0};
120 uint32_t mCachedRequests{0};
123 } // namespace net
124 } // namespace mozilla
126 #endif // nsLoadGroup_h__