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

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

Issue 252633003: Introduce worker_devtools_agent_route_id for EmbeddedWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RenderProcessHostImpl::GetNextRoutingIDForProcess Created 6 years, 8 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_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 10 matching lines...) Expand all
21 const GURL& script_url) { 21 const GURL& script_url) {
22 DCHECK(status_ == STOPPED); 22 DCHECK(status_ == STOPPED);
23 if (!ChooseProcess()) 23 if (!ChooseProcess())
24 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; 24 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
25 status_ = STARTING; 25 status_ = STARTING;
26 ServiceWorkerStatusCode status = 26 ServiceWorkerStatusCode status =
27 registry_->StartWorker(process_id_, 27 registry_->StartWorker(process_id_,
28 embedded_worker_id_, 28 embedded_worker_id_,
29 service_worker_version_id, 29 service_worker_version_id,
30 scope, 30 scope,
31 script_url); 31 script_url,
32 &worker_devtools_agent_route_id_);
32 if (status != SERVICE_WORKER_OK) { 33 if (status != SERVICE_WORKER_OK) {
33 status_ = STOPPED; 34 status_ = STOPPED;
34 process_id_ = -1; 35 process_id_ = -1;
36 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE;
35 } 37 }
36 return status; 38 return status;
37 } 39 }
38 40
39 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { 41 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() {
40 DCHECK(status_ == STARTING || status_ == RUNNING); 42 DCHECK(status_ == STARTING || status_ == RUNNING);
41 ServiceWorkerStatusCode status = 43 ServiceWorkerStatusCode status =
42 registry_->StopWorker(process_id_, embedded_worker_id_); 44 registry_->StopWorker(process_id_, embedded_worker_id_);
43 if (status == SERVICE_WORKER_OK) 45 if (status == SERVICE_WORKER_OK)
44 status_ = STOPPING; 46 status_ = STOPPING;
(...skipping 18 matching lines...) Expand all
63 void EmbeddedWorkerInstance::ReleaseProcessReference(int process_id) { 65 void EmbeddedWorkerInstance::ReleaseProcessReference(int process_id) {
64 ProcessRefMap::iterator found = process_refs_.find(process_id); 66 ProcessRefMap::iterator found = process_refs_.find(process_id);
65 if (found == process_refs_.end()) { 67 if (found == process_refs_.end()) {
66 NOTREACHED() << "Releasing unknown process ref " << process_id; 68 NOTREACHED() << "Releasing unknown process ref " << process_id;
67 return; 69 return;
68 } 70 }
69 if (--found->second == 0) 71 if (--found->second == 0)
70 process_refs_.erase(found); 72 process_refs_.erase(found);
71 } 73 }
72 74
73 EmbeddedWorkerInstance::EmbeddedWorkerInstance( 75 EmbeddedWorkerInstance::EmbeddedWorkerInstance(EmbeddedWorkerRegistry* registry,
74 EmbeddedWorkerRegistry* registry, 76 int embedded_worker_id)
75 int embedded_worker_id)
76 : registry_(registry), 77 : registry_(registry),
77 embedded_worker_id_(embedded_worker_id), 78 embedded_worker_id_(embedded_worker_id),
78 status_(STOPPED), 79 status_(STOPPED),
79 process_id_(-1), 80 process_id_(-1),
80 thread_id_(-1) { 81 thread_id_(-1),
82 worker_devtools_agent_route_id_(MSG_ROUTING_NONE) {
81 } 83 }
82 84
83 void EmbeddedWorkerInstance::OnStarted(int thread_id) { 85 void EmbeddedWorkerInstance::OnStarted(int thread_id) {
84 // Stop is requested before OnStarted is sent back from the worker. 86 // Stop is requested before OnStarted is sent back from the worker.
85 if (status_ == STOPPING) 87 if (status_ == STOPPING)
86 return; 88 return;
87 DCHECK(status_ == STARTING); 89 DCHECK(status_ == STARTING);
88 status_ = RUNNING; 90 status_ = RUNNING;
89 thread_id_ = thread_id; 91 thread_id_ = thread_id;
90 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); 92 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted());
91 } 93 }
92 94
93 void EmbeddedWorkerInstance::OnStopped() { 95 void EmbeddedWorkerInstance::OnStopped() {
94 status_ = STOPPED; 96 status_ = STOPPED;
95 process_id_ = -1; 97 process_id_ = -1;
96 thread_id_ = -1; 98 thread_id_ = -1;
99 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE;
97 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); 100 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped());
98 } 101 }
99 102
100 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { 103 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) {
101 ListenerList::Iterator it(listener_list_); 104 ListenerList::Iterator it(listener_list_);
102 while (Listener* listener = it.GetNext()) { 105 while (Listener* listener = it.GetNext()) {
103 if (listener->OnMessageReceived(message)) 106 if (listener->OnMessageReceived(message))
104 return true; 107 return true;
105 } 108 }
106 return false; 109 return false;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 max_ref_iter->second < iter->second) 152 max_ref_iter->second < iter->second)
150 max_ref_iter = iter; 153 max_ref_iter = iter;
151 } 154 }
152 if (max_ref_iter == process_refs_.end()) 155 if (max_ref_iter == process_refs_.end())
153 return false; 156 return false;
154 process_id_ = max_ref_iter->first; 157 process_id_ = max_ref_iter->first;
155 return true; 158 return true;
156 } 159 }
157 160
158 } // namespace content 161 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698