0

Apply StateTransitions to RenderFrameHostImpl::SetLifecycleState.

Change-Id: I75299d96f0418c56eb50c9a9f93c45d15097aee8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227929
Commit-Queue: Fergal Daly <fergal@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: Alexander Timin <altimin@chromium.org>
Reviewed-by: Sreeja Kamishetty <sreejakshetty@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779218}
This commit is contained in:
Fergal Daly
2020-06-17 07:56:52 +00:00
committed by Commit Bot
parent db0165503e
commit 9d3684af7f
4 changed files with 53 additions and 26 deletions

@ -136,6 +136,7 @@
#include "content/common/navigation_params_utils.h"
#include "content/common/render_message_filter.mojom.h"
#include "content/common/renderer.mojom.h"
#include "content/common/state_transitions.h"
#include "content/common/unfreezable_frame_messages.h"
#include "content/public/browser/ax_event_notification_details.h"
#include "content/public/browser/browser_accessibility_state.h"
@ -9092,31 +9093,36 @@ void RenderFrameHostImpl::SetLifecycleStateToActive() {
}
void RenderFrameHostImpl::SetLifecycleState(LifecycleState state) {
// Cross-verify that |lifecycle_state_| transition happens correctly.
switch (state) {
case LifecycleState::kSpeculative:
// RenderFrameHost is only set speculative during its creation and no
// transitions happen to this state during its lifetime.
NOTREACHED();
break;
case LifecycleState::kActive:
DCHECK(lifecycle_state_ == LifecycleState::kSpeculative ||
lifecycle_state_ == LifecycleState::kInBackForwardCache)
<< "Unexpected LifeCycleState " << int(lifecycle_state_);
break;
case LifecycleState::kInBackForwardCache:
DCHECK_EQ(lifecycle_state_, LifecycleState::kActive)
<< "Unexpected LifeCycleState " << int(lifecycle_state_);
break;
case LifecycleState::kRunningUnloadHandlers:
DCHECK_EQ(lifecycle_state_, LifecycleState::kActive)
<< "Unexpected LifeCycleState " << int(lifecycle_state_);
break;
case LifecycleState::kReadyToBeDeleted:
DCHECK_NE(lifecycle_state_, LifecycleState::kReadyToBeDeleted)
<< "Unexpected LifeCycleState " << int(lifecycle_state_);
break;
}
#if DCHECK_IS_ON()
static const base::NoDestructor<StateTransitions<LifecycleState>>
allowed_transitions(
// For a graph of state transitions, see
// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/render-frame-host-lifecycle-state.png
// To update the graph, see the corresponding .gv file.
// RenderFrameHost is only set speculative during its creation and no
// transitions happen to this state during its lifetime.
StateTransitions<LifecycleState>({
{LifecycleState::kSpeculative,
{LifecycleState::kActive, LifecycleState::kReadyToBeDeleted}},
{LifecycleState::kActive,
{LifecycleState::kInBackForwardCache,
LifecycleState::kRunningUnloadHandlers,
LifecycleState::kReadyToBeDeleted}},
{LifecycleState::kInBackForwardCache,
{LifecycleState::kActive, LifecycleState::kReadyToBeDeleted}},
{LifecycleState::kRunningUnloadHandlers,
{LifecycleState::kReadyToBeDeleted}},
{LifecycleState::kReadyToBeDeleted, {}},
}));
DCHECK_STATE_TRANSITION(allowed_transitions, /*old_state=*/lifecycle_state_,
/*new_state*/ state);
#endif // DCHECK_IS_ON()
LifecycleState old_state = lifecycle_state_;
lifecycle_state_ = state;
// Notify the delegate about change in |lifecycle_state_|.
@ -9166,4 +9172,9 @@ void RenderFrameHostImpl::CheckSandboxFlags() {
DCHECK(false);
}
std::ostream& operator<<(std::ostream& o,
const RenderFrameHostImpl::LifecycleState& s) {
return o << LifecycleStateToString(s);
}
} // namespace content

@ -733,7 +733,7 @@ class CONTENT_EXPORT RenderFrameHostImpl
void Stop();
// Defines different states the RenderFrameHost can be in during its lifetime
// i.e., from point of creation to deletion.
// i.e., from point of creation to deletion. See |SetLifecycleState|.
enum class LifecycleState {
// This state corresponds to when a speculative RenderFrameHost is created
// for an ongoing navigation (to new URL) but hasn't been swapped in the
@ -3083,6 +3083,11 @@ class CONTENT_EXPORT RenderFrameHostImpl
DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
};
// Used when DCHECK_STATE_TRANSITION triggers.
CONTENT_EXPORT std::ostream& operator<<(
std::ostream& o,
const RenderFrameHostImpl::LifecycleState& s);
} // namespace content
#endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_

@ -0,0 +1,11 @@
// Generated with https://crrev.com/c/2220116 and:
// python3 tools/state_transitions/state_graph.py content/browser/frame_host/render_frame_host_impl.cc LifecycleState
//
// See tools/state_transitions/README.md
digraph createflow {
kSpeculative -> {kActive, kReadyToBeDeleted};
kActive -> {kInBackForwardCache, kRunningUnloadHandlers, kReadyToBeDeleted};
kInBackForwardCache -> {kActive, kReadyToBeDeleted};
kRunningUnloadHandlers -> {kReadyToBeDeleted};
kReadyToBeDeleted -> {};
}

Binary file not shown.

After

(image error) Size: 45 KiB