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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 running_status(), | 153 running_status(), |
154 status(), | 154 status(), |
155 script_url(), | 155 script_url(), |
156 version_id(), | 156 version_id(), |
157 embedded_worker()->process_id(), | 157 embedded_worker()->process_id(), |
158 embedded_worker()->thread_id(), | 158 embedded_worker()->thread_id(), |
159 embedded_worker()->worker_devtools_agent_route_id()); | 159 embedded_worker()->worker_devtools_agent_route_id()); |
160 } | 160 } |
161 | 161 |
162 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 162 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
163 StartWorkerWithCandidateProcesses(std::vector<int>(), false, callback); | 163 StartWorker(false, callback); |
164 } | 164 } |
165 | 165 |
166 void ServiceWorkerVersion::StartWorkerWithCandidateProcesses( | 166 void ServiceWorkerVersion::StartWorker( |
167 const std::vector<int>& possible_process_ids, | |
168 bool pause_after_download, | 167 bool pause_after_download, |
169 const StatusCallback& callback) { | 168 const StatusCallback& callback) { |
170 switch (running_status()) { | 169 switch (running_status()) { |
171 case RUNNING: | 170 case RUNNING: |
172 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 171 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
173 return; | 172 return; |
174 case STOPPING: | 173 case STOPPING: |
175 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); | 174 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); |
176 return; | 175 return; |
177 case STOPPED: | 176 case STOPPED: |
178 case STARTING: | 177 case STARTING: |
179 start_callbacks_.push_back(callback); | 178 start_callbacks_.push_back(callback); |
180 if (running_status() == STOPPED) { | 179 if (running_status() == STOPPED) { |
181 embedded_worker_->Start( | 180 embedded_worker_->Start( |
182 version_id_, | 181 version_id_, |
183 scope_, | 182 scope_, |
184 script_url_, | 183 script_url_, |
185 pause_after_download, | 184 pause_after_download, |
186 possible_process_ids, | |
187 base::Bind(&ServiceWorkerVersion::RunStartWorkerCallbacksOnError, | 185 base::Bind(&ServiceWorkerVersion::RunStartWorkerCallbacksOnError, |
188 weak_factory_.GetWeakPtr())); | 186 weak_factory_.GetWeakPtr())); |
189 } | 187 } |
190 return; | 188 return; |
191 } | 189 } |
192 } | 190 } |
193 | 191 |
194 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { | 192 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { |
195 if (running_status() == STOPPED) { | 193 if (running_status() == STOPPED) { |
196 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 194 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 367 |
370 int request_id = push_callbacks_.Add(new StatusCallback(callback)); | 368 int request_id = push_callbacks_.Add(new StatusCallback(callback)); |
371 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 369 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
372 ServiceWorkerMsg_PushEvent(request_id, data)); | 370 ServiceWorkerMsg_PushEvent(request_id, data)); |
373 if (status != SERVICE_WORKER_OK) { | 371 if (status != SERVICE_WORKER_OK) { |
374 push_callbacks_.Remove(request_id); | 372 push_callbacks_.Remove(request_id); |
375 RunSoon(base::Bind(callback, status)); | 373 RunSoon(base::Bind(callback, status)); |
376 } | 374 } |
377 } | 375 } |
378 | 376 |
379 void ServiceWorkerVersion::AddProcessToWorker(int process_id) { | |
380 embedded_worker_->AddProcessReference(process_id); | |
381 } | |
382 | |
383 void ServiceWorkerVersion::RemoveProcessFromWorker(int process_id) { | |
384 embedded_worker_->ReleaseProcessReference(process_id); | |
385 } | |
386 | |
387 bool ServiceWorkerVersion::HasProcessToRun() const { | |
388 return embedded_worker_->HasProcessToRun(); | |
389 } | |
390 | |
391 void ServiceWorkerVersion::AddControllee( | 377 void ServiceWorkerVersion::AddControllee( |
392 ServiceWorkerProviderHost* provider_host) { | 378 ServiceWorkerProviderHost* provider_host) { |
393 DCHECK(!ContainsKey(controllee_map_, provider_host)); | 379 DCHECK(!ContainsKey(controllee_map_, provider_host)); |
394 int controllee_id = controllee_by_id_.Add(provider_host); | 380 int controllee_id = controllee_by_id_.Add(provider_host); |
395 controllee_map_[provider_host] = controllee_id; | 381 controllee_map_[provider_host] = controllee_id; |
396 AddProcessToWorker(provider_host->process_id()); | |
397 if (stop_worker_timer_.IsRunning()) | 382 if (stop_worker_timer_.IsRunning()) |
398 stop_worker_timer_.Stop(); | 383 stop_worker_timer_.Stop(); |
399 } | 384 } |
400 | 385 |
401 void ServiceWorkerVersion::RemoveControllee( | 386 void ServiceWorkerVersion::RemoveControllee( |
402 ServiceWorkerProviderHost* provider_host) { | 387 ServiceWorkerProviderHost* provider_host) { |
403 ControlleeMap::iterator found = controllee_map_.find(provider_host); | 388 ControlleeMap::iterator found = controllee_map_.find(provider_host); |
404 DCHECK(found != controllee_map_.end()); | 389 DCHECK(found != controllee_map_.end()); |
405 controllee_by_id_.Remove(found->second); | 390 controllee_by_id_.Remove(found->second); |
406 controllee_map_.erase(found); | 391 controllee_map_.erase(found); |
407 RemoveProcessFromWorker(provider_host->process_id()); | |
408 if (HasControllee()) | 392 if (HasControllee()) |
409 return; | 393 return; |
410 FOR_EACH_OBSERVER(Listener, listeners_, OnNoControllees(this)); | 394 FOR_EACH_OBSERVER(Listener, listeners_, OnNoControllees(this)); |
411 if (is_doomed_) { | 395 if (is_doomed_) { |
412 DoomInternal(); | 396 DoomInternal(); |
413 return; | 397 return; |
414 } | 398 } |
415 ScheduleStopWorker(); | 399 ScheduleStopWorker(); |
416 } | 400 } |
417 | 401 |
418 void ServiceWorkerVersion::AddPotentialControllee( | |
419 ServiceWorkerProviderHost* provider_host) { | |
420 AddProcessToWorker(provider_host->process_id()); | |
421 } | |
422 | |
423 void ServiceWorkerVersion::RemovePotentialControllee( | |
424 ServiceWorkerProviderHost* provider_host) { | |
425 RemoveProcessFromWorker(provider_host->process_id()); | |
426 } | |
427 | |
428 void ServiceWorkerVersion::AddListener(Listener* listener) { | 402 void ServiceWorkerVersion::AddListener(Listener* listener) { |
429 listeners_.AddObserver(listener); | 403 listeners_.AddObserver(listener); |
430 } | 404 } |
431 | 405 |
432 void ServiceWorkerVersion::RemoveListener(Listener* listener) { | 406 void ServiceWorkerVersion::RemoveListener(Listener* listener) { |
433 listeners_.RemoveObserver(listener); | 407 listeners_.RemoveObserver(listener); |
434 } | 408 } |
435 | 409 |
436 void ServiceWorkerVersion::Doom() { | 410 void ServiceWorkerVersion::Doom() { |
437 if (is_doomed_) | 411 if (is_doomed_) |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 SetStatus(REDUNDANT); | 689 SetStatus(REDUNDANT); |
716 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 690 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
717 if (!context_) | 691 if (!context_) |
718 return; | 692 return; |
719 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 693 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
720 script_cache_map_.GetResources(&resources); | 694 script_cache_map_.GetResources(&resources); |
721 context_->storage()->PurgeResources(resources); | 695 context_->storage()->PurgeResources(resources); |
722 } | 696 } |
723 | 697 |
724 } // namespace content | 698 } // namespace content |
OLD | NEW |