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

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

Issue 261753008: Call EmbeddedWorkerDevToolsManager::ServiceWorkerCreated, WorkerContextStarted and WorkerDestroyed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delete ServiceWorkerStorage::path() 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_instance.h" 5 #include "content/browser/service_worker/embedded_worker_instance.h"
6 6
7 #include "content/browser/devtools/embedded_worker_devtools_manager.h"
7 #include "content/browser/service_worker/embedded_worker_registry.h" 8 #include "content/browser/service_worker/embedded_worker_registry.h"
8 #include "content/common/service_worker/embedded_worker_messages.h" 9 #include "content/common/service_worker/embedded_worker_messages.h"
10 #include "content/public/browser/browser_thread.h"
9 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
10 #include "url/gurl.h" 12 #include "url/gurl.h"
11 13
12 namespace content { 14 namespace content {
13 15
14 namespace { 16 namespace {
15 // Functor to sort by the .second element of a struct. 17 // Functor to sort by the .second element of a struct.
16 struct SecondGreater { 18 struct SecondGreater {
17 template <typename Value> 19 template <typename Value>
18 bool operator()(const Value& lhs, const Value& rhs) { 20 bool operator()(const Value& lhs, const Value& rhs) {
19 return lhs.second > rhs.second; 21 return lhs.second > rhs.second;
20 } 22 }
21 }; 23 };
24
25 void NotifyWorkerContextStartedOnUI(int worker_process_id,
26 int worker_route_id) {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
28 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerContextStarted(
29 worker_process_id, worker_route_id);
30 }
31
32 void NotifyWorkerDestroyedOnUI(int worker_process_id, int worker_route_id) {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed(
35 worker_process_id, worker_route_id);
36 }
kinuko 2014/05/02 11:12:45 This part... and GetRoutingIDAndNotifyWorkerCreate
horo 2014/05/07 08:34:44 Introduced DevToolsManagerBridge and moved DevTool
37
22 } // namespace 38 } // namespace
23 39
24 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { 40 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() {
25 registry_->RemoveWorker(process_id_, embedded_worker_id_); 41 registry_->RemoveWorker(process_id_, embedded_worker_id_);
26 } 42 }
27 43
28 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, 44 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id,
29 const GURL& scope, 45 const GURL& scope,
30 const GURL& script_url, 46 const GURL& script_url,
31 const std::vector<int>& possible_process_ids, 47 const std::vector<int>& possible_process_ids,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 DCHECK_EQ(worker_devtools_agent_route_id_, MSG_ROUTING_NONE); 109 DCHECK_EQ(worker_devtools_agent_route_id_, MSG_ROUTING_NONE);
94 if (status == SERVICE_WORKER_OK) { 110 if (status == SERVICE_WORKER_OK) {
95 process_id_ = process_id; 111 process_id_ = process_id;
96 worker_devtools_agent_route_id_ = worker_devtools_agent_route_id; 112 worker_devtools_agent_route_id_ = worker_devtools_agent_route_id;
97 } else { 113 } else {
98 status_ = STOPPED; 114 status_ = STOPPED;
99 } 115 }
100 } 116 }
101 117
102 void EmbeddedWorkerInstance::OnScriptLoaded() { 118 void EmbeddedWorkerInstance::OnScriptLoaded() {
103 // TODO(horo): Implement this. 119 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) {
120 BrowserThread::PostTask(BrowserThread::UI,
121 FROM_HERE,
122 base::Bind(NotifyWorkerContextStartedOnUI,
123 process_id_,
124 worker_devtools_agent_route_id_));
125 }
104 } 126 }
105 127
106 void EmbeddedWorkerInstance::OnScriptLoadFailed() { 128 void EmbeddedWorkerInstance::OnScriptLoadFailed() {
107 } 129 }
108 130
109 void EmbeddedWorkerInstance::OnStarted(int thread_id) { 131 void EmbeddedWorkerInstance::OnStarted(int thread_id) {
110 // Stop is requested before OnStarted is sent back from the worker. 132 // Stop is requested before OnStarted is sent back from the worker.
111 if (status_ == STOPPING) 133 if (status_ == STOPPING)
112 return; 134 return;
113 DCHECK(status_ == STARTING); 135 DCHECK(status_ == STARTING);
114 status_ = RUNNING; 136 status_ = RUNNING;
115 thread_id_ = thread_id; 137 thread_id_ = thread_id;
116 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); 138 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted());
117 } 139 }
118 140
119 void EmbeddedWorkerInstance::OnStopped() { 141 void EmbeddedWorkerInstance::OnStopped() {
142 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) {
143 BrowserThread::PostTask(BrowserThread::UI,
144 FROM_HERE,
145 base::Bind(NotifyWorkerDestroyedOnUI,
146 process_id_,
147 worker_devtools_agent_route_id_));
148 }
120 status_ = STOPPED; 149 status_ = STOPPED;
121 process_id_ = -1; 150 process_id_ = -1;
122 thread_id_ = -1; 151 thread_id_ = -1;
123 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE; 152 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE;
124 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); 153 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped());
125 } 154 }
126 155
127 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { 156 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) {
128 ListenerList::Iterator it(listener_list_); 157 ListenerList::Iterator it(listener_list_);
129 while (Listener* listener = it.GetNext()) { 158 while (Listener* listener = it.GetNext()) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // Sort descending by the reference count. 210 // Sort descending by the reference count.
182 std::sort(counted.begin(), counted.end(), SecondGreater()); 211 std::sort(counted.begin(), counted.end(), SecondGreater());
183 212
184 std::vector<int> result(counted.size()); 213 std::vector<int> result(counted.size());
185 for (size_t i = 0; i < counted.size(); ++i) 214 for (size_t i = 0; i < counted.size(); ++i)
186 result[i] = counted[i].first; 215 result[i] = counted[i].first;
187 return result; 216 return result;
188 } 217 }
189 218
190 } // namespace content 219 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698