ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_handle.cc
blob114e3e2bba83cea5c4b6c3da514e76d36d8c5591
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
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_handle.h"
7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_registration.h"
9 #include "content/common/service_worker/service_worker_messages.h"
10 #include "content/common/service_worker/service_worker_types.h"
12 namespace content {
14 namespace {
16 blink::WebServiceWorkerState
17 GetWebServiceWorkerState(ServiceWorkerVersion* version) {
18 DCHECK(version);
19 switch (version->status()) {
20 case ServiceWorkerVersion::NEW:
21 return blink::WebServiceWorkerStateUnknown;
22 case ServiceWorkerVersion::INSTALLING:
23 return blink::WebServiceWorkerStateInstalling;
24 case ServiceWorkerVersion::INSTALLED:
25 return blink::WebServiceWorkerStateInstalled;
26 case ServiceWorkerVersion::ACTIVATING:
27 return blink::WebServiceWorkerStateActivating;
28 case ServiceWorkerVersion::ACTIVATED:
29 return blink::WebServiceWorkerStateActivated;
30 case ServiceWorkerVersion::REDUNDANT:
31 return blink::WebServiceWorkerStateRedundant;
33 NOTREACHED() << version->status();
34 return blink::WebServiceWorkerStateUnknown;
37 } // namespace
39 scoped_ptr<ServiceWorkerHandle> ServiceWorkerHandle::Create(
40 base::WeakPtr<ServiceWorkerContextCore> context,
41 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
42 ServiceWorkerVersion* version) {
43 if (!context || !provider_host || !version)
44 return scoped_ptr<ServiceWorkerHandle>();
45 DCHECK(context->GetLiveRegistration(version->registration_id()));
46 return make_scoped_ptr(new ServiceWorkerHandle(
47 context, provider_host, version));
50 ServiceWorkerHandle::ServiceWorkerHandle(
51 base::WeakPtr<ServiceWorkerContextCore> context,
52 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
53 ServiceWorkerVersion* version)
54 : context_(context),
55 provider_host_(provider_host),
56 handle_id_(context.get() ? context->GetNewServiceWorkerHandleId() : -1),
57 ref_count_(1),
58 version_(version) {
59 version_->AddListener(this);
62 ServiceWorkerHandle::~ServiceWorkerHandle() {
63 version_->RemoveListener(this);
66 void ServiceWorkerHandle::OnVersionStateChanged(ServiceWorkerVersion* version) {
67 if (!provider_host_)
68 return;
69 provider_host_->SendServiceWorkerStateChangedMessage(
70 handle_id_, GetWebServiceWorkerState(version));
73 ServiceWorkerObjectInfo ServiceWorkerHandle::GetObjectInfo() {
74 ServiceWorkerObjectInfo info;
75 info.handle_id = handle_id_;
76 info.url = version_->script_url();
77 info.state = GetWebServiceWorkerState(version_.get());
78 info.version_id = version_->version_id();
79 return info;
82 void ServiceWorkerHandle::IncrementRefCount() {
83 DCHECK_GT(ref_count_, 0);
84 ++ref_count_;
87 void ServiceWorkerHandle::DecrementRefCount() {
88 DCHECK_GE(ref_count_, 0);
89 --ref_count_;
92 } // namespace content