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

Unified Diff: chrome/browser/android/offline_pages/background_loader_offliner.cc

Issue 2789503002: Revert of [Offline pages] Integrate snapshot controller fully into background loader. (Closed)
Patch Set: Created 3 years, 9 months 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 | « chrome/browser/android/offline_pages/background_loader_offliner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/offline_pages/background_loader_offliner.cc
diff --git a/chrome/browser/android/offline_pages/background_loader_offliner.cc b/chrome/browser/android/offline_pages/background_loader_offliner.cc
index 5a15362940c38295967db1f5f00b5335dd0cd064..6ccd766b020e6031d7bef1c4b247235233143674 100644
--- a/chrome/browser/android/offline_pages/background_loader_offliner.cc
+++ b/chrome/browser/android/offline_pages/background_loader_offliner.cc
@@ -14,7 +14,6 @@
#include "components/offline_pages/core/offline_page_model.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
-#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_user_data.h"
@@ -22,7 +21,6 @@
namespace {
const long kOfflinePageDelayMs = 2000;
-const long kOfflineDomContentLoadedMs = 25000;
class OfflinerData : public content::WebContentsUserData<OfflinerData> {
public:
@@ -155,6 +153,9 @@
if (!loader_)
ResetState();
+ // Invalidate ptrs for all delayed/saving tasks.
+ weak_ptr_factory_.InvalidateWeakPtrs();
+
// Track copy of pending request.
pending_request_.reset(new SavePageRequest(request));
completion_callback_ = completion_callback;
@@ -168,16 +169,12 @@
// Load page attempt.
loader_.get()->LoadPage(request.url());
- snapshot_controller_.reset(
- new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this,
- kOfflineDomContentLoadedMs, page_delay_ms_));
-
return true;
}
void BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) {
// TODO(chili): We are not able to cancel a pending
- // OfflinePageModel::SaveSnapshot() operation. We will notify caller that
+ // OfflinePageModel::SavePage() operation. We will notify caller that
// cancel completed once the SavePage operation returns.
if (!pending_request_) {
callback.Run(0LL);
@@ -201,20 +198,21 @@
return false;
}
-void BackgroundLoaderOffliner::DocumentLoadedInFrame(
- content::RenderFrameHost* render_host) {
- // Inform snapshot controller if in main frame.
- if (!render_host->GetParent())
- snapshot_controller_->DocumentAvailableInMainFrame();
-}
-
void BackgroundLoaderOffliner::DidStopLoading() {
if (!pending_request_.get()) {
DVLOG(1) << "DidStopLoading called even though no pending request.";
return;
}
- snapshot_controller_->DocumentOnLoadCompletedInMainFrame();
+ // Invalidate ptrs for any ongoing save operation.
+ weak_ptr_factory_.InvalidateWeakPtrs();
+
+ // Post SavePage task with 2 second delay.
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&BackgroundLoaderOffliner::SavePage,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(page_delay_ms_));
}
void BackgroundLoaderOffliner::RenderProcessGone(
@@ -288,6 +286,18 @@
page_load_state_ = RETRIABLE;
}
}
+
+ // If the document is not the same invalidate any pending save tasks.
+ //
+ // Downloads or 204/205 response codes do not commit (no new navigation)
+ // Same-Document (committed) navigations are:
+ // - reference fragment navigations
+ // - pushState/replaceState
+ // - same document history navigation
+ if (navigation_handle->HasCommitted() &&
+ !navigation_handle->IsSameDocument()) {
+ weak_ptr_factory_.InvalidateWeakPtrs();
+ }
}
void BackgroundLoaderOffliner::SetPageDelayForTest(long delay_ms) {
@@ -301,7 +311,7 @@
}
}
-void BackgroundLoaderOffliner::StartSnapshot() {
+void BackgroundLoaderOffliner::SavePage() {
if (!pending_request_.get()) {
DVLOG(1) << "Pending request was cleared during delay.";
return;
@@ -372,8 +382,6 @@
}
save_state_ = NONE;
- // Prevent snapshot controller from making any more snapshots.
- snapshot_controller_->Stop();
Offliner::RequestStatus save_status;
if (save_result == SavePageResult::SUCCESS)
@@ -386,7 +394,6 @@
void BackgroundLoaderOffliner::ResetState() {
pending_request_.reset();
- snapshot_controller_.reset();
page_load_state_ = SUCCESS;
network_bytes_ = 0LL;
// TODO(chili): Remove after RequestCoordinator can handle multiple offliners.
« no previous file with comments | « chrome/browser/android/offline_pages/background_loader_offliner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698