2007-03-22 10:30:00 -07:00
|
|
|
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-/
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsUrlClassifierStreamUpdater_h_
|
|
|
|
#define nsUrlClassifierStreamUpdater_h_
|
|
|
|
|
|
|
|
#include <nsISupportsUtils.h>
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIUrlClassifierStreamUpdater.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsNetUtil.h"
|
2008-01-12 14:22:03 -08:00
|
|
|
#include "nsTArray.h"
|
2008-05-07 13:33:45 -07:00
|
|
|
#include "nsITimer.h"
|
2012-07-17 20:46:21 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Forward declare pointers
|
|
|
|
class nsIURI;
|
|
|
|
|
2012-07-17 20:46:21 -07:00
|
|
|
class nsUrlClassifierStreamUpdater MOZ_FINAL : public nsIUrlClassifierStreamUpdater,
|
|
|
|
public nsIUrlClassifierUpdateObserver,
|
|
|
|
public nsIStreamListener,
|
|
|
|
public nsIObserver,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsITimerCallback
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsUrlClassifierStreamUpdater();
|
|
|
|
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIURLCLASSIFIERSTREAMUPDATER
|
2008-01-12 14:22:03 -08:00
|
|
|
NS_DECL_NSIURLCLASSIFIERUPDATEOBSERVER
|
2008-01-15 07:06:34 -08:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2008-01-12 14:22:03 -08:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIOBSERVER
|
2008-05-07 13:33:45 -07:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
// No subclassing
|
2007-04-23 07:21:53 -07:00
|
|
|
~nsUrlClassifierStreamUpdater() {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-12 14:22:03 -08:00
|
|
|
// When the dbservice sends an UpdateComplete or UpdateFailure, we call this
|
|
|
|
// to reset the stream updater.
|
|
|
|
void DownloadDone();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Disallow copy constructor
|
|
|
|
nsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&);
|
|
|
|
|
2007-07-25 23:38:43 -07:00
|
|
|
nsresult AddRequestBody(const nsACString &aRequestBody);
|
|
|
|
|
2013-09-06 17:12:33 -07:00
|
|
|
// Fetches an update for a single table.
|
2008-01-29 12:57:18 -08:00
|
|
|
nsresult FetchUpdate(nsIURI *aURI,
|
|
|
|
const nsACString &aRequestBody,
|
2014-01-16 00:27:58 -08:00
|
|
|
const nsACString &aTable);
|
2013-09-06 17:12:33 -07:00
|
|
|
// Dumb wrapper so we don't have to create URIs.
|
2008-01-29 12:57:18 -08:00
|
|
|
nsresult FetchUpdate(const nsACString &aURI,
|
|
|
|
const nsACString &aRequestBody,
|
2014-01-16 00:27:58 -08:00
|
|
|
const nsACString &aTable);
|
2008-01-12 14:22:03 -08:00
|
|
|
|
2013-09-06 17:12:33 -07:00
|
|
|
// Fetches the next table, from mPendingUpdates.
|
2008-05-07 13:33:45 -07:00
|
|
|
nsresult FetchNext();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsUpdating;
|
|
|
|
bool mInitialized;
|
|
|
|
bool mDownloadError;
|
|
|
|
bool mBeganStream;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mUpdateUrl;
|
2008-01-29 12:57:18 -08:00
|
|
|
nsCString mStreamTable;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2008-01-12 14:22:03 -08:00
|
|
|
nsCOMPtr<nsIUrlClassifierDBService> mDBService;
|
2008-05-07 13:33:45 -07:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2008-01-12 14:22:03 -08:00
|
|
|
|
2008-01-29 12:57:18 -08:00
|
|
|
struct PendingUpdate {
|
|
|
|
nsCString mUrl;
|
|
|
|
nsCString mTable;
|
|
|
|
};
|
|
|
|
nsTArray<PendingUpdate> mPendingUpdates;
|
2008-01-12 14:22:03 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIUrlClassifierCallback> mSuccessCallback;
|
|
|
|
nsCOMPtr<nsIUrlClassifierCallback> mUpdateErrorCallback;
|
|
|
|
nsCOMPtr<nsIUrlClassifierCallback> mDownloadErrorCallback;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsUrlClassifierStreamUpdater_h_
|