/src/mozilla-central/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.h
Line | Count | Source (jump to first uncovered line) |
1 | | //* -*- Mode: C++; tab-width: 8; 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/. */ |
5 | | |
6 | | #ifndef nsUrlClassifierStreamUpdater_h_ |
7 | | #define nsUrlClassifierStreamUpdater_h_ |
8 | | |
9 | | #include <nsISupportsUtils.h> |
10 | | |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsINamed.h" |
13 | | #include "nsIObserver.h" |
14 | | #include "nsIUrlClassifierStreamUpdater.h" |
15 | | #include "nsIStreamListener.h" |
16 | | #include "nsIChannel.h" |
17 | | #include "nsTArray.h" |
18 | | #include "nsITimer.h" |
19 | | #include "mozilla/Attributes.h" |
20 | | |
21 | | // Forward declare pointers |
22 | | class nsIURI; |
23 | | |
24 | | class nsUrlClassifierStreamUpdater final : public nsIUrlClassifierStreamUpdater, |
25 | | public nsIUrlClassifierUpdateObserver, |
26 | | public nsIStreamListener, |
27 | | public nsIObserver, |
28 | | public nsIInterfaceRequestor, |
29 | | public nsITimerCallback, |
30 | | public nsINamed |
31 | | { |
32 | | public: |
33 | | nsUrlClassifierStreamUpdater(); |
34 | | |
35 | | NS_DECL_THREADSAFE_ISUPPORTS |
36 | | NS_DECL_NSIURLCLASSIFIERSTREAMUPDATER |
37 | | NS_DECL_NSIURLCLASSIFIERUPDATEOBSERVER |
38 | | NS_DECL_NSIINTERFACEREQUESTOR |
39 | | NS_DECL_NSIREQUESTOBSERVER |
40 | | NS_DECL_NSISTREAMLISTENER |
41 | | NS_DECL_NSIOBSERVER |
42 | | NS_DECL_NSITIMERCALLBACK |
43 | | NS_DECL_NSINAMED |
44 | | |
45 | | private: |
46 | | // No subclassing |
47 | 0 | ~nsUrlClassifierStreamUpdater() {} |
48 | | |
49 | | // When the dbservice sends an UpdateComplete or UpdateFailure, we call this |
50 | | // to reset the stream updater. |
51 | | void DownloadDone(); |
52 | | |
53 | | // Disallow copy constructor |
54 | | nsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&); |
55 | | |
56 | | nsresult AddRequestBody(const nsACString &aRequestBody); |
57 | | |
58 | | // Fetches an update for a single table. |
59 | | nsresult FetchUpdate(nsIURI *aURI, |
60 | | const nsACString &aRequest, |
61 | | bool aIsPostRequest, |
62 | | const nsACString &aTable); |
63 | | // Dumb wrapper so we don't have to create URIs. |
64 | | nsresult FetchUpdate(const nsACString &aURI, |
65 | | const nsACString &aRequest, |
66 | | bool aIsPostRequest, |
67 | | const nsACString &aTable); |
68 | | |
69 | | // Fetches the next table, from mPendingUpdates. |
70 | | nsresult FetchNext(); |
71 | | // Fetches the next request, from mPendingRequests |
72 | | nsresult FetchNextRequest(); |
73 | | |
74 | | struct UpdateRequest { |
75 | | nsCString mTables; |
76 | | nsCString mRequestPayload; |
77 | | bool mIsPostRequest; |
78 | | nsCString mUrl; |
79 | | nsCOMPtr<nsIUrlClassifierCallback> mSuccessCallback; |
80 | | nsCOMPtr<nsIUrlClassifierCallback> mUpdateErrorCallback; |
81 | | nsCOMPtr<nsIUrlClassifierCallback> mDownloadErrorCallback; |
82 | | }; |
83 | | // Utility function to create an update request. |
84 | | void |
85 | | BuildUpdateRequest(const nsACString &aRequestTables, |
86 | | const nsACString &aRequestPayload, |
87 | | bool aIsPostRequest, |
88 | | const nsACString &aUpdateUrl, |
89 | | nsIUrlClassifierCallback *aSuccessCallback, |
90 | | nsIUrlClassifierCallback *aUpdateErrorCallback, |
91 | | nsIUrlClassifierCallback *aDownloadErrorCallback, |
92 | | UpdateRequest* aRequest); |
93 | | |
94 | | bool mIsUpdating; |
95 | | bool mInitialized; |
96 | | bool mDownloadError; |
97 | | bool mBeganStream; |
98 | | |
99 | | nsCString mDownloadErrorStatusStr; |
100 | | |
101 | | // Note that mStreamTable is only used by v2, it is empty for v4 update. |
102 | | nsCString mStreamTable; |
103 | | |
104 | | nsCOMPtr<nsIChannel> mChannel; |
105 | | nsCOMPtr<nsIUrlClassifierDBService> mDBService; |
106 | | |
107 | | // In v2, a update response might contain redirection and this |
108 | | // timer is for fetching the redirected update. |
109 | | nsCOMPtr<nsITimer> mFetchIndirectUpdatesTimer; |
110 | | |
111 | | // When we DownloadUpdate(), the DBService might be busy on processing |
112 | | // request issused outside of StreamUpdater. We have to fire a timer to |
113 | | // retry on our own. |
114 | | nsCOMPtr<nsITimer> mFetchNextRequestTimer; |
115 | | |
116 | | // Timer to abort the download if the server takes too long to respond. |
117 | | nsCOMPtr<nsITimer> mResponseTimeoutTimer; |
118 | | |
119 | | // Timer to abort the download if it takes too long. |
120 | | nsCOMPtr<nsITimer> mTimeoutTimer; |
121 | | |
122 | | mozilla::UniquePtr<UpdateRequest> mCurrentRequest; |
123 | | nsTArray<UpdateRequest> mPendingRequests; |
124 | | |
125 | | struct PendingUpdate { |
126 | | nsCString mUrl; |
127 | | nsCString mTable; |
128 | | }; |
129 | | nsTArray<PendingUpdate> mPendingUpdates; |
130 | | |
131 | | |
132 | | // The provider for current update request and should be only used by telemetry |
133 | | // since it would show up as "other" for any other providers. |
134 | | nsCString mTelemetryProvider; |
135 | | PRIntervalTime mTelemetryClockStart; |
136 | | }; |
137 | | |
138 | | #endif // nsUrlClassifierStreamUpdater_h_ |