OLD | NEW |
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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 class DefaultDelegate: public offline_pages::RecentTabHelper::Delegate { | 37 class DefaultDelegate: public offline_pages::RecentTabHelper::Delegate { |
38 public: | 38 public: |
39 DefaultDelegate() : is_low_end_device_(base::SysInfo::IsLowEndDevice()) {} | 39 DefaultDelegate() : is_low_end_device_(base::SysInfo::IsLowEndDevice()) {} |
40 | 40 |
41 // offline_pages::RecentTabHelper::Delegate | 41 // offline_pages::RecentTabHelper::Delegate |
42 std::unique_ptr<offline_pages::OfflinePageArchiver> CreatePageArchiver( | 42 std::unique_ptr<offline_pages::OfflinePageArchiver> CreatePageArchiver( |
43 content::WebContents* web_contents) override { | 43 content::WebContents* web_contents) override { |
44 return base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>( | 44 return base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>( |
45 web_contents); | 45 web_contents); |
46 } | 46 } |
47 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override { | |
48 return base::ThreadTaskRunnerHandle::Get(); | |
49 } | |
50 bool GetTabId(content::WebContents* web_contents, int* tab_id) override { | 47 bool GetTabId(content::WebContents* web_contents, int* tab_id) override { |
51 return offline_pages::OfflinePageUtils::GetTabId(web_contents, tab_id); | 48 return offline_pages::OfflinePageUtils::GetTabId(web_contents, tab_id); |
52 } | 49 } |
53 bool IsLowEndDevice() override { return is_low_end_device_; } | 50 bool IsLowEndDevice() override { return is_low_end_device_; } |
54 | 51 |
55 private: | 52 private: |
56 // Cached value of whether low end device. | 53 // Cached value of whether low end device. |
57 bool is_low_end_device_; | 54 bool is_low_end_device_; |
58 }; | 55 }; |
59 } // namespace | 56 } // namespace |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 157 } |
161 | 158 |
162 // Initialize lazily. It needs TabAndroid for initialization, which is also a | 159 // Initialize lazily. It needs TabAndroid for initialization, which is also a |
163 // TabHelper - so can't initialize in constructor because of uncertain order | 160 // TabHelper - so can't initialize in constructor because of uncertain order |
164 // of creation of TabHelpers. | 161 // of creation of TabHelpers. |
165 bool RecentTabHelper::EnsureInitialized() { | 162 bool RecentTabHelper::EnsureInitialized() { |
166 if (snapshot_controller_) // Initialized already. | 163 if (snapshot_controller_) // Initialized already. |
167 return snapshots_enabled_; | 164 return snapshots_enabled_; |
168 | 165 |
169 snapshot_controller_.reset( | 166 snapshot_controller_.reset( |
170 new SnapshotController(delegate_->GetTaskRunner(), this)); | 167 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this)); |
171 snapshot_controller_->Stop(); // It is reset when navigation commits. | 168 snapshot_controller_->Stop(); // It is reset when navigation commits. |
172 | 169 |
173 int tab_id_number = 0; | 170 int tab_id_number = 0; |
174 tab_id_.clear(); | 171 tab_id_.clear(); |
175 | 172 |
176 if (delegate_->GetTabId(web_contents(), &tab_id_number)) | 173 if (delegate_->GetTabId(web_contents(), &tab_id_number)) |
177 tab_id_ = base::IntToString(tab_id_number); | 174 tab_id_ = base::IntToString(tab_id_number); |
178 | 175 |
179 // TODO(dimich): When we have BackgroundOffliner, avoid capturing prerenderer | 176 // TODO(dimich): When we have BackgroundOffliner, avoid capturing prerenderer |
180 // WebContents with its origin as well. | 177 // WebContents with its origin as well. |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 460 } |
464 | 461 |
465 void RecentTabHelper::CancelInFlightSnapshots() { | 462 void RecentTabHelper::CancelInFlightSnapshots() { |
466 weak_ptr_factory_.InvalidateWeakPtrs(); | 463 weak_ptr_factory_.InvalidateWeakPtrs(); |
467 downloads_ongoing_snapshot_info_.reset(); | 464 downloads_ongoing_snapshot_info_.reset(); |
468 downloads_latest_saved_snapshot_info_.reset(); | 465 downloads_latest_saved_snapshot_info_.reset(); |
469 last_n_ongoing_snapshot_info_.reset(); | 466 last_n_ongoing_snapshot_info_.reset(); |
470 } | 467 } |
471 | 468 |
472 } // namespace offline_pages | 469 } // namespace offline_pages |
OLD | NEW |