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

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

Issue 224733014: Introduce ServiceWorkerHandle for tracking WebServiceWorkerImpl reference (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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 "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/service_worker/service_worker_context_core.h" 8 #include "content/browser/service_worker/service_worker_context_core.h"
9 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
10 #include "content/browser/service_worker/service_worker_handle.h"
9 #include "content/browser/service_worker/service_worker_utils.h" 11 #include "content/browser/service_worker/service_worker_utils.h"
10 #include "content/browser/service_worker/service_worker_version.h" 12 #include "content/browser/service_worker/service_worker_version.h"
11 13
12 namespace content { 14 namespace content {
13 15
14 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 16 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
15 int process_id, int provider_id, 17 int process_id, int provider_id,
16 base::WeakPtr<ServiceWorkerContextCore> context) 18 base::WeakPtr<ServiceWorkerContextCore> context,
19 ServiceWorkerDispatcherHost* dispatcher_host)
17 : process_id_(process_id), 20 : process_id_(process_id),
18 provider_id_(provider_id), 21 provider_id_(provider_id),
19 context_(context) { 22 context_(context),
23 dispatcher_host_(dispatcher_host) {
20 } 24 }
21 25
22 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { 26 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
23 if (active_version_) 27 if (active_version_)
24 active_version_->RemoveControllee(this); 28 active_version_->RemoveControllee(this);
25 } 29 }
26 30
27 void ServiceWorkerProviderHost::AddScriptClient(int thread_id) { 31 void ServiceWorkerProviderHost::AddScriptClient(int thread_id) {
28 DCHECK(!ContainsKey(script_client_thread_ids_, thread_id)); 32 DCHECK(!ContainsKey(script_client_thread_ids_, thread_id));
29 script_client_thread_ids_.insert(thread_id); 33 script_client_thread_ids_.insert(thread_id);
30 } 34 }
31 35
32 void ServiceWorkerProviderHost::RemoveScriptClient(int thread_id) { 36 void ServiceWorkerProviderHost::RemoveScriptClient(int thread_id) {
33 DCHECK(ContainsKey(script_client_thread_ids_, thread_id)); 37 DCHECK(ContainsKey(script_client_thread_ids_, thread_id));
34 script_client_thread_ids_.erase(thread_id); 38 script_client_thread_ids_.erase(thread_id);
35 } 39 }
36 40
37 void ServiceWorkerProviderHost::SetActiveVersion( 41 void ServiceWorkerProviderHost::SetActiveVersion(
38 ServiceWorkerVersion* version) { 42 ServiceWorkerVersion* version) {
39 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; 43 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_;
40 active_version_ = version; 44 active_version_ = version;
41 if (version) 45 if (version)
42 version->AddControllee(this); 46 version->AddControllee(this);
43 if (previous_version) 47 if (previous_version)
44 previous_version->RemoveControllee(this); 48 previous_version->RemoveControllee(this);
49
50 dispatcher_host_->RegisterServiceWorkerHandle(
51 ServiceWorkerHandle::Create(context_, dispatcher_host_, version));
45 // TODO(kinuko): dispatch activechange event to the script clients. 52 // TODO(kinuko): dispatch activechange event to the script clients.
53 // dispatcher_host_->Send(ServiceWorkerMsg_ActiveChangeEvent(...));
46 } 54 }
47 55
48 void ServiceWorkerProviderHost::SetPendingVersion( 56 void ServiceWorkerProviderHost::SetPendingVersion(
49 ServiceWorkerVersion* version) { 57 ServiceWorkerVersion* version) {
50 pending_version_ = version; 58 pending_version_ = version;
59
60 dispatcher_host_->RegisterServiceWorkerHandle(
61 ServiceWorkerHandle::Create(context_, dispatcher_host_, version));
51 // TODO(kinuko): dispatch pendingchange event to the script clients. 62 // TODO(kinuko): dispatch pendingchange event to the script clients.
63 // dispatcher_host_->Send(ServiceWorkerMsg_PendingChangeEvent(...));
52 } 64 }
53 65
54 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 66 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
55 if (!context_) 67 if (!context_)
56 return true; // System is shutting down. 68 return true; // System is shutting down.
57 if (active_version_) 69 if (active_version_)
58 return false; // Unexpected bad message. 70 return false; // Unexpected bad message.
59 71
60 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 72 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
61 if (!live_version) 73 if (!live_version)
(...skipping 20 matching lines...) Expand all
82 return true; 94 return true;
83 95
84 // TODO(kinuko): Handle ServiceWorker cases. 96 // TODO(kinuko): Handle ServiceWorker cases.
85 // For now we always return false here, so that we don't handle 97 // For now we always return false here, so that we don't handle
86 // requests for ServiceWorker (either for the main or sub resources). 98 // requests for ServiceWorker (either for the main or sub resources).
87 99
88 return false; 100 return false;
89 } 101 }
90 102
91 } // namespace content 103 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698