nsUrlClassifierStreamUpdater.h 3.2 KB

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