OLD | NEW |
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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "content/browser/service_worker/embedded_worker_instance.h" | 10 #include "content/browser/service_worker/embedded_worker_instance.h" |
(...skipping 73 matching lines...) Loading... |
84 ServiceWorkerStatusCode status) { | 84 ServiceWorkerStatusCode status) { |
85 callback.Run(status, | 85 callback.Run(status, |
86 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 86 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
87 ServiceWorkerResponse()); | 87 ServiceWorkerResponse()); |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
91 | 91 |
92 ServiceWorkerVersion::ServiceWorkerVersion( | 92 ServiceWorkerVersion::ServiceWorkerVersion( |
93 ServiceWorkerRegistration* registration, | 93 ServiceWorkerRegistration* registration, |
| 94 const GURL& script_url, |
94 int64 version_id, | 95 int64 version_id, |
95 base::WeakPtr<ServiceWorkerContextCore> context) | 96 base::WeakPtr<ServiceWorkerContextCore> context) |
96 : version_id_(version_id), | 97 : version_id_(version_id), |
97 registration_id_(kInvalidServiceWorkerVersionId), | 98 registration_id_(kInvalidServiceWorkerVersionId), |
| 99 script_url_(script_url), |
98 status_(NEW), | 100 status_(NEW), |
99 context_(context), | 101 context_(context), |
100 script_cache_map_(this, context), | 102 script_cache_map_(this, context), |
101 is_doomed_(false), | 103 is_doomed_(false), |
102 weak_factory_(this) { | 104 weak_factory_(this) { |
103 DCHECK(context_); | 105 DCHECK(context_); |
104 DCHECK(registration); | 106 DCHECK(registration); |
105 if (registration) { | 107 if (registration) { |
106 registration_id_ = registration->id(); | 108 registration_id_ = registration->id(); |
107 script_url_ = registration->script_url(); | |
108 scope_ = registration->pattern(); | 109 scope_ = registration->pattern(); |
109 } | 110 } |
110 context_->AddLiveVersion(this); | 111 context_->AddLiveVersion(this); |
111 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 112 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
112 embedded_worker_->AddListener(this); | 113 embedded_worker_->AddListener(this); |
113 cache_listener_.reset(new ServiceWorkerCacheListener(this, context)); | 114 cache_listener_.reset(new ServiceWorkerCacheListener(this, context)); |
114 embedded_worker_->AddListener(cache_listener_.get()); | 115 embedded_worker_->AddListener(cache_listener_.get()); |
115 } | 116 } |
116 | 117 |
117 ServiceWorkerVersion::~ServiceWorkerVersion() { | 118 ServiceWorkerVersion::~ServiceWorkerVersion() { |
(...skipping 26 matching lines...) Loading... |
144 void ServiceWorkerVersion::RegisterStatusChangeCallback( | 145 void ServiceWorkerVersion::RegisterStatusChangeCallback( |
145 const base::Closure& callback) { | 146 const base::Closure& callback) { |
146 status_change_callbacks_.push_back(callback); | 147 status_change_callbacks_.push_back(callback); |
147 } | 148 } |
148 | 149 |
149 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { | 150 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { |
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
151 return ServiceWorkerVersionInfo( | 152 return ServiceWorkerVersionInfo( |
152 running_status(), | 153 running_status(), |
153 status(), | 154 status(), |
| 155 script_url(), |
154 version_id(), | 156 version_id(), |
155 embedded_worker()->process_id(), | 157 embedded_worker()->process_id(), |
156 embedded_worker()->thread_id(), | 158 embedded_worker()->thread_id(), |
157 embedded_worker()->worker_devtools_agent_route_id()); | 159 embedded_worker()->worker_devtools_agent_route_id()); |
158 } | 160 } |
159 | 161 |
160 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 162 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
161 StartWorkerWithCandidateProcesses(std::vector<int>(), false, callback); | 163 StartWorkerWithCandidateProcesses(std::vector<int>(), false, callback); |
162 } | 164 } |
163 | 165 |
(...skipping 55 matching lines...) Loading... |
219 if (update_timer_.IsRunning()) | 221 if (update_timer_.IsRunning()) |
220 update_timer_.Reset(); | 222 update_timer_.Reset(); |
221 } | 223 } |
222 | 224 |
223 void ServiceWorkerVersion::StartUpdate() { | 225 void ServiceWorkerVersion::StartUpdate() { |
224 update_timer_.Stop(); | 226 update_timer_.Stop(); |
225 if (!context_) | 227 if (!context_) |
226 return; | 228 return; |
227 ServiceWorkerRegistration* registration = | 229 ServiceWorkerRegistration* registration = |
228 context_->GetLiveRegistration(registration_id_); | 230 context_->GetLiveRegistration(registration_id_); |
229 if (!registration) | 231 if (!registration || !registration->GetNewestVersion()) |
230 return; | 232 return; |
231 context_->UpdateServiceWorker(registration); | 233 context_->UpdateServiceWorker(registration); |
232 } | 234 } |
233 | 235 |
234 void ServiceWorkerVersion::SendMessage( | 236 void ServiceWorkerVersion::SendMessage( |
235 const IPC::Message& message, const StatusCallback& callback) { | 237 const IPC::Message& message, const StatusCallback& callback) { |
236 if (running_status() != RUNNING) { | 238 if (running_status() != RUNNING) { |
237 // Schedule calling this method after starting the worker. | 239 // Schedule calling this method after starting the worker. |
238 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 240 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
239 weak_factory_.GetWeakPtr(), callback, | 241 weak_factory_.GetWeakPtr(), callback, |
(...skipping 450 matching lines...) Loading... |
690 SetStatus(REDUNDANT); | 692 SetStatus(REDUNDANT); |
691 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 693 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
692 if (!context_) | 694 if (!context_) |
693 return; | 695 return; |
694 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 696 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
695 script_cache_map_.GetResources(&resources); | 697 script_cache_map_.GetResources(&resources); |
696 context_->storage()->PurgeResources(resources); | 698 context_->storage()->PurgeResources(resources); |
697 } | 699 } |
698 | 700 |
699 } // namespace content | 701 } // namespace content |
OLD | NEW |