2006-06-15 23:10:04 +04:00
|
|
|
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-/
|
2012-05-21 15:12:37 +04: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/. */
|
2006-06-15 23:10:04 +04:00
|
|
|
|
|
|
|
#ifndef nsUrlClassifierStreamUpdater_h_
|
|
|
|
#define nsUrlClassifierStreamUpdater_h_
|
|
|
|
|
|
|
|
#include <nsISupportsUtils.h>
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2017-07-26 21:18:20 +03:00
|
|
|
#include "nsINamed.h"
|
2006-11-20 21:24:01 +03:00
|
|
|
#include "nsIObserver.h"
|
2006-06-15 23:10:04 +04:00
|
|
|
#include "nsIUrlClassifierStreamUpdater.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIChannel.h"
|
2008-01-13 01:22:03 +03:00
|
|
|
#include "nsTArray.h"
|
2008-05-08 00:33:45 +04:00
|
|
|
#include "nsITimer.h"
|
2012-07-18 07:46:21 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2006-06-15 23:10:04 +04:00
|
|
|
|
|
|
|
// Forward declare pointers
|
|
|
|
class nsIURI;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsUrlClassifierStreamUpdater final
|
|
|
|
: public nsIUrlClassifierStreamUpdater,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIUrlClassifierUpdateObserver,
|
|
|
|
public nsIStreamListener,
|
|
|
|
public nsIObserver,
|
|
|
|
public nsIInterfaceRequestor,
|
2017-07-26 21:18:20 +03:00
|
|
|
public nsITimerCallback,
|
|
|
|
public nsINamed {
|
2006-06-15 23:10:04 +04:00
|
|
|
public:
|
|
|
|
nsUrlClassifierStreamUpdater();
|
|
|
|
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2006-06-15 23:10:04 +04:00
|
|
|
NS_DECL_NSIURLCLASSIFIERSTREAMUPDATER
|
2008-01-13 01:22:03 +03:00
|
|
|
NS_DECL_NSIURLCLASSIFIERUPDATEOBSERVER
|
2008-01-15 18:06:34 +03:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2008-01-13 01:22:03 +03:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2006-11-20 21:24:01 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2008-05-08 00:33:45 +04:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_DECL_NSINAMED
|
2006-06-15 23:10:04 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// No subclassing
|
2020-03-10 11:48:24 +03:00
|
|
|
~nsUrlClassifierStreamUpdater() = default;
|
2006-06-15 23:10:04 +04:00
|
|
|
|
2008-01-13 01:22:03 +03:00
|
|
|
// When the dbservice sends an UpdateComplete or UpdateFailure, we call this
|
|
|
|
// to reset the stream updater.
|
|
|
|
void DownloadDone();
|
|
|
|
|
2006-06-15 23:10:04 +04:00
|
|
|
// Disallow copy constructor
|
|
|
|
nsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&);
|
|
|
|
|
2007-07-26 10:38:43 +04:00
|
|
|
nsresult AddRequestBody(const nsACString& aRequestBody);
|
|
|
|
|
2013-09-07 04:12:33 +04:00
|
|
|
// Fetches an update for a single table.
|
2008-01-29 23:57:18 +03:00
|
|
|
nsresult FetchUpdate(nsIURI* aURI, const nsACString& aRequest,
|
2014-01-16 12:27:58 +04:00
|
|
|
bool aIsPostRequest, const nsACString& aTable);
|
2013-09-07 04:12:33 +04:00
|
|
|
// Dumb wrapper so we don't have to create URIs.
|
2008-01-29 23:57:18 +03:00
|
|
|
nsresult FetchUpdate(const nsACString& aURI, const nsACString& aRequest,
|
2014-01-16 12:27:58 +04:00
|
|
|
bool aIsPostRequest, const nsACString& aTable);
|
2008-01-13 01:22:03 +03:00
|
|
|
|
2013-09-07 04:12:33 +04:00
|
|
|
// Fetches the next table, from mPendingUpdates.
|
2008-05-08 00:33:45 +04:00
|
|
|
nsresult FetchNext();
|
2014-06-12 21:24:03 +04:00
|
|
|
// Fetches the next request, from mPendingRequests
|
|
|
|
nsresult FetchNextRequest();
|
|
|
|
|
2017-10-05 03:37:29 +03:00
|
|
|
struct UpdateRequest {
|
|
|
|
nsCString mTables;
|
|
|
|
nsCString mRequestPayload;
|
|
|
|
bool mIsPostRequest;
|
|
|
|
nsCString mUrl;
|
|
|
|
nsCOMPtr<nsIUrlClassifierCallback> mSuccessCallback;
|
|
|
|
nsCOMPtr<nsIUrlClassifierCallback> mUpdateErrorCallback;
|
|
|
|
nsCOMPtr<nsIUrlClassifierCallback> mDownloadErrorCallback;
|
|
|
|
};
|
|
|
|
// Utility function to create an update request.
|
|
|
|
void BuildUpdateRequest(const nsACString& aRequestTables,
|
|
|
|
const nsACString& aRequestPayload,
|
|
|
|
bool aIsPostRequest, const nsACString& aUpdateUrl,
|
|
|
|
nsIUrlClassifierCallback* aSuccessCallback,
|
|
|
|
nsIUrlClassifierCallback* aUpdateErrorCallback,
|
|
|
|
nsIUrlClassifierCallback* aDownloadErrorCallback,
|
|
|
|
UpdateRequest* aRequest);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsUpdating;
|
|
|
|
bool mInitialized;
|
|
|
|
bool mDownloadError;
|
|
|
|
bool mBeganStream;
|
2017-01-27 13:02:36 +03:00
|
|
|
|
2017-03-13 16:16:07 +03:00
|
|
|
nsCString mDownloadErrorStatusStr;
|
|
|
|
|
2017-01-27 13:02:36 +03:00
|
|
|
// Note that mStreamTable is only used by v2, it is empty for v4 update.
|
2008-01-29 23:57:18 +03:00
|
|
|
nsCString mStreamTable;
|
2017-01-27 13:02:36 +03:00
|
|
|
|
2006-11-20 21:24:01 +03:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2008-01-13 01:22:03 +03:00
|
|
|
nsCOMPtr<nsIUrlClassifierDBService> mDBService;
|
2017-04-11 12:13:01 +03:00
|
|
|
|
|
|
|
// In v2, a update response might contain redirection and this
|
|
|
|
// timer is for fetching the redirected update.
|
|
|
|
nsCOMPtr<nsITimer> mFetchIndirectUpdatesTimer;
|
|
|
|
|
|
|
|
// When we DownloadUpdate(), the DBService might be busy on processing
|
|
|
|
// request issused outside of StreamUpdater. We have to fire a timer to
|
|
|
|
// retry on our own.
|
|
|
|
nsCOMPtr<nsITimer> mFetchNextRequestTimer;
|
2008-01-13 01:22:03 +03:00
|
|
|
|
2017-04-24 12:51:06 +03:00
|
|
|
// Timer to abort the download if the server takes too long to respond.
|
|
|
|
nsCOMPtr<nsITimer> mResponseTimeoutTimer;
|
|
|
|
|
|
|
|
// Timer to abort the download if it takes too long.
|
|
|
|
nsCOMPtr<nsITimer> mTimeoutTimer;
|
|
|
|
|
2017-10-05 03:37:29 +03:00
|
|
|
mozilla::UniquePtr<UpdateRequest> mCurrentRequest;
|
|
|
|
nsTArray<UpdateRequest> mPendingRequests;
|
2014-06-12 21:24:03 +04:00
|
|
|
|
2008-01-29 23:57:18 +03:00
|
|
|
struct PendingUpdate {
|
|
|
|
nsCString mUrl;
|
|
|
|
nsCString mTable;
|
|
|
|
};
|
|
|
|
nsTArray<PendingUpdate> mPendingUpdates;
|
2008-01-13 01:22:03 +03:00
|
|
|
|
2017-01-27 13:02:36 +03:00
|
|
|
// The provider for current update request and should be only used by
|
|
|
|
// telemetry since it would show up as "other" for any other providers.
|
|
|
|
nsCString mTelemetryProvider;
|
2017-03-24 10:41:23 +03:00
|
|
|
PRIntervalTime mTelemetryClockStart;
|
2006-06-15 23:10:04 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsUrlClassifierStreamUpdater_h_
|