#ifndef NET_HTTP_INFINITE_CACHE_H_
#define NET_HTTP_INFINITE_CACHE_H_
#include <string>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/timer.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
class FilePath;
namespace base {
class SequencedTaskRunner;
class SequencedWorkerPool;
}
namespace net {
class HttpCache;
class HttpResponseInfo;
class InfiniteCache;
struct HttpRequestInfo;
class NET_EXPORT_PRIVATE InfiniteCacheTransaction {
public:
explicit InfiniteCacheTransaction(InfiniteCache* cache);
~InfiniteCacheTransaction();
void OnRequestStart(const HttpRequestInfo* request);
void OnResponseReceived(const HttpResponseInfo* response);
void OnDataRead(const char* data, int data_len);
void OnTruncatedResponse();
void OnServedFromCache(const HttpResponseInfo* response);
private:
friend class InfiniteCache;
struct ResourceData;
void Finish();
base::WeakPtr<InfiniteCache> cache_;
scoped_ptr<ResourceData> resource_data_;
bool must_doom_entry_;
DISALLOW_COPY_AND_ASSIGN(InfiniteCacheTransaction);
};
class NET_EXPORT_PRIVATE InfiniteCache
: public base::SupportsWeakPtr<InfiniteCache> {
public:
InfiniteCache();
~InfiniteCache();
void Init(const FilePath& path);
InfiniteCacheTransaction* CreateInfiniteCacheTransaction();
int DeleteData(const CompletionCallback& callback);
int DeleteDataBetween(base::Time initial_time,
base::Time end_time,
const CompletionCallback& callback);
int QueryItemsForTest(const CompletionCallback& callback);
int FlushDataForTest(const CompletionCallback& callback);
private:
class Worker;
friend class base::RepeatingTimer<InfiniteCache>;
friend class InfiniteCacheTransaction;
std::string GenerateKey(const HttpRequestInfo* request);
void ProcessResource(scoped_ptr<InfiniteCacheTransaction::ResourceData> data);
void OnTimer();
scoped_refptr<Worker> worker_;
scoped_refptr<base::SequencedWorkerPool> worker_pool_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
base::RepeatingTimer<InfiniteCache> timer_;
DISALLOW_COPY_AND_ASSIGN(InfiniteCache);
};
}
#endif