Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_context_wrapper.h
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.
4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
7
8 #include <vector>
9
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"
16
17 namespace base {
18 class FilePath;
19 class SequencedTaskRunner;
20 }
21
22 namespace quota {
23 class QuotaManagerProxy;
24 }
25
26 namespace content {
27
28 class BrowserContext;
29 class ServiceWorkerContextCore;
30 class ServiceWorkerContextObserver;
31
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> {
39  public:
40   ServiceWorkerContextWrapper(BrowserContext* browser_context);
41
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);
46   void Shutdown();
47
48   // The core context is only for use on the IO thread.
49   ServiceWorkerContextCore* context();
50
51   // ServiceWorkerContext implementation:
52   virtual void RegisterServiceWorker(
53       const GURL& pattern,
54       const GURL& script_url,
55       const ResultCallback& continuation) OVERRIDE;
56   virtual void UnregisterServiceWorker(const GURL& pattern,
57                                        const ResultCallback& continuation)
58       OVERRIDE;
59
60   void AddObserver(ServiceWorkerContextObserver* observer);
61   void RemoveObserver(ServiceWorkerContextObserver* observer);
62
63  private:
64   friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
65   friend class EmbeddedWorkerTestHelper;
66   friend class ServiceWorkerProcessManager;
67   virtual ~ServiceWorkerContextWrapper();
68
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);
75
76   const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
77       observer_list_;
78   // Cleared in Shutdown():
79   BrowserContext* browser_context_;
80   scoped_ptr<ServiceWorkerContextCore> context_core_;
81 };
82
83 }  // namespace content
84
85 #endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_