2015-03-02 16:20:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_cache_FetchPut_h
|
|
|
|
#define mozilla_dom_cache_FetchPut_h
|
|
|
|
|
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/dom/cache/Manager.h"
|
|
|
|
#include "mozilla/dom/cache/PCacheTypes.h"
|
|
|
|
#include "mozilla/dom/cache/Types.h"
|
|
|
|
#include "mozilla/dom/cache/TypeUtils.h"
|
|
|
|
#include "nsRefPtr.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class nsIInputStream;
|
|
|
|
class nsIRunnable;
|
|
|
|
class nsIThread;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Request;
|
|
|
|
class Response;
|
|
|
|
|
|
|
|
namespace cache {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class FetchPut final : public Manager::Listener
|
2015-03-22 09:52:12 +03:00
|
|
|
, public TypeUtils
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::pair<nsRefPtr<Request>, nsRefPtr<Response>> PutPair;
|
|
|
|
|
|
|
|
class Listener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void
|
|
|
|
OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, nsresult aRv) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
Create(Listener* aListener, Manager* aManager,
|
|
|
|
RequestId aRequestId, CacheId aCacheId,
|
|
|
|
const nsTArray<PCacheRequest>& aRequests,
|
|
|
|
const nsTArray<nsCOMPtr<nsIInputStream>>& aRequestStreams,
|
|
|
|
FetchPut** aFetchPutOut);
|
|
|
|
|
|
|
|
void ClearListener();
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Runnable;
|
|
|
|
class FetchObserver;
|
|
|
|
struct State
|
|
|
|
{
|
|
|
|
PCacheRequest mPCacheRequest;
|
|
|
|
nsCOMPtr<nsIInputStream> mRequestStream;
|
|
|
|
nsRefPtr<FetchObserver> mFetchObserver;
|
|
|
|
PCacheResponse mPCacheResponse;
|
|
|
|
nsCOMPtr<nsIInputStream> mResponseStream;
|
|
|
|
|
|
|
|
nsRefPtr<Request> mRequest;
|
|
|
|
nsRefPtr<Response> mResponse;
|
|
|
|
};
|
|
|
|
|
|
|
|
FetchPut(Listener* aListener, Manager* aManager,
|
|
|
|
RequestId aRequestId, CacheId aCacheId,
|
|
|
|
const nsTArray<PCacheRequest>& aRequests,
|
|
|
|
const nsTArray<nsCOMPtr<nsIInputStream>>& aRequestStreams);
|
|
|
|
~FetchPut();
|
|
|
|
|
|
|
|
nsresult DispatchToMainThread();
|
|
|
|
void DispatchToInitiatingThread();
|
|
|
|
|
|
|
|
void DoFetchOnMainThread();
|
|
|
|
void FetchComplete(FetchObserver* aObserver,
|
|
|
|
InternalResponse* aInternalResponse);
|
|
|
|
void MaybeCompleteOnMainThread();
|
|
|
|
|
|
|
|
void DoPutOnWorkerThread();
|
|
|
|
static bool MatchInPutList(const PCacheRequest& aRequest,
|
|
|
|
const nsTArray<CacheRequestResponse>& aPutList);
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void OnCachePutAll(RequestId aRequestId, nsresult aRv) override;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
void MaybeSetError(nsresult aRv);
|
|
|
|
void MaybeNotifyListener();
|
|
|
|
|
|
|
|
// TypeUtils methods
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsIGlobalObject* GetGlobalObject() const override;
|
2015-03-02 16:20:00 +03:00
|
|
|
#ifdef DEBUG
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void AssertOwningThread() const override;
|
2015-03-02 16:20:00 +03:00
|
|
|
#endif
|
|
|
|
|
2015-03-22 09:52:12 +03:00
|
|
|
virtual CachePushStreamChild*
|
|
|
|
CreatePushStream(nsIAsyncInputStream* aStream) override;
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
Listener* mListener;
|
|
|
|
nsRefPtr<Manager> mManager;
|
|
|
|
const RequestId mRequestId;
|
|
|
|
const CacheId mCacheId;
|
|
|
|
nsCOMPtr<nsIThread> mInitiatingThread;
|
|
|
|
nsTArray<State> mStateList;
|
|
|
|
uint32_t mPendingCount;
|
|
|
|
nsresult mResult;
|
|
|
|
nsCOMPtr<nsIRunnable> mRunnable;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::dom::cache::FetchPut)
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_cache_FetchPut_h
|