Fix link in German terms of service.
[chromium-blink-merge.git] / content / child / service_worker / service_worker_network_provider.cc
blob85c20688a1f29cd63a1e0ca9ca452796da46757f
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/child/service_worker/service_worker_network_provider.h"
7 #include "base/atomic_sequence_num.h"
8 #include "content/child/child_thread_impl.h"
9 #include "content/child/service_worker/service_worker_provider_context.h"
10 #include "content/common/service_worker/service_worker_messages.h"
12 namespace content {
14 namespace {
16 const char kUserDataKey[] = "SWProviderKey";
18 // Must be unique in the child process.
19 int GetNextProviderId() {
20 static base::StaticAtomicSequenceNumber sequence;
21 return sequence.GetNext(); // We start at zero.
24 } // namespace
26 void ServiceWorkerNetworkProvider::AttachToDocumentState(
27 base::SupportsUserData* datasource_userdata,
28 scoped_ptr<ServiceWorkerNetworkProvider> network_provider) {
29 datasource_userdata->SetUserData(&kUserDataKey, network_provider.release());
32 ServiceWorkerNetworkProvider* ServiceWorkerNetworkProvider::FromDocumentState(
33 base::SupportsUserData* datasource_userdata) {
34 return static_cast<ServiceWorkerNetworkProvider*>(
35 datasource_userdata->GetUserData(&kUserDataKey));
38 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider(
39 int render_frame_id,
40 ServiceWorkerProviderType provider_type)
41 : provider_id_(GetNextProviderId()),
42 context_(new ServiceWorkerProviderContext(provider_id_)) {
43 if (!ChildThreadImpl::current())
44 return; // May be null in some tests.
45 ChildThreadImpl::current()->Send(
46 new ServiceWorkerHostMsg_ProviderCreated(
47 provider_id_, render_frame_id, provider_type));
50 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() {
51 if (!ChildThreadImpl::current())
52 return; // May be null in some tests.
53 ChildThreadImpl::current()->Send(
54 new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_));
57 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId(
58 int64 version_id) {
59 if (!ChildThreadImpl::current())
60 return; // May be null in some tests.
61 ChildThreadImpl::current()->Send(
62 new ServiceWorkerHostMsg_SetVersionId(provider_id_, version_id));
65 } // namespace content