#ifndef CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_
#define CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "content/common/service_worker/service_worker_types.h"
#include "ipc/ipc_listener.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
#include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h"
#include "url/gurl.h"
namespace base {
class MessageLoopProxy;
class TaskRunner;
}
namespace blink {
class WebDataSource;
}
namespace content {
class ServiceWorkerScriptContext;
class ThreadSafeSender;
class EmbeddedWorkerContextClient
: public blink::WebServiceWorkerContextClient {
public:
static EmbeddedWorkerContextClient* ThreadSpecificInstance();
EmbeddedWorkerContextClient(int embedded_worker_id,
int64 service_worker_version_id,
const GURL& script_url);
virtual ~EmbeddedWorkerContextClient();
bool OnMessageReceived(const IPC::Message& msg);
void SendMessageToBrowser(int request_id, const IPC::Message& message);
virtual void workerContextFailedToStart();
virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy);
virtual void workerContextDestroyed();
virtual void didHandleActivateEvent(int request_id,
blink::WebServiceWorkerEventResult);
virtual void didHandleInstallEvent(int request_id,
blink::WebServiceWorkerEventResult result);
virtual void didHandleFetchEvent(int request_id);
virtual void didHandleFetchEvent(
int request_id,
const blink::WebServiceWorkerResponse& response);
virtual blink::WebServiceWorkerNetworkProvider*
createServiceWorkerNetworkProvider(blink::WebDataSource* data_source);
virtual void didHandleSyncEvent(int request_id);
int embedded_worker_id() const { return embedded_worker_id_; }
base::MessageLoopProxy* main_thread_proxy() const {
return main_thread_proxy_;
}
private:
void OnSendMessageToWorker(int thread_id,
int embedded_worker_id,
int request_id,
const IPC::Message& message);
void SendWorkerStarted();
const int embedded_worker_id_;
const int64 service_worker_version_id_;
const GURL script_url_;
scoped_refptr<ThreadSafeSender> sender_;
scoped_refptr<base::MessageLoopProxy> main_thread_proxy_;
scoped_refptr<base::TaskRunner> worker_task_runner_;
scoped_ptr<ServiceWorkerScriptContext> script_context_;
base::WeakPtrFactory<EmbeddedWorkerContextClient> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerContextClient);
};
}
#endif