OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 void Init(const base::FilePath& user_data_directory, | 48 void Init(const base::FilePath& user_data_directory, |
49 storage::QuotaManagerProxy* quota_manager_proxy, | 49 storage::QuotaManagerProxy* quota_manager_proxy, |
50 storage::SpecialStoragePolicy* special_storage_policy); | 50 storage::SpecialStoragePolicy* special_storage_policy); |
51 void Shutdown(); | 51 void Shutdown(); |
52 | 52 |
53 // Deletes all files on disk and restarts the system asynchronously. This | 53 // Deletes all files on disk and restarts the system asynchronously. This |
54 // leaves the system in a disabled state until it's done. This should be | 54 // leaves the system in a disabled state until it's done. This should be |
55 // called on the IO thread. | 55 // called on the IO thread. |
56 void DeleteAndStartOver(); | 56 void DeleteAndStartOver(); |
57 | 57 |
58 // The core context is only for use on the IO thread. | |
59 // Can be null before/during init, during/after shutdown, and after | |
60 // DeleteAndStartOver fails. | |
61 ServiceWorkerContextCore* context(); | |
62 | |
63 // The StoragePartition should only be used on the UI thread. | 58 // The StoragePartition should only be used on the UI thread. |
64 // Can be null before/during init and during/after shutdown. | 59 // Can be null before/during init and during/after shutdown. |
65 StoragePartitionImpl* storage_partition() const; | 60 StoragePartitionImpl* storage_partition() const; |
66 | 61 |
67 void set_storage_partition(StoragePartitionImpl* storage_partition); | 62 void set_storage_partition(StoragePartitionImpl* storage_partition); |
68 | 63 |
69 // The process manager can be used on either UI or IO. | 64 // The process manager can be used on either UI or IO. |
70 ServiceWorkerProcessManager* process_manager() { | 65 ServiceWorkerProcessManager* process_manager() { |
71 return process_manager_.get(); | 66 return process_manager_.get(); |
72 } | 67 } |
73 | 68 |
74 // ServiceWorkerContext implementation: | 69 // ServiceWorkerContext implementation: |
75 void RegisterServiceWorker(const GURL& pattern, | 70 void RegisterServiceWorker(const GURL& pattern, |
76 const GURL& script_url, | 71 const GURL& script_url, |
77 const ResultCallback& continuation) override; | 72 const ResultCallback& continuation) override; |
78 void UnregisterServiceWorker(const GURL& pattern, | 73 void UnregisterServiceWorker(const GURL& pattern, |
79 const ResultCallback& continuation) override; | 74 const ResultCallback& continuation) override; |
80 void CanHandleMainResourceOffline( | 75 void CanHandleMainResourceOffline( |
81 const GURL& url, | 76 const GURL& url, |
82 const GURL& first_party, | 77 const GURL& first_party, |
83 const net::CompletionCallback& callback) override; | 78 const net::CompletionCallback& callback) override; |
84 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override; | 79 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override; |
85 void DeleteForOrigin(const GURL& origin_url) override; | 80 void DeleteForOrigin(const GURL& origin_url) override; |
86 void CheckHasServiceWorker( | 81 void CheckHasServiceWorker( |
87 const GURL& url, | 82 const GURL& url, |
88 const GURL& other_url, | 83 const GURL& other_url, |
89 const CheckHasServiceWorkerCallback& callback) override; | 84 const CheckHasServiceWorkerCallback& callback) override; |
90 | 85 |
| 86 ServiceWorkerRegistration* GetLiveRegistration(int64_t registration_id); |
| 87 ServiceWorkerVersion* GetLiveVersion(int64_t version_id); |
| 88 std::vector<ServiceWorkerRegistrationInfo> GetAllLiveRegistrationInfo(); |
| 89 std::vector<ServiceWorkerVersionInfo> GetAllLiveVersionInfo(); |
| 90 |
| 91 void FindRegistrationForDocument( |
| 92 const GURL& document_url, |
| 93 const ServiceWorkerStorage::FindRegistrationCallback& callback); |
| 94 void FindRegistrationForId( |
| 95 int64_t registration_id, |
| 96 const GURL& origin, |
| 97 const ServiceWorkerStorage::FindRegistrationCallback& callback); |
| 98 void GetAllRegistrations( |
| 99 const ServiceWorkerStorage::GetRegistrationsInfosCallback& callback); |
| 100 void GetRegistrationUserData( |
| 101 int64_t registration_id, |
| 102 const std::string& key, |
| 103 const ServiceWorkerStorage::GetUserDataCallback& callback); |
| 104 void StoreRegistrationUserData(int64_t registration_id, |
| 105 const GURL& origin, |
| 106 const std::string& key, |
| 107 const std::string& data, |
| 108 const StatusCallback& callback); |
| 109 void ClearRegistrationUserData(int64_t registration_id, |
| 110 const std::string& key, |
| 111 const StatusCallback& callback); |
| 112 void GetUserDataForAllRegistrations( |
| 113 const std::string& key, |
| 114 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& |
| 115 callback); |
| 116 |
91 // DeleteForOrigin with completion callback. Does not exit early, and returns | 117 // DeleteForOrigin with completion callback. Does not exit early, and returns |
92 // false if one or more of the deletions fail. | 118 // false if one or more of the deletions fail. |
93 virtual void DeleteForOrigin(const GURL& origin_url, | 119 virtual void DeleteForOrigin(const GURL& origin_url, |
94 const ResultCallback& done); | 120 const ResultCallback& done); |
95 | 121 |
96 void StartServiceWorker(const GURL& pattern, const StatusCallback& callback); | 122 void StartServiceWorker(const GURL& pattern, const StatusCallback& callback); |
97 void AddObserver(ServiceWorkerContextObserver* observer); | 123 void AddObserver(ServiceWorkerContextObserver* observer); |
98 void RemoveObserver(ServiceWorkerContextObserver* observer); | 124 void RemoveObserver(ServiceWorkerContextObserver* observer); |
99 | 125 |
100 bool is_incognito() const { return is_incognito_; } | 126 bool is_incognito() const { return is_incognito_; } |
101 | 127 |
102 private: | 128 private: |
103 friend class BackgroundSyncManagerTest; | 129 friend class BackgroundSyncManagerTest; |
104 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>; | 130 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>; |
105 friend class EmbeddedWorkerTestHelper; | 131 friend class EmbeddedWorkerTestHelper; |
| 132 friend class EmbeddedWorkerBrowserTest; |
| 133 friend class ServiceWorkerDispatcherHost; |
| 134 friend class ServiceWorkerInternalsUI; |
106 friend class ServiceWorkerProcessManager; | 135 friend class ServiceWorkerProcessManager; |
| 136 friend class ServiceWorkerRequestHandler; |
| 137 friend class ServiceWorkerVersionBrowserTest; |
107 friend class MockServiceWorkerContextWrapper; | 138 friend class MockServiceWorkerContextWrapper; |
108 | 139 |
109 ~ServiceWorkerContextWrapper() override; | 140 ~ServiceWorkerContextWrapper() override; |
110 | 141 |
111 void InitInternal( | 142 void InitInternal( |
112 const base::FilePath& user_data_directory, | 143 const base::FilePath& user_data_directory, |
113 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, | 144 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, |
114 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 145 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
115 storage::QuotaManagerProxy* quota_manager_proxy, | 146 storage::QuotaManagerProxy* quota_manager_proxy, |
116 storage::SpecialStoragePolicy* special_storage_policy); | 147 storage::SpecialStoragePolicy* special_storage_policy); |
117 void ShutdownOnIO(); | 148 void ShutdownOnIO(); |
118 | 149 |
119 void DidDeleteAndStartOver(ServiceWorkerStatusCode status); | 150 void DidDeleteAndStartOver(ServiceWorkerStatusCode status); |
120 | 151 |
121 void DidGetAllRegistrationsForGetAllOrigins( | 152 void DidGetAllRegistrationsForGetAllOrigins( |
122 const GetUsageInfoCallback& callback, | 153 const GetUsageInfoCallback& callback, |
123 const std::vector<ServiceWorkerRegistrationInfo>& registrations); | 154 const std::vector<ServiceWorkerRegistrationInfo>& registrations); |
124 | 155 |
125 void DidFindRegistrationForCheckHasServiceWorker( | 156 void DidFindRegistrationForCheckHasServiceWorker( |
126 const GURL& other_url, | 157 const GURL& other_url, |
127 const CheckHasServiceWorkerCallback& callback, | 158 const CheckHasServiceWorkerCallback& callback, |
128 ServiceWorkerStatusCode status, | 159 ServiceWorkerStatusCode status, |
129 const scoped_refptr<ServiceWorkerRegistration>& registration); | 160 const scoped_refptr<ServiceWorkerRegistration>& registration); |
130 | 161 |
| 162 // The core context is only for use on the IO thread. |
| 163 // Can be null before/during init, during/after shutdown, and after |
| 164 // DeleteAndStartOver fails. |
| 165 ServiceWorkerContextCore* context(); |
| 166 |
131 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > | 167 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > |
132 observer_list_; | 168 observer_list_; |
133 const scoped_ptr<ServiceWorkerProcessManager> process_manager_; | 169 const scoped_ptr<ServiceWorkerProcessManager> process_manager_; |
134 // Cleared in Shutdown(): | 170 // Cleared in Shutdown(): |
135 scoped_ptr<ServiceWorkerContextCore> context_core_; | 171 scoped_ptr<ServiceWorkerContextCore> context_core_; |
136 | 172 |
137 // Initialized in Init(); true if the user data directory is empty. | 173 // Initialized in Init(); true if the user data directory is empty. |
138 bool is_incognito_; | 174 bool is_incognito_; |
139 | 175 |
140 // Raw pointer to the StoragePartitionImpl owning |this|. | 176 // Raw pointer to the StoragePartitionImpl owning |this|. |
141 StoragePartitionImpl* storage_partition_; | 177 StoragePartitionImpl* storage_partition_; |
142 }; | 178 }; |
143 | 179 |
144 } // namespace content | 180 } // namespace content |
145 | 181 |
146 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 182 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
OLD | NEW |