OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_ | 5 #ifndef EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_ |
6 #define EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_ | 6 #define EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_ |
7 | 7 |
8 #include "extensions/common/extension_id.h" | 8 #include "extensions/common/extension_id.h" |
9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 class BrowserContext; | 12 class BrowserContext; |
13 } | 13 } |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 class LazyBackgroundTaskQueue; | 16 class LazyContextTaskQueue; |
17 | 17 |
18 class LazyContextId { | 18 class LazyContextId { |
19 public: | 19 public: |
20 enum class Type { | 20 enum class Type { |
21 kEventPage, | 21 kEventPage, |
| 22 kServiceWorker, |
22 }; | 23 }; |
23 | 24 |
24 // An event page (lazy background) context. | 25 // An event page (lazy background) context. |
25 LazyContextId(content::BrowserContext* context, | 26 LazyContextId(content::BrowserContext* context, |
26 const ExtensionId& extension_id); | 27 const ExtensionId& extension_id); |
27 // TODO(lazyboy): Service worker context. | 28 |
| 29 // An extension service worker context. |
| 30 LazyContextId(content::BrowserContext* context, |
| 31 const ExtensionId& extension_id, |
| 32 const GURL& service_worker_scope); |
28 | 33 |
29 bool is_for_event_page() const { return type_ == Type::kEventPage; } | 34 bool is_for_event_page() const { return type_ == Type::kEventPage; } |
| 35 bool is_for_service_worker() const { return type_ == Type::kServiceWorker; } |
30 | 36 |
31 content::BrowserContext* browser_context() const { return context_; } | 37 content::BrowserContext* browser_context() const { return context_; } |
32 void set_browser_context(content::BrowserContext* context) { | 38 void set_browser_context(content::BrowserContext* context) { |
33 context_ = context; | 39 context_ = context; |
34 } | 40 } |
35 | 41 |
36 const ExtensionId& extension_id() const { return extension_id_; } | 42 const ExtensionId& extension_id() const { return extension_id_; } |
37 | 43 |
38 // TODO(lazyboy): Use a generic interface to support service workers. | 44 const GURL& service_worker_scope() const { |
39 LazyBackgroundTaskQueue* GetTaskQueue(); | 45 DCHECK(is_for_service_worker()); |
| 46 return service_worker_scope_; |
| 47 } |
| 48 |
| 49 LazyContextTaskQueue* GetTaskQueue(); |
40 | 50 |
41 private: | 51 private: |
42 const Type type_; | 52 const Type type_; |
43 content::BrowserContext* context_; | 53 content::BrowserContext* context_; |
44 const ExtensionId extension_id_; | 54 const ExtensionId extension_id_; |
| 55 const GURL service_worker_scope_; |
45 | 56 |
46 DISALLOW_COPY_AND_ASSIGN(LazyContextId); | 57 DISALLOW_COPY_AND_ASSIGN(LazyContextId); |
47 }; | 58 }; |
48 | 59 |
49 } // namespace extensions | 60 } // namespace extensions |
50 | 61 |
51 #endif // EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_ | 62 #endif // EXTENSIONS_BROWSER_LAZY_CONTEXT_ID_H_ |
OLD | NEW |