OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
| 14 #include "content/browser/service_worker/service_worker_process_manager.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "content/public/browser/service_worker_context.h" | 16 #include "content/public/browser/service_worker_context.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class FilePath; | 19 class FilePath; |
19 class MessageLoopProxy; | 20 class MessageLoopProxy; |
20 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
21 } | 22 } |
22 | 23 |
23 namespace quota { | 24 namespace quota { |
24 class QuotaManagerProxy; | 25 class QuotaManagerProxy; |
25 } | 26 } |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 class BrowserContext; | 30 class BrowserContext; |
30 class ServiceWorkerContextCore; | 31 class ServiceWorkerContextCore; |
31 class ServiceWorkerContextObserver; | 32 class ServiceWorkerContextObserver; |
| 33 class ServiceWorkerProcessManager; |
32 | 34 |
33 // A refcounted wrapper class for our core object. Higher level content lib | 35 // A refcounted wrapper class for our core object. Higher level content lib |
34 // classes keep references to this class on mutliple threads. The inner core | 36 // classes keep references to this class on mutliple threads. The inner core |
35 // instance is strictly single threaded and is not refcounted, the core object | 37 // instance is strictly single threaded and is not refcounted, the core object |
36 // is what is used internally in the service worker lib. | 38 // is what is used internally in the service worker lib. |
37 class CONTENT_EXPORT ServiceWorkerContextWrapper | 39 class CONTENT_EXPORT ServiceWorkerContextWrapper |
38 : NON_EXPORTED_BASE(public ServiceWorkerContext), | 40 : NON_EXPORTED_BASE(public ServiceWorkerContext), |
39 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> { | 41 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> { |
40 public: | 42 public: |
41 ServiceWorkerContextWrapper(BrowserContext* browser_context); | 43 ServiceWorkerContextWrapper(BrowserContext* browser_context); |
42 | 44 |
43 // Init and Shutdown are for use on the UI thread when the profile, | 45 // Init and Shutdown are for use on the UI thread when the profile, |
44 // storagepartition is being setup and torn down. | 46 // storagepartition is being setup and torn down. |
45 void Init(const base::FilePath& user_data_directory, | 47 void Init(const base::FilePath& user_data_directory, |
46 quota::QuotaManagerProxy* quota_manager_proxy); | 48 quota::QuotaManagerProxy* quota_manager_proxy); |
47 void Shutdown(); | 49 void Shutdown(); |
48 | 50 |
49 // The core context is only for use on the IO thread. | 51 // The core context is only for use on the IO thread. |
50 ServiceWorkerContextCore* context(); | 52 ServiceWorkerContextCore* context(); |
51 | 53 |
| 54 // The process manager can be used on either UI or IO. |
| 55 ServiceWorkerProcessManager* process_manager() { |
| 56 return process_manager_.get(); |
| 57 } |
| 58 |
52 // ServiceWorkerContext implementation: | 59 // ServiceWorkerContext implementation: |
53 virtual void RegisterServiceWorker( | 60 virtual void RegisterServiceWorker( |
54 const GURL& pattern, | 61 const GURL& pattern, |
55 const GURL& script_url, | 62 const GURL& script_url, |
56 const ResultCallback& continuation) OVERRIDE; | 63 const ResultCallback& continuation) OVERRIDE; |
57 virtual void UnregisterServiceWorker(const GURL& pattern, | 64 virtual void UnregisterServiceWorker(const GURL& pattern, |
58 const ResultCallback& continuation) | 65 const ResultCallback& continuation) |
59 OVERRIDE; | 66 OVERRIDE; |
60 | 67 |
61 void AddObserver(ServiceWorkerContextObserver* observer); | 68 void AddObserver(ServiceWorkerContextObserver* observer); |
62 void RemoveObserver(ServiceWorkerContextObserver* observer); | 69 void RemoveObserver(ServiceWorkerContextObserver* observer); |
63 | 70 |
64 private: | 71 private: |
65 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>; | 72 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>; |
66 friend class EmbeddedWorkerTestHelper; | 73 friend class EmbeddedWorkerTestHelper; |
67 friend class ServiceWorkerProcessManager; | 74 friend class ServiceWorkerProcessManager; |
68 virtual ~ServiceWorkerContextWrapper(); | 75 virtual ~ServiceWorkerContextWrapper(); |
69 | 76 |
70 void InitInternal(const base::FilePath& user_data_directory, | 77 void InitInternal(const base::FilePath& user_data_directory, |
71 base::SequencedTaskRunner* database_task_runner, | 78 base::SequencedTaskRunner* database_task_runner, |
72 base::MessageLoopProxy* disk_cache_thread, | 79 base::MessageLoopProxy* disk_cache_thread, |
73 quota::QuotaManagerProxy* quota_manager_proxy); | 80 quota::QuotaManagerProxy* quota_manager_proxy); |
| 81 void ShutdownOnIO(); |
74 | 82 |
75 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > | 83 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > |
76 observer_list_; | 84 observer_list_; |
| 85 const scoped_ptr<ServiceWorkerProcessManager> process_manager_; |
77 // Cleared in Shutdown(): | 86 // Cleared in Shutdown(): |
78 BrowserContext* browser_context_; | |
79 scoped_ptr<ServiceWorkerContextCore> context_core_; | 87 scoped_ptr<ServiceWorkerContextCore> context_core_; |
80 }; | 88 }; |
81 | 89 |
82 } // namespace content | 90 } // namespace content |
83 | 91 |
84 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 92 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
OLD | NEW |