Chromium Code Reviews| Index: chrome/browser/offline_pages/android/load_termination_listener_impl.cc |
| diff --git a/chrome/browser/offline_pages/android/load_termination_listener_impl.cc b/chrome/browser/offline_pages/android/load_termination_listener_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3bdb1101f2bc87c33006a112b9233a55b612b83e |
| --- /dev/null |
| +++ b/chrome/browser/offline_pages/android/load_termination_listener_impl.cc |
| @@ -0,0 +1,35 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/offline_pages/android/load_termination_listener_impl.h" |
| + |
| +#include "base/android/application_status_listener.h" |
| +#include "base/logging.h" |
| +#include "base/sys_info.h" |
| + |
| +namespace offline_pages { |
| + |
| +LoadTerminationListenerImpl::LoadTerminationListenerImpl() |
| + : weak_ptr_factory_(this) { |
| + if (base::SysInfo::IsLowEndDevice()) { |
| + app_listener_ = base::MakeUnique<base::android::ApplicationStatusListener>( |
| + base::Bind(&LoadTerminationListenerImpl::OnApplicationStateChange, |
| + weak_ptr_factory_.GetWeakPtr())); |
|
dewittj
2017/05/24 23:24:40
q: technically could this be base::Unretained(this
Dmitry Titov
2017/05/25 23:24:13
It indeed would be, in this specific case. I'm hes
|
| + } |
| +} |
| + |
| +LoadTerminationListenerImpl::~LoadTerminationListenerImpl() { |
| +} |
| + |
| +void LoadTerminationListenerImpl::OnApplicationStateChange( |
| + base::android::ApplicationState application_state) { |
| + if (offliner_ && |
| + application_state == |
| + base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { |
| + DVLOG(1) << "App became foreground, canceling current offlining request"; |
| + offliner_->TerminateLoadIfInProgress(); |
| + } |
| +} |
| + |
| +} // namespace offline_pages |