#ifndef WEBKIT_APPCACHE_APPCACHE_SERVICE_H_
#define WEBKIT_APPCACHE_APPCACHE_SERVICE_H_
#include <map>
#include <set>
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
#include "webkit/appcache/appcache_export.h"
#include "webkit/appcache/appcache_interfaces.h"
#include "webkit/appcache/appcache_storage.h"
class FilePath;
namespace net {
class URLRequestContext;
}
namespace base {
class MessageLoopProxy;
}
namespace quota {
class QuotaManagerProxy;
class SpecialStoragePolicy;
}
namespace appcache {
class AppCacheBackendImpl;
class AppCacheQuotaClient;
class AppCachePolicy;
struct APPCACHE_EXPORT AppCacheInfoCollection
: public base::RefCountedThreadSafe<AppCacheInfoCollection> {
AppCacheInfoCollection();
std::map<GURL, AppCacheInfoVector> infos_by_origin;
private:
friend class base::RefCountedThreadSafe<AppCacheInfoCollection>;
virtual ~AppCacheInfoCollection();
};
class APPCACHE_EXPORT AppCacheService {
public:
explicit AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy);
virtual ~AppCacheService();
void Initialize(const FilePath& cache_directory,
base::MessageLoopProxy* db_thread,
base::MessageLoopProxy* cache_thread);
void PurgeMemory() {
if (storage_.get())
storage_->PurgeMemory();
}
void CanHandleMainResourceOffline(const GURL& url,
const GURL& first_party,
const net::CompletionCallback& callback);
void GetAllAppCacheInfo(AppCacheInfoCollection* collection,
const net::CompletionCallback& callback);
void DeleteAppCacheGroup(const GURL& manifest_url,
const net::CompletionCallback& callback);
virtual void DeleteAppCachesForOrigin(
const GURL& origin, const net::CompletionCallback& callback);
void CheckAppCacheResponse(const GURL& manifest_url, int64 cache_id,
int64 response_id);
net::URLRequestContext* request_context() const { return request_context_; }
void set_request_context(net::URLRequestContext* context) {
request_context_ = context;
}
AppCachePolicy* appcache_policy() const { return appcache_policy_; }
void set_appcache_policy(AppCachePolicy* policy) {
appcache_policy_ = policy;
}
quota::SpecialStoragePolicy* special_storage_policy() const {
return special_storage_policy_.get();
}
void set_special_storage_policy(quota::SpecialStoragePolicy* policy);
quota::QuotaManagerProxy* quota_manager_proxy() const {
return quota_manager_proxy_.get();
}
AppCacheQuotaClient* quota_client() const {
return quota_client_;
}
void RegisterBackend(AppCacheBackendImpl* backend_impl);
void UnregisterBackend(AppCacheBackendImpl* backend_impl);
AppCacheBackendImpl* GetBackend(int id) const {
BackendMap::const_iterator it = backends_.find(id);
return (it != backends_.end()) ? it->second : NULL;
}
AppCacheStorage* storage() const { return storage_.get(); }
void set_force_keep_session_state() { force_keep_session_state_ = true; }
bool force_keep_session_state() const { return force_keep_session_state_; }
protected:
friend class AppCacheStorageImplTest;
friend class AppCacheServiceTest;
class AsyncHelper;
class CanHandleOfflineHelper;
class DeleteHelper;
class DeleteOriginHelper;
class GetInfoHelper;
class CheckResponseHelper;
typedef std::set<AsyncHelper*> PendingAsyncHelpers;
typedef std::map<int, AppCacheBackendImpl*> BackendMap;
AppCachePolicy* appcache_policy_;
AppCacheQuotaClient* quota_client_;
scoped_ptr<AppCacheStorage> storage_;
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
PendingAsyncHelpers pending_helpers_;
BackendMap backends_;
net::URLRequestContext* request_context_;
bool force_keep_session_state_;
DISALLOW_COPY_AND_ASSIGN(AppCacheService);
};
}
#endif