Chromium Code Reviews| 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 9b163c5ee7c1e196bcf3eca650134188c3371e59..ed080b36c5c2b288ede8d2b1253238c18d65f578 100644 |
| --- a/chrome/browser/android/offline_pages/background_loader_offliner.cc |
| +++ b/chrome/browser/android/offline_pages/background_loader_offliner.cc |
| @@ -14,6 +14,7 @@ |
| #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" |
| @@ -21,6 +22,7 @@ namespace offline_pages { |
| namespace { |
| const long kOfflinePageDelayMs = 2000; |
| +const long kOfflineDomContentLoadedMs = 25000; |
| class OfflinerData : public content::WebContentsUserData<OfflinerData> { |
| public: |
| @@ -152,12 +154,16 @@ bool BackgroundLoaderOffliner::LoadAndSave( |
| // 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::SavePage() operation. We will notify caller that |
| + // OfflinePageModel::SaveSnapshot() operation. We will notify caller that |
| // cancel completed once the SavePage operation returns. |
| if (!pending_request_) { |
| callback.Run(0LL); |
| @@ -181,21 +187,19 @@ bool BackgroundLoaderOffliner::HandleTimeout(const SavePageRequest& request) { |
| return false; |
| } |
| +void BackgroundLoaderOffliner::DocumentLoadedInFrame( |
| + content::RenderFrameHost* render_host) { |
| + if (!render_host->GetParent()) |
|
Pete Williamson
2017/03/27 21:45:45
Let's add a comment here:
// If this was for the m
chili
2017/03/27 23:43:43
Done.
|
| + snapshot_controller_->DocumentAvailableInMainFrame(); |
| +} |
| + |
| void BackgroundLoaderOffliner::DidStopLoading() { |
| if (!pending_request_.get()) { |
| DVLOG(1) << "DidStopLoading called even though no pending request."; |
| return; |
| } |
| - // 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_)); |
| + snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); |
| } |
| void BackgroundLoaderOffliner::RenderProcessGone( |
| @@ -291,7 +295,7 @@ void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { |
| } |
| } |
| -void BackgroundLoaderOffliner::SavePage() { |
| +void BackgroundLoaderOffliner::StartSnapshot() { |
| if (!pending_request_.get()) { |
| DVLOG(1) << "Pending request was cleared during delay."; |
| return; |