blob: 79bb81ee1fb611e0ec4c46619d7a9819f9e30bea [file] [log] [blame]
lazyboye464732f2017-06-15 21:17:271// Copyright 2017 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
5#ifndef EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_
6#define EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_
7
David Bertoni64786432018-12-21 23:10:128#include <tuple>
9
lazyboye464732f2017-06-15 21:17:2710#include "extensions/common/extension_id.h"
11#include "url/gurl.h"
12
13namespace content {
14class BrowserContext;
15}
16
17namespace extensions {
lazyboy63b994a2017-06-30 21:20:2318class LazyContextTaskQueue;
lazyboye464732f2017-06-15 21:17:2719
20class LazyContextId {
21 public:
22 enum class Type {
23 kEventPage,
lazyboy63b994a2017-06-30 21:20:2324 kServiceWorker,
lazyboye464732f2017-06-15 21:17:2725 };
26
27 // An event page (lazy background) context.
28 LazyContextId(content::BrowserContext* context,
29 const ExtensionId& extension_id);
lazyboy63b994a2017-06-30 21:20:2330
31 // An extension service worker context.
32 LazyContextId(content::BrowserContext* context,
33 const ExtensionId& extension_id,
34 const GURL& service_worker_scope);
lazyboye464732f2017-06-15 21:17:2735
David Bertoni64786432018-12-21 23:10:1236 // Copy and move constructors.
37 LazyContextId(const LazyContextId& other) = default;
38 LazyContextId(LazyContextId&& other) = default;
39
40 LazyContextId& operator=(const LazyContextId&) noexcept = default;
41 LazyContextId& operator=(LazyContextId&&) noexcept = default;
42
lazyboye464732f2017-06-15 21:17:2743 bool is_for_event_page() const { return type_ == Type::kEventPage; }
lazyboy63b994a2017-06-30 21:20:2344 bool is_for_service_worker() const { return type_ == Type::kServiceWorker; }
lazyboye464732f2017-06-15 21:17:2745
46 content::BrowserContext* browser_context() const { return context_; }
47 void set_browser_context(content::BrowserContext* context) {
48 context_ = context;
49 }
50
51 const ExtensionId& extension_id() const { return extension_id_; }
52
lazyboy63b994a2017-06-30 21:20:2353 const GURL& service_worker_scope() const {
54 DCHECK(is_for_service_worker());
55 return service_worker_scope_;
56 }
57
David Bertoni27dfaff22018-12-12 20:05:3758 LazyContextTaskQueue* GetTaskQueue() const;
lazyboye464732f2017-06-15 21:17:2759
David Bertoni64786432018-12-21 23:10:1260 bool operator<(const LazyContextId& rhs) const {
Istiaque Ahmed92ad7fc2019-11-18 19:02:2661 return std::tie(type_, context_, extension_id_, service_worker_scope_) <
62 std::tie(rhs.type_, rhs.context_, rhs.extension_id_,
63 rhs.service_worker_scope_);
David Bertoni64786432018-12-21 23:10:1264 }
lazyboye464732f2017-06-15 21:17:2765
Istiaque Ahmed92ad7fc2019-11-18 19:02:2666 bool operator==(const LazyContextId& rhs) const {
67 return std::tie(type_, context_, extension_id_, service_worker_scope_) ==
68 std::tie(rhs.type_, rhs.context_, rhs.extension_id_,
69 rhs.service_worker_scope_);
70 }
71
72 bool operator!=(const LazyContextId& rhs) const { return !(*this == rhs); }
73
David Bertoni64786432018-12-21 23:10:1274 private:
75 Type type_;
76 content::BrowserContext* context_;
77 ExtensionId extension_id_;
78 GURL service_worker_scope_;
lazyboye464732f2017-06-15 21:17:2779};
80
81} // namespace extensions
82
83#endif // EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_