Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.cc

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // static 84 // static
85 std::unique_ptr<ServiceWorkerProviderHost> 85 std::unique_ptr<ServiceWorkerProviderHost>
86 ServiceWorkerProviderHost::PreCreateNavigationHost( 86 ServiceWorkerProviderHost::PreCreateNavigationHost(
87 base::WeakPtr<ServiceWorkerContextCore> context, 87 base::WeakPtr<ServiceWorkerContextCore> context,
88 bool are_ancestors_secure, 88 bool are_ancestors_secure,
89 const WebContentsGetter& web_contents_getter) { 89 const WebContentsGetter& web_contents_getter) {
90 CHECK(IsBrowserSideNavigationEnabled()); 90 CHECK(IsBrowserSideNavigationEnabled());
91 // Generate a new browser-assigned id for the host. 91 // Generate a new browser-assigned id for the host.
92 int provider_id = g_next_navigation_provider_id--; 92 int provider_id = g_next_navigation_provider_id--;
93 auto host = base::MakeUnique<ServiceWorkerProviderHost>( 93 auto host = base::WrapUnique(new ServiceWorkerProviderHost(
94 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, 94 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id,
95 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 95 SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure, context,
96 are_ancestors_secure ? FrameSecurityLevel::SECURE 96 nullptr));
97 : FrameSecurityLevel::INSECURE,
98 context, nullptr);
99 host->web_contents_getter_ = web_contents_getter; 97 host->web_contents_getter_ = web_contents_getter;
100 return host; 98 return host;
101 } 99 }
102 100
101 // static
102 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create(
103 int process_id,
104 ServiceWorkerProviderHostInfo info,
105 base::WeakPtr<ServiceWorkerContextCore> context,
106 ServiceWorkerDispatcherHost* dispatcher_host) {
107 return base::WrapUnique(new ServiceWorkerProviderHost(
108 process_id, info.route_id, info.provider_id, info.type,
109 info.is_parent_frame_secure, context, dispatcher_host));
110 }
111
103 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 112 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
104 int render_process_id, 113 int render_process_id,
105 int route_id, 114 int route_id,
106 int provider_id, 115 int provider_id,
107 ServiceWorkerProviderType provider_type, 116 ServiceWorkerProviderType provider_type,
108 FrameSecurityLevel parent_frame_security_level, 117 bool is_parent_frame_secure,
109 base::WeakPtr<ServiceWorkerContextCore> context, 118 base::WeakPtr<ServiceWorkerContextCore> context,
110 ServiceWorkerDispatcherHost* dispatcher_host) 119 ServiceWorkerDispatcherHost* dispatcher_host)
111 : client_uuid_(base::GenerateGUID()), 120 : client_uuid_(base::GenerateGUID()),
112 render_process_id_(render_process_id), 121 render_process_id_(render_process_id),
113 route_id_(route_id), 122 route_id_(route_id),
114 render_thread_id_(kDocumentMainThreadId), 123 render_thread_id_(kDocumentMainThreadId),
115 provider_id_(provider_id), 124 provider_id_(provider_id),
116 provider_type_(provider_type), 125 provider_type_(provider_type),
117 parent_frame_security_level_(parent_frame_security_level), 126 is_parent_frame_secure_(is_parent_frame_secure),
118 context_(context), 127 context_(context),
119 dispatcher_host_(dispatcher_host), 128 dispatcher_host_(dispatcher_host),
120 allow_association_(true) { 129 allow_association_(true) {
121 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); 130 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_);
122 131
123 // PlzNavigate 132 // PlzNavigate
124 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || 133 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID ||
125 IsBrowserSideNavigationEnabled()); 134 IsBrowserSideNavigationEnabled());
126 135
127 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { 136 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 492
484 bool ServiceWorkerProviderHost::GetRegistrationForReady( 493 bool ServiceWorkerProviderHost::GetRegistrationForReady(
485 const GetRegistrationForReadyCallback& callback) { 494 const GetRegistrationForReadyCallback& callback) {
486 if (get_ready_callback_) 495 if (get_ready_callback_)
487 return false; 496 return false;
488 get_ready_callback_.reset(new OneShotGetReadyCallback(callback)); 497 get_ready_callback_.reset(new OneShotGetReadyCallback(callback));
489 ReturnRegistrationForReadyIfNeeded(); 498 ReturnRegistrationForReadyIfNeeded();
490 return true; 499 return true;
491 } 500 }
492 501
493 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { 502 std::unique_ptr<ServiceWorkerProviderHost>
503 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
494 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 504 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
495 DCHECK_NE(MSG_ROUTING_NONE, route_id_); 505 DCHECK_NE(MSG_ROUTING_NONE, route_id_);
496 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 506 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
497 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); 507 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_);
498 508
509 std::unique_ptr<ServiceWorkerProviderHost> new_provider_host =
510 base::WrapUnique(new ServiceWorkerProviderHost(
511 process_id(), frame_id(), provider_id(), provider_type(),
512 is_parent_frame_secure(), context_, dispatcher_host()));
513
499 for (const GURL& pattern : associated_patterns_) 514 for (const GURL& pattern : associated_patterns_)
500 DecreaseProcessReference(pattern); 515 DecreaseProcessReference(pattern);
501 516
502 for (auto& key_registration : matching_registrations_) 517 for (auto& key_registration : matching_registrations_)
503 DecreaseProcessReference(key_registration.second->pattern()); 518 DecreaseProcessReference(key_registration.second->pattern());
504 519
505 if (associated_registration_.get()) { 520 if (associated_registration_.get()) {
506 if (dispatcher_host_) { 521 if (dispatcher_host_) {
507 Send(new ServiceWorkerMsg_DisassociateRegistration( 522 Send(new ServiceWorkerMsg_DisassociateRegistration(
508 render_thread_id_, provider_id())); 523 render_thread_id_, provider_id()));
509 } 524 }
510 } 525 }
511 526
512 render_process_id_ = ChildProcessHost::kInvalidUniqueID; 527 render_process_id_ = ChildProcessHost::kInvalidUniqueID;
513 route_id_ = MSG_ROUTING_NONE; 528 route_id_ = MSG_ROUTING_NONE;
514 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; 529 render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
515 provider_id_ = kInvalidServiceWorkerProviderId; 530 provider_id_ = kInvalidServiceWorkerProviderId;
516 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; 531 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN;
517 dispatcher_host_ = nullptr; 532 dispatcher_host_ = nullptr;
533 return new_provider_host;
518 } 534 }
519 535
520 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( 536 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer(
521 int new_process_id, 537 int new_process_id,
522 int new_frame_id, 538 int new_frame_id,
523 int new_provider_id, 539 int new_provider_id,
524 ServiceWorkerProviderType new_provider_type, 540 ServiceWorkerProviderType new_provider_type,
525 ServiceWorkerDispatcherHost* new_dispatcher_host) { 541 ServiceWorkerDispatcherHost* new_dispatcher_host) {
526 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 542 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
527 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); 543 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 render_thread_id_, provider_id(), 751 render_thread_id_, provider_id(),
736 GetOrCreateServiceWorkerHandle( 752 GetOrCreateServiceWorkerHandle(
737 associated_registration_->active_version()), 753 associated_registration_->active_version()),
738 false /* shouldNotifyControllerChange */, 754 false /* shouldNotifyControllerChange */,
739 associated_registration_->active_version()->used_features())); 755 associated_registration_->active_version()->used_features()));
740 } 756 }
741 } 757 }
742 } 758 }
743 759
744 } // namespace content 760 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698