michael@0: //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-/ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsUrlClassifierStreamUpdater_h_ michael@0: #define nsUrlClassifierStreamUpdater_h_ michael@0: michael@0: #include michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIUrlClassifierStreamUpdater.h" michael@0: #include "nsIStreamListener.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsTArray.h" michael@0: #include "nsITimer.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: // Forward declare pointers michael@0: class nsIURI; michael@0: michael@0: class nsUrlClassifierStreamUpdater MOZ_FINAL : public nsIUrlClassifierStreamUpdater, michael@0: public nsIUrlClassifierUpdateObserver, michael@0: public nsIStreamListener, michael@0: public nsIObserver, michael@0: public nsIInterfaceRequestor, michael@0: public nsITimerCallback michael@0: { michael@0: public: michael@0: nsUrlClassifierStreamUpdater(); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIURLCLASSIFIERSTREAMUPDATER michael@0: NS_DECL_NSIURLCLASSIFIERUPDATEOBSERVER michael@0: NS_DECL_NSIINTERFACEREQUESTOR michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: NS_DECL_NSISTREAMLISTENER michael@0: NS_DECL_NSIOBSERVER michael@0: NS_DECL_NSITIMERCALLBACK michael@0: michael@0: private: michael@0: // No subclassing michael@0: ~nsUrlClassifierStreamUpdater() {} michael@0: michael@0: // When the dbservice sends an UpdateComplete or UpdateFailure, we call this michael@0: // to reset the stream updater. michael@0: void DownloadDone(); michael@0: michael@0: // Disallow copy constructor michael@0: nsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&); michael@0: michael@0: nsresult AddRequestBody(const nsACString &aRequestBody); michael@0: michael@0: // Fetches an update for a single table. michael@0: nsresult FetchUpdate(nsIURI *aURI, michael@0: const nsACString &aRequestBody, michael@0: const nsACString &aTable); michael@0: // Dumb wrapper so we don't have to create URIs. michael@0: nsresult FetchUpdate(const nsACString &aURI, michael@0: const nsACString &aRequestBody, michael@0: const nsACString &aTable); michael@0: michael@0: // Fetches the next table, from mPendingUpdates. michael@0: nsresult FetchNext(); michael@0: michael@0: bool mIsUpdating; michael@0: bool mInitialized; michael@0: bool mDownloadError; michael@0: bool mBeganStream; michael@0: nsCOMPtr mUpdateUrl; michael@0: nsCString mStreamTable; michael@0: nsCOMPtr mChannel; michael@0: nsCOMPtr mDBService; michael@0: nsCOMPtr mTimer; michael@0: michael@0: struct PendingUpdate { michael@0: nsCString mUrl; michael@0: nsCString mTable; michael@0: }; michael@0: nsTArray mPendingUpdates; michael@0: michael@0: nsCOMPtr mSuccessCallback; michael@0: nsCOMPtr mUpdateErrorCallback; michael@0: nsCOMPtr mDownloadErrorCallback; michael@0: }; michael@0: michael@0: #endif // nsUrlClassifierStreamUpdater_h_