1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148

content / browser / service_worker / service_worker_context_core_observer.h [blame]

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_OBSERVER_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_OBSERVER_H_

#include <stdint.h>
#include <string>

#include "base/functional/callback.h"
#include "base/time/time.h"
#include "content/browser/service_worker/service_worker_info.h"
#include "content/browser/service_worker/service_worker_version.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/service_worker_context_observer.h"
#include "third_party/blink/public/common/service_worker/embedded_worker_status.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_client.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_container_type.mojom.h"
#include "url/gurl.h"

namespace blink {
class StorageKey;
}  // namespace blink

namespace content {

struct ConsoleMessage;

class ServiceWorkerContextCoreObserver {
 public:
  virtual void OnNewLiveRegistration(int64_t registration_id,
                                     const GURL& scope,
                                     const blink::StorageKey& key) {}
  virtual void OnNewLiveVersion(const ServiceWorkerVersionInfo& version_info) {}
  virtual void OnLiveVersionDestroyed(int64_t version_id) {}
  virtual void OnStarting(int64_t version_id) {}
  virtual void OnStarted(int64_t version_id,
                         const GURL& scope,
                         int process_id,
                         const GURL& script_url,
                         const blink::ServiceWorkerToken& token,
                         const blink::StorageKey& key) {}
  virtual void OnStopping(int64_t version_id) {}
  virtual void OnStopped(int64_t version_id) {}
  // Called when the context core is about to be deleted. After this is called,
  // method calls on this observer will be for a new context core, possibly
  // reusing version/registration IDs previously seen. So this method gives the
  // observer a chance to discard any state it has.
  virtual void OnDeleteAndStartOver() {}
  virtual void OnVersionStateChanged(int64_t version_id,
                                     const GURL& scope,
                                     const blink::StorageKey& key,
                                     ServiceWorkerVersion::Status status) {}
  virtual void OnVersionRouterRulesChanged(int64_t version_id,
                                           const std::string& router_rules) {}
  virtual void OnVersionDevToolsRoutingIdChanged(int64_t version_id,
                                                 int process_id,
                                                 int devtools_agent_route_id) {}
  virtual void OnMainScriptResponseSet(int64_t version_id,
                                       base::Time script_response_time,
                                       base::Time script_last_modified) {}
  virtual void OnErrorReported(
      int64_t version_id,
      const GURL& scope,
      const blink::StorageKey& key,
      const ServiceWorkerContextObserver::ErrorInfo& info) {}
  virtual void OnReportConsoleMessage(int64_t version_id,
                                      const GURL& scope,
                                      const blink::StorageKey& key,
                                      const ConsoleMessage& message) {}
  virtual void OnControlleeAdded(int64_t version_id,
                                 const std::string& uuid,
                                 const ServiceWorkerClientInfo& info) {}
  virtual void OnControlleeRemoved(int64_t version_id,
                                   const std::string& uuid) {}
  virtual void OnNoControllees(int64_t version_id,
                               const GURL& scope,
                               const blink::StorageKey& key) {}
  virtual void OnControlleeNavigationCommitted(
      int64_t version_id,
      const std::string& uuid,
      GlobalRenderFrameHostId render_frame_host_id) {}
  // Called when the ServiceWorkerContainer.register() promise is resolved.
  //
  // This is called before the service worker registration is persisted to
  // storage. The implementation cannot assume that the ServiceWorkerContextCore
  // will find the registration at this point.
  virtual void OnRegistrationCompleted(int64_t registration_id,
                                       const GURL& scope,
                                       const blink::StorageKey& key) {}
  // Called after a service worker registration is persisted to storage.
  //
  // This happens after OnRegistrationCompleted(). The implementation can assume
  // that ServiceWorkerContextCore will find the registration, and can safely
  // add user data to the registration.
  virtual void OnRegistrationStored(int64_t registration_id,
                                    const GURL& scope,
                                    const blink::StorageKey& key) {}

  // Called after a task has been posted to delete a registration from storage.
  // This is roughly equivalent to the same time that the promise for
  // unregister() would be resolved. This means the live
  // ServiceWorkerRegistration may still exist, and the deletion operator may
  // not yet have finished.
  virtual void OnRegistrationDeleted(int64_t registration_id,
                                     const GURL& scope,
                                     const blink::StorageKey& key) {}

  // Called after all registrations for `key` are deleted from storage. There
  // may still be live registrations for this origin in the kUninstalling or
  // kUninstalled state.
  //
  // This is called after OnRegistrationDeleted(). It is called once
  // ServiceWorkerRegistry gets confirmation that the delete operation finished.
  virtual void OnAllRegistrationsDeletedForStorageKey(
      const blink::StorageKey& key) {}

  // Notified when the storage corruption recovery is completed and all stored
  // data is wiped out.
  virtual void OnStorageWiped() {}

  // Called when a container host representing a client is execution ready. See
  // https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-execution-ready-flag
  virtual void OnClientIsExecutionReady(
      ukm::SourceId source_id,
      const GURL& url,
      blink::mojom::ServiceWorkerClientType type) {}

  // Called when a container host representing a client is destroyed.
  virtual void OnClientDestroyed(ukm::SourceId source_id,
                                 const GURL& url,
                                 blink::mojom::ServiceWorkerClientType type) {}

  // Called when a Service Worker opens a new window.
  virtual void OnWindowOpened(const GURL& script_url, const GURL& url) {}

  // Called when a Service Worker navigates an existing tab.
  virtual void OnClientNavigated(const GURL& script_url, const GURL& url) {}

 protected:
  virtual ~ServiceWorkerContextCoreObserver() {}
};

}  // namespace content

#endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_OBSERVER_H_