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

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: sigh, rebased 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 AssociateVersion(NULL); 27 AssociateVersion(NULL);
24 } 28 }
25 29
26 void ServiceWorkerProviderHost::AddScriptClient(int thread_id) { 30 void ServiceWorkerProviderHost::AddScriptClient(int thread_id) {
27 DCHECK(!ContainsKey(script_client_thread_ids_, thread_id)); 31 DCHECK(!ContainsKey(script_client_thread_ids_, thread_id));
28 script_client_thread_ids_.insert(thread_id); 32 script_client_thread_ids_.insert(thread_id);
29 } 33 }
30 34
31 void ServiceWorkerProviderHost::RemoveScriptClient(int thread_id) { 35 void ServiceWorkerProviderHost::RemoveScriptClient(int thread_id) {
32 DCHECK(ContainsKey(script_client_thread_ids_, thread_id)); 36 DCHECK(ContainsKey(script_client_thread_ids_, thread_id));
33 script_client_thread_ids_.erase(thread_id); 37 script_client_thread_ids_.erase(thread_id);
34 } 38 }
35 39
36 void ServiceWorkerProviderHost::AssociateVersion( 40 void ServiceWorkerProviderHost::AssociateVersion(
37 ServiceWorkerVersion* version) { 41 ServiceWorkerVersion* version) {
38 if (associated_version()) 42 if (associated_version())
39 associated_version_->RemoveProcessToWorker(process_id_); 43 associated_version_->RemoveProcessFromWorker(process_id_);
40 associated_version_ = version; 44 associated_version_ = version;
41 if (version) 45 if (version)
42 version->AddProcessToWorker(process_id_); 46 version->AddProcessToWorker(process_id_);
47
48 if (!dispatcher_host_)
49 return; // Could be NULL in some tests.
50
51 for (std::set<int>::iterator it = script_client_thread_ids_.begin();
52 it != script_client_thread_ids_.end();
53 ++it) {
54 dispatcher_host_->RegisterServiceWorkerHandle(
55 ServiceWorkerHandle::Create(context_, dispatcher_host_, *it, version));
56 }
57 // TODO(kinuko): change this method into two for .active and .pending,
58 // and dispatch activechange/pendingchange event to the script clients here.
43 } 59 }
44 60
45 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 61 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
46 if (!context_) 62 if (!context_)
47 return true; // System is shutting down. 63 return true; // System is shutting down.
48 if (associated_version_) 64 if (associated_version_)
49 return false; // Unexpected bad message. 65 return false; // Unexpected bad message.
50 66
51 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 67 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
52 if (!live_version) 68 if (!live_version)
(...skipping 20 matching lines...) Expand all
73 return true; 89 return true;
74 90
75 // TODO(kinuko): Handle ServiceWorker cases. 91 // TODO(kinuko): Handle ServiceWorker cases.
76 // For now we always return false here, so that we don't handle 92 // For now we always return false here, so that we don't handle
77 // requests for ServiceWorker (either for the main or sub resources). 93 // requests for ServiceWorker (either for the main or sub resources).
78 94
79 return false; 95 return false;
80 } 96 }
81 97
82 } // namespace content 98 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698