#include "content/common/content_export.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/common/service_worker/service_worker_types.h"
+#include "third_party/WebKit/public/platform/WebGeofencingEventType.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
class GURL;
+namespace blink {
+struct WebCircularGeofencingRegion;
+}
+
namespace content {
class EmbeddedWorkerRegistry;
ServiceWorkerVersion(
ServiceWorkerRegistration* registration,
+ const GURL& script_url,
int64 version_id,
base::WeakPtr<ServiceWorkerContextCore> context);
void StartWorker(const StatusCallback& callback);
// Starts an embedded worker for this version.
- // |potential_process_ids| is a list of processes in which to start the
- // worker.
+ // |pause_after_download| notifies worker to pause after download finished
+ // which could be resumed by EmbeddedWorkerInstance::ResumeAfterDownload.
// This returns OK (success) if the worker is already running.
- void StartWorkerWithCandidateProcesses(
- const std::vector<int>& potential_process_ids,
- bool pause_after_download,
- const StatusCallback& callback);
+ void StartWorker(bool pause_after_download,
+ const StatusCallback& callback);
// Stops an embedded worker for this version.
// This returns OK (success) if the worker is already stopped.
void SendMessage(const IPC::Message& message, const StatusCallback& callback);
// Sends install event to the associated embedded worker and asynchronously
- // calls |callback| when it errors out or it gets response from the worker
+ // calls |callback| when it errors out or it gets a response from the worker
// to notify install completion.
// |active_version_id| must be a valid positive ID
// if there's an activated (previous) version running.
const StatusCallback& callback);
// Sends activate event to the associated embedded worker and asynchronously
- // calls |callback| when it errors out or it gets response from the worker
+ // calls |callback| when it errors out or it gets a response from the worker
// to notify activation completion.
//
// This must be called when the status() is INSTALLED. Calling this changes
// This must be called when the status() is ACTIVATED. Calling this in other
// statuses will result in an error SERVICE_WORKER_ERROR_FAILED.
void DispatchFetchEvent(const ServiceWorkerFetchRequest& request,
- const FetchCallback& callback);
+ const base::Closure& prepare_callback,
+ const FetchCallback& fetch_callback);
// Sends sync event to the associated embedded worker and asynchronously calls
- // |callback| when it errors out or it gets response from the worker to notify
- // completion.
+ // |callback| when it errors out or it gets a response from the worker to
+ // notify completion.
//
// This must be called when the status() is ACTIVATED.
void DispatchSyncEvent(const StatusCallback& callback);
// Sends push event to the associated embedded worker and asynchronously calls
- // |callback| when it errors out or it gets response from the worker to notify
- // completion.
+ // |callback| when it errors out or it gets a response from the worker to
+ // notify completion.
//
// This must be called when the status() is ACTIVATED.
void DispatchPushEvent(const StatusCallback& callback,
const std::string& data);
- // These are expected to be called when a renderer process host for the
- // same-origin as for this ServiceWorkerVersion is created. The added
- // processes are used to run an in-renderer embedded worker.
- void AddProcessToWorker(int process_id);
- void RemoveProcessFromWorker(int process_id);
-
- // Returns true if this has at least one process to run.
- bool HasProcessToRun() const;
+ // Sends geofencing event to the associated embedded worker and asynchronously
+ // calls |callback| when it errors out or it gets a response from the worker
+ // to notify completion.
+ //
+ // This must be called when the status() is ACTIVATED.
+ void DispatchGeofencingEvent(
+ const StatusCallback& callback,
+ blink::WebGeofencingEventType event_type,
+ const std::string& region_id,
+ const blink::WebCircularGeofencingRegion& region);
// Adds and removes |provider_host| as a controllee of this ServiceWorker.
// A potential controllee is a host having the version as its .installing
// or .waiting version.
void AddControllee(ServiceWorkerProviderHost* provider_host);
void RemoveControllee(ServiceWorkerProviderHost* provider_host);
- void AddPotentialControllee(ServiceWorkerProviderHost* provider_host);
- void RemovePotentialControllee(ServiceWorkerProviderHost* provider_host);
// Returns if it has controllee.
bool HasControllee() const { return !controllee_map_.empty(); }
friend class base::RefCounted<ServiceWorkerVersion>;
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
ActivateWaitingVersion);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability);
typedef ServiceWorkerVersion self;
typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap;
typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap;
- FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker);
- virtual ~ServiceWorkerVersion();
+ ~ServiceWorkerVersion() override;
// EmbeddedWorkerInstance::Listener overrides:
- virtual void OnStarted() OVERRIDE;
- virtual void OnStopped() OVERRIDE;
- virtual void OnReportException(const base::string16& error_message,
- int line_number,
- int column_number,
- const GURL& source_url) OVERRIDE;
- virtual void OnReportConsoleMessage(int source_identifier,
- int message_level,
- const base::string16& message,
- int line_number,
- const GURL& source_url) OVERRIDE;
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
-
- void RunStartWorkerCallbacksOnError(ServiceWorkerStatusCode status);
+ void OnStarted() override;
+ void OnStopped() override;
+ void OnReportException(const base::string16& error_message,
+ int line_number,
+ int column_number,
+ const GURL& source_url) override;
+ void OnReportConsoleMessage(int source_identifier,
+ int message_level,
+ const base::string16& message,
+ int line_number,
+ const GURL& source_url) override;
+ bool OnMessageReceived(const IPC::Message& message) override;
+
+ void OnStartMessageSent(ServiceWorkerStatusCode status);
void DispatchInstallEventAfterStartWorker(int active_version_id,
const StatusCallback& callback);
const ServiceWorkerResponse& response);
void OnSyncEventFinished(int request_id);
void OnPushEventFinished(int request_id);
+ void OnGeofencingEventFinished(int request_id);
void OnPostMessageToDocument(int client_id,
const base::string16& message,
const std::vector<int>& sent_message_port_ids);
IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_;
IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_;
IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_;
+ IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_;
ControlleeMap controllee_map_;
ControlleeByIDMap controllee_by_id_;