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/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
6 | 6 |
7 #include "content/browser/service_worker/embedded_worker_registry.h" | 7 #include "content/browser/service_worker/embedded_worker_registry.h" |
8 #include "content/common/service_worker/embedded_worker_messages.h" | 8 #include "content/common/service_worker/embedded_worker_messages.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 namespace { | 14 namespace { |
15 // Functor to sort by the .second element of a struct. | 15 // Functor to sort by the .second element of a struct. |
16 struct SecondGreater { | 16 struct SecondGreater { |
17 template <typename Value> | 17 template <typename Value> |
18 bool operator()(const Value& lhs, const Value& rhs) { | 18 bool operator()(const Value& lhs, const Value& rhs) { |
19 return lhs.second > rhs.second; | 19 return lhs.second > rhs.second; |
20 } | 20 } |
21 }; | 21 }; |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { | 24 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { |
25 if (status_ == STARTING || status_ == RUNNING) | |
26 Stop(); | |
27 registry_->RemoveWorker(process_id_, embedded_worker_id_); | 25 registry_->RemoveWorker(process_id_, embedded_worker_id_); |
28 } | 26 } |
29 | 27 |
30 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, | 28 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, |
31 const GURL& scope, | 29 const GURL& scope, |
32 const GURL& script_url, | 30 const GURL& script_url, |
33 const std::vector<int>& possible_process_ids, | 31 const std::vector<int>& possible_process_ids, |
34 const StatusCallback& callback) { | 32 const StatusCallback& callback) { |
35 DCHECK(status_ == STOPPED); | 33 DCHECK(status_ == STOPPED); |
36 status_ = STARTING; | 34 status_ = STARTING; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Sort descending by the reference count. | 181 // Sort descending by the reference count. |
184 std::sort(counted.begin(), counted.end(), SecondGreater()); | 182 std::sort(counted.begin(), counted.end(), SecondGreater()); |
185 | 183 |
186 std::vector<int> result(counted.size()); | 184 std::vector<int> result(counted.size()); |
187 for (size_t i = 0; i < counted.size(); ++i) | 185 for (size_t i = 0; i < counted.size(); ++i) |
188 result[i] = counted[i].first; | 186 result[i] = counted[i].first; |
189 return result; | 187 return result; |
190 } | 188 } |
191 | 189 |
192 } // namespace content | 190 } // namespace content |
OLD | NEW |