service_worker_client.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_PERFORMANCE_MANAGER_SERVICE_WORKER_CLIENT_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_SERVICE_WORKER_CLIENT_H_
  6. #include "content/public/browser/global_routing_id.h"
  7. #include "content/public/browser/service_worker_client_info.h"
  8. #include "third_party/blink/public/common/tokens/tokens.h"
  9. #include "third_party/blink/public/mojom/service_worker/service_worker_client.mojom.h"
  10. // Represents a client of a service worker node.
  11. //
  12. // This class is essentially a tagged union where only the field corresponding
  13. // to the |type()| can be accessed.
  14. class ServiceWorkerClient {
  15. public:
  16. explicit ServiceWorkerClient(
  17. content::GlobalRenderFrameHostId render_frame_host_id);
  18. explicit ServiceWorkerClient(
  19. blink::DedicatedWorkerToken dedicated_worker_token);
  20. explicit ServiceWorkerClient(blink::SharedWorkerToken shared_worker_token);
  21. ServiceWorkerClient(const ServiceWorkerClient& other);
  22. ServiceWorkerClient& operator=(const ServiceWorkerClient& other);
  23. ~ServiceWorkerClient();
  24. blink::mojom::ServiceWorkerClientType type() const { return type_; }
  25. content::GlobalRenderFrameHostId GetRenderFrameHostId() const;
  26. blink::DedicatedWorkerToken GetDedicatedWorkerToken() const;
  27. blink::SharedWorkerToken GetSharedWorkerToken() const;
  28. bool operator<(const ServiceWorkerClient& other) const;
  29. private:
  30. // The client type.
  31. blink::mojom::ServiceWorkerClientType type_;
  32. union {
  33. // The frame tree node ID, if this is a window client.
  34. content::GlobalRenderFrameHostId render_frame_host_id_;
  35. // The token of the client, if this is a worker client.
  36. content::DedicatedOrSharedWorkerToken worker_token_;
  37. };
  38. };
  39. #endif // COMPONENTS_PERFORMANCE_MANAGER_SERVICE_WORKER_CLIENT_H_