Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: content/renderer/render_view_impl.cc

Issue 694963003: Revert of Clean up the page state saving mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/shell/renderer/layout_test/webkit_test_runner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_view_impl.cc
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index ef5087f895127e0761e31192d3420de843face67..077b624c1cc5ebc3f8d24364f8faf9bb30bebdda 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -325,8 +325,8 @@
// foreground renderer. This means there is a small window of time from which
// content state is modified and not sent to session restore, but this is
// better than having to wake up all renderers during shutdown.
-const int kHiddenPageStateSendingDelaySeconds = 5;
-const int kPageStateSendingDelaySeconds = 1;
+const int kDelaySecondsForContentStateSyncHidden = 5;
+const int kDelaySecondsForContentStateSync = 1;
#if defined(OS_ANDROID)
// Delay between tapping in content and launching the associated android intent.
@@ -649,14 +649,13 @@
params->hidden,
params->never_visible),
webkit_preferences_(params->webkit_prefs),
+ send_content_state_immediately_(false),
enabled_bindings_(0),
send_preferred_size_changes_(false),
navigation_gesture_(NavigationGestureUnknown),
opened_by_user_gesture_(true),
opener_suppressed_(false),
suppress_dialogs_until_swap_out_(false),
- page_state_sent_immediately_(false),
- page_state_dirty_(false),
page_id_(-1),
last_page_id_sent_to_browser_(-1),
next_page_id_(params->next_page_id),
@@ -1528,6 +1527,29 @@
///////////////////////////////////////////////////////////////////////////////
+// Sends the current history state to the browser so it will be saved before we
+// navigate to a new page.
+void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
+ // If we have a valid page ID at this point, then it corresponds to the page
+ // we are navigating away from. Otherwise, this is the first navigation, so
+ // there is no past session history to record.
+ if (page_id_ == -1)
+ return;
+ SendUpdateState(history_controller_->GetCurrentEntry());
+}
+
+void RenderViewImpl::SendUpdateState(HistoryEntry* entry) {
+ if (!entry)
+ return;
+
+ // Don't send state updates for kSwappedOutURL.
+ if (entry->root().urlString() == WebString::fromUTF8(kSwappedOutURL))
+ return;
+
+ Send(new ViewHostMsg_UpdateState(
+ routing_id_, page_id_, HistoryEntryToPageState(entry)));
+}
+
bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
// Before WebKit asks us to show an alert (etc.), it takes care of doing the
// equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
@@ -1877,50 +1899,30 @@
return window_rect;
}
-void RenderViewImpl::MarkPageStateAsDirty() {
- // No need to send state if no page has committed yet.
+void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
+ // No need to update state if no page has committed yet.
if (page_id_ == -1)
return;
- page_state_dirty_ = true;
-
int delay;
- if (page_state_sent_immediately_)
+ if (send_content_state_immediately_)
delay = 0;
else if (is_hidden())
- delay = kHiddenPageStateSendingDelaySeconds;
+ delay = kDelaySecondsForContentStateSyncHidden;
else
- delay = kPageStateSendingDelaySeconds;
-
- if (page_state_timer_.IsRunning()) {
+ delay = kDelaySecondsForContentStateSync;
+
+ if (nav_state_sync_timer_.IsRunning()) {
// The timer is already running. If the delay of the timer maches the amount
// we want to delay by, then return. Otherwise stop the timer so that it
// gets started with the right delay.
- if (page_state_timer_.GetCurrentDelay().InSeconds() == delay)
+ if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
return;
- page_state_timer_.Stop();
- }
-
- page_state_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
- &RenderViewImpl::FlushPageState);
-}
-
-void RenderViewImpl::FlushPageState() {
- if (!page_state_dirty_ || page_id_ == -1 || !webview())
- return;
-
- HistoryEntry* entry = history_controller_->GetCurrentEntry();
- if (!entry)
- return;
-
- // Don't send state updates for kSwappedOutURL.
- if (entry->root().urlString() == WebString::fromUTF8(kSwappedOutURL))
- return;
-
- Send(new ViewHostMsg_UpdateState(
- routing_id_, page_id_, HistoryEntryToPageState(entry)));
-
- page_state_dirty_ = false;
+ nav_state_sync_timer_.Stop();
+ }
+
+ nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
+ &RenderViewImpl::SyncNavigationState);
}
void RenderViewImpl::setMouseOverURL(const WebURL& url) {
@@ -2406,7 +2408,7 @@
}
void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) {
- MarkPageStateAsDirty();
+ StartNavStateSyncTimerIfNecessary();
}
void RenderViewImpl::CheckPreferredSize() {
@@ -2439,7 +2441,7 @@
}
void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) {
- MarkPageStateAsDirty();
+ StartNavStateSyncTimerIfNecessary();
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, DidChangeScrollOffset(frame));
@@ -2563,8 +2565,8 @@
return enabled_bindings_;
}
-bool RenderViewImpl::IsPageStateSentImmediately() const {
- return page_state_sent_immediately_;
+bool RenderViewImpl::GetContentStateImmediately() const {
+ return send_content_state_immediately_;
}
blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
@@ -2579,8 +2581,10 @@
main_render_frame_->didStopLoading();
}
-void RenderViewImpl::ForcePageStateFlushForTesting() {
- FlushPageState();
+void RenderViewImpl::SyncNavigationState() {
+ if (!webview())
+ return;
+ SendUpdateState(history_controller_->GetCurrentEntry());
}
blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() {
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/shell/renderer/layout_test/webkit_test_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698