Commit 776ef981 authored by Liquan(Max) Gu's avatar Liquan(Max) Gu Committed by Commit Bot

[UserTimingL3] Move mark API logic to performance-user-timing

We have the Performance class and the PerformanceUserTiming class. The
Performance is used to connect different performance APIs, one of which is the
UserTiming's mark API. The PerformanceUserTiming should be the main part to
deal with UserTiming logic. Currently, too much UserTiming logic is stored in
Performance. We should move them to PerformanceUserTiming.

This CL is intended for the refactoring.

Bug: 738685
Change-Id: I77c3b685a1a7f6df49539f6661c41492f0a44b7f
Reviewed-on: https://chromium-review.googlesource.com/c/1348865Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Commit-Queue: Liquan (Max) Gǔ <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610981}
parent ab0c2e92
......@@ -647,33 +647,10 @@ PerformanceMark* Performance::mark(
const AtomicString& mark_name,
DoubleOrPerformanceMarkOptions& start_time_or_mark_options,
ExceptionState& exception_state) {
if (!RuntimeEnabledFeatures::CustomUserTimingEnabled()) {
DCHECK(start_time_or_mark_options.IsNull());
}
if (!user_timing_)
user_timing_ = UserTiming::Create(*this);
DOMHighResTimeStamp start = 0.0;
if (start_time_or_mark_options.IsDouble()) {
start = start_time_or_mark_options.GetAsDouble();
} else if (start_time_or_mark_options.IsPerformanceMarkOptions() &&
start_time_or_mark_options.GetAsPerformanceMarkOptions()
->hasStartTime()) {
start =
start_time_or_mark_options.GetAsPerformanceMarkOptions()->startTime();
} else {
start = now();
}
ScriptValue detail = ScriptValue::CreateNull(script_state);
if (start_time_or_mark_options.IsPerformanceMarkOptions()) {
detail = start_time_or_mark_options.GetAsPerformanceMarkOptions()->detail();
}
// Pass in a null ScriptValue if the mark's detail doesn't exist.
PerformanceMark* performance_mark = user_timing_->Mark(
script_state, mark_name, start, detail, exception_state);
script_state, mark_name, start_time_or_mark_options, exception_state);
if (performance_mark)
NotifyObserversOfEntry(*performance_mark);
if (RuntimeEnabledFeatures::CustomUserTimingEnabled())
......
......@@ -26,6 +26,7 @@
#include "third_party/blink/renderer/core/timing/performance_user_timing.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/double_or_performance_mark_options.h"
#include "third_party/blink/renderer/core/timing/performance.h"
#include "third_party/blink/renderer/core/timing/performance_mark.h"
#include "third_party/blink/renderer/core/timing/performance_measure.h"
......@@ -99,11 +100,39 @@ static void ClearPeformanceEntries(PerformanceEntryMap& performance_entry_map,
performance_entry_map.erase(name);
}
PerformanceMark* UserTiming::Mark(ScriptState* script_state,
const AtomicString& mark_name,
const DOMHighResTimeStamp& start_time,
const ScriptValue& detail,
ExceptionState& exception_state) {
PerformanceMark* UserTiming::Mark(
ScriptState* script_state,
const AtomicString& mark_name,
DoubleOrPerformanceMarkOptions& start_time_or_mark_options,
ExceptionState& exception_state) {
if (!RuntimeEnabledFeatures::CustomUserTimingEnabled())
DCHECK(start_time_or_mark_options.IsNull());
DOMHighResTimeStamp start = 0.0;
if (start_time_or_mark_options.IsDouble()) {
start = start_time_or_mark_options.GetAsDouble();
} else if (start_time_or_mark_options.IsPerformanceMarkOptions() &&
start_time_or_mark_options.GetAsPerformanceMarkOptions()
->hasStartTime()) {
start =
start_time_or_mark_options.GetAsPerformanceMarkOptions()->startTime();
} else {
start = performance_->now();
}
// Pass in a null ScriptValue if the mark's detail doesn't exist.
ScriptValue detail = ScriptValue::CreateNull(script_state);
if (start_time_or_mark_options.IsPerformanceMarkOptions())
detail = start_time_or_mark_options.GetAsPerformanceMarkOptions()->detail();
return MarkInternal(script_state, mark_name, start, detail, exception_state);
}
PerformanceMark* UserTiming::MarkInternal(ScriptState* script_state,
const AtomicString& mark_name,
const DOMHighResTimeStamp& start_time,
const ScriptValue& detail,
ExceptionState& exception_state) {
if (GetRestrictedKeyMap().Contains(mark_name)) {
exception_state.ThrowDOMException(
DOMExceptionCode::kSyntaxError,
......
......@@ -47,11 +47,12 @@ class UserTiming final : public GarbageCollected<UserTiming> {
return new UserTiming(performance);
}
PerformanceMark* Mark(ScriptState*,
const AtomicString& mark_name,
const DOMHighResTimeStamp& start_time,
const ScriptValue& detail,
ExceptionState&);
PerformanceMark* Mark(
ScriptState* script_state,
const AtomicString& mark_name,
DoubleOrPerformanceMarkOptions& start_time_or_mark_options,
ExceptionState& exception_state);
void ClearMarks(const AtomicString& mark_name);
PerformanceMeasure* Measure(ScriptState*,
......@@ -73,6 +74,11 @@ class UserTiming final : public GarbageCollected<UserTiming> {
private:
explicit UserTiming(Performance&);
PerformanceMark* MarkInternal(ScriptState*,
const AtomicString& mark_name,
const DOMHighResTimeStamp& start_time,
const ScriptValue& detail,
ExceptionState&);
double FindExistingMarkStartTime(const AtomicString& mark_name,
ExceptionState&);
double FindStartMarkOrTime(const StringOrDouble& start, ExceptionState&);
......
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