toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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/. */
     6 #ifndef nsUrlClassifierStreamUpdater_h_
     7 #define nsUrlClassifierStreamUpdater_h_
     9 #include <nsISupportsUtils.h>
    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"
    20 // Forward declare pointers
    21 class nsIURI;
    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();
    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
    42 private:
    43   // No subclassing
    44   ~nsUrlClassifierStreamUpdater() {}
    46   // When the dbservice sends an UpdateComplete or UpdateFailure, we call this
    47   // to reset the stream updater.
    48   void DownloadDone();
    50   // Disallow copy constructor
    51   nsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&);
    53   nsresult AddRequestBody(const nsACString &aRequestBody);
    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);
    64   // Fetches the next table, from mPendingUpdates.
    65   nsresult FetchNext();
    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;
    77   struct PendingUpdate {
    78     nsCString mUrl;
    79     nsCString mTable;
    80   };
    81   nsTArray<PendingUpdate> mPendingUpdates;
    83   nsCOMPtr<nsIUrlClassifierCallback> mSuccessCallback;
    84   nsCOMPtr<nsIUrlClassifierCallback> mUpdateErrorCallback;
    85   nsCOMPtr<nsIUrlClassifierCallback> mDownloadErrorCallback;
    86 };
    88 #endif // nsUrlClassifierStreamUpdater_h_

mercurial