| 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" | |
| 22 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "content/browser/renderer_host/render_process_host_impl.h" | 23 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 25 #include "content/browser/service_worker/embedded_worker_status.h" | 24 #include "content/browser/service_worker/embedded_worker_status.h" |
| 26 #include "content/browser/service_worker/service_worker_context_core.h" | 25 #include "content/browser/service_worker/service_worker_context_core.h" |
| 27 #include "content/browser/service_worker/service_worker_context_observer.h" | 26 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 28 #include "content/browser/service_worker/service_worker_process_manager.h" | 27 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 29 #include "content/browser/service_worker/service_worker_quota_client.h" | 28 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 30 #include "content/browser/service_worker/service_worker_version.h" | 29 #include "content/browser/service_worker/service_worker_version.h" |
| 31 #include "content/browser/storage_partition_impl.h" | 30 #include "content/browser/storage_partition_impl.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, | 283 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, |
| 285 this)); | 284 this)); |
| 286 } | 285 } |
| 287 | 286 |
| 288 void ServiceWorkerContextWrapper::StartServiceWorkerForNavigationHint( | 287 void ServiceWorkerContextWrapper::StartServiceWorkerForNavigationHint( |
| 289 const GURL& document_url, | 288 const GURL& document_url, |
| 290 blink::WebNavigationHintType type, | 289 blink::WebNavigationHintType type, |
| 291 int render_process_id, | 290 int render_process_id, |
| 292 const ResultCallback& callback) { | 291 const ResultCallback& callback) { |
| 293 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 294 ++navigation_hint_task_count_per_process_[render_process_id]; | |
| 295 ResultCallback wrapped_callback = | |
| 296 base::Bind(&ServiceWorkerContextWrapper::DidFinishNavigationHintTaskOnUI, | |
| 297 this, render_process_id, callback); | |
| 298 | |
| 299 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 293 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
| 300 if (!host || | 294 if (!host || |
| 301 !RenderProcessHostImpl::IsSuitableHost(host, host->GetBrowserContext(), | 295 !RenderProcessHostImpl::IsSuitableHost(host, host->GetBrowserContext(), |
| 302 document_url)) { | 296 document_url)) { |
| 303 wrapped_callback.Run(false); | 297 callback.Run(false); |
| 304 return; | 298 return; |
| 305 } | 299 } |
| 306 | 300 |
| 307 BrowserThread::PostTask( | 301 BrowserThread::PostTask( |
| 308 BrowserThread::IO, FROM_HERE, | 302 BrowserThread::IO, FROM_HERE, |
| 309 base::Bind( | 303 base::Bind( |
| 310 &ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint, | 304 &ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint, |
| 311 this, document_url, type, render_process_id, wrapped_callback)); | 305 this, document_url, type, render_process_id, callback)); |
| 312 } | 306 } |
| 313 | 307 |
| 314 void ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint( | 308 void ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint( |
| 315 const GURL& document_url, | 309 const GURL& document_url, |
| 316 blink::WebNavigationHintType type, | 310 blink::WebNavigationHintType type, |
| 317 int render_process_id, | 311 int render_process_id, |
| 318 const ResultCallback& callback) { | 312 const ResultCallback& callback) { |
| 319 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 313 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 320 if (!context_core_) { | 314 if (!context_core_) { |
| 321 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 315 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 ServiceWorkerStatusCode code) { | 362 ServiceWorkerStatusCode code) { |
| 369 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 363 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 370 | 364 |
| 371 // Remove the process reference added in DidFindRegistrationForNavigationHint. | 365 // Remove the process reference added in DidFindRegistrationForNavigationHint. |
| 372 context_core_->process_manager()->RemoveProcessReferenceFromPattern( | 366 context_core_->process_manager()->RemoveProcessReferenceFromPattern( |
| 373 pattern, render_process_id); | 367 pattern, render_process_id); |
| 374 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 368 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 375 base::Bind(callback, code == SERVICE_WORKER_OK)); | 369 base::Bind(callback, code == SERVICE_WORKER_OK)); |
| 376 } | 370 } |
| 377 | 371 |
| 378 void ServiceWorkerContextWrapper::DidFinishNavigationHintTaskOnUI( | |
| 379 int render_process_id, | |
| 380 const ResultCallback& callback, | |
| 381 bool result) { | |
| 382 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 383 if (!--navigation_hint_task_count_per_process_[render_process_id]) | |
| 384 navigation_hint_task_count_per_process_.erase(render_process_id); | |
| 385 callback.Run(result); | |
| 386 } | |
| 387 | |
| 388 bool ServiceWorkerContextWrapper::IsRunningNavigationHintTask( | |
| 389 int render_process_id) const { | |
| 390 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 391 return base::ContainsKey(navigation_hint_task_count_per_process_, | |
| 392 render_process_id); | |
| 393 } | |
| 394 | |
| 395 void ServiceWorkerContextWrapper::StartServiceWorker( | 372 void ServiceWorkerContextWrapper::StartServiceWorker( |
| 396 const GURL& pattern, | 373 const GURL& pattern, |
| 397 const StatusCallback& callback) { | 374 const StatusCallback& callback) { |
| 398 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 375 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 399 BrowserThread::PostTask( | 376 BrowserThread::PostTask( |
| 400 BrowserThread::IO, FROM_HERE, | 377 BrowserThread::IO, FROM_HERE, |
| 401 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, | 378 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, |
| 402 pattern, callback)); | 379 pattern, callback)); |
| 403 return; | 380 return; |
| 404 } | 381 } |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 observer_list_->Notify(FROM_HERE, | 901 observer_list_->Notify(FROM_HERE, |
| 925 &ServiceWorkerContextObserver::OnStorageWiped); | 902 &ServiceWorkerContextObserver::OnStorageWiped); |
| 926 } | 903 } |
| 927 | 904 |
| 928 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 905 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 929 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 906 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 930 return context_core_.get(); | 907 return context_core_.get(); |
| 931 } | 908 } |
| 932 | 909 |
| 933 } // namespace content | 910 } // namespace content |
| OLD | NEW |