Commit baeb23f1 authored by Michele Mancina's avatar Michele Mancina Committed by Commit Bot

Add parameter to control whether to aquire the wake lock or not.

Bug: b/161674018
Change-Id: If93e5eaab7391fad3af8b29d4030a6cc43d47737
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2360070
Commit-Queue: Michele Mancina <micantox@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801297}
parent 8d185aa7
......@@ -30,7 +30,7 @@ DevtoolsClient::DevtoolsClient(
next_message_id_(0),
frame_tracker_(this) {
browser_main_thread_ = content::GetUIThreadTaskRunner({});
agent_host_->AttachClient(this);
agent_host_->AttachClientWithoutWakeLock(this);
frame_tracker_.Start();
}
......
......@@ -67,7 +67,8 @@ BrowserDevToolsAgentHost::~BrowserDevToolsAgentHost() {
BrowserDevToolsAgentHostInstances().erase(this);
}
bool BrowserDevToolsAgentHost::AttachSession(DevToolsSession* session) {
bool BrowserDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
if (!session->GetClient()->MayAttachToBrowser())
return false;
......
......@@ -24,7 +24,7 @@ class BrowserDevToolsAgentHost : public DevToolsAgentHostImpl {
~BrowserDevToolsAgentHost() override;
// DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override;
bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override;
// DevToolsAgentHost implementation.
......
......@@ -129,10 +129,16 @@ DevToolsSession* DevToolsAgentHostImpl::SessionByClient(
bool DevToolsAgentHostImpl::AttachInternal(
std::unique_ptr<DevToolsSession> session_owned) {
return AttachInternal(std::move(session_owned), true);
}
bool DevToolsAgentHostImpl::AttachInternal(
std::unique_ptr<DevToolsSession> session_owned,
bool acquire_wake_lock) {
scoped_refptr<DevToolsAgentHostImpl> protect(this);
DevToolsSession* session = session_owned.get();
session->SetAgentHost(this);
if (!AttachSession(session))
if (!AttachSession(session, acquire_wake_lock))
return false;
renderer_channel_.AttachSession(session);
sessions_.push_back(session);
......@@ -151,7 +157,17 @@ bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) {
if (SessionByClient(client))
return false;
return AttachInternal(
std::make_unique<DevToolsSession>(client, /*session_id=*/""));
std::make_unique<DevToolsSession>(client, /*session_id=*/""),
/*acquire_wake_lock=*/true);
}
bool DevToolsAgentHostImpl::AttachClientWithoutWakeLock(
content::DevToolsAgentHostClient* client) {
if (SessionByClient(client))
return false;
return AttachInternal(
std::make_unique<DevToolsSession>(client, /*session_id=*/""),
/*acquire_wake_lock=*/false);
}
bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) {
......@@ -281,7 +297,8 @@ void DevToolsAgentHostImpl::ForceDetachRestrictedSessions(
}
}
bool DevToolsAgentHostImpl::AttachSession(DevToolsSession* session) {
bool DevToolsAgentHostImpl::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
return false;
}
......
......@@ -30,6 +30,7 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
public:
// DevToolsAgentHost implementation.
bool AttachClient(DevToolsAgentHostClient* client) override;
bool AttachClientWithoutWakeLock(DevToolsAgentHostClient* client) override;
bool DetachClient(DevToolsAgentHostClient* client) override;
void DispatchProtocolMessage(DevToolsAgentHostClient* client,
base::span<const uint8_t> message) override;
......@@ -72,7 +73,7 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
static bool ShouldForceCreation();
// Returning |false| will block the attach.
virtual bool AttachSession(DevToolsSession* session);
virtual bool AttachSession(DevToolsSession* session, bool acquire_wake_lock);
virtual void DetachSession(DevToolsSession* session);
virtual void UpdateRendererChannel(bool force);
......@@ -93,6 +94,8 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
friend class DevToolsRendererChannel;
bool AttachInternal(std::unique_ptr<DevToolsSession> session);
bool AttachInternal(std::unique_ptr<DevToolsSession> session,
bool acquire_wake_lock);
void DetachInternal(DevToolsSession* session);
void NotifyAttached();
void NotifyDetached();
......
......@@ -19,7 +19,8 @@ ForwardingAgentHost::ForwardingAgentHost(
ForwardingAgentHost::~ForwardingAgentHost() = default;
bool ForwardingAgentHost::AttachSession(DevToolsSession* session) {
bool ForwardingAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
session->TurnIntoExternalProxy(delegate_.get());
return true;
}
......
......@@ -23,7 +23,7 @@ class ForwardingAgentHost : public DevToolsAgentHostImpl {
~ForwardingAgentHost() override;
// DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override;
bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override;
// DevToolsAgentHost implementation.
......
......@@ -285,7 +285,8 @@ WebContents* RenderFrameDevToolsAgentHost::GetWebContents() {
return web_contents();
}
bool RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) {
bool RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
if (!ShouldAllowSession(session))
return false;
......@@ -358,7 +359,8 @@ bool RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) {
#endif
UpdateRawHeadersAccess(nullptr, frame_host_);
#if defined(OS_ANDROID)
GetWakeLock()->RequestWakeLock();
if (acquire_wake_lock)
GetWakeLock()->RequestWakeLock();
#endif
}
return true;
......
......@@ -117,7 +117,7 @@ class CONTENT_EXPORT RenderFrameDevToolsAgentHost
~RenderFrameDevToolsAgentHost() override;
// DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override;
bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override;
void InspectElement(RenderFrameHost* frame_host, int x, int y) override;
void UpdateRendererChannel(bool force) override;
......
......@@ -127,7 +127,8 @@ ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() {
ServiceWorkerDevToolsManager::GetInstance()->AgentHostDestroyed(this);
}
bool ServiceWorkerDevToolsAgentHost::AttachSession(DevToolsSession* session) {
bool ServiceWorkerDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
session->AddHandler(base::WrapUnique(new protocol::InspectorHandler()));
session->AddHandler(base::WrapUnique(new protocol::NetworkHandler(
GetId(), devtools_worker_token_, GetIOContext(), base::DoNothing())));
......
......@@ -86,7 +86,7 @@ class ServiceWorkerDevToolsAgentHost : public DevToolsAgentHostImpl {
void UpdateIsAttached(bool attached);
// DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override;
bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override;
void UpdateLoaderFactories(base::OnceClosure callback);
......
......@@ -69,7 +69,8 @@ bool SharedWorkerDevToolsAgentHost::Close() {
return true;
}
bool SharedWorkerDevToolsAgentHost::AttachSession(DevToolsSession* session) {
bool SharedWorkerDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
session->AddHandler(std::make_unique<protocol::InspectorHandler>());
session->AddHandler(std::make_unique<protocol::NetworkHandler>(
GetId(), devtools_worker_token_, GetIOContext(),
......
......@@ -50,7 +50,7 @@ class SharedWorkerDevToolsAgentHost : public DevToolsAgentHostImpl {
~SharedWorkerDevToolsAgentHost() override;
// DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override;
bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override;
enum WorkerState {
......
......@@ -79,7 +79,8 @@ bool WorkerDevToolsAgentHost::Close() {
return false;
}
bool WorkerDevToolsAgentHost::AttachSession(DevToolsSession* session) {
bool WorkerDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
session->AddHandler(std::make_unique<protocol::TargetHandler>(
protocol::TargetHandler::AccessMode::kAutoAttachOnly, GetId(),
GetRendererChannel(), session->GetRootSession()));
......
......@@ -40,7 +40,7 @@ class WorkerDevToolsAgentHost : public DevToolsAgentHostImpl {
void Disconnected();
// DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override;
bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override;
const int process_id_;
......
......@@ -126,6 +126,9 @@ class CONTENT_EXPORT DevToolsAgentHost
// embedder or |client| itself may prevent attaching.
virtual bool AttachClient(DevToolsAgentHostClient* client) = 0;
// Same as the above, but does not acquire the WakeLock.
virtual bool AttachClientWithoutWakeLock(DevToolsAgentHostClient* client) = 0;
// Already attached client detaches from this agent host to stop debugging it.
// Returns true iff detach succeeded.
virtual bool DetachClient(DevToolsAgentHostClient* client) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment