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

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

Issue 825383004: ServiceWorker: Send state change events via SWProviderHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_handle.h" 5 #include "content/browser/service_worker/service_worker_handle.h"
6 6
7 #include "content/browser/service_worker/service_worker_context_core.h" 7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_registration.h" 8 #include "content/browser/service_worker/service_worker_registration.h"
9 #include "content/common/service_worker/service_worker_messages.h" 9 #include "content/common/service_worker/service_worker_messages.h"
10 #include "content/common/service_worker/service_worker_types.h" 10 #include "content/common/service_worker/service_worker_types.h"
11 #include "ipc/ipc_sender.h"
12 11
13 namespace content { 12 namespace content {
14 13
15 namespace { 14 namespace {
16 15
17 blink::WebServiceWorkerState 16 blink::WebServiceWorkerState
18 GetWebServiceWorkerState(ServiceWorkerVersion* version) { 17 GetWebServiceWorkerState(ServiceWorkerVersion* version) {
19 DCHECK(version); 18 DCHECK(version);
20 switch (version->status()) { 19 switch (version->status()) {
21 case ServiceWorkerVersion::NEW: 20 case ServiceWorkerVersion::NEW:
(...skipping 10 matching lines...) Expand all
32 return blink::WebServiceWorkerStateRedundant; 31 return blink::WebServiceWorkerStateRedundant;
33 } 32 }
34 NOTREACHED() << version->status(); 33 NOTREACHED() << version->status();
35 return blink::WebServiceWorkerStateUnknown; 34 return blink::WebServiceWorkerStateUnknown;
36 } 35 }
37 36
38 } // namespace 37 } // namespace
39 38
40 scoped_ptr<ServiceWorkerHandle> ServiceWorkerHandle::Create( 39 scoped_ptr<ServiceWorkerHandle> ServiceWorkerHandle::Create(
41 base::WeakPtr<ServiceWorkerContextCore> context, 40 base::WeakPtr<ServiceWorkerContextCore> context,
42 IPC::Sender* sender, 41 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
43 ServiceWorkerVersion* version) { 42 ServiceWorkerVersion* version) {
44 if (!context || !version) 43 if (!context || !provider_host || !version)
45 return scoped_ptr<ServiceWorkerHandle>(); 44 return scoped_ptr<ServiceWorkerHandle>();
46 ServiceWorkerRegistration* registration = 45 ServiceWorkerRegistration* registration =
47 context->GetLiveRegistration(version->registration_id()); 46 context->GetLiveRegistration(version->registration_id());
48 return make_scoped_ptr(new ServiceWorkerHandle( 47 return make_scoped_ptr(new ServiceWorkerHandle(
49 context, sender, registration, version)); 48 context, provider_host, registration, version));
50 } 49 }
51 50
52 ServiceWorkerHandle::ServiceWorkerHandle( 51 ServiceWorkerHandle::ServiceWorkerHandle(
53 base::WeakPtr<ServiceWorkerContextCore> context, 52 base::WeakPtr<ServiceWorkerContextCore> context,
54 IPC::Sender* sender, 53 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
55 ServiceWorkerRegistration* registration, 54 ServiceWorkerRegistration* registration,
56 ServiceWorkerVersion* version) 55 ServiceWorkerVersion* version)
57 : context_(context), 56 : context_(context),
58 sender_(sender), 57 provider_host_(provider_host),
59 handle_id_(context.get() ? context->GetNewServiceWorkerHandleId() : -1), 58 handle_id_(context.get() ? context->GetNewServiceWorkerHandleId() : -1),
60 ref_count_(1), 59 ref_count_(1),
61 registration_(registration), 60 registration_(registration),
62 version_(version) { 61 version_(version) {
63 version_->AddListener(this); 62 version_->AddListener(this);
64 } 63 }
65 64
66 ServiceWorkerHandle::~ServiceWorkerHandle() { 65 ServiceWorkerHandle::~ServiceWorkerHandle() {
67 version_->RemoveListener(this); 66 version_->RemoveListener(this);
68 // TODO(kinuko): At this point we can discard the registration if 67 // TODO(kinuko): At this point we can discard the registration if
69 // all documents/handles that have a reference to the registration is 68 // all documents/handles that have a reference to the registration is
70 // closed or freed up, but could also keep it alive in cache 69 // closed or freed up, but could also keep it alive in cache
71 // (e.g. in context_) for a while with some timer so that we don't 70 // (e.g. in context_) for a while with some timer so that we don't
72 // need to re-load the same registration from disk over and over. 71 // need to re-load the same registration from disk over and over.
73 } 72 }
74 73
75 void ServiceWorkerHandle::OnVersionStateChanged(ServiceWorkerVersion* version) { 74 void ServiceWorkerHandle::OnVersionStateChanged(ServiceWorkerVersion* version) {
76 sender_->Send(new ServiceWorkerMsg_ServiceWorkerStateChanged( 75 if (!provider_host_)
77 kDocumentMainThreadId, handle_id_, GetWebServiceWorkerState(version))); 76 return;
77 provider_host_->SendServiceWorkerStateChangedMessage(
78 handle_id_, GetWebServiceWorkerState(version));
78 } 79 }
79 80
80 ServiceWorkerObjectInfo ServiceWorkerHandle::GetObjectInfo() { 81 ServiceWorkerObjectInfo ServiceWorkerHandle::GetObjectInfo() {
81 ServiceWorkerObjectInfo info; 82 ServiceWorkerObjectInfo info;
82 info.handle_id = handle_id_; 83 info.handle_id = handle_id_;
83 info.url = version_->script_url(); 84 info.url = version_->script_url();
84 info.state = GetWebServiceWorkerState(version_.get()); 85 info.state = GetWebServiceWorkerState(version_.get());
85 info.version_id = version_->version_id(); 86 info.version_id = version_->version_id();
86 return info; 87 return info;
87 } 88 }
88 89
89 void ServiceWorkerHandle::IncrementRefCount() { 90 void ServiceWorkerHandle::IncrementRefCount() {
90 DCHECK_GT(ref_count_, 0); 91 DCHECK_GT(ref_count_, 0);
91 ++ref_count_; 92 ++ref_count_;
92 } 93 }
93 94
94 void ServiceWorkerHandle::DecrementRefCount() { 95 void ServiceWorkerHandle::DecrementRefCount() {
95 DCHECK_GE(ref_count_, 0); 96 DCHECK_GE(ref_count_, 0);
96 --ref_count_; 97 --ref_count_;
97 } 98 }
98 99
99 } // namespace content 100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698