#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
#include <map>
#include <vector>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_vector.h"
#include "content/common/content_export.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "url/gurl.h"
namespace quota {
class QuotaManagerProxy;
}
namespace content {
class ServiceWorkerRegistration;
class ServiceWorkerRegistrationInfo;
class CONTENT_EXPORT ServiceWorkerStorage {
public:
typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback;
typedef base::Callback<void(ServiceWorkerStatusCode status,
const scoped_refptr<ServiceWorkerRegistration>&
registration)> FindRegistrationCallback;
ServiceWorkerStorage(const base::FilePath& path,
quota::QuotaManagerProxy* quota_manager_proxy);
~ServiceWorkerStorage();
void FindRegistrationForDocument(const GURL& document_url,
const FindRegistrationCallback& callback);
void FindRegistrationForPattern(const GURL& pattern,
const FindRegistrationCallback& callback);
void FindRegistrationForId(int64 registration_id,
const FindRegistrationCallback& callback);
typedef base::Callback<
void(const std::vector<ServiceWorkerRegistrationInfo>& registrations)>
GetAllRegistrationInfosCallback;
void GetAllRegistrations(const GetAllRegistrationInfosCallback& callback);
void StoreRegistration(ServiceWorkerRegistration* registration,
const StatusCallback& callback);
void DeleteRegistration(const GURL& pattern,
const StatusCallback& callback);
int64 NewRegistrationId();
int64 NewVersionId();
private:
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, PatternMatches);
typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> >
PatternToRegistrationMap;
static bool PatternMatches(const GURL& pattern, const GURL& script_url);
PatternToRegistrationMap registration_by_pattern_;
int last_registration_id_;
int last_version_id_;
scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
base::FilePath path_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage);
};
}
#endif