| 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 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/barrier_closure.h" | 13 #include "base/barrier_closure.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/stl_util.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "content/browser/renderer_host/render_process_host_impl.h" | 24 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 24 #include "content/browser/service_worker/service_worker_context_core.h" | 25 #include "content/browser/service_worker/service_worker_context_core.h" |
| 25 #include "content/browser/service_worker/service_worker_context_observer.h" | 26 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 26 #include "content/browser/service_worker/service_worker_process_manager.h" | 27 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 27 #include "content/browser/service_worker/service_worker_quota_client.h" | 28 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 28 #include "content/browser/service_worker/service_worker_version.h" | 29 #include "content/browser/service_worker/service_worker_version.h" |
| 29 #include "content/browser/storage_partition_impl.h" | 30 #include "content/browser/storage_partition_impl.h" |
| 30 #include "content/common/service_worker/service_worker_utils.h" | 31 #include "content/common/service_worker/service_worker_utils.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, | 283 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, |
| 283 this)); | 284 this)); |
| 284 } | 285 } |
| 285 | 286 |
| 286 void ServiceWorkerContextWrapper::StartServiceWorkerForNavigationHint( | 287 void ServiceWorkerContextWrapper::StartServiceWorkerForNavigationHint( |
| 287 const GURL& document_url, | 288 const GURL& document_url, |
| 288 blink::WebNavigationHintType type, | 289 blink::WebNavigationHintType type, |
| 289 int render_process_id, | 290 int render_process_id, |
| 290 const ResultCallback& callback) { | 291 const ResultCallback& callback) { |
| 291 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 293 ++navigation_hint_task_count_per_process_[render_process_id]; |
| 294 ResultCallback wrapped_callback = |
| 295 base::Bind(&ServiceWorkerContextWrapper::DidFinishNavigationHintTaskOnUI, |
| 296 this, render_process_id, callback); |
| 297 |
| 292 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 298 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
| 293 if (!host || | 299 if (!host || |
| 294 !RenderProcessHostImpl::IsSuitableHost(host, host->GetBrowserContext(), | 300 !RenderProcessHostImpl::IsSuitableHost(host, host->GetBrowserContext(), |
| 295 document_url)) { | 301 document_url)) { |
| 296 callback.Run(false); | 302 wrapped_callback.Run(false); |
| 297 return; | 303 return; |
| 298 } | 304 } |
| 299 | 305 |
| 300 BrowserThread::PostTask( | 306 BrowserThread::PostTask( |
| 301 BrowserThread::IO, FROM_HERE, | 307 BrowserThread::IO, FROM_HERE, |
| 302 base::Bind( | 308 base::Bind( |
| 303 &ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint, | 309 &ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint, |
| 304 this, document_url, type, render_process_id, callback)); | 310 this, document_url, type, render_process_id, wrapped_callback)); |
| 305 } | 311 } |
| 306 | 312 |
| 307 void ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint( | 313 void ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint( |
| 308 const GURL& document_url, | 314 const GURL& document_url, |
| 309 blink::WebNavigationHintType type, | 315 blink::WebNavigationHintType type, |
| 310 int render_process_id, | 316 int render_process_id, |
| 311 const ResultCallback& callback) { | 317 const ResultCallback& callback) { |
| 312 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 318 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 313 if (!context_core_) { | 319 if (!context_core_) { |
| 314 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 320 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 ServiceWorkerStatusCode code) { | 360 ServiceWorkerStatusCode code) { |
| 355 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 361 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 356 | 362 |
| 357 // Remove the process reference added in DidFindRegistrationForNavigationHint. | 363 // Remove the process reference added in DidFindRegistrationForNavigationHint. |
| 358 context_core_->process_manager()->RemoveProcessReferenceFromPattern( | 364 context_core_->process_manager()->RemoveProcessReferenceFromPattern( |
| 359 pattern, render_process_id); | 365 pattern, render_process_id); |
| 360 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 366 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 361 base::Bind(callback, code == SERVICE_WORKER_OK)); | 367 base::Bind(callback, code == SERVICE_WORKER_OK)); |
| 362 } | 368 } |
| 363 | 369 |
| 370 void ServiceWorkerContextWrapper::DidFinishNavigationHintTaskOnUI( |
| 371 int render_process_id, |
| 372 const ResultCallback& callback, |
| 373 bool result) { |
| 374 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 375 if (!--navigation_hint_task_count_per_process_[render_process_id]) |
| 376 navigation_hint_task_count_per_process_.erase(render_process_id); |
| 377 callback.Run(result); |
| 378 } |
| 379 |
| 380 bool ServiceWorkerContextWrapper::IsRunningNavigationHintTask( |
| 381 int render_process_id) const { |
| 382 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 383 return base::ContainsKey(navigation_hint_task_count_per_process_, |
| 384 render_process_id); |
| 385 } |
| 386 |
| 364 void ServiceWorkerContextWrapper::StartServiceWorker( | 387 void ServiceWorkerContextWrapper::StartServiceWorker( |
| 365 const GURL& pattern, | 388 const GURL& pattern, |
| 366 const StatusCallback& callback) { | 389 const StatusCallback& callback) { |
| 367 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 390 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 368 BrowserThread::PostTask( | 391 BrowserThread::PostTask( |
| 369 BrowserThread::IO, FROM_HERE, | 392 BrowserThread::IO, FROM_HERE, |
| 370 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, | 393 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, |
| 371 pattern, callback)); | 394 pattern, callback)); |
| 372 return; | 395 return; |
| 373 } | 396 } |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 observer_list_->Notify(FROM_HERE, | 838 observer_list_->Notify(FROM_HERE, |
| 816 &ServiceWorkerContextObserver::OnStorageWiped); | 839 &ServiceWorkerContextObserver::OnStorageWiped); |
| 817 } | 840 } |
| 818 | 841 |
| 819 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 842 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 820 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 843 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 821 return context_core_.get(); | 844 return context_core_.get(); |
| 822 } | 845 } |
| 823 | 846 |
| 824 } // namespace content | 847 } // namespace content |
| OLD | NEW |