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
;
23 class QuotaManagerProxy
;
29 class ServiceWorkerContextCore
;
30 class ServiceWorkerContextObserver
;
32 // A refcounted wrapper class for our core object. Higher level content lib
33 // classes keep references to this class on mutliple threads. The inner core
34 // instance is strictly single threaded and is not refcounted, the core object
35 // is what is used internally in the service worker lib.
36 class CONTENT_EXPORT ServiceWorkerContextWrapper
37 : NON_EXPORTED_BASE(public ServiceWorkerContext
),
38 public base::RefCountedThreadSafe
<ServiceWorkerContextWrapper
> {
40 ServiceWorkerContextWrapper(BrowserContext
* browser_context
);
42 // Init and Shutdown are for use on the UI thread when the profile,
43 // storagepartition is being setup and torn down.
44 void Init(const base::FilePath
& user_data_directory
,
45 quota::QuotaManagerProxy
* quota_manager_proxy
);
48 // The core context is only for use on the IO thread.
49 ServiceWorkerContextCore
* context();
51 // ServiceWorkerContext implementation:
52 virtual void RegisterServiceWorker(
54 const GURL
& script_url
,
55 const ResultCallback
& continuation
) OVERRIDE
;
56 virtual void UnregisterServiceWorker(const GURL
& pattern
,
57 const ResultCallback
& continuation
)
60 void AddObserver(ServiceWorkerContextObserver
* observer
);
61 void RemoveObserver(ServiceWorkerContextObserver
* observer
);
64 friend class base::RefCountedThreadSafe
<ServiceWorkerContextWrapper
>;
65 friend class EmbeddedWorkerTestHelper
;
66 friend class ServiceWorkerProcessManager
;
67 virtual ~ServiceWorkerContextWrapper();
69 void InitForTesting(const base::FilePath
& user_data_directory
,
70 base::SequencedTaskRunner
* database_task_runner
,
71 quota::QuotaManagerProxy
* quota_manager_proxy
);
72 void InitInternal(const base::FilePath
& user_data_directory
,
73 base::SequencedTaskRunner
* database_task_runner
,
74 quota::QuotaManagerProxy
* quota_manager_proxy
);
76 const scoped_refptr
<ObserverListThreadSafe
<ServiceWorkerContextObserver
> >
78 // Cleared in Shutdown():
79 BrowserContext
* browser_context_
;
80 scoped_ptr
<ServiceWorkerContextCore
> context_core_
;
83 } // namespace content
85 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_