Rename isSystemLocationEnabled to isLocationEnabled, as per internal review (185995).
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_context_wrapper.h
blob7df3cb093b1f33da2fa2aa62bbdcefabb127dbe4
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_
8 #include <vector>
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"
17 namespace base {
18 class FilePath;
19 class SequencedTaskRunner;
20 class SingleThreadTaskRunner;
23 namespace net {
24 class URLRequestContextGetter;
27 namespace storage {
28 class QuotaManagerProxy;
29 class SpecialStoragePolicy;
32 namespace content {
34 class BrowserContext;
35 class ChromeBlobStorageContext;
36 class ServiceWorkerContextCore;
37 class ServiceWorkerContextObserver;
39 // A refcounted wrapper class for our core object. Higher level content lib
40 // classes keep references to this class on mutliple threads. The inner core
41 // instance is strictly single threaded and is not refcounted, the core object
42 // is what is used internally in the service worker lib.
43 class CONTENT_EXPORT ServiceWorkerContextWrapper
44 : NON_EXPORTED_BASE(public ServiceWorkerContext),
45 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
46 public:
47 ServiceWorkerContextWrapper(BrowserContext* browser_context);
49 // Init and Shutdown are for use on the UI thread when the profile,
50 // storagepartition is being setup and torn down.
51 void Init(const base::FilePath& user_data_directory,
52 storage::QuotaManagerProxy* quota_manager_proxy,
53 storage::SpecialStoragePolicy* special_storage_policy);
54 void Shutdown();
56 // Deletes all files on disk and restarts the system asynchronously. This
57 // leaves the system in a disabled state until it's done. This should be
58 // called on the IO thread.
59 void DeleteAndStartOver();
61 // The core context is only for use on the IO thread.
62 ServiceWorkerContextCore* context();
64 // The process manager can be used on either UI or IO.
65 ServiceWorkerProcessManager* process_manager() {
66 return process_manager_.get();
69 // ServiceWorkerContext implementation:
70 void RegisterServiceWorker(const GURL& pattern,
71 const GURL& script_url,
72 const ResultCallback& continuation) override;
73 void UnregisterServiceWorker(const GURL& pattern,
74 const ResultCallback& continuation) override;
75 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override;
76 void DeleteForOrigin(const GURL& origin_url) override;
78 // DeleteForOrigin with completion callback. Does not exit early, and returns
79 // false if one or more of the deletions fail.
80 virtual void DeleteForOrigin(const GURL& origin_url,
81 const ResultCallback& done);
83 void AddObserver(ServiceWorkerContextObserver* observer);
84 void RemoveObserver(ServiceWorkerContextObserver* observer);
86 bool is_incognito() const { return is_incognito_; }
88 // The URLRequestContext doesn't exist until after the StoragePartition is
89 // made (which is after this object is made). This function must be called
90 // after this object is created but before any ServiceWorkerCache operations.
91 // It must be called on the IO thread. If either parameter is NULL the
92 // function immediately returns without forwarding to the
93 // ServiceWorkerCacheStorageManager.
94 void SetBlobParametersForCache(
95 net::URLRequestContextGetter* request_context,
96 ChromeBlobStorageContext* blob_storage_context);
98 private:
99 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
100 friend class EmbeddedWorkerTestHelper;
101 friend class ServiceWorkerProcessManager;
102 friend class MockServiceWorkerContextWrapper;
104 ~ServiceWorkerContextWrapper() override;
106 void InitInternal(
107 const base::FilePath& user_data_directory,
108 const scoped_refptr<base::SequencedTaskRunner>& stores_task_runner,
109 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
110 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
111 storage::QuotaManagerProxy* quota_manager_proxy,
112 storage::SpecialStoragePolicy* special_storage_policy);
113 void ShutdownOnIO();
115 void DidDeleteAndStartOver(ServiceWorkerStatusCode status);
117 void DidGetAllRegistrationsForGetAllOrigins(
118 const GetUsageInfoCallback& callback,
119 const std::vector<ServiceWorkerRegistrationInfo>& registrations);
121 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
122 observer_list_;
123 const scoped_ptr<ServiceWorkerProcessManager> process_manager_;
124 // Cleared in Shutdown():
125 scoped_ptr<ServiceWorkerContextCore> context_core_;
127 // Initialized in Init(); true if the user data directory is empty.
128 bool is_incognito_;
131 } // namespace content
133 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_