[go: nahoru, domu]

Skip to content

Commit

Permalink
Always report lifecycle timestamps. (#3682)
Browse files Browse the repository at this point in the history
Always report lifecycle timestamps, otherwise PerformanceLifecycleTiming
may get inconsistent lifecycle transitions.

b/194127386
b/349423027
  • Loading branch information
jellefoks committed Jun 27, 2024
1 parent deb0b8f commit b432540
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
8 changes: 5 additions & 3 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "cobalt/web/csp_delegate_factory.h"
#include "cobalt/web/navigator_ua_data.h"
#include "starboard/atomic.h"
#include "starboard/common/time.h"
#include "starboard/configuration.h"
#include "starboard/extension/graphics.h"
#include "starboard/system.h"
Expand Down Expand Up @@ -460,15 +461,16 @@ BrowserModule::~BrowserModule() {

// Transition into the suspended state from whichever state we happen to
// currently be in, to prepare for shutdown.
int64_t now = starboard::CurrentMonotonicTime();
switch (application_state_) {
case base::kApplicationStateStarted:
Blur(0);
Blur(now);
FALLTHROUGH;
case base::kApplicationStateBlurred:
Conceal(0);
Conceal(now);
FALLTHROUGH;
case base::kApplicationStateConcealed:
Freeze(0);
Freeze(now);
break;
case base::kApplicationStateStopped:
NOTREACHED() << "BrowserModule does not support the stopped state.";
Expand Down
12 changes: 6 additions & 6 deletions cobalt/browser/debug_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ class DebugConsole : public LifecycleObserver {
}

// LifecycleObserver implementation.
void Blur(int64_t timestamp) override { web_module_->Blur(0); }
void Blur(int64_t timestamp) override { web_module_->Blur(timestamp); }
void Conceal(render_tree::ResourceProvider* resource_provider,
int64_t timestamp) override {
web_module_->Conceal(resource_provider, 0);
web_module_->Conceal(resource_provider, timestamp);
}
void Freeze(int64_t timestamp) override { web_module_->Freeze(0); }
void Freeze(int64_t timestamp) override { web_module_->Freeze(timestamp); }
void Unfreeze(render_tree::ResourceProvider* resource_provider,
int64_t timestamp) override {
web_module_->Unfreeze(resource_provider, 0);
web_module_->Unfreeze(resource_provider, timestamp);
}
void Reveal(render_tree::ResourceProvider* resource_provider,
int64_t timestamp) override {
web_module_->Reveal(resource_provider, 0);
web_module_->Reveal(resource_provider, timestamp);
}
void Focus(int64_t timestamp) override { web_module_->Focus(0); }
void Focus(int64_t timestamp) override { web_module_->Focus(timestamp); }

void ReduceMemory() { web_module_->ReduceMemory(); }

Expand Down
12 changes: 6 additions & 6 deletions cobalt/browser/splash_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ class SplashScreen : public LifecycleObserver {
}

// LifecycleObserver implementation.
void Blur(int64_t timestamp) override { web_module_->Blur(0); }
void Blur(int64_t timestamp) override { web_module_->Blur(timestamp); }
void Conceal(render_tree::ResourceProvider* resource_provider,
int64_t timestamp) override {
web_module_->Conceal(resource_provider, 0);
web_module_->Conceal(resource_provider, timestamp);
}
void Freeze(int64_t timestamp) override { web_module_->Freeze(0); }
void Freeze(int64_t timestamp) override { web_module_->Freeze(timestamp); }
void Unfreeze(render_tree::ResourceProvider* resource_provider,
int64_t timestamp) override {
web_module_->Unfreeze(resource_provider, 0);
web_module_->Unfreeze(resource_provider, timestamp);
}
void Reveal(render_tree::ResourceProvider* resource_provider,
int64_t timestamp) override {
web_module_->Reveal(resource_provider, 0);
web_module_->Reveal(resource_provider, timestamp);
}
void Focus(int64_t timestamp) override { web_module_->Focus(0); }
void Focus(int64_t timestamp) override { web_module_->Focus(timestamp); }

void ReduceMemory() { web_module_->ReduceMemory(); }

Expand Down
20 changes: 10 additions & 10 deletions cobalt/dom/performance_lifecycle_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ std::string PerformanceLifecycleTiming::last_state() const {
return TranslateApplicationStateToString(lifecycle_timing_info_.last_state);
}

void PerformanceLifecycleTiming::LogInvalidStateTransition(
base::ApplicationState state) {
DLOG(INFO) << "Current State: "
<< TranslateApplicationStateToString(GetCurrentState());
DLOG(INFO) << "Next State: " << TranslateApplicationStateToString(state);
NOTREACHED() << "Invalid application state transition.";
}

void PerformanceLifecycleTiming::SetApplicationState(
base::ApplicationState state, int64_t timestamp) {
switch (state) {
Expand All @@ -116,11 +124,7 @@ void PerformanceLifecycleTiming::SetApplicationState(
} else if (GetCurrentState() == base::kApplicationStateConcealed) {
lifecycle_timing_info_.app_reveal = timestamp;
} else {
DLOG(INFO) << "Current State: "
<< TranslateApplicationStateToString(GetCurrentState());
DLOG(INFO) << "Next State: "
<< TranslateApplicationStateToString(state);
NOTREACHED() << "Invalid application state transition.";
LogInvalidStateTransition(state);
}
break;
case base::kApplicationStateConcealed:
Expand All @@ -130,11 +134,7 @@ void PerformanceLifecycleTiming::SetApplicationState(
} else if (GetCurrentState() == base::kApplicationStateFrozen) {
lifecycle_timing_info_.app_unfreeze = timestamp;
} else {
DLOG(INFO) << "Current State: "
<< TranslateApplicationStateToString(GetCurrentState());
DLOG(INFO) << "Next State: "
<< TranslateApplicationStateToString(state);
NOTREACHED() << "Invalid application state transition.";
LogInvalidStateTransition(state);
}
break;
case base::kApplicationStateFrozen:
Expand Down
3 changes: 3 additions & 0 deletions cobalt/dom/performance_lifecycle_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class PerformanceLifecycleTiming : public PerformanceEntry {
void SetLifecycleTimingInfoState(base::ApplicationState state);
DOMHighResTimeStamp ReportDOMHighResTimeStamp(int64_t timestamp) const;
base::ApplicationState GetCurrentState() const;

void LogInvalidStateTransition(base::ApplicationState state);

struct LifecycleTimingInfo {
int64_t app_preload = 0;
int64_t app_start = 0;
Expand Down
1 change: 0 additions & 1 deletion cobalt/dom/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ void Window::SetApplicationState(base::ApplicationState state,
int64_t timestamp) {
html_element_context()->application_lifecycle_state()->SetApplicationState(
state);
if (timestamp == 0) return;
performance_->SetApplicationState(state, timestamp);
window_timers_.SetApplicationState(state);
}
Expand Down

0 comments on commit b432540

Please sign in to comment.