Chromium Code Reviews| 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 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/barrier_closure.h" | |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 13 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 13 #include "content/browser/service_worker/service_worker_context_core.h" | 14 #include "content/browser/service_worker/service_worker_context_core.h" |
| 14 #include "content/browser/service_worker/service_worker_context_observer.h" | 15 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 15 #include "content/browser/service_worker/service_worker_process_manager.h" | 16 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 17 #include "content/browser/service_worker/service_worker_quota_client.h" | |
| 16 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 19 #include "storage/browser/blob/blob_storage_context.h" | 21 #include "storage/browser/blob/blob_storage_context.h" |
| 20 #include "storage/browser/quota/quota_manager_proxy.h" | 22 #include "storage/browser/quota/quota_manager_proxy.h" |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 | 25 |
| 24 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( | 26 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
| 25 BrowserContext* browser_context) | 27 BrowserContext* browser_context) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 46 scoped_refptr<base::SequencedTaskRunner> cache_task_runner = | 48 scoped_refptr<base::SequencedTaskRunner> cache_task_runner = |
| 47 BrowserThread::GetBlockingPool() | 49 BrowserThread::GetBlockingPool() |
| 48 ->GetSequencedTaskRunnerWithShutdownBehavior( | 50 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 49 BrowserThread::GetBlockingPool()->GetSequenceToken(), | 51 BrowserThread::GetBlockingPool()->GetSequenceToken(), |
| 50 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 52 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 51 InitInternal(user_data_directory, | 53 InitInternal(user_data_directory, |
| 52 cache_task_runner, | 54 cache_task_runner, |
| 53 database_task_runner, | 55 database_task_runner, |
| 54 disk_cache_thread, | 56 disk_cache_thread, |
| 55 quota_manager_proxy); | 57 quota_manager_proxy); |
| 58 if (quota_manager_proxy) { | |
|
jsbell
2014/10/08 19:26:41
When is this NULL?
dmurph
2014/10/11 00:02:25
Other classes checked if the proxy was null, but i
| |
| 59 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); | |
| 60 } | |
| 56 } | 61 } |
| 57 | 62 |
| 58 void ServiceWorkerContextWrapper::Shutdown() { | 63 void ServiceWorkerContextWrapper::Shutdown() { |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 60 process_manager_->Shutdown(); | 65 process_manager_->Shutdown(); |
| 61 BrowserThread::PostTask( | 66 BrowserThread::PostTask( |
| 62 BrowserThread::IO, | 67 BrowserThread::IO, |
| 63 FROM_HERE, | 68 FROM_HERE, |
| 64 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 69 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
| 65 } | 70 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 script_url, | 112 script_url, |
| 108 NULL /* provider_host */, | 113 NULL /* provider_host */, |
| 109 base::Bind(&FinishRegistrationOnIO, continuation)); | 114 base::Bind(&FinishRegistrationOnIO, continuation)); |
| 110 } | 115 } |
| 111 | 116 |
| 112 static void FinishUnregistrationOnIO( | 117 static void FinishUnregistrationOnIO( |
| 113 const ServiceWorkerContext::ResultCallback& continuation, | 118 const ServiceWorkerContext::ResultCallback& continuation, |
| 114 ServiceWorkerStatusCode status) { | 119 ServiceWorkerStatusCode status) { |
| 115 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 120 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 116 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 117 BrowserThread::UI, | 122 BrowserThread::UI, |
|
michaeln
2014/10/14 00:50:31
Not related to your cl...
Oh, the wrapper class i
dmurph
2014/10/14 21:04:50
Should I add a TODO anywhere?
| |
| 118 FROM_HERE, | 123 FROM_HERE, |
| 119 base::Bind(continuation, status == SERVICE_WORKER_OK)); | 124 base::Bind(continuation, status == SERVICE_WORKER_OK)); |
| 120 } | 125 } |
| 121 | 126 |
| 122 void ServiceWorkerContextWrapper::UnregisterServiceWorker( | 127 void ServiceWorkerContextWrapper::UnregisterServiceWorker( |
| 123 const GURL& pattern, | 128 const GURL& pattern, |
| 124 const ResultCallback& continuation) { | 129 const ResultCallback& continuation) { |
| 125 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 130 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 126 BrowserThread::PostTask( | 131 BrowserThread::PostTask( |
| 127 BrowserThread::IO, | 132 BrowserThread::IO, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 for (std::map<GURL, ServiceWorkerUsageInfo>::const_iterator it = | 180 for (std::map<GURL, ServiceWorkerUsageInfo>::const_iterator it = |
| 176 origins.begin(); | 181 origins.begin(); |
| 177 it != origins.end(); | 182 it != origins.end(); |
| 178 ++it) { | 183 ++it) { |
| 179 usage_infos.push_back(it->second); | 184 usage_infos.push_back(it->second); |
| 180 } | 185 } |
| 181 | 186 |
| 182 callback.Run(usage_infos); | 187 callback.Run(usage_infos); |
| 183 } | 188 } |
| 184 | 189 |
| 185 namespace { | 190 namespace { |
|
jsbell
2014/10/08 19:26:41
nit: I think we like having blank lines inside at
dmurph
2014/10/11 00:02:25
clang-format didn't change it
| |
| 186 | 191 void SuccessCollectorCallback(const base::Closure& done_closure, |
| 187 void EmptySuccessCallback(bool success) { | 192 bool* overall_success, bool success) { |
| 193 if (!success) { | |
|
michaeln
2014/10/08 23:09:15
nit: {}'s not needed
dmurph
2014/10/11 00:02:25
I would like them
| |
| 194 *overall_success = false; | |
| 195 } | |
| 196 done_closure.Run(); | |
| 188 } | 197 } |
| 189 | 198 |
| 199 void SuccessReportingCallback( | |
| 200 const bool* success, const ServiceWorkerContext::ResultCallback& callback) { | |
|
jsbell
2014/10/08 19:26:40
nit: Per chromium style, put each arg on a separat
dmurph
2014/10/11 00:02:25
Done.
| |
| 201 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
|
michaeln
2014/10/08 23:09:15
Do you ever expect this to be called on some other
dmurph
2014/10/11 00:02:25
Yes, this comes from the database runner, so I nee
| |
| 202 BrowserThread::PostTask( | |
| 203 BrowserThread::IO, FROM_HERE, | |
| 204 base::Bind(&SuccessReportingCallback, success, callback)); | |
| 205 return; | |
| 206 } | |
| 207 | |
| 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 209 bool result = *success; | |
| 210 delete success; | |
|
michaeln
2014/10/08 23:09:15
I'm not sure it's safe to assume that the final ca
dmurph
2014/10/11 00:02:25
Done.
| |
| 211 callback.Run(result); | |
| 212 } | |
| 213 | |
| 214 void EmptySuccessCallback(bool success) {} | |
|
jsbell
2014/10/08 19:26:41
nit: leave this with { } wrapped to minimize diff
dmurph
2014/10/11 00:02:25
Done.
| |
| 190 } // namespace | 215 } // namespace |
| 191 | 216 |
| 192 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { | 217 void ServiceWorkerContextWrapper::DeleteForOrigin( |
| 218 const GURL& origin_url, const ResultCallback& done) { | |
| 193 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 219 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 194 context_core_->storage()->GetAllRegistrations(base::Bind( | 220 context_core_->storage()->GetAllRegistrations(base::Bind( |
| 195 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin, | 221 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin, |
| 196 this, | 222 this, |
| 197 origin_url)); | 223 origin_url, |
| 224 done)); | |
| 225 } | |
| 226 | |
| 227 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { | |
| 228 DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback)); | |
| 198 } | 229 } |
| 199 | 230 |
| 200 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin( | 231 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin( |
| 201 const GURL& origin, | 232 const GURL& origin, |
| 233 const ResultCallback& done, | |
| 202 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { | 234 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 235 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 204 | 236 |
| 237 std::set<GURL> applicable_patterns; | |
|
jsbell
2014/10/08 19:26:40
For brevity, how about just 'scopes' ?
(We'll pro
dmurph
2014/10/11 00:02:25
Done.
| |
| 205 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it = | 238 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it = |
| 206 registrations.begin(); | 239 registrations.begin(); |
| 207 it != registrations.end(); | 240 it != registrations.end(); |
| 208 ++it) { | 241 ++it) { |
| 209 const ServiceWorkerRegistrationInfo& registration_info = *it; | 242 const ServiceWorkerRegistrationInfo& registration_info = *it; |
| 210 if (origin == registration_info.pattern.GetOrigin()) { | 243 if (origin == registration_info.pattern.GetOrigin()) { |
|
jsbell
2014/10/08 19:26:41
nit: can drop the braces here
dmurph
2014/10/11 00:02:25
I would rather keep them :)
| |
| 211 UnregisterServiceWorker(registration_info.pattern, | 244 applicable_patterns.insert(registration_info.pattern); |
| 212 base::Bind(&EmptySuccessCallback)); | |
| 213 } | 245 } |
| 214 } | 246 } |
| 247 bool *success = new bool(true); | |
|
michaeln
2014/10/08 23:09:15
maybe call this overall_success for clarity throug
dmurph
2014/10/11 00:02:25
Done.
| |
| 248 base::Closure barrier = base::BarrierClosure( | |
|
michaeln
2014/10/08 23:09:15
neat, hadn't seen barrier closure before
dmurph
2014/10/11 00:02:25
Acknowledged.
| |
| 249 applicable_patterns.size(), | |
| 250 base::Bind(&SuccessReportingCallback, success, done)); | |
|
michaeln
2014/10/08 23:09:15
base::Owned(overall_success) here or maybe base::P
dmurph
2014/10/11 00:02:25
Done.
| |
| 251 | |
| 252 for (const GURL& pattern : applicable_patterns) { | |
| 253 UnregisterServiceWorker( | |
| 254 pattern, base::Bind(&SuccessCollectorCallback, barrier, success)); | |
|
michaeln
2014/10/08 23:09:15
base::Unretained(overall_success) here?
dmurph
2014/10/11 00:02:25
Unneeded. Only applicable to refcounted objects o
| |
| 255 } | |
| 215 } | 256 } |
| 216 | 257 |
| 217 void ServiceWorkerContextWrapper::AddObserver( | 258 void ServiceWorkerContextWrapper::AddObserver( |
| 218 ServiceWorkerContextObserver* observer) { | 259 ServiceWorkerContextObserver* observer) { |
| 219 observer_list_->AddObserver(observer); | 260 observer_list_->AddObserver(observer); |
| 220 } | 261 } |
| 221 | 262 |
| 222 void ServiceWorkerContextWrapper::RemoveObserver( | 263 void ServiceWorkerContextWrapper::RemoveObserver( |
| 223 ServiceWorkerContextObserver* observer) { | 264 ServiceWorkerContextObserver* observer) { |
| 224 observer_list_->RemoveObserver(observer); | 265 observer_list_->RemoveObserver(observer); |
| 225 } | 266 } |
| 226 | 267 |
| 227 void ServiceWorkerContextWrapper::SetBlobParametersForCache( | 268 void ServiceWorkerContextWrapper::SetBlobParametersForCache( |
| 228 net::URLRequestContextGetter* request_context, | 269 net::URLRequestContextGetter* request_context, |
| 229 ChromeBlobStorageContext* blob_storage_context) { | 270 ChromeBlobStorageContext* blob_storage_context) { |
| 230 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 271 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 231 | 272 |
| 232 if (context_core_ && request_context && blob_storage_context) { | 273 if (context_core_ && request_context && blob_storage_context) { |
| 233 context_core_->SetBlobParametersForCache( | 274 context_core_->SetBlobParametersForCache( |
| 234 request_context->GetURLRequestContext(), | 275 request_context->GetURLRequestContext(), |
| 235 blob_storage_context->context()->AsWeakPtr()); | 276 blob_storage_context->context()->AsWeakPtr()); |
| 236 } | 277 } |
| 237 } | 278 } |
| 238 | 279 |
| 239 void ServiceWorkerContextWrapper::InitInternal( | 280 void ServiceWorkerContextWrapper::InitInternal( |
|
michaeln
2014/10/08 23:28:46
I think it'd be nicer of the 'client' class where
dmurph
2014/10/11 00:02:25
After offline discussion, we decided that the func
| |
| 240 const base::FilePath& user_data_directory, | 281 const base::FilePath& user_data_directory, |
| 241 const scoped_refptr<base::SequencedTaskRunner>& stores_task_runner, | 282 const scoped_refptr<base::SequencedTaskRunner>& stores_task_runner, |
| 242 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, | 283 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, |
| 243 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 284 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
| 244 storage::QuotaManagerProxy* quota_manager_proxy) { | 285 storage::QuotaManagerProxy* quota_manager_proxy) { |
| 245 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 286 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 246 BrowserThread::PostTask( | 287 BrowserThread::PostTask( |
| 247 BrowserThread::IO, | 288 BrowserThread::IO, |
| 248 FROM_HERE, | 289 FROM_HERE, |
| 249 base::Bind(&ServiceWorkerContextWrapper::InitInternal, | 290 base::Bind(&ServiceWorkerContextWrapper::InitInternal, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 275 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 316 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 276 if (status != SERVICE_WORKER_OK) { | 317 if (status != SERVICE_WORKER_OK) { |
| 277 context_core_.reset(); | 318 context_core_.reset(); |
| 278 return; | 319 return; |
| 279 } | 320 } |
| 280 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 321 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 281 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 322 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 282 } | 323 } |
| 283 | 324 |
| 284 } // namespace content | 325 } // namespace content |
| OLD | NEW |