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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void EmbeddedWorkerInstance::ReleaseProcessReference(int process_id) { | 68 void EmbeddedWorkerInstance::ReleaseProcessReference(int process_id) { |
69 ProcessRefMap::iterator found = process_refs_.find(process_id); | 69 ProcessRefMap::iterator found = process_refs_.find(process_id); |
70 if (found == process_refs_.end()) { | 70 if (found == process_refs_.end()) { |
71 NOTREACHED() << "Releasing unknown process ref " << process_id; | 71 NOTREACHED() << "Releasing unknown process ref " << process_id; |
72 return; | 72 return; |
73 } | 73 } |
74 if (--found->second == 0) | 74 if (--found->second == 0) |
75 process_refs_.erase(found); | 75 process_refs_.erase(found); |
76 } | 76 } |
77 | 77 |
78 EmbeddedWorkerInstance::EmbeddedWorkerInstance( | 78 EmbeddedWorkerInstance::EmbeddedWorkerInstance(EmbeddedWorkerRegistry* registry, |
79 EmbeddedWorkerRegistry* registry, | 79 int embedded_worker_id) |
80 int embedded_worker_id) | |
81 : registry_(registry), | 80 : registry_(registry), |
82 embedded_worker_id_(embedded_worker_id), | 81 embedded_worker_id_(embedded_worker_id), |
83 status_(STOPPED), | 82 status_(STOPPED), |
84 process_id_(-1), | 83 process_id_(-1), |
85 thread_id_(-1) { | 84 thread_id_(-1), |
| 85 worker_devtools_agent_route_id_(MSG_ROUTING_NONE) { |
86 } | 86 } |
87 | 87 |
88 void EmbeddedWorkerInstance::RecordProcessId(int process_id, | 88 void EmbeddedWorkerInstance::RecordProcessId( |
89 ServiceWorkerStatusCode status) { | 89 int process_id, |
| 90 ServiceWorkerStatusCode status, |
| 91 int worker_devtools_agent_route_id) { |
90 DCHECK_EQ(process_id_, -1); | 92 DCHECK_EQ(process_id_, -1); |
| 93 DCHECK_EQ(worker_devtools_agent_route_id_, MSG_ROUTING_NONE); |
91 if (status == SERVICE_WORKER_OK) { | 94 if (status == SERVICE_WORKER_OK) { |
92 process_id_ = process_id; | 95 process_id_ = process_id; |
| 96 worker_devtools_agent_route_id_ = worker_devtools_agent_route_id; |
93 } else { | 97 } else { |
94 status_ = STOPPED; | 98 status_ = STOPPED; |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
98 void EmbeddedWorkerInstance::OnStarted(int thread_id) { | 102 void EmbeddedWorkerInstance::OnStarted(int thread_id) { |
99 // Stop is requested before OnStarted is sent back from the worker. | 103 // Stop is requested before OnStarted is sent back from the worker. |
100 if (status_ == STOPPING) | 104 if (status_ == STOPPING) |
101 return; | 105 return; |
102 DCHECK(status_ == STARTING); | 106 DCHECK(status_ == STARTING); |
103 status_ = RUNNING; | 107 status_ = RUNNING; |
104 thread_id_ = thread_id; | 108 thread_id_ = thread_id; |
105 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); | 109 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); |
106 } | 110 } |
107 | 111 |
108 void EmbeddedWorkerInstance::OnStopped() { | 112 void EmbeddedWorkerInstance::OnStopped() { |
109 status_ = STOPPED; | 113 status_ = STOPPED; |
110 process_id_ = -1; | 114 process_id_ = -1; |
111 thread_id_ = -1; | 115 thread_id_ = -1; |
| 116 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE; |
112 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); | 117 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); |
113 } | 118 } |
114 | 119 |
115 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { | 120 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { |
116 ListenerList::Iterator it(listener_list_); | 121 ListenerList::Iterator it(listener_list_); |
117 while (Listener* listener = it.GetNext()) { | 122 while (Listener* listener = it.GetNext()) { |
118 if (listener->OnMessageReceived(message)) | 123 if (listener->OnMessageReceived(message)) |
119 return true; | 124 return true; |
120 } | 125 } |
121 return false; | 126 return false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Sort descending by the reference count. | 174 // Sort descending by the reference count. |
170 std::sort(counted.begin(), counted.end(), SecondGreater()); | 175 std::sort(counted.begin(), counted.end(), SecondGreater()); |
171 | 176 |
172 std::vector<int> result(counted.size()); | 177 std::vector<int> result(counted.size()); |
173 for (size_t i = 0; i < counted.size(); ++i) | 178 for (size_t i = 0; i < counted.size(); ++i) |
174 result[i] = counted[i].first; | 179 result[i] = counted[i].first; |
175 return result; | 180 return result; |
176 } | 181 } |
177 | 182 |
178 } // namespace content | 183 } // namespace content |
OLD | NEW |