| Index: chrome/browser/offline_pages/background_loader_offliner.cc
|
| diff --git a/chrome/browser/offline_pages/background_loader_offliner.cc b/chrome/browser/offline_pages/background_loader_offliner.cc
|
| index 726a40444de9277afe4c5c8953fdfb59a1aa39ef..7860f5ead47813c7344b9f438ac634b6232ec01b 100644
|
| --- a/chrome/browser/offline_pages/background_loader_offliner.cc
|
| +++ b/chrome/browser/offline_pages/background_loader_offliner.cc
|
| @@ -73,7 +73,7 @@ void RecordErrorCauseUMA(const ClientId& client_id, net::Error error_code) {
|
| std::abs(error_code));
|
| }
|
|
|
| -void HandleApplicationStateChangeCancel(
|
| +void HandleLoadTerminationCancel(
|
| const Offliner::CompletionCallback& completion_callback,
|
| const SavePageRequest& canceled_request) {
|
| completion_callback.Run(canceled_request,
|
| @@ -85,11 +85,12 @@ void HandleApplicationStateChangeCancel(
|
| BackgroundLoaderOffliner::BackgroundLoaderOffliner(
|
| content::BrowserContext* browser_context,
|
| const OfflinerPolicy* policy,
|
| - OfflinePageModel* offline_page_model)
|
| + OfflinePageModel* offline_page_model,
|
| + std::unique_ptr<LoadTerminationListener> load_termination_listener)
|
| : browser_context_(browser_context),
|
| offline_page_model_(offline_page_model),
|
| policy_(policy),
|
| - is_low_end_device_(base::SysInfo::IsLowEndDevice()),
|
| + load_termination_listener_(std::move(load_termination_listener)),
|
| save_state_(NONE),
|
| page_load_state_(SUCCESS),
|
| network_bytes_(0LL),
|
| @@ -98,6 +99,7 @@ BackgroundLoaderOffliner::BackgroundLoaderOffliner(
|
| weak_ptr_factory_(this) {
|
| DCHECK(offline_page_model_);
|
| DCHECK(browser_context_);
|
| + load_termination_listener_->set_offliner(this);
|
| }
|
|
|
| BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {}
|
| @@ -182,11 +184,6 @@ bool BackgroundLoaderOffliner::LoadAndSave(
|
| completion_callback_ = completion_callback;
|
| progress_callback_ = progress_callback;
|
|
|
| - // Listen for app foreground/background change.
|
| - app_listener_.reset(new base::android::ApplicationStatusListener(
|
| - base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange,
|
| - weak_ptr_factory_.GetWeakPtr())));
|
| -
|
| // Load page attempt.
|
| loader_.get()->LoadPage(request.url());
|
|
|
| @@ -219,6 +216,13 @@ bool BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) {
|
| return true;
|
| }
|
|
|
| +void BackgroundLoaderOffliner::TerminateLoadIfInProgress() {
|
| + if (!pending_request_)
|
| + return;
|
| +
|
| + Cancel(base::Bind(HandleLoadTerminationCancel, completion_callback_));
|
| +}
|
| +
|
| bool BackgroundLoaderOffliner::HandleTimeout(int64_t request_id) {
|
| if (pending_request_) {
|
| DCHECK(request_id == pending_request_->request_id());
|
| @@ -469,20 +473,6 @@ void BackgroundLoaderOffliner::AttachObservers() {
|
| OfflinerData::AddToWebContents(contents, this);
|
| }
|
|
|
| -void BackgroundLoaderOffliner::OnApplicationStateChange(
|
| - base::android::ApplicationState application_state) {
|
| - if (pending_request_ && is_low_end_device_ &&
|
| - application_state ==
|
| - base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
|
| - DVLOG(1) << "App became active, canceling current offlining request";
|
| - // No need to check the return value or complete early, as false would
|
| - // indicate that there was no request, in which case the state change is
|
| - // ignored.
|
| - Cancel(
|
| - base::Bind(HandleApplicationStateChangeCancel, completion_callback_));
|
| - }
|
| -}
|
| -
|
| void BackgroundLoaderOffliner::AddLoadingSignal(const char* signal_name) {
|
| base::TimeTicks current_time = base::TimeTicks::Now();
|
| base::TimeDelta delay_so_far = current_time - load_start_time_;
|
|
|