[Ozone-Gbm] Explicitly crash if trying software rendering on GBM
[chromium-blink-merge.git] / content / browser / devtools / worker_devtools_agent_host.cc
bloba95a50e70b5eed15951a1224f1a70d80a0510cd3
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/devtools/worker_devtools_agent_host.h"
7 #include "content/browser/devtools/ipc_devtools_agent_host.h"
8 #include "content/browser/devtools/protocol/devtools_protocol_handler.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_process_host.h"
12 namespace content {
14 bool WorkerDevToolsAgentHost::IsWorker() const {
15 return true;
18 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() {
19 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first);
20 return rph ? rph->GetBrowserContext() : nullptr;
23 void WorkerDevToolsAgentHost::SendMessageToAgent(
24 IPC::Message* message_raw) {
25 scoped_ptr<IPC::Message> message(message_raw);
26 if (state_ != WORKER_INSPECTED)
27 return;
28 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) {
29 message->set_routing_id(worker_id_.second);
30 host->Send(message.release());
34 void WorkerDevToolsAgentHost::Attach() {
35 if (state_ != WORKER_INSPECTED) {
36 state_ = WORKER_INSPECTED;
37 AttachToWorker();
39 IPCDevToolsAgentHost::Attach();
42 void WorkerDevToolsAgentHost::OnClientAttached() {
43 DevToolsAgentHostImpl::NotifyCallbacks(this, true);
46 void WorkerDevToolsAgentHost::OnClientDetached() {
47 if (state_ == WORKER_INSPECTED) {
48 state_ = WORKER_UNINSPECTED;
49 DetachFromWorker();
50 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) {
51 state_ = WORKER_UNINSPECTED;
53 DevToolsAgentHostImpl::NotifyCallbacks(this, false);
56 bool WorkerDevToolsAgentHost::OnMessageReceived(
57 const IPC::Message& msg) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 bool handled = true;
60 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg)
61 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend,
62 OnDispatchOnInspectorFrontend)
63 IPC_MESSAGE_UNHANDLED(handled = false)
64 IPC_END_MESSAGE_MAP()
65 return handled;
68 void WorkerDevToolsAgentHost::WorkerReadyForInspection() {
69 if (state_ == WORKER_PAUSED_FOR_DEBUG_ON_START) {
70 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first);
71 Inspect(rph->GetBrowserContext());
72 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) {
73 DCHECK(IsAttached());
74 state_ = WORKER_INSPECTED;
75 AttachToWorker();
76 Reattach();
80 void WorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) {
81 DCHECK_EQ(WORKER_TERMINATED, state_);
82 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED;
83 worker_id_ = worker_id;
84 WorkerCreated();
87 void WorkerDevToolsAgentHost::WorkerDestroyed() {
88 DCHECK_NE(WORKER_TERMINATED, state_);
89 if (state_ == WORKER_INSPECTED) {
90 DCHECK(IsAttached());
91 // Client host is debugging this worker agent host.
92 base::Callback<void(const std::string&)> raw_message_callback(
93 base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
94 base::Unretained(this)));
95 devtools::worker::Client worker(raw_message_callback);
96 worker.DisconnectedFromWorker(
97 devtools::worker::DisconnectedFromWorkerParams::Create());
98 DetachFromWorker();
100 state_ = WORKER_TERMINATED;
101 Release(); // Balanced in WorkerCreated().
104 bool WorkerDevToolsAgentHost::IsTerminated() {
105 return state_ == WORKER_TERMINATED;
108 WorkerDevToolsAgentHost::WorkerDevToolsAgentHost(
109 WorkerId worker_id)
110 : state_(WORKER_UNINSPECTED),
111 worker_id_(worker_id) {
112 WorkerCreated();
115 WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() {
116 DCHECK_EQ(WORKER_TERMINATED, state_);
119 void WorkerDevToolsAgentHost::AttachToWorker() {
120 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
121 host->AddRoute(worker_id_.second, this);
124 void WorkerDevToolsAgentHost::DetachFromWorker() {
125 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
126 host->RemoveRoute(worker_id_.second);
129 void WorkerDevToolsAgentHost::WorkerCreated() {
130 AddRef(); // Balanced in WorkerDestroyed()
133 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend(
134 const DevToolsMessageChunk& message) {
135 if (!IsAttached())
136 return;
138 ProcessChunkedMessageFromAgent(message);
141 } // namespace content