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

Side by Side Diff: chrome/browser/ui/webui/workers_ui.cc

Issue 9150017: Add a Content API around BrowserChildProcessHost, similar to what was done with ChildProcessHost.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix?! Created 8 years, 11 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/workers_ui.h" 5 #include "chrome/browser/ui/webui/workers_ui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/debugger/devtools_window.h" 14 #include "chrome/browser/debugger/devtools_window.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 16 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "content/browser/worker_host/worker_process_host.h" 19 #include "content/browser/worker_host/worker_process_host.h"
20 #include "content/public/browser/child_process_data.h"
20 #include "content/public/browser/devtools_agent_host_registry.h" 21 #include "content/public/browser/devtools_agent_host_registry.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_ui.h" 24 #include "content/public/browser/web_ui.h"
24 #include "content/public/browser/worker_service.h" 25 #include "content/public/browser/worker_service.h"
25 #include "content/public/browser/worker_service_observer.h" 26 #include "content/public/browser/worker_service_observer.h"
26 #include "content/public/browser/web_ui_message_handler.h" 27 #include "content/public/browser/web_ui_message_handler.h"
27 #include "content/public/common/process_type.h" 28 #include "content/public/common/process_type.h"
28 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
29 #include "grit/workers_resources.h" 30 #include "grit/workers_resources.h"
30 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
31 32
32 using content::BrowserThread; 33 using content::BrowserThread;
34 using content::ChildProcessData;
33 using content::DevToolsAgentHost; 35 using content::DevToolsAgentHost;
34 using content::DevToolsAgentHostRegistry; 36 using content::DevToolsAgentHostRegistry;
35 using content::WebContents; 37 using content::WebContents;
36 using content::WebUIMessageHandler; 38 using content::WebUIMessageHandler;
37 using content::WorkerService; 39 using content::WorkerService;
38 using content::WorkerServiceObserver; 40 using content::WorkerServiceObserver;
39 41
40 static const char kWorkersDataFile[] = "workers_data.json"; 42 static const char kWorkersDataFile[] = "workers_data.json";
41 43
42 static const char kOpenDevToolsCommand[] = "openDevTools"; 44 static const char kOpenDevToolsCommand[] = "openDevTools";
43 static const char kTerminateWorkerCommand[] = "terminateWorker"; 45 static const char kTerminateWorkerCommand[] = "terminateWorker";
44 46
45 static const char kWorkerProcessHostIdField[] = "workerProcessHostId"; 47 static const char kWorkerProcessHostIdField[] = "workerProcessHostId";
46 static const char kWorkerRouteIdField[] = "workerRouteId"; 48 static const char kWorkerRouteIdField[] = "workerRouteId";
47 static const char kUrlField[] = "url"; 49 static const char kUrlField[] = "url";
48 static const char kNameField[] = "name"; 50 static const char kNameField[] = "name";
49 static const char kPidField[] = "pid"; 51 static const char kPidField[] = "pid";
50 52
51 namespace { 53 namespace {
52 54
53 55
54 DictionaryValue* BuildWorkerData( 56 DictionaryValue* BuildWorkerData(const ChildProcessData& data,
55 WorkerProcessHost* process,
56 const WorkerProcessHost::WorkerInstance& instance) { 57 const WorkerProcessHost::WorkerInstance& instance) {
57 DictionaryValue* worker_data = new DictionaryValue(); 58 DictionaryValue* worker_data = new DictionaryValue();
58 worker_data->SetInteger(kWorkerProcessHostIdField, process->data().id); 59 worker_data->SetInteger(kWorkerProcessHostIdField, data.id);
59 worker_data->SetInteger(kWorkerRouteIdField, instance.worker_route_id()); 60 worker_data->SetInteger(kWorkerRouteIdField, instance.worker_route_id());
60 worker_data->SetString(kUrlField, instance.url().spec()); 61 worker_data->SetString(kUrlField, instance.url().spec());
61 worker_data->SetString(kNameField, instance.name()); 62 worker_data->SetString(kNameField, instance.name());
62 worker_data->SetInteger(kPidField, base::GetProcId(process->data().handle)); 63 worker_data->SetInteger(kPidField, base::GetProcId(data.handle));
63 return worker_data; 64 return worker_data;
64 } 65 }
65 66
66 class WorkersUIHTMLSource : public ChromeWebUIDataSource { 67 class WorkersUIHTMLSource : public ChromeWebUIDataSource {
67 public: 68 public:
68 WorkersUIHTMLSource(); 69 WorkersUIHTMLSource();
69 70
70 virtual void StartDataRequest(const std::string& path, 71 virtual void StartDataRequest(const std::string& path,
71 bool is_incognito, 72 bool is_incognito,
72 int request_id); 73 int request_id);
(...skipping 14 matching lines...) Expand all
87 int request_id) { 88 int request_id) {
88 if (path == kWorkersDataFile) { 89 if (path == kWorkersDataFile) {
89 SendSharedWorkersData(request_id); 90 SendSharedWorkersData(request_id);
90 } else { 91 } else {
91 ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id); 92 ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id);
92 } 93 }
93 } 94 }
94 95
95 void WorkersUIHTMLSource::SendSharedWorkersData(int request_id) { 96 void WorkersUIHTMLSource::SendSharedWorkersData(int request_id) {
96 ListValue workers_list; 97 ListValue workers_list;
97 BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); 98 for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) {
98 for (; !iter.Done(); ++iter) { 99 const WorkerProcessHost::Instances& instances = iter->instances();
99 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
100 const WorkerProcessHost::Instances& instances = worker->instances();
101 for (WorkerProcessHost::Instances::const_iterator i = instances.begin(); 100 for (WorkerProcessHost::Instances::const_iterator i = instances.begin();
102 i != instances.end(); ++i) { 101 i != instances.end(); ++i) {
103 workers_list.Append(BuildWorkerData(worker, *i)); 102 workers_list.Append(BuildWorkerData(iter.GetData(), *i));
104 } 103 }
105 } 104 }
106 105
107 std::string json_string; 106 std::string json_string;
108 base::JSONWriter::Write(&workers_list, false, &json_string); 107 base::JSONWriter::Write(&workers_list, false, &json_string);
109 108
110 SendResponse(request_id, base::RefCountedString::TakeString(&json_string)); 109 SendResponse(request_id, base::RefCountedString::TakeString(&json_string));
111 } 110 }
112 111
113 class WorkersDOMHandler : public WebUIMessageHandler { 112 class WorkersDOMHandler : public WebUIMessageHandler {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (!profile) 150 if (!profile)
152 return; 151 return;
153 DevToolsAgentHost* agent_host = 152 DevToolsAgentHost* agent_host =
154 DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( 153 DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker(
155 worker_process_host_id, 154 worker_process_host_id,
156 worker_route_id); 155 worker_route_id);
157 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); 156 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
158 } 157 }
159 158
160 static void TerminateWorker(int worker_process_id, int worker_route_id) { 159 static void TerminateWorker(int worker_process_id, int worker_route_id) {
161 for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); 160 for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) {
162 !iter.Done(); ++iter) { 161 if (iter.GetData().id == worker_process_id) {
163 if (iter->data().id == worker_process_id) { 162 iter->TerminateWorker(worker_route_id);
164 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
165 worker->TerminateWorker(worker_route_id);
166 return; 163 return;
167 } 164 }
168 } 165 }
169 } 166 }
170 167
171 void WorkersDOMHandler::HandleTerminateWorker(const ListValue* args) { 168 void WorkersDOMHandler::HandleTerminateWorker(const ListValue* args) {
172 std::string worker_process_host_id_str; 169 std::string worker_process_host_id_str;
173 std::string worker_route_id_str; 170 std::string worker_route_id_str;
174 int worker_process_host_id; 171 int worker_process_host_id;
175 int worker_route_id; 172 int worker_route_id;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 private: 206 private:
210 friend class base::RefCountedThreadSafe<WorkerCreationDestructionListener>; 207 friend class base::RefCountedThreadSafe<WorkerCreationDestructionListener>;
211 virtual ~WorkerCreationDestructionListener() { 208 virtual ~WorkerCreationDestructionListener() {
212 } 209 }
213 210
214 virtual void WorkerCreated( 211 virtual void WorkerCreated(
215 WorkerProcessHost* process, 212 WorkerProcessHost* process,
216 const WorkerProcessHost::WorkerInstance& instance) OVERRIDE { 213 const WorkerProcessHost::WorkerInstance& instance) OVERRIDE {
217 BrowserThread::PostTask( 214 BrowserThread::PostTask(
218 BrowserThread::UI, FROM_HERE, 215 BrowserThread::UI, FROM_HERE,
219 base::Bind(&WorkerCreationDestructionListener::NotifyWorkerCreated, 216 base::Bind(
220 this, base::Owned(BuildWorkerData(process, instance)))); 217 &WorkerCreationDestructionListener::NotifyWorkerCreated,
218 this, base::Owned(BuildWorkerData(process->GetData(), instance))));
221 } 219 }
222 virtual void WorkerDestroyed( 220 virtual void WorkerDestroyed(
223 WorkerProcessHost* process, 221 WorkerProcessHost* process,
224 int worker_route_id) OVERRIDE { 222 int worker_route_id) OVERRIDE {
225 DictionaryValue* worker_data = new DictionaryValue(); 223 DictionaryValue* worker_data = new DictionaryValue();
226 worker_data->SetInteger(kWorkerProcessHostIdField, process->data().id); 224 worker_data->SetInteger(kWorkerProcessHostIdField, process->GetData().id);
227 worker_data->SetInteger(kWorkerRouteIdField, worker_route_id); 225 worker_data->SetInteger(kWorkerRouteIdField, worker_route_id);
228 226
229 BrowserThread::PostTask( 227 BrowserThread::PostTask(
230 BrowserThread::UI, FROM_HERE, 228 BrowserThread::UI, FROM_HERE,
231 base::Bind(&WorkerCreationDestructionListener::NotifyWorkerDestroyed, 229 base::Bind(&WorkerCreationDestructionListener::NotifyWorkerDestroyed,
232 this, base::Owned(worker_data))); 230 this, base::Owned(worker_data)));
233 } 231 }
234 virtual void WorkerContextStarted(WorkerProcessHost*, int) OVERRIDE {} 232 virtual void WorkerContextStarted(WorkerProcessHost*, int) OVERRIDE {}
235 233
236 void NotifyWorkerCreated(DictionaryValue* worker_data) { 234 void NotifyWorkerCreated(DictionaryValue* worker_data) {
(...skipping 29 matching lines...) Expand all
266 264
267 // Set up the chrome://workers/ source. 265 // Set up the chrome://workers/ source.
268 Profile* profile = Profile::FromWebUI(web_ui); 266 Profile* profile = Profile::FromWebUI(web_ui);
269 profile->GetChromeURLDataManager()->AddDataSource(html_source); 267 profile->GetChromeURLDataManager()->AddDataSource(html_source);
270 } 268 }
271 269
272 WorkersUI::~WorkersUI() { 270 WorkersUI::~WorkersUI() {
273 observer_->WorkersUIDestroyed(); 271 observer_->WorkersUIDestroyed();
274 observer_ = NULL; 272 observer_ = NULL;
275 } 273 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/chromeos/user_image_source2.cc ('k') | chrome/browser/web_resource/web_resource_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698