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" |
11 #include "content/browser/service_worker/embedded_worker_registry.h" | 11 #include "content/browser/service_worker/embedded_worker_registry.h" |
12 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
| 13 #include "content/browser/service_worker/service_worker_process_manager.h" |
13 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
14 #include "content/browser/service_worker/service_worker_utils.h" | 15 #include "content/browser/service_worker/service_worker_utils.h" |
15 #include "content/common/service_worker/service_worker_messages.h" | 16 #include "content/common/service_worker/service_worker_messages.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 typedef ServiceWorkerVersion::StatusCallback StatusCallback; | 22 typedef ServiceWorkerVersion::StatusCallback StatusCallback; |
22 typedef ServiceWorkerVersion::MessageCallback MessageCallback; | 23 typedef ServiceWorkerVersion::MessageCallback MessageCallback; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return ServiceWorkerVersionInfo( | 150 return ServiceWorkerVersionInfo( |
150 running_status(), | 151 running_status(), |
151 status(), | 152 status(), |
152 version_id(), | 153 version_id(), |
153 embedded_worker()->process_id(), | 154 embedded_worker()->process_id(), |
154 embedded_worker()->thread_id(), | 155 embedded_worker()->thread_id(), |
155 embedded_worker()->worker_devtools_agent_route_id()); | 156 embedded_worker()->worker_devtools_agent_route_id()); |
156 } | 157 } |
157 | 158 |
158 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 159 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
159 StartWorkerWithCandidateProcesses(std::vector<int>(), false, callback); | 160 StartWorker(false, callback); |
160 } | 161 } |
161 | 162 |
162 void ServiceWorkerVersion::StartWorkerWithCandidateProcesses( | 163 void ServiceWorkerVersion::StartWorker( |
163 const std::vector<int>& possible_process_ids, | |
164 bool pause_after_download, | 164 bool pause_after_download, |
165 const StatusCallback& callback) { | 165 const StatusCallback& callback) { |
166 switch (running_status()) { | 166 switch (running_status()) { |
167 case RUNNING: | 167 case RUNNING: |
168 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 168 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
169 return; | 169 return; |
170 case STOPPING: | 170 case STOPPING: |
171 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); | 171 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); |
172 return; | 172 return; |
173 case STOPPED: | 173 case STOPPED: |
174 case STARTING: | 174 case STARTING: |
175 start_callbacks_.push_back(callback); | 175 start_callbacks_.push_back(callback); |
176 if (running_status() == STOPPED) { | 176 if (running_status() == STOPPED) { |
177 embedded_worker_->Start( | 177 embedded_worker_->Start( |
178 version_id_, | 178 version_id_, |
179 scope_, | 179 scope_, |
180 script_url_, | 180 script_url_, |
181 pause_after_download, | 181 pause_after_download, |
182 possible_process_ids, | |
183 base::Bind(&ServiceWorkerVersion::RunStartWorkerCallbacksOnError, | 182 base::Bind(&ServiceWorkerVersion::RunStartWorkerCallbacksOnError, |
184 weak_factory_.GetWeakPtr())); | 183 weak_factory_.GetWeakPtr())); |
185 } | 184 } |
186 return; | 185 return; |
187 } | 186 } |
188 } | 187 } |
189 | 188 |
190 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { | 189 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { |
191 if (running_status() == STOPPED) { | 190 if (running_status() == STOPPED) { |
192 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 191 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 int request_id = push_callbacks_.Add(new StatusCallback(callback)); | 360 int request_id = push_callbacks_.Add(new StatusCallback(callback)); |
362 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 361 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
363 ServiceWorkerMsg_PushEvent(request_id, data)); | 362 ServiceWorkerMsg_PushEvent(request_id, data)); |
364 if (status != SERVICE_WORKER_OK) { | 363 if (status != SERVICE_WORKER_OK) { |
365 push_callbacks_.Remove(request_id); | 364 push_callbacks_.Remove(request_id); |
366 RunSoon(base::Bind(callback, status)); | 365 RunSoon(base::Bind(callback, status)); |
367 } | 366 } |
368 } | 367 } |
369 | 368 |
370 void ServiceWorkerVersion::AddProcessToWorker(int process_id) { | 369 void ServiceWorkerVersion::AddProcessToWorker(int process_id) { |
371 embedded_worker_->AddProcessReference(process_id); | 370 if (context_ && context_->process_manager()) { |
| 371 context_->process_manager()->AddScopeProcessReference( |
| 372 scope_, process_id); |
| 373 } |
372 } | 374 } |
373 | 375 |
374 void ServiceWorkerVersion::RemoveProcessFromWorker(int process_id) { | 376 void ServiceWorkerVersion::RemoveProcessFromWorker(int process_id) { |
375 embedded_worker_->ReleaseProcessReference(process_id); | 377 if (context_ && context_->process_manager()) { |
376 } | 378 context_->process_manager()->RemoveScopeProcessReference( |
377 | 379 scope_, process_id); |
378 bool ServiceWorkerVersion::HasProcessToRun() const { | 380 } |
379 return embedded_worker_->HasProcessToRun(); | |
380 } | 381 } |
381 | 382 |
382 void ServiceWorkerVersion::AddControllee( | 383 void ServiceWorkerVersion::AddControllee( |
383 ServiceWorkerProviderHost* provider_host) { | 384 ServiceWorkerProviderHost* provider_host) { |
384 DCHECK(!ContainsKey(controllee_map_, provider_host)); | 385 DCHECK(!ContainsKey(controllee_map_, provider_host)); |
385 int controllee_id = controllee_by_id_.Add(provider_host); | 386 int controllee_id = controllee_by_id_.Add(provider_host); |
386 controllee_map_[provider_host] = controllee_id; | 387 controllee_map_[provider_host] = controllee_id; |
387 AddProcessToWorker(provider_host->process_id()); | 388 AddProcessToWorker(provider_host->process_id()); |
388 if (stop_worker_timer_.IsRunning()) | 389 if (stop_worker_timer_.IsRunning()) |
389 stop_worker_timer_.Stop(); | 390 stop_worker_timer_.Stop(); |
(...skipping 19 matching lines...) Expand all Loading... |
409 void ServiceWorkerVersion::AddPotentialControllee( | 410 void ServiceWorkerVersion::AddPotentialControllee( |
410 ServiceWorkerProviderHost* provider_host) { | 411 ServiceWorkerProviderHost* provider_host) { |
411 AddProcessToWorker(provider_host->process_id()); | 412 AddProcessToWorker(provider_host->process_id()); |
412 } | 413 } |
413 | 414 |
414 void ServiceWorkerVersion::RemovePotentialControllee( | 415 void ServiceWorkerVersion::RemovePotentialControllee( |
415 ServiceWorkerProviderHost* provider_host) { | 416 ServiceWorkerProviderHost* provider_host) { |
416 RemoveProcessFromWorker(provider_host->process_id()); | 417 RemoveProcessFromWorker(provider_host->process_id()); |
417 } | 418 } |
418 | 419 |
| 420 void ServiceWorkerVersion::AddPendingProcesses( |
| 421 const std::vector<int>& pending_processes) { |
| 422 if (context_ && context_->process_manager() && !pending_processes.empty()) { |
| 423 context_->process_manager()->AddScopePendingProcesses( |
| 424 scope_, pending_processes); |
| 425 } |
| 426 } |
| 427 |
419 void ServiceWorkerVersion::AddListener(Listener* listener) { | 428 void ServiceWorkerVersion::AddListener(Listener* listener) { |
420 listeners_.AddObserver(listener); | 429 listeners_.AddObserver(listener); |
421 } | 430 } |
422 | 431 |
423 void ServiceWorkerVersion::RemoveListener(Listener* listener) { | 432 void ServiceWorkerVersion::RemoveListener(Listener* listener) { |
424 listeners_.RemoveObserver(listener); | 433 listeners_.RemoveObserver(listener); |
425 } | 434 } |
426 | 435 |
427 void ServiceWorkerVersion::Doom() { | 436 void ServiceWorkerVersion::Doom() { |
428 if (is_doomed_) | 437 if (is_doomed_) |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 SetStatus(REDUNDANT); | 697 SetStatus(REDUNDANT); |
689 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 698 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
690 if (!context_) | 699 if (!context_) |
691 return; | 700 return; |
692 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 701 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
693 script_cache_map_.GetResources(&resources); | 702 script_cache_map_.GetResources(&resources); |
694 context_->storage()->PurgeResources(resources); | 703 context_->storage()->PurgeResources(resources); |
695 } | 704 } |
696 | 705 |
697 } // namespace content | 706 } // namespace content |
OLD | NEW |