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);
};
......
......@@ -83,23 +83,6 @@ namespace blink {
using protocol::Response;
namespace PageAgentState {
static const char kPageAgentEnabled[] = "pageAgentEnabled";
static const char kScreencastEnabled[] = "screencastEnabled";
static const char kLifecycleEventsEnabled[] = "lifecycleEventsEnabled";
static const char kBypassCSPEnabled[] = "bypassCSPEnabled";
static const char kStandardFontFamily[] = "standardFontFamily";
static const char kFixedFontFamily[] = "fixedFontFamily";
static const char kSerifFontFamily[] = "serifFontFamily";
static const char kSansSerifFontFamily[] = "sansSerifFontFamily";
static const char kCursiveFontFamily[] = "cursiveFontFamily";
static const char kFantasyFontFamily[] = "fantasyFontFamily";
static const char kPictographFontFamily[] = "pictographFontFamily";
static const char kStandardFontSize[] = "standardFontSize";
static const char kFixedFontSize[] = "fixedFontSize";
static const char kProduceCompilationCache[] = "generateCompilationCache";
} // namespace PageAgentState
namespace {
String ScheduledNavigationReasonToProtocol(ScheduledNavigation::Reason reason) {
......@@ -462,82 +445,89 @@ InspectorPageAgent::InspectorPageAgent(
v8_session_(v8_session),
client_(client),
last_script_identifier_(0),
enabled_(false),
reloading_(false),
inspector_resource_content_loader_(resource_content_loader),
resource_content_loader_client_id_(
resource_content_loader->CreateClientId()),
enabled_(&agent_state_, /*default_value=*/false),
screencast_enabled_(&agent_state_, /*default_value=*/false),
lifecycle_events_enabled_(&agent_state_, /*default_value=*/false),
bypass_csp_enabled_(&agent_state_, /*default_value=*/false),
scripts_to_evaluate_on_load_(&agent_state_,
/*default_value=*/WTF::String()) {}
/*default_value=*/WTF::String()),
standard_font_family_(&agent_state_, /*default_value=*/WTF::String()),
fixed_font_family_(&agent_state_, /*default_value=*/WTF::String()),
serif_font_family_(&agent_state_, /*default_value=*/WTF::String()),
sans_serif_font_family_(&agent_state_, /*default_value=*/WTF::String()),
cursive_font_family_(&agent_state_, /*default_value=*/WTF::String()),
fantasy_font_family_(&agent_state_, /*default_value=*/WTF::String()),
pictograph_font_family_(&agent_state_, /*default_value=*/WTF::String()),
standard_font_size_(&agent_state_, /*default_value=*/0),
fixed_font_size_(&agent_state_, /*default_value=*/0),
produce_compilation_cache_(&agent_state_, /*default_value=*/false) {}
void InspectorPageAgent::Restore() {
if (state_->booleanProperty(PageAgentState::kPageAgentEnabled, false))
if (enabled_.Get())
enable();
if (state_->booleanProperty(PageAgentState::kBypassCSPEnabled, false))
if (bypass_csp_enabled_.Get())
setBypassCSP(true);
// Re-apply generic fonts overrides.
String font;
bool notifyGenericFontFamilyChange = false;
LocalFrame* frame = inspected_frames_->Root();
auto* settings = frame->GetSettings();
if (settings) {
auto& family_settings = settings->GetGenericFontFamilySettings();
if (state_->getString(PageAgentState::kStandardFontFamily, &font)) {
family_settings.UpdateStandard(AtomicString(font));
if (!standard_font_family_.Get().IsNull()) {
family_settings.UpdateStandard(AtomicString(standard_font_family_.Get()));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kFixedFontFamily, &font)) {
family_settings.UpdateFixed(AtomicString(font));
if (!fixed_font_family_.Get().IsNull()) {
family_settings.UpdateFixed(AtomicString(fixed_font_family_.Get()));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kSerifFontFamily, &font)) {
family_settings.UpdateSerif(AtomicString(font));
if (!serif_font_family_.Get().IsNull()) {
family_settings.UpdateSerif(AtomicString(serif_font_family_.Get()));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kSansSerifFontFamily, &font)) {
family_settings.UpdateSansSerif(AtomicString(font));
if (!sans_serif_font_family_.Get().IsNull()) {
family_settings.UpdateSansSerif(
AtomicString(sans_serif_font_family_.Get()));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kCursiveFontFamily, &font)) {
family_settings.UpdateCursive(AtomicString(font));
if (!cursive_font_family_.Get().IsNull()) {
family_settings.UpdateCursive(AtomicString(cursive_font_family_.Get()));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kFantasyFontFamily, &font)) {
family_settings.UpdateFantasy(AtomicString(font));
if (!fantasy_font_family_.Get().IsNull()) {
family_settings.UpdateFantasy(AtomicString(fantasy_font_family_.Get()));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kPictographFontFamily, &font)) {
family_settings.UpdatePictograph(AtomicString(font));
if (!pictograph_font_family_.Get().IsNull()) {
family_settings.UpdatePictograph(
AtomicString(pictograph_font_family_.Get()));
notifyGenericFontFamilyChange = true;
}
if (notifyGenericFontFamilyChange) {
if (notifyGenericFontFamilyChange)
settings->NotifyGenericFontFamilyChange();
}
}
// Re-apply default font size overrides.
int font_size;
if (settings) {
if (state_->getInteger(PageAgentState::kStandardFontSize, &font_size)) {
settings->SetDefaultFontSize(font_size);
}
if (state_->getInteger(PageAgentState::kFixedFontSize, &font_size)) {
settings->SetDefaultFixedFontSize(font_size);
}
if (standard_font_size_.Get() != 0)
settings->SetDefaultFontSize(standard_font_size_.Get());
if (fixed_font_size_.Get() != 0)
settings->SetDefaultFixedFontSize(fixed_font_size_.Get());
}
}
Response InspectorPageAgent::enable() {
enabled_ = true;
state_->setBoolean(PageAgentState::kPageAgentEnabled, true);
enabled_.Set(true);
instrumenting_agents_->addInspectorPageAgent(this);
return Response::OK();
}
Response InspectorPageAgent::disable() {
enabled_ = false;
state_->setBoolean(PageAgentState::kPageAgentEnabled, false);
enabled_.Set(false);
scripts_to_evaluate_on_load_.ClearAll();
script_to_evaluate_on_load_once_ = String();
pending_script_to_evaluate_on_load_once_ = String();
......@@ -583,7 +573,7 @@ Response InspectorPageAgent::removeScriptToEvaluateOnNewDocument(
}
Response InspectorPageAgent::setLifecycleEventsEnabled(bool enabled) {
state_->setBoolean(PageAgentState::kLifecycleEventsEnabled, enabled);
lifecycle_events_enabled_.Set(enabled);
if (!enabled)
return Response::OK();
......@@ -740,7 +730,7 @@ void InspectorPageAgent::getResourceContent(
const String& frame_id,
const String& url,
std::unique_ptr<GetResourceContentCallback> callback) {
if (!enabled_) {
if (!enabled_.Get()) {
callback->sendFailure(Response::Error("Agent is not enabled."));
return;
}
......@@ -791,7 +781,7 @@ void InspectorPageAgent::searchInResource(
Maybe<bool> optional_case_sensitive,
Maybe<bool> optional_is_regex,
std::unique_ptr<SearchInResourceCallback> callback) {
if (!enabled_) {
if (!enabled_.Get()) {
callback->sendFailure(Response::Error("Agent is not enabled."));
return;
}
......@@ -807,7 +797,7 @@ void InspectorPageAgent::searchInResource(
Response InspectorPageAgent::setBypassCSP(bool enabled) {
LocalFrame* frame = inspected_frames_->Root();
frame->GetSettings()->SetBypassCSP(enabled);
state_->setBoolean(PageAgentState::kBypassCSPEnabled, enabled);
bypass_csp_enabled_.Set(enabled);
return Response::OK();
}
......@@ -890,8 +880,7 @@ void InspectorPageAgent::FrameDetachedFromParent(LocalFrame* frame) {
}
bool InspectorPageAgent::ScreencastEnabled() {
return enabled_ &&
state_->booleanProperty(PageAgentState::kScreencastEnabled, false);
return enabled_.Get() && screencast_enabled_.Get();
}
void InspectorPageAgent::FrameStartedLoading(LocalFrame* frame) {
......@@ -941,8 +930,7 @@ void InspectorPageAgent::LifecycleEvent(LocalFrame* frame,
DocumentLoader* loader,
const char* name,
double timestamp) {
if (!loader ||
!state_->booleanProperty(PageAgentState::kLifecycleEventsEnabled, false))
if (!loader || !lifecycle_events_enabled_.Get())
return;
GetFrontend()->lifecycleEvent(IdentifiersFactory::FrameId(frame),
IdentifiersFactory::LoaderId(loader), name,
......@@ -970,7 +958,7 @@ void InspectorPageAgent::Did(const probe::RecalculateStyle&) {
}
void InspectorPageAgent::PageLayoutInvalidated(bool resized) {
if (enabled_ && client_)
if (enabled_.Get() && client_)
client_->PageLayoutInvalidated(resized);
}
......@@ -1095,12 +1083,12 @@ Response InspectorPageAgent::startScreencast(Maybe<String> format,
Maybe<int> max_width,
Maybe<int> max_height,
Maybe<int> every_nth_frame) {
state_->setBoolean(PageAgentState::kScreencastEnabled, true);
screencast_enabled_.Set(true);
return Response::OK();
}
Response InspectorPageAgent::stopScreencast() {
state_->setBoolean(PageAgentState::kScreencastEnabled, false);
screencast_enabled_.Set(false);
return Response::OK();
}
......@@ -1191,46 +1179,34 @@ Response InspectorPageAgent::setFontFamilies(
if (settings) {
auto& family_settings = settings->GetGenericFontFamilySettings();
if (font_families->hasStandard()) {
state_->setString(PageAgentState::kStandardFontFamily,
font_families->getStandard(String()));
family_settings.UpdateStandard(
AtomicString(font_families->getStandard(String())));
standard_font_family_.Set(font_families->getStandard(String()));
family_settings.UpdateStandard(AtomicString(standard_font_family_.Get()));
}
if (font_families->hasFixed()) {
state_->setString(PageAgentState::kFixedFontFamily,
font_families->getFixed(String()));
family_settings.UpdateFixed(
AtomicString(font_families->getFixed(String())));
fixed_font_family_.Set(font_families->getFixed(String()));
family_settings.UpdateFixed(AtomicString(fixed_font_family_.Get()));
}
if (font_families->hasSerif()) {
state_->setString(PageAgentState::kSerifFontFamily,
font_families->getSerif(String()));
family_settings.UpdateSerif(
AtomicString(font_families->getSerif(String())));
serif_font_family_.Set(font_families->getSerif(String()));
family_settings.UpdateSerif(AtomicString(serif_font_family_.Get()));
}
if (font_families->hasSansSerif()) {
state_->setString(PageAgentState::kSansSerifFontFamily,
font_families->getSansSerif(String()));
sans_serif_font_family_.Set(font_families->getSansSerif(String()));
family_settings.UpdateSansSerif(
AtomicString(font_families->getSansSerif(String())));
AtomicString(sans_serif_font_family_.Get()));
}
if (font_families->hasCursive()) {
state_->setString(PageAgentState::kCursiveFontFamily,
font_families->getCursive(String()));
family_settings.UpdateCursive(
AtomicString(font_families->getCursive(String())));
cursive_font_family_.Set(font_families->getCursive(String()));
family_settings.UpdateCursive(AtomicString(cursive_font_family_.Get()));
}
if (font_families->hasFantasy()) {
state_->setString(PageAgentState::kFantasyFontFamily,
font_families->getFantasy(String()));
family_settings.UpdateFantasy(
AtomicString(font_families->getFantasy(String())));
fantasy_font_family_.Set(font_families->getFantasy(String()));
family_settings.UpdateFantasy(AtomicString(fantasy_font_family_.Get()));
}
if (font_families->hasPictograph()) {
state_->setString(PageAgentState::kPictographFontFamily,
font_families->getPictograph(String()));
pictograph_font_family_.Set(font_families->getPictograph(String()));
family_settings.UpdatePictograph(
AtomicString(font_families->getPictograph(String())));
AtomicString(pictograph_font_family_.Get()));
}
settings->NotifyGenericFontFamilyChange();
}
......@@ -1244,14 +1220,12 @@ Response InspectorPageAgent::setFontSizes(
auto* settings = frame->GetSettings();
if (settings) {
if (font_sizes->hasStandard()) {
state_->setInteger(PageAgentState::kStandardFontSize,
font_sizes->getStandard(0));
settings->SetDefaultFontSize(font_sizes->getStandard(0));
standard_font_size_.Set(font_sizes->getStandard(0));
settings->SetDefaultFontSize(standard_font_size_.Get());
}
if (font_sizes->hasFixed()) {
state_->setInteger(PageAgentState::kFixedFontSize,
font_sizes->getFixed(0));
settings->SetDefaultFixedFontSize(font_sizes->getFixed(0));
fixed_font_size_.Set(font_sizes->getFixed(0));
settings->SetDefaultFixedFontSize(fixed_font_size_.Get());
}
}
......@@ -1276,7 +1250,7 @@ void InspectorPageAgent::ConsumeCompilationCache(
void InspectorPageAgent::ProduceCompilationCache(const ScriptSourceCode& source,
v8::Local<v8::Script> script) {
if (!state_->booleanProperty(PageAgentState::kProduceCompilationCache, false))
if (!produce_compilation_cache_.Get())
return;
KURL url = source.Url();
if (source.Streamer())
......@@ -1298,7 +1272,7 @@ void InspectorPageAgent::ProduceCompilationCache(const ScriptSourceCode& source,
}
Response InspectorPageAgent::setProduceCompilationCache(bool enabled) {
state_->setBoolean(PageAgentState::kProduceCompilationCache, enabled);
produce_compilation_cache_.Set(enabled);
return Response::OK();
}
......
......@@ -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