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

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

Issue 252633003: Introduce worker_devtools_agent_route_id for EmbeddedWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests failure 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
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_registry.h" 5 #include "content/browser/service_worker/embedded_worker_registry.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/devtools/shared_worker_devtools_manager.h"
8 #include "content/browser/service_worker/embedded_worker_instance.h" 9 #include "content/browser/service_worker/embedded_worker_instance.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 10 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/common/service_worker/embedded_worker_messages.h" 11 #include "content/common/service_worker/embedded_worker_messages.h"
12 #include "content/common/service_worker/service_worker_messages.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/render_process_host.h"
11 #include "ipc/ipc_message.h" 15 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_sender.h" 16 #include "ipc/ipc_sender.h"
13 17
14 namespace content { 18 namespace content {
15 19
16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( 20 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry(
17 base::WeakPtr<ServiceWorkerContextCore> context) 21 base::WeakPtr<ServiceWorkerContextCore> context)
18 : context_(context), 22 : context_(context),
19 next_embedded_worker_id_(0) {} 23 next_embedded_worker_id_(0) {}
20 24
21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { 25 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() {
22 scoped_ptr<EmbeddedWorkerInstance> worker( 26 scoped_ptr<EmbeddedWorkerInstance> worker(
23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); 27 new EmbeddedWorkerInstance(this, next_embedded_worker_id_));
24 worker_map_[next_embedded_worker_id_++] = worker.get(); 28 worker_map_[next_embedded_worker_id_++] = worker.get();
25 return worker.Pass(); 29 return worker.Pass();
26 } 30 }
27 31
28 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker( 32 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker(
29 int process_id, 33 int process_id,
30 int embedded_worker_id, 34 int embedded_worker_id,
31 int64 service_worker_version_id, 35 int64 service_worker_version_id,
32 const GURL& scope, 36 const GURL& scope,
33 const GURL& script_url) { 37 const GURL& script_url,
38 int* worker_devtools_agent_route_id) {
39 ProcessToNextRoutingIDCallbackMap::iterator found_callback =
40 process_next_id_callback_map_.find(process_id);
41 if (found_callback == process_next_id_callback_map_.end())
42 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
43 *worker_devtools_agent_route_id = found_callback->second.Run();
34 return Send( 44 return Send(
35 process_id, 45 process_id,
36 new EmbeddedWorkerMsg_StartWorker( 46 new EmbeddedWorkerMsg_StartWorker(embedded_worker_id,
37 embedded_worker_id, service_worker_version_id, scope, script_url)); 47 service_worker_version_id,
48 scope,
49 script_url,
50 *worker_devtools_agent_route_id));
38 } 51 }
39 52
40 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( 53 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
41 int process_id, int embedded_worker_id) { 54 int process_id, int embedded_worker_id) {
42 return Send(process_id, 55 return Send(process_id,
43 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); 56 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
44 } 57 }
45 58
46 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) { 59 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) {
47 // TODO(kinuko): Move all EmbeddedWorker message handling from 60 // TODO(kinuko): Move all EmbeddedWorker message handling from
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 it != worker_set.end(); 141 it != worker_set.end();
129 ++it) { 142 ++it) {
130 int embedded_worker_id = *it; 143 int embedded_worker_id = *it;
131 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 144 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
132 worker_map_[embedded_worker_id]->OnStopped(); 145 worker_map_[embedded_worker_id]->OnStopped();
133 } 146 }
134 worker_process_map_.erase(found); 147 worker_process_map_.erase(found);
135 } 148 }
136 } 149 }
137 150
151 void EmbeddedWorkerRegistry::AddChildProcessNextRoutingIDCallback(
152 int process_id,
153 const base::Callback<int(void)>& callback) {
154 process_next_id_callback_map_.insert(std::make_pair(process_id, callback));
kinuko 2014/04/25 13:56:57 It might be nicer if AddChildProcessSender() can j
155 }
156
157 void EmbeddedWorkerRegistry::RemoveChildProcessNextRoutingIDCallback(
158 int process_id) {
159 process_next_id_callback_map_.erase(process_id);
160 }
161
138 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker( 162 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker(
139 int embedded_worker_id) { 163 int embedded_worker_id) {
140 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 164 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
141 if (found == worker_map_.end()) 165 if (found == worker_map_.end())
142 return NULL; 166 return NULL;
143 return found->second; 167 return found->second;
144 } 168 }
145 169
146 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {} 170 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {}
147 171
(...skipping 10 matching lines...) Expand all
158 } 182 }
159 183
160 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 184 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
161 int embedded_worker_id) { 185 int embedded_worker_id) {
162 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 186 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
163 worker_map_.erase(embedded_worker_id); 187 worker_map_.erase(embedded_worker_id);
164 worker_process_map_.erase(process_id); 188 worker_process_map_.erase(process_id);
165 } 189 }
166 190
167 } // namespace content 191 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698