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( ...@@ -30,7 +30,7 @@ DevtoolsClient::DevtoolsClient(
next_message_id_(0), next_message_id_(0),
frame_tracker_(this) { frame_tracker_(this) {
browser_main_thread_ = content::GetUIThreadTaskRunner({}); browser_main_thread_ = content::GetUIThreadTaskRunner({});
agent_host_->AttachClient(this); agent_host_->AttachClientWithoutWakeLock(this);
frame_tracker_.Start(); frame_tracker_.Start();
} }
......
...@@ -67,7 +67,8 @@ BrowserDevToolsAgentHost::~BrowserDevToolsAgentHost() { ...@@ -67,7 +67,8 @@ BrowserDevToolsAgentHost::~BrowserDevToolsAgentHost() {
BrowserDevToolsAgentHostInstances().erase(this); BrowserDevToolsAgentHostInstances().erase(this);
} }
bool BrowserDevToolsAgentHost::AttachSession(DevToolsSession* session) { bool BrowserDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
if (!session->GetClient()->MayAttachToBrowser()) if (!session->GetClient()->MayAttachToBrowser())
return false; return false;
......
...@@ -24,7 +24,7 @@ class BrowserDevToolsAgentHost : public DevToolsAgentHostImpl { ...@@ -24,7 +24,7 @@ class BrowserDevToolsAgentHost : public DevToolsAgentHostImpl {
~BrowserDevToolsAgentHost() override; ~BrowserDevToolsAgentHost() override;
// DevToolsAgentHostImpl overrides. // DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override; bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override; void DetachSession(DevToolsSession* session) override;
// DevToolsAgentHost implementation. // DevToolsAgentHost implementation.
......
...@@ -129,10 +129,16 @@ DevToolsSession* DevToolsAgentHostImpl::SessionByClient( ...@@ -129,10 +129,16 @@ DevToolsSession* DevToolsAgentHostImpl::SessionByClient(
bool DevToolsAgentHostImpl::AttachInternal( bool DevToolsAgentHostImpl::AttachInternal(
std::unique_ptr<DevToolsSession> session_owned) { 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); scoped_refptr<DevToolsAgentHostImpl> protect(this);
DevToolsSession* session = session_owned.get(); DevToolsSession* session = session_owned.get();
session->SetAgentHost(this); session->SetAgentHost(this);
if (!AttachSession(session)) if (!AttachSession(session, acquire_wake_lock))
return false; return false;
renderer_channel_.AttachSession(session); renderer_channel_.AttachSession(session);
sessions_.push_back(session); sessions_.push_back(session);
...@@ -151,7 +157,17 @@ bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { ...@@ -151,7 +157,17 @@ bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) {
if (SessionByClient(client)) if (SessionByClient(client))
return false; return false;
return AttachInternal( 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) { bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) {
...@@ -281,7 +297,8 @@ void DevToolsAgentHostImpl::ForceDetachRestrictedSessions( ...@@ -281,7 +297,8 @@ void DevToolsAgentHostImpl::ForceDetachRestrictedSessions(
} }
} }
bool DevToolsAgentHostImpl::AttachSession(DevToolsSession* session) { bool DevToolsAgentHostImpl::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
return false; return false;
} }
......
...@@ -30,6 +30,7 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { ...@@ -30,6 +30,7 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
public: public:
// DevToolsAgentHost implementation. // DevToolsAgentHost implementation.
bool AttachClient(DevToolsAgentHostClient* client) override; bool AttachClient(DevToolsAgentHostClient* client) override;
bool AttachClientWithoutWakeLock(DevToolsAgentHostClient* client) override;
bool DetachClient(DevToolsAgentHostClient* client) override; bool DetachClient(DevToolsAgentHostClient* client) override;
void DispatchProtocolMessage(DevToolsAgentHostClient* client, void DispatchProtocolMessage(DevToolsAgentHostClient* client,
base::span<const uint8_t> message) override; base::span<const uint8_t> message) override;
...@@ -72,7 +73,7 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { ...@@ -72,7 +73,7 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
static bool ShouldForceCreation(); static bool ShouldForceCreation();
// Returning |false| will block the attach. // 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 DetachSession(DevToolsSession* session);
virtual void UpdateRendererChannel(bool force); virtual void UpdateRendererChannel(bool force);
...@@ -93,6 +94,8 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { ...@@ -93,6 +94,8 @@ class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
friend class DevToolsRendererChannel; friend class DevToolsRendererChannel;
bool AttachInternal(std::unique_ptr<DevToolsSession> session); bool AttachInternal(std::unique_ptr<DevToolsSession> session);
bool AttachInternal(std::unique_ptr<DevToolsSession> session,
bool acquire_wake_lock);
void DetachInternal(DevToolsSession* session); void DetachInternal(DevToolsSession* session);
void NotifyAttached(); void NotifyAttached();
void NotifyDetached(); void NotifyDetached();
......
...@@ -19,7 +19,8 @@ ForwardingAgentHost::ForwardingAgentHost( ...@@ -19,7 +19,8 @@ ForwardingAgentHost::ForwardingAgentHost(
ForwardingAgentHost::~ForwardingAgentHost() = default; ForwardingAgentHost::~ForwardingAgentHost() = default;
bool ForwardingAgentHost::AttachSession(DevToolsSession* session) { bool ForwardingAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
session->TurnIntoExternalProxy(delegate_.get()); session->TurnIntoExternalProxy(delegate_.get());
return true; return true;
} }
......
...@@ -23,7 +23,7 @@ class ForwardingAgentHost : public DevToolsAgentHostImpl { ...@@ -23,7 +23,7 @@ class ForwardingAgentHost : public DevToolsAgentHostImpl {
~ForwardingAgentHost() override; ~ForwardingAgentHost() override;
// DevToolsAgentHostImpl overrides. // DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override; bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override; void DetachSession(DevToolsSession* session) override;
// DevToolsAgentHost implementation. // DevToolsAgentHost implementation.
......
...@@ -285,7 +285,8 @@ WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { ...@@ -285,7 +285,8 @@ WebContents* RenderFrameDevToolsAgentHost::GetWebContents() {
return web_contents(); return web_contents();
} }
bool RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) { bool RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
if (!ShouldAllowSession(session)) if (!ShouldAllowSession(session))
return false; return false;
...@@ -358,7 +359,8 @@ bool RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) { ...@@ -358,7 +359,8 @@ bool RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) {
#endif #endif
UpdateRawHeadersAccess(nullptr, frame_host_); UpdateRawHeadersAccess(nullptr, frame_host_);
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
GetWakeLock()->RequestWakeLock(); if (acquire_wake_lock)
GetWakeLock()->RequestWakeLock();
#endif #endif
} }
return true; return true;
......
...@@ -117,7 +117,7 @@ class CONTENT_EXPORT RenderFrameDevToolsAgentHost ...@@ -117,7 +117,7 @@ class CONTENT_EXPORT RenderFrameDevToolsAgentHost
~RenderFrameDevToolsAgentHost() override; ~RenderFrameDevToolsAgentHost() override;
// DevToolsAgentHostImpl overrides. // DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override; bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override; void DetachSession(DevToolsSession* session) override;
void InspectElement(RenderFrameHost* frame_host, int x, int y) override; void InspectElement(RenderFrameHost* frame_host, int x, int y) override;
void UpdateRendererChannel(bool force) override; void UpdateRendererChannel(bool force) override;
......
...@@ -127,7 +127,8 @@ ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() { ...@@ -127,7 +127,8 @@ ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() {
ServiceWorkerDevToolsManager::GetInstance()->AgentHostDestroyed(this); 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::InspectorHandler()));
session->AddHandler(base::WrapUnique(new protocol::NetworkHandler( session->AddHandler(base::WrapUnique(new protocol::NetworkHandler(
GetId(), devtools_worker_token_, GetIOContext(), base::DoNothing()))); GetId(), devtools_worker_token_, GetIOContext(), base::DoNothing())));
......
...@@ -86,7 +86,7 @@ class ServiceWorkerDevToolsAgentHost : public DevToolsAgentHostImpl { ...@@ -86,7 +86,7 @@ class ServiceWorkerDevToolsAgentHost : public DevToolsAgentHostImpl {
void UpdateIsAttached(bool attached); void UpdateIsAttached(bool attached);
// DevToolsAgentHostImpl overrides. // DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override; bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override; void DetachSession(DevToolsSession* session) override;
void UpdateLoaderFactories(base::OnceClosure callback); void UpdateLoaderFactories(base::OnceClosure callback);
......
...@@ -69,7 +69,8 @@ bool SharedWorkerDevToolsAgentHost::Close() { ...@@ -69,7 +69,8 @@ bool SharedWorkerDevToolsAgentHost::Close() {
return true; 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::InspectorHandler>());
session->AddHandler(std::make_unique<protocol::NetworkHandler>( session->AddHandler(std::make_unique<protocol::NetworkHandler>(
GetId(), devtools_worker_token_, GetIOContext(), GetId(), devtools_worker_token_, GetIOContext(),
......
...@@ -50,7 +50,7 @@ class SharedWorkerDevToolsAgentHost : public DevToolsAgentHostImpl { ...@@ -50,7 +50,7 @@ class SharedWorkerDevToolsAgentHost : public DevToolsAgentHostImpl {
~SharedWorkerDevToolsAgentHost() override; ~SharedWorkerDevToolsAgentHost() override;
// DevToolsAgentHostImpl overrides. // DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override; bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override; void DetachSession(DevToolsSession* session) override;
enum WorkerState { enum WorkerState {
......
...@@ -79,7 +79,8 @@ bool WorkerDevToolsAgentHost::Close() { ...@@ -79,7 +79,8 @@ bool WorkerDevToolsAgentHost::Close() {
return false; return false;
} }
bool WorkerDevToolsAgentHost::AttachSession(DevToolsSession* session) { bool WorkerDevToolsAgentHost::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) {
session->AddHandler(std::make_unique<protocol::TargetHandler>( session->AddHandler(std::make_unique<protocol::TargetHandler>(
protocol::TargetHandler::AccessMode::kAutoAttachOnly, GetId(), protocol::TargetHandler::AccessMode::kAutoAttachOnly, GetId(),
GetRendererChannel(), session->GetRootSession())); GetRendererChannel(), session->GetRootSession()));
......
...@@ -40,7 +40,7 @@ class WorkerDevToolsAgentHost : public DevToolsAgentHostImpl { ...@@ -40,7 +40,7 @@ class WorkerDevToolsAgentHost : public DevToolsAgentHostImpl {
void Disconnected(); void Disconnected();
// DevToolsAgentHostImpl overrides. // DevToolsAgentHostImpl overrides.
bool AttachSession(DevToolsSession* session) override; bool AttachSession(DevToolsSession* session, bool acquire_wake_lock) override;
void DetachSession(DevToolsSession* session) override; void DetachSession(DevToolsSession* session) override;
const int process_id_; const int process_id_;
......
...@@ -126,6 +126,9 @@ class CONTENT_EXPORT DevToolsAgentHost ...@@ -126,6 +126,9 @@ class CONTENT_EXPORT DevToolsAgentHost
// embedder or |client| itself may prevent attaching. // embedder or |client| itself may prevent attaching.
virtual bool AttachClient(DevToolsAgentHostClient* client) = 0; 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. // Already attached client detaches from this agent host to stop debugging it.
// Returns true iff detach succeeded. // Returns true iff detach succeeded.
virtual bool DetachClient(DevToolsAgentHostClient* client) = 0; 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