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 #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/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "content/browser/renderer_host/render_process_host_impl.h" | |
| 23 #include "content/browser/service_worker/service_worker_context_core.h" | 24 #include "content/browser/service_worker/service_worker_context_core.h" |
| 24 #include "content/browser/service_worker/service_worker_context_observer.h" | 25 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 25 #include "content/browser/service_worker/service_worker_process_manager.h" | 26 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 26 #include "content/browser/service_worker/service_worker_quota_client.h" | 27 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 27 #include "content/browser/service_worker/service_worker_version.h" | 28 #include "content/browser/service_worker/service_worker_version.h" |
| 28 #include "content/browser/storage_partition_impl.h" | 29 #include "content/browser/storage_partition_impl.h" |
| 29 #include "content/common/service_worker/service_worker_utils.h" | 30 #include "content/common/service_worker/service_worker_utils.h" |
| 30 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/render_process_host.h" | |
| 32 #include "net/base/url_util.h" | 34 #include "net/base/url_util.h" |
| 33 #include "storage/browser/quota/quota_manager_proxy.h" | 35 #include "storage/browser/quota/quota_manager_proxy.h" |
| 34 #include "storage/browser/quota/special_storage_policy.h" | 36 #include "storage/browser/quota/special_storage_policy.h" |
| 37 #include "third_party/WebKit/public/platform/WebNavigationHintType.h" | |
| 35 | 38 |
| 36 namespace content { | 39 namespace content { |
| 37 | 40 |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 typedef std::set<std::string> HeaderNameSet; | 43 typedef std::set<std::string> HeaderNameSet; |
| 41 base::LazyInstance<HeaderNameSet> g_excluded_header_name_set = | 44 base::LazyInstance<HeaderNameSet> g_excluded_header_name_set = |
| 42 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
| 43 | 46 |
| 44 void RunSoon(const base::Closure& closure) { | 47 void RunSoon(const base::Closure& closure) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 74 ServiceWorkerStatusCode status, | 77 ServiceWorkerStatusCode status, |
| 75 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 78 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 76 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 77 if (status != SERVICE_WORKER_OK || !registration->waiting_version()) | 80 if (status != SERVICE_WORKER_OK || !registration->waiting_version()) |
| 78 return; | 81 return; |
| 79 | 82 |
| 80 registration->waiting_version()->set_skip_waiting(true); | 83 registration->waiting_version()->set_skip_waiting(true); |
| 81 registration->ActivateWaitingVersionWhenReady(); | 84 registration->ActivateWaitingVersionWhenReady(); |
| 82 } | 85 } |
| 83 | 86 |
| 87 ServiceWorkerMetrics::EventType GetNavigationHintEventType( | |
| 88 blink::WebNavigationHintType type) { | |
| 89 switch (type) { | |
| 90 case blink::WebNavigationHintType::LinkMouseDown: | |
| 91 return ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_MOUSE_DOWN; | |
| 92 case blink::WebNavigationHintType::LinkTapUnconfirmed: | |
| 93 return ServiceWorkerMetrics::EventType:: | |
| 94 NAVIGATION_HINT_LINK_TAP_UNCONFIRMED; | |
| 95 case blink::WebNavigationHintType::LinkTapDown: | |
| 96 return ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_TAP_DOWN; | |
| 97 default: | |
|
nhiroki
2016/07/25 06:15:13
I'd prefer to list all enum types on switch-statem
horo
2016/07/25 08:24:27
Done.
| |
| 98 NOTREACHED() << "Unexpected navigation hint" << static_cast<int>(type); | |
| 99 return ServiceWorkerMetrics::EventType::UNKNOWN; | |
| 100 } | |
| 101 } | |
| 102 | |
| 84 } // namespace | 103 } // namespace |
| 85 | 104 |
| 86 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( | 105 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( |
| 87 const std::set<std::string>& header_names) { | 106 const std::set<std::string>& header_names) { |
| 88 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 107 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
| 89 tracked_objects::ScopedTracker tracking_profile( | 108 tracked_objects::ScopedTracker tracking_profile( |
| 90 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 109 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 91 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent")); | 110 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent")); |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 111 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 93 g_excluded_header_name_set.Get().insert(header_names.begin(), | 112 g_excluded_header_name_set.Get().insert(header_names.begin(), |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 return; | 294 return; |
| 276 } | 295 } |
| 277 if (!context_core_) | 296 if (!context_core_) |
| 278 return; | 297 return; |
| 279 context_core_->storage()->FindRegistrationForPattern( | 298 context_core_->storage()->FindRegistrationForPattern( |
| 280 net::SimplifyUrlForRequest(pattern), | 299 net::SimplifyUrlForRequest(pattern), |
| 281 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, | 300 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, |
| 282 this)); | 301 this)); |
| 283 } | 302 } |
| 284 | 303 |
| 304 void ServiceWorkerContextWrapper::StartServiceWorkerForNavigationHint( | |
| 305 const GURL& document_url, | |
| 306 blink::WebNavigationHintType type, | |
| 307 int render_process_id, | |
| 308 const ResultCallback& callback) { | |
| 309 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 310 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | |
| 311 if (!host || | |
| 312 !RenderProcessHostImpl::IsSuitableHost(host, host->GetBrowserContext(), | |
| 313 document_url)) { | |
| 314 callback.Run(false); | |
| 315 return; | |
| 316 } | |
| 317 | |
| 318 BrowserThread::PostTask( | |
| 319 BrowserThread::IO, FROM_HERE, | |
| 320 base::Bind( | |
| 321 &ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint, | |
| 322 this, document_url, type, render_process_id, callback)); | |
| 323 } | |
| 324 | |
| 325 void ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint( | |
| 326 const GURL& document_url, | |
| 327 blink::WebNavigationHintType type, | |
| 328 int render_process_id, | |
| 329 const ResultCallback& callback) { | |
| 330 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 331 if (!context_core_) { | |
| 332 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 333 base::Bind(callback, false)); | |
| 334 return; | |
| 335 } | |
| 336 context_core_->storage()->FindRegistrationForDocument( | |
|
nhiroki
2016/07/25 06:15:13
ServiceWorkerContextWrapper::FindReadyRegistration
horo
2016/07/25 08:24:26
Done.
| |
| 337 document_url, | |
| 338 base::Bind( | |
| 339 &ServiceWorkerContextWrapper::DidFindRegistrationForNavigationHint, | |
| 340 this, type, render_process_id, callback)); | |
| 341 } | |
| 342 | |
| 343 void ServiceWorkerContextWrapper::DidFindRegistrationForNavigationHint( | |
| 344 blink::WebNavigationHintType type, | |
| 345 int render_process_id, | |
| 346 const ResultCallback& callback, | |
| 347 ServiceWorkerStatusCode status, | |
| 348 const scoped_refptr<ServiceWorkerRegistration>& registration) { | |
| 349 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 350 if (status != SERVICE_WORKER_OK || !registration->active_version()) { | |
| 351 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 352 base::Bind(callback, false)); | |
| 353 return; | |
| 354 } | |
| 355 | |
| 356 context_core_->process_manager()->AddProcessReferenceToPattern( | |
|
nhiroki
2016/07/25 06:15:13
Let me check my understanding... we add a process
horo
2016/07/25 08:24:26
Done.
| |
| 357 registration->pattern(), render_process_id); | |
| 358 | |
| 359 registration->active_version()->StartWorker( | |
| 360 GetNavigationHintEventType(type), | |
| 361 base::Bind( | |
| 362 &ServiceWorkerContextWrapper::DidStartServiceWorkerForNavigationHint, | |
| 363 this, registration->pattern(), render_process_id, callback)); | |
| 364 } | |
| 365 | |
| 366 void ServiceWorkerContextWrapper::DidStartServiceWorkerForNavigationHint( | |
| 367 const GURL& pattern, | |
| 368 int render_process_id, | |
| 369 const ResultCallback& callback, | |
| 370 ServiceWorkerStatusCode code) { | |
| 371 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 372 | |
| 373 context_core_->process_manager()->RemoveProcessReferenceFromPattern( | |
| 374 pattern, render_process_id); | |
| 375 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 376 base::Bind(callback, code == SERVICE_WORKER_OK)); | |
| 377 } | |
| 378 | |
| 285 void ServiceWorkerContextWrapper::StartServiceWorker( | 379 void ServiceWorkerContextWrapper::StartServiceWorker( |
| 286 const GURL& pattern, | 380 const GURL& pattern, |
| 287 const StatusCallback& callback) { | 381 const StatusCallback& callback) { |
| 288 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 382 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 289 BrowserThread::PostTask( | 383 BrowserThread::PostTask( |
| 290 BrowserThread::IO, FROM_HERE, | 384 BrowserThread::IO, FROM_HERE, |
| 291 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, | 385 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, |
| 292 pattern, callback)); | 386 pattern, callback)); |
| 293 return; | 387 return; |
| 294 } | 388 } |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 observer_list_->Notify(FROM_HERE, | 834 observer_list_->Notify(FROM_HERE, |
| 741 &ServiceWorkerContextObserver::OnStorageWiped); | 835 &ServiceWorkerContextObserver::OnStorageWiped); |
| 742 } | 836 } |
| 743 | 837 |
| 744 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 838 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 745 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 839 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 746 return context_core_.get(); | 840 return context_core_.get(); |
| 747 } | 841 } |
| 748 | 842 |
| 749 } // namespace content | 843 } // namespace content |
| OLD | NEW |