Commit 52083d87 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Migrate more agents to the new InspectorSessionState.

- InspectorWorkerAgent
- InspectorTracingAgent
- InspectorAnimationAgent
- InspectorPageAgent (started earlier)

For reference the PR that introduced the new
InspectorSessionState / InspectorAgentState / Fields
was https://chromium-review.googlesource.com/c/chromium/src/+/1149201.

Change-Id: Id0e94a9c944341fa2c08dcb3d7bfb00c4b437614
Reviewed-on: https://chromium-review.googlesource.com/1152695Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578877}
parent d8d5fff4
......@@ -33,11 +33,6 @@
#include "third_party/blink/renderer/platform/animation/timing_function.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
namespace AnimationAgentState {
static const char animationAgentEnabled[] = "animationAgentEnabled";
static const char animationAgentPlaybackRate[] = "animationAgentPlaybackRate";
} // namespace AnimationAgentState
namespace blink {
using protocol::Response;
......@@ -49,30 +44,26 @@ InspectorAnimationAgent::InspectorAnimationAgent(
: inspected_frames_(inspected_frames),
css_agent_(css_agent),
v8_session_(v8_session),
is_cloning_(false) {}
is_cloning_(false),
enabled_(&agent_state_, /*default_value=*/false),
playback_rate_(&agent_state_, /*default_value=*/1.0) {}
void InspectorAnimationAgent::Restore() {
if (state_->booleanProperty(AnimationAgentState::animationAgentEnabled,
false)) {
enable();
double playback_rate = 1;
state_->getDouble(AnimationAgentState::animationAgentPlaybackRate,
&playback_rate);
setPlaybackRate(playback_rate);
}
if (enabled_.Get())
setPlaybackRate(playback_rate_.Get());
}
Response InspectorAnimationAgent::enable() {
state_->setBoolean(AnimationAgentState::animationAgentEnabled, true);
enabled_.Set(true);
instrumenting_agents_->addInspectorAnimationAgent(this);
return Response::OK();
}
Response InspectorAnimationAgent::disable() {
setPlaybackRate(1);
setPlaybackRate(1.0);
for (const auto& clone : id_to_animation_clone_.Values())
clone->cancel();
state_->setBoolean(AnimationAgentState::animationAgentEnabled, false);
enabled_.Clear();
instrumenting_agents_->removeInspectorAnimationAgent(this);
id_to_animation_.clear();
id_to_animation_type_.clear();
......@@ -88,10 +79,7 @@ void InspectorAnimationAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) {
id_to_animation_clone_.clear();
cleared_animations_.clear();
}
double playback_rate = 1;
state_->getDouble(AnimationAgentState::animationAgentPlaybackRate,
&playback_rate);
setPlaybackRate(playback_rate);
setPlaybackRate(playback_rate_.Get());
}
static std::unique_ptr<protocol::Animation::AnimationEffect>
......@@ -234,8 +222,7 @@ Response InspectorAnimationAgent::getPlaybackRate(double* playback_rate) {
Response InspectorAnimationAgent::setPlaybackRate(double playback_rate) {
for (LocalFrame* frame : *inspected_frames_)
frame->GetDocument()->Timeline().SetPlaybackRate(playback_rate);
state_->setDouble(AnimationAgentState::animationAgentPlaybackRate,
playback_rate);
playback_rate_.Set(playback_rate);
return Response::OK();
}
......@@ -525,8 +512,7 @@ void InspectorAnimationAgent::AnimationPlayStateChanged(
void InspectorAnimationAgent::DidClearDocumentOfWindowObject(
LocalFrame* frame) {
if (!state_->booleanProperty(AnimationAgentState::animationAgentEnabled,
false))
if (!enabled_.Get())
return;
DCHECK(frame->GetDocument());
frame->GetDocument()->Timeline().SetPlaybackRate(
......
......@@ -90,6 +90,8 @@ class CORE_EXPORT InspectorAnimationAgent final
HashMap<String, String> id_to_animation_type_;
bool is_cloning_;
HashSet<String> cleared_animations_;
InspectorAgentState::Boolean enabled_;
InspectorAgentState::Double playback_rate_;
DISALLOW_COPY_AND_ASSIGN(InspectorAnimationAgent);
};
......
......@@ -239,11 +239,24 @@ class CORE_EXPORT InspectorPageAgent final
long last_script_identifier_;
String pending_script_to_evaluate_on_load_once_;
String script_to_evaluate_on_load_once_;
bool enabled_;
bool reloading_;
Member<InspectorResourceContentLoader> inspector_resource_content_loader_;
int resource_content_loader_client_id_;
InspectorAgentState::Boolean enabled_;
InspectorAgentState::Boolean screencast_enabled_;
InspectorAgentState::Boolean lifecycle_events_enabled_;
InspectorAgentState::Boolean bypass_csp_enabled_;
InspectorAgentState::StringMap scripts_to_evaluate_on_load_;
InspectorAgentState::String standard_font_family_;
InspectorAgentState::String fixed_font_family_;
InspectorAgentState::String serif_font_family_;
InspectorAgentState::String sans_serif_font_family_;
InspectorAgentState::String cursive_font_family_;
InspectorAgentState::String fantasy_font_family_;
InspectorAgentState::String pictograph_font_family_;
InspectorAgentState::Integer standard_font_size_;
InspectorAgentState::Integer fixed_font_size_;
InspectorAgentState::Boolean produce_compilation_cache_;
DISALLOW_COPY_AND_ASSIGN(InspectorPageAgent);
};
......
......@@ -15,17 +15,14 @@ namespace blink {
using protocol::Maybe;
using protocol::Response;
namespace TracingAgentState {
const char kSessionId[] = "sessionId";
}
namespace {
const char kDevtoolsMetadataEventCategory[] =
TRACE_DISABLED_BY_DEFAULT("devtools.timeline");
}
InspectorTracingAgent::InspectorTracingAgent(InspectedFrames* inspected_frames)
: inspected_frames_(inspected_frames) {}
: session_id_(&agent_state_, /*default_value=*/ WTF::String()),
inspected_frames_(inspected_frames) {}
InspectorTracingAgent::~InspectorTracingAgent() {}
......@@ -35,7 +32,6 @@ void InspectorTracingAgent::Trace(blink::Visitor* visitor) {
}
void InspectorTracingAgent::Restore() {
state_->getString(TracingAgentState::kSessionId, &session_id_);
if (IsStarted())
EmitMetadataEvents();
}
......@@ -54,8 +50,7 @@ void InspectorTracingAgent::start(Maybe<String> categories,
return;
}
session_id_ = IdentifiersFactory::CreateIdentifier();
state_->setString(TracingAgentState::kSessionId, session_id_);
session_id_.Set(IdentifiersFactory::CreateIdentifier());
// Tracing is already started by DevTools TracingHandler::Start for the
// renderer target in the browser process. It will eventually start tracing
......@@ -75,14 +70,14 @@ void InspectorTracingAgent::end(std::unique_ptr<EndCallback> callback) {
}
bool InspectorTracingAgent::IsStarted() const {
return !session_id_.IsEmpty();
return !session_id_.Get().IsEmpty();
}
void InspectorTracingAgent::EmitMetadataEvents() {
TRACE_EVENT_INSTANT1(kDevtoolsMetadataEventCategory, "TracingStartedInPage",
TRACE_EVENT_SCOPE_THREAD, "data",
InspectorTracingStartedInFrame::Data(
session_id_, inspected_frames_->Root()));
session_id_.Get(), inspected_frames_->Root()));
}
Response InspectorTracingAgent::disable() {
......@@ -91,8 +86,7 @@ Response InspectorTracingAgent::disable() {
}
void InspectorTracingAgent::InnerDisable() {
state_->remove(TracingAgentState::kSessionId);
session_id_ = String();
session_id_.Clear();
}
} // namespace blink
......@@ -44,7 +44,7 @@ class CORE_EXPORT InspectorTracingAgent final
void InnerDisable();
bool IsStarted() const;
String session_id_;
InspectorAgentState::String session_id_;
Member<InspectedFrames> inspected_frames_;
DISALLOW_COPY_AND_ASSIGN(InspectorTracingAgent);
......
......@@ -44,52 +44,47 @@ namespace blink {
using protocol::Maybe;
using protocol::Response;
namespace WorkerAgentState {
static const char kAutoAttach[] = "autoAttach";
static const char kWaitForDebuggerOnStart[] = "waitForDebuggerOnStart";
static const char kAttachedSessionIds[] = "attachedSessionIds";
}; // namespace WorkerAgentState
int InspectorWorkerAgent::s_last_connection_ = 0;
InspectorWorkerAgent::InspectorWorkerAgent(
InspectedFrames* inspected_frames,
WorkerGlobalScope* worker_global_scope)
: inspected_frames_(inspected_frames),
worker_global_scope_(worker_global_scope) {}
worker_global_scope_(worker_global_scope),
auto_attach_(&agent_state_, /*default_value=*/ false),
wait_for_debugger_on_start_(&agent_state_, /*default_value=*/ false),
attached_session_ids_(&agent_state_, /*default_value*/ false) {}
InspectorWorkerAgent::~InspectorWorkerAgent() = default;
void InspectorWorkerAgent::Restore() {
if (!AutoAttachEnabled())
if (!auto_attach_.Get())
return;
instrumenting_agents_->addInspectorWorkerAgent(this);
protocol::DictionaryValue* attached = AttachedSessionIds();
for (size_t i = 0; i < attached->size(); ++i)
GetFrontend()->detachedFromTarget(attached->at(i).first);
state_->remove(WorkerAgentState::kAttachedSessionIds);
for (const WTF::String& session_id : attached_session_ids_.Keys())
GetFrontend()->detachedFromTarget(session_id);
attached_session_ids_.ClearAll();
ConnectToAllProxies();
}
Response InspectorWorkerAgent::disable() {
if (AutoAttachEnabled()) {
if (auto_attach_.Get()) {
DisconnectFromAllProxies(false);
instrumenting_agents_->removeInspectorWorkerAgent(this);
}
state_->setBoolean(WorkerAgentState::kAutoAttach, false);
state_->setBoolean(WorkerAgentState::kWaitForDebuggerOnStart, false);
state_->remove(WorkerAgentState::kAttachedSessionIds);
auto_attach_.Clear();
wait_for_debugger_on_start_.Clear();
attached_session_ids_.ClearAll();
return Response::OK();
}
Response InspectorWorkerAgent::setAutoAttach(bool auto_attach,
bool wait_for_debugger_on_start) {
state_->setBoolean(WorkerAgentState::kWaitForDebuggerOnStart,
wait_for_debugger_on_start);
wait_for_debugger_on_start_.Set(wait_for_debugger_on_start);
if (auto_attach == AutoAttachEnabled())
if (auto_attach == auto_attach_.Get())
return Response::OK();
state_->setBoolean(WorkerAgentState::kAutoAttach, auto_attach);
auto_attach_.Set(auto_attach);
if (auto_attach) {
instrumenting_agents_->addInspectorWorkerAgent(this);
ConnectToAllProxies();
......@@ -100,10 +95,6 @@ Response InspectorWorkerAgent::setAutoAttach(bool auto_attach,
return Response::OK();
}
bool InspectorWorkerAgent::AutoAttachEnabled() {
return state_->booleanProperty(WorkerAgentState::kAutoAttach, false);
}
Response InspectorWorkerAgent::sendMessageToTarget(const String& message,
Maybe<String> session_id,
Maybe<String> target_id) {
......@@ -134,26 +125,25 @@ Response InspectorWorkerAgent::sendMessageToTarget(const String& message,
}
void InspectorWorkerAgent::ShouldWaitForDebuggerOnWorkerStart(bool* result) {
if (AutoAttachEnabled() &&
state_->booleanProperty(WorkerAgentState::kWaitForDebuggerOnStart, false))
if (auto_attach_.Get() && wait_for_debugger_on_start_.Get())
*result = true;
}
void InspectorWorkerAgent::DidStartWorker(WorkerInspectorProxy* proxy,
bool waiting_for_debugger) {
DCHECK(GetFrontend() && AutoAttachEnabled());
DCHECK(GetFrontend() && auto_attach_.Get());
ConnectToProxy(proxy, waiting_for_debugger);
}
void InspectorWorkerAgent::WorkerTerminated(WorkerInspectorProxy* proxy) {
DCHECK(GetFrontend() && AutoAttachEnabled());
DCHECK(GetFrontend() && auto_attach_.Get());
Vector<String> session_ids;
for (auto& it : session_id_to_connection_) {
if (connected_proxies_.at(it.value) == proxy)
session_ids.push_back(it.key);
}
for (const String& session_id : session_ids) {
AttachedSessionIds()->remove(session_id);
attached_session_ids_.Clear(session_id);
GetFrontend()->detachedFromTarget(session_id, proxy->InspectorId());
int connection = session_id_to_connection_.at(session_id);
proxy->DisconnectFromInspector(connection, this);
......@@ -186,7 +176,7 @@ void InspectorWorkerAgent::DisconnectFromAllProxies(bool report_to_frontend) {
for (auto& it : session_id_to_connection_) {
WorkerInspectorProxy* proxy = connected_proxies_.at(it.value);
if (report_to_frontend) {
AttachedSessionIds()->remove(it.key);
attached_session_ids_.Clear(it.key);
GetFrontend()->detachedFromTarget(it.key, proxy->InspectorId());
}
proxy->DisconnectFromInspector(it.value, this);
......@@ -197,7 +187,7 @@ void InspectorWorkerAgent::DisconnectFromAllProxies(bool report_to_frontend) {
}
void InspectorWorkerAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) {
if (!AutoAttachEnabled() || frame != inspected_frames_->Root())
if (!auto_attach_.Get() || frame != inspected_frames_->Root())
return;
// During navigation workers from old page may die after a while.
......@@ -206,19 +196,6 @@ void InspectorWorkerAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) {
DisconnectFromAllProxies(true);
}
protocol::DictionaryValue* InspectorWorkerAgent::AttachedSessionIds() {
protocol::DictionaryValue* ids =
state_->getObject(WorkerAgentState::kAttachedSessionIds);
if (!ids) {
std::unique_ptr<protocol::DictionaryValue> new_ids =
protocol::DictionaryValue::create();
ids = new_ids.get();
state_->setObject(WorkerAgentState::kAttachedSessionIds,
std::move(new_ids));
}
return ids;
}
void InspectorWorkerAgent::ConnectToProxy(WorkerInspectorProxy* proxy,
bool waiting_for_debugger) {
int connection = ++s_last_connection_;
......@@ -230,7 +207,7 @@ void InspectorWorkerAgent::ConnectToProxy(WorkerInspectorProxy* proxy,
proxy->ConnectToInspector(connection, this);
DCHECK(GetFrontend());
AttachedSessionIds()->setBoolean(session_id, true);
attached_session_ids_.Set(session_id, true);
GetFrontend()->attachedToTarget(session_id,
protocol::Target::TargetInfo::create()
.setTargetId(proxy->InspectorId())
......
......@@ -70,11 +70,9 @@ class CORE_EXPORT InspectorWorkerAgent final
protocol::Maybe<String> target_id) override;
private:
bool AutoAttachEnabled();
void ConnectToAllProxies();
void DisconnectFromAllProxies(bool report_to_frontend);
void ConnectToProxy(WorkerInspectorProxy*, bool waiting_for_debugger);
protocol::DictionaryValue* AttachedSessionIds();
// WorkerInspectorProxy::PageInspector implementation.
void DispatchMessageFromWorker(WorkerInspectorProxy*,
......@@ -88,6 +86,9 @@ class CORE_EXPORT InspectorWorkerAgent final
HeapHashMap<int, Member<WorkerInspectorProxy>> connected_proxies_;
HashMap<int, String> connection_to_session_id_;
HashMap<String, int> session_id_to_connection_;
InspectorAgentState::Boolean auto_attach_;
InspectorAgentState::Boolean wait_for_debugger_on_start_;
InspectorAgentState::BooleanMap attached_session_ids_;
static int s_last_connection_;
DISALLOW_COPY_AND_ASSIGN(InspectorWorkerAgent);
};
......
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