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

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

Issue 2898393002: Split Android-specific dependency from BackgroundLoaderOffliner. Create a subfolder of c/b/offline_… (Closed)
Patch Set: more build fixes Created 3 years, 7 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
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

Powered by Google App Engine
This is Rietveld 408576698