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

Side by Side Diff: chrome/browser/android/offline_pages/recent_tab_helper.cc

Issue 2705453003: Last_n: disable on Svelte devices. (Closed)
Patch Set: Detect low end device through delegate; add pointer to default test delegate. Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/sys_info.h"
16 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati on_bridge.h" 19 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati on_bridge.h"
19 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 20 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
20 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 21 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
21 #include "chrome/browser/android/offline_pages/offline_page_utils.h" 22 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
22 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 23 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
23 #include "components/offline_pages/core/background/request_coordinator.h" 24 #include "components/offline_pages/core/background/request_coordinator.h"
24 #include "components/offline_pages/core/client_namespace_constants.h" 25 #include "components/offline_pages/core/client_namespace_constants.h"
25 #include "components/offline_pages/core/offline_page_feature.h" 26 #include "components/offline_pages/core/offline_page_feature.h"
26 #include "components/offline_pages/core/offline_page_item.h" 27 #include "components/offline_pages/core/offline_page_item.h"
27 #include "components/offline_pages/core/offline_page_model.h" 28 #include "components/offline_pages/core/offline_page_model.h"
28 #include "content/public/browser/browser_context.h" 29 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/navigation_entry.h" 31 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/navigation_handle.h" 32 #include "content/public/browser/navigation_handle.h"
32 33
33 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::RecentTabHelper); 34 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::RecentTabHelper);
34 35
35 namespace { 36 namespace {
36 class DefaultDelegate: public offline_pages::RecentTabHelper::Delegate { 37 class DefaultDelegate: public offline_pages::RecentTabHelper::Delegate {
37 public: 38 public:
38 DefaultDelegate() {} 39 DefaultDelegate() : is_low_end_device_(base::SysInfo::IsLowEndDevice()) {}
39 40
40 // offline_pages::RecentTabHelper::Delegate 41 // offline_pages::RecentTabHelper::Delegate
41 std::unique_ptr<offline_pages::OfflinePageArchiver> CreatePageArchiver( 42 std::unique_ptr<offline_pages::OfflinePageArchiver> CreatePageArchiver(
42 content::WebContents* web_contents) override { 43 content::WebContents* web_contents) override {
43 return base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>( 44 return base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>(
44 web_contents); 45 web_contents);
45 } 46 }
46 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override { 47 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override {
47 return base::ThreadTaskRunnerHandle::Get(); 48 return base::ThreadTaskRunnerHandle::Get();
48 } 49 }
49 bool GetTabId(content::WebContents* web_contents, int* tab_id) override { 50 bool GetTabId(content::WebContents* web_contents, int* tab_id) override {
50 return offline_pages::OfflinePageUtils::GetTabId(web_contents, tab_id); 51 return offline_pages::OfflinePageUtils::GetTabId(web_contents, tab_id);
51 } 52 }
53 bool IsLowEndDevice() override { return is_low_end_device_; }
54
55 private:
56 // Cached value of whether low end device.
57 bool is_low_end_device_;
52 }; 58 };
53 } // namespace 59 } // namespace
54 60
55 namespace offline_pages { 61 namespace offline_pages {
56 62
57 using PageQuality = SnapshotController::PageQuality; 63 using PageQuality = SnapshotController::PageQuality;
58 64
59 // Keeps client_id/request_id that will be used for the offline snapshot. 65 // Keeps client_id/request_id that will be used for the offline snapshot.
60 struct RecentTabHelper::SnapshotProgressInfo { 66 struct RecentTabHelper::SnapshotProgressInfo {
61 public: 67 public:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Check for conditions that would cause us not to snapshot. 211 // Check for conditions that would cause us not to snapshot.
206 bool can_save = !navigation_handle->IsErrorPage() && 212 bool can_save = !navigation_handle->IsErrorPage() &&
207 OfflinePageModel::CanSaveURL(snapshot_url_) && 213 OfflinePageModel::CanSaveURL(snapshot_url_) &&
208 OfflinePageUtils::GetOfflinePageFromWebContents( 214 OfflinePageUtils::GetOfflinePageFromWebContents(
209 web_contents()) == nullptr; 215 web_contents()) == nullptr;
210 216
211 UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save); 217 UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save);
212 218
213 if (!can_save) 219 if (!can_save)
214 snapshot_controller_->Stop(); 220 snapshot_controller_->Stop();
215 last_n_listen_to_tab_hidden_ = can_save && IsOffliningRecentPagesEnabled(); 221 last_n_listen_to_tab_hidden_ = can_save && !delegate_->IsLowEndDevice() &&
222 IsOffliningRecentPagesEnabled();
216 last_n_latest_saved_quality_ = PageQuality::POOR; 223 last_n_latest_saved_quality_ = PageQuality::POOR;
217 } 224 }
218 225
219 void RecentTabHelper::DocumentAvailableInMainFrame() { 226 void RecentTabHelper::DocumentAvailableInMainFrame() {
220 EnsureInitialized(); 227 EnsureInitialized();
221 snapshot_controller_->DocumentAvailableInMainFrame(); 228 snapshot_controller_->DocumentAvailableInMainFrame();
222 } 229 }
223 230
224 void RecentTabHelper::DocumentOnLoadCompletedInMainFrame() { 231 void RecentTabHelper::DocumentOnLoadCompletedInMainFrame() {
225 EnsureInitialized(); 232 EnsureInitialized();
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 431 }
425 432
426 void RecentTabHelper::CancelInFlightSnapshots() { 433 void RecentTabHelper::CancelInFlightSnapshots() {
427 weak_ptr_factory_.InvalidateWeakPtrs(); 434 weak_ptr_factory_.InvalidateWeakPtrs();
428 downloads_ongoing_snapshot_info_.reset(); 435 downloads_ongoing_snapshot_info_.reset();
429 downloads_latest_saved_snapshot_info_.reset(); 436 downloads_latest_saved_snapshot_info_.reset();
430 last_n_ongoing_snapshot_info_.reset(); 437 last_n_ongoing_snapshot_info_.reset();
431 } 438 }
432 439
433 } // namespace offline_pages 440 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698