|
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 "nsIObserver.h" |
|
13 #include "nsIUrlClassifierStreamUpdater.h" |
|
14 #include "nsIStreamListener.h" |
|
15 #include "nsNetUtil.h" |
|
16 #include "nsTArray.h" |
|
17 #include "nsITimer.h" |
|
18 #include "mozilla/Attributes.h" |
|
19 |
|
20 // Forward declare pointers |
|
21 class nsIURI; |
|
22 |
|
23 class nsUrlClassifierStreamUpdater MOZ_FINAL : public nsIUrlClassifierStreamUpdater, |
|
24 public nsIUrlClassifierUpdateObserver, |
|
25 public nsIStreamListener, |
|
26 public nsIObserver, |
|
27 public nsIInterfaceRequestor, |
|
28 public nsITimerCallback |
|
29 { |
|
30 public: |
|
31 nsUrlClassifierStreamUpdater(); |
|
32 |
|
33 NS_DECL_THREADSAFE_ISUPPORTS |
|
34 NS_DECL_NSIURLCLASSIFIERSTREAMUPDATER |
|
35 NS_DECL_NSIURLCLASSIFIERUPDATEOBSERVER |
|
36 NS_DECL_NSIINTERFACEREQUESTOR |
|
37 NS_DECL_NSIREQUESTOBSERVER |
|
38 NS_DECL_NSISTREAMLISTENER |
|
39 NS_DECL_NSIOBSERVER |
|
40 NS_DECL_NSITIMERCALLBACK |
|
41 |
|
42 private: |
|
43 // No subclassing |
|
44 ~nsUrlClassifierStreamUpdater() {} |
|
45 |
|
46 // When the dbservice sends an UpdateComplete or UpdateFailure, we call this |
|
47 // to reset the stream updater. |
|
48 void DownloadDone(); |
|
49 |
|
50 // Disallow copy constructor |
|
51 nsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&); |
|
52 |
|
53 nsresult AddRequestBody(const nsACString &aRequestBody); |
|
54 |
|
55 // Fetches an update for a single table. |
|
56 nsresult FetchUpdate(nsIURI *aURI, |
|
57 const nsACString &aRequestBody, |
|
58 const nsACString &aTable); |
|
59 // Dumb wrapper so we don't have to create URIs. |
|
60 nsresult FetchUpdate(const nsACString &aURI, |
|
61 const nsACString &aRequestBody, |
|
62 const nsACString &aTable); |
|
63 |
|
64 // Fetches the next table, from mPendingUpdates. |
|
65 nsresult FetchNext(); |
|
66 |
|
67 bool mIsUpdating; |
|
68 bool mInitialized; |
|
69 bool mDownloadError; |
|
70 bool mBeganStream; |
|
71 nsCOMPtr<nsIURI> mUpdateUrl; |
|
72 nsCString mStreamTable; |
|
73 nsCOMPtr<nsIChannel> mChannel; |
|
74 nsCOMPtr<nsIUrlClassifierDBService> mDBService; |
|
75 nsCOMPtr<nsITimer> mTimer; |
|
76 |
|
77 struct PendingUpdate { |
|
78 nsCString mUrl; |
|
79 nsCString mTable; |
|
80 }; |
|
81 nsTArray<PendingUpdate> mPendingUpdates; |
|
82 |
|
83 nsCOMPtr<nsIUrlClassifierCallback> mSuccessCallback; |
|
84 nsCOMPtr<nsIUrlClassifierCallback> mUpdateErrorCallback; |
|
85 nsCOMPtr<nsIUrlClassifierCallback> mDownloadErrorCallback; |
|
86 }; |
|
87 |
|
88 #endif // nsUrlClassifierStreamUpdater_h_ |