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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/browser/service_worker/service_worker_context_core.h"
14 #include "content/common/content_export.h"
15 #include "content/public/browser/service_worker_context.h"
19 class SequencedTaskRunner
;
20 class SingleThreadTaskRunner
;
24 class URLRequestContextGetter
;
28 class QuotaManagerProxy
;
34 class ChromeBlobStorageContext
;
35 class ServiceWorkerContextCore
;
36 class ServiceWorkerContextObserver
;
38 // A refcounted wrapper class for our core object. Higher level content lib
39 // classes keep references to this class on mutliple threads. The inner core
40 // instance is strictly single threaded and is not refcounted, the core object
41 // is what is used internally in the service worker lib.
42 class CONTENT_EXPORT ServiceWorkerContextWrapper
43 : NON_EXPORTED_BASE(public ServiceWorkerContext
),
44 public base::RefCountedThreadSafe
<ServiceWorkerContextWrapper
> {
46 ServiceWorkerContextWrapper(BrowserContext
* browser_context
);
48 // Init and Shutdown are for use on the UI thread when the profile,
49 // storagepartition is being setup and torn down.
50 void Init(const base::FilePath
& user_data_directory
,
51 storage::QuotaManagerProxy
* quota_manager_proxy
);
54 // Deletes all files on disk and restarts the system asynchronously. This
55 // leaves the system in a disabled state until it's done. This should be
56 // called on the IO thread.
57 void DeleteAndStartOver();
59 // The core context is only for use on the IO thread.
60 ServiceWorkerContextCore
* context();
62 // The process manager can be used on either UI or IO.
63 ServiceWorkerProcessManager
* process_manager() {
64 return process_manager_
.get();
67 // ServiceWorkerContext implementation:
68 virtual void RegisterServiceWorker(
70 const GURL
& script_url
,
71 const ResultCallback
& continuation
) OVERRIDE
;
72 virtual void UnregisterServiceWorker(const GURL
& pattern
,
73 const ResultCallback
& continuation
)
75 virtual void Terminate() OVERRIDE
;
76 virtual void GetAllOriginsInfo(const GetUsageInfoCallback
& callback
) OVERRIDE
;
77 virtual void DeleteForOrigin(const GURL
& origin_url
) OVERRIDE
;
79 void AddObserver(ServiceWorkerContextObserver
* observer
);
80 void RemoveObserver(ServiceWorkerContextObserver
* observer
);
82 bool is_incognito() const { return is_incognito_
; }
84 // The URLRequestContext doesn't exist until after the StoragePartition is
85 // made (which is after this object is made). This function must be called
86 // after this object is created but before any ServiceWorkerCache operations.
87 // It must be called on the IO thread. If either parameter is NULL the
88 // function immediately returns without forwarding to the
89 // ServiceWorkerCacheStorageManager.
90 void SetBlobParametersForCache(
91 net::URLRequestContextGetter
* request_context
,
92 ChromeBlobStorageContext
* blob_storage_context
);
95 friend class base::RefCountedThreadSafe
<ServiceWorkerContextWrapper
>;
96 friend class EmbeddedWorkerTestHelper
;
97 friend class ServiceWorkerProcessManager
;
98 virtual ~ServiceWorkerContextWrapper();
101 const base::FilePath
& user_data_directory
,
102 const scoped_refptr
<base::SequencedTaskRunner
>& stores_task_runner
,
103 const scoped_refptr
<base::SequencedTaskRunner
>& database_task_runner
,
104 const scoped_refptr
<base::SingleThreadTaskRunner
>& disk_cache_thread
,
105 storage::QuotaManagerProxy
* quota_manager_proxy
);
108 void DidDeleteAndStartOver(ServiceWorkerStatusCode status
);
110 void DidGetAllRegistrationsForGetAllOrigins(
111 const GetUsageInfoCallback
& callback
,
112 const std::vector
<ServiceWorkerRegistrationInfo
>& registrations
);
113 void DidGetAllRegistrationsForDeleteForOrigin(
115 const std::vector
<ServiceWorkerRegistrationInfo
>& registrations
);
117 const scoped_refptr
<ObserverListThreadSafe
<ServiceWorkerContextObserver
> >
119 const scoped_ptr
<ServiceWorkerProcessManager
> process_manager_
;
120 // Cleared in Shutdown():
121 scoped_ptr
<ServiceWorkerContextCore
> context_core_
;
123 // Initialized in Init(); true of the user data directory is empty.
127 } // namespace content
129 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_