#ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
#define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
#include <map>
#include <set>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "content/common/service_worker/service_worker_status_code.h"
class GURL;
namespace IPC {
class Message;
class Sender;
}
namespace content {
class EmbeddedWorkerInstance;
class ServiceWorkerContextCore;
class CONTENT_EXPORT EmbeddedWorkerRegistry
: public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) {
public:
explicit EmbeddedWorkerRegistry(
base::WeakPtr<ServiceWorkerContextCore> context);
scoped_ptr<EmbeddedWorkerInstance> CreateWorker();
ServiceWorkerStatusCode StartWorker(int process_id,
int embedded_worker_id,
int64 service_worker_version_id,
const GURL& script_url);
ServiceWorkerStatusCode StopWorker(int process_id,
int embedded_worker_id);
void OnWorkerStarted(int process_id, int thread_id, int embedded_worker_id);
void OnWorkerStopped(int process_id, int embedded_worker_id);
void OnSendMessageToBrowser(int embedded_worker_id,
int request_id,
const IPC::Message& message);
void AddChildProcessSender(int process_id, IPC::Sender* sender);
void RemoveChildProcessSender(int process_id);
EmbeddedWorkerInstance* GetWorker(int embedded_worker_id);
private:
friend class base::RefCounted<EmbeddedWorkerRegistry>;
friend class EmbeddedWorkerInstance;
typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap;
typedef std::map<int, IPC::Sender*> ProcessToSenderMap;
~EmbeddedWorkerRegistry();
ServiceWorkerStatusCode Send(int process_id, IPC::Message* message);
void RemoveWorker(int process_id, int embedded_worker_id);
base::WeakPtr<ServiceWorkerContextCore> context_;
WorkerInstanceMap worker_map_;
ProcessToSenderMap process_sender_map_;
std::map<int, std::set<int> > worker_process_map_;
int next_embedded_worker_id_;
DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry);
};
}
#endif