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

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 272183005: Stop ServiceWorker context when no controllee is associated (and when all refs are dropped) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated, and updated tests Created 6 years, 7 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/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)
michaeln 2014/05/15 19:02:20 nice catch, STARTING too
26 Stop();
25 registry_->RemoveWorker(process_id_, embedded_worker_id_); 27 registry_->RemoveWorker(process_id_, embedded_worker_id_);
26 } 28 }
27 29
28 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, 30 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id,
29 const GURL& scope, 31 const GURL& scope,
30 const GURL& script_url, 32 const GURL& script_url,
31 const std::vector<int>& possible_process_ids, 33 const std::vector<int>& possible_process_ids,
32 const StatusCallback& callback) { 34 const StatusCallback& callback) {
33 DCHECK(status_ == STOPPED); 35 DCHECK(status_ == STOPPED);
34 status_ = STARTING; 36 status_ = STARTING;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // Sort descending by the reference count. 183 // Sort descending by the reference count.
182 std::sort(counted.begin(), counted.end(), SecondGreater()); 184 std::sort(counted.begin(), counted.end(), SecondGreater());
183 185
184 std::vector<int> result(counted.size()); 186 std::vector<int> result(counted.size());
185 for (size_t i = 0; i < counted.size(); ++i) 187 for (size_t i = 0; i < counted.size(); ++i)
186 result[i] = counted[i].first; 188 result[i] = counted[i].first;
187 return result; 189 return result;
188 } 190 }
189 191
190 } // namespace content 192 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698