toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-/
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsUrlClassifierStreamUpdater_h_
    1.10 +#define nsUrlClassifierStreamUpdater_h_
    1.11 +
    1.12 +#include <nsISupportsUtils.h>
    1.13 +
    1.14 +#include "nsCOMPtr.h"
    1.15 +#include "nsIObserver.h"
    1.16 +#include "nsIUrlClassifierStreamUpdater.h"
    1.17 +#include "nsIStreamListener.h"
    1.18 +#include "nsNetUtil.h"
    1.19 +#include "nsTArray.h"
    1.20 +#include "nsITimer.h"
    1.21 +#include "mozilla/Attributes.h"
    1.22 +
    1.23 +// Forward declare pointers
    1.24 +class nsIURI;
    1.25 +
    1.26 +class nsUrlClassifierStreamUpdater MOZ_FINAL : public nsIUrlClassifierStreamUpdater,
    1.27 +                                               public nsIUrlClassifierUpdateObserver,
    1.28 +                                               public nsIStreamListener,
    1.29 +                                               public nsIObserver,
    1.30 +                                               public nsIInterfaceRequestor,
    1.31 +                                               public nsITimerCallback
    1.32 +{
    1.33 +public:
    1.34 +  nsUrlClassifierStreamUpdater();
    1.35 +
    1.36 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.37 +  NS_DECL_NSIURLCLASSIFIERSTREAMUPDATER
    1.38 +  NS_DECL_NSIURLCLASSIFIERUPDATEOBSERVER
    1.39 +  NS_DECL_NSIINTERFACEREQUESTOR
    1.40 +  NS_DECL_NSIREQUESTOBSERVER
    1.41 +  NS_DECL_NSISTREAMLISTENER
    1.42 +  NS_DECL_NSIOBSERVER
    1.43 +  NS_DECL_NSITIMERCALLBACK
    1.44 +
    1.45 +private:
    1.46 +  // No subclassing
    1.47 +  ~nsUrlClassifierStreamUpdater() {}
    1.48 +
    1.49 +  // When the dbservice sends an UpdateComplete or UpdateFailure, we call this
    1.50 +  // to reset the stream updater.
    1.51 +  void DownloadDone();
    1.52 +
    1.53 +  // Disallow copy constructor
    1.54 +  nsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&);
    1.55 +
    1.56 +  nsresult AddRequestBody(const nsACString &aRequestBody);
    1.57 +
    1.58 +  // Fetches an update for a single table.
    1.59 +  nsresult FetchUpdate(nsIURI *aURI,
    1.60 +                       const nsACString &aRequestBody,
    1.61 +                       const nsACString &aTable);
    1.62 +  // Dumb wrapper so we don't have to create URIs.
    1.63 +  nsresult FetchUpdate(const nsACString &aURI,
    1.64 +                       const nsACString &aRequestBody,
    1.65 +                       const nsACString &aTable);
    1.66 +
    1.67 +  // Fetches the next table, from mPendingUpdates.
    1.68 +  nsresult FetchNext();
    1.69 +
    1.70 +  bool mIsUpdating;
    1.71 +  bool mInitialized;
    1.72 +  bool mDownloadError;
    1.73 +  bool mBeganStream;
    1.74 +  nsCOMPtr<nsIURI> mUpdateUrl;
    1.75 +  nsCString mStreamTable;
    1.76 +  nsCOMPtr<nsIChannel> mChannel;
    1.77 +  nsCOMPtr<nsIUrlClassifierDBService> mDBService;
    1.78 +  nsCOMPtr<nsITimer> mTimer;
    1.79 +
    1.80 +  struct PendingUpdate {
    1.81 +    nsCString mUrl;
    1.82 +    nsCString mTable;
    1.83 +  };
    1.84 +  nsTArray<PendingUpdate> mPendingUpdates;
    1.85 +
    1.86 +  nsCOMPtr<nsIUrlClassifierCallback> mSuccessCallback;
    1.87 +  nsCOMPtr<nsIUrlClassifierCallback> mUpdateErrorCallback;
    1.88 +  nsCOMPtr<nsIUrlClassifierCallback> mDownloadErrorCallback;
    1.89 +};
    1.90 +
    1.91 +#endif // nsUrlClassifierStreamUpdater_h_

mercurial