Add key_mobile_sites_cycler.py that contains page sets that does not do scrolling.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_context_wrapper.h
blob4eb6771dd3ef33da99b24890611f2981b82fc05e
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;
38 class StoragePartitionImpl;
40 // A refcounted wrapper class for our core object. Higher level content lib
41 // classes keep references to this class on mutliple threads. The inner core
42 // instance is strictly single threaded and is not refcounted, the core object
43 // is what is used internally in the service worker lib.
44 class CONTENT_EXPORT ServiceWorkerContextWrapper
45 : NON_EXPORTED_BASE(public ServiceWorkerContext),
46 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
47 public:
48 ServiceWorkerContextWrapper(BrowserContext* browser_context);
50 // Init and Shutdown are for use on the UI thread when the profile,
51 // storagepartition is being setup and torn down.
52 void Init(const base::FilePath& user_data_directory,
53 storage::QuotaManagerProxy* quota_manager_proxy,
54 storage::SpecialStoragePolicy* special_storage_policy);
55 void Shutdown();
57 // Deletes all files on disk and restarts the system asynchronously. This
58 // leaves the system in a disabled state until it's done. This should be
59 // called on the IO thread.
60 void DeleteAndStartOver();
62 // The core context is only for use on the IO thread.
63 ServiceWorkerContextCore* context();
65 // The StoragePartition should only be used on the UI thread.
66 // Can be null before/during init and during/after shutdown.
67 StoragePartitionImpl* storage_partition() const;
69 void set_storage_partition(StoragePartitionImpl* storage_partition);
71 // The process manager can be used on either UI or IO.
72 ServiceWorkerProcessManager* process_manager() {
73 return process_manager_.get();
76 // ServiceWorkerContext implementation:
77 void RegisterServiceWorker(const GURL& pattern,
78 const GURL& script_url,
79 const ResultCallback& continuation) override;
80 void UnregisterServiceWorker(const GURL& pattern,
81 const ResultCallback& continuation) override;
82 void CanHandleMainResourceOffline(
83 const GURL& url,
84 const GURL& first_party,
85 const net::CompletionCallback& callback) override;
86 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override;
87 void DeleteForOrigin(const GURL& origin_url) override;
88 void CheckHasServiceWorker(
89 const GURL& url,
90 const GURL& other_url,
91 const CheckHasServiceWorkerCallback& callback) override;
93 // DeleteForOrigin with completion callback. Does not exit early, and returns
94 // false if one or more of the deletions fail.
95 virtual void DeleteForOrigin(const GURL& origin_url,
96 const ResultCallback& done);
98 void AddObserver(ServiceWorkerContextObserver* observer);
99 void RemoveObserver(ServiceWorkerContextObserver* observer);
101 bool is_incognito() const { return is_incognito_; }
103 // The URLRequestContext doesn't exist until after the StoragePartition is
104 // made (which is after this object is made). This function must be called
105 // after this object is created but before any ServiceWorkerCache operations.
106 // It must be called on the IO thread. If either parameter is NULL the
107 // function immediately returns without forwarding to the
108 // ServiceWorkerCacheStorageManager.
109 void SetBlobParametersForCache(
110 net::URLRequestContextGetter* request_context,
111 ChromeBlobStorageContext* blob_storage_context);
113 private:
114 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
115 friend class EmbeddedWorkerTestHelper;
116 friend class ServiceWorkerProcessManager;
117 friend class MockServiceWorkerContextWrapper;
119 ~ServiceWorkerContextWrapper() override;
121 void InitInternal(
122 const base::FilePath& user_data_directory,
123 const scoped_refptr<base::SequencedTaskRunner>& stores_task_runner,
124 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
125 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
126 storage::QuotaManagerProxy* quota_manager_proxy,
127 storage::SpecialStoragePolicy* special_storage_policy);
128 void ShutdownOnIO();
130 void DidDeleteAndStartOver(ServiceWorkerStatusCode status);
132 void DidGetAllRegistrationsForGetAllOrigins(
133 const GetUsageInfoCallback& callback,
134 const std::vector<ServiceWorkerRegistrationInfo>& registrations);
136 void DidFindRegistrationForCheckHasServiceWorker(
137 const GURL& other_url,
138 const CheckHasServiceWorkerCallback& callback,
139 ServiceWorkerStatusCode status,
140 const scoped_refptr<ServiceWorkerRegistration>& registration);
142 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
143 observer_list_;
144 const scoped_ptr<ServiceWorkerProcessManager> process_manager_;
145 // Cleared in Shutdown():
146 scoped_ptr<ServiceWorkerContextCore> context_core_;
148 // Initialized in Init(); true if the user data directory is empty.
149 bool is_incognito_;
151 // Raw pointer to the StoragePartitionImpl owning |this|.
152 StoragePartitionImpl* storage_partition_;
155 } // namespace content
157 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_