| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 ReportDownloadStatusToRequestCoordinator(); | 84 ReportDownloadStatusToRequestCoordinator(); |
| 85 download_info_.reset(); | 85 download_info_.reset(); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // No snapshots yet happened on the current page - return and wait for some. | 89 // No snapshots yet happened on the current page - return and wait for some. |
| 90 if (!is_page_ready_for_snapshot_) | 90 if (!is_page_ready_for_snapshot_) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 // If snapshot already happened and we missed it, go ahead and snapshot now. | 93 // If snapshot already happened and we missed it, go ahead and snapshot now. |
| 94 OfflinePageModel::SavePageParams save_page_params; |
| 95 save_page_params.url = web_contents()->GetLastCommittedURL(); |
| 96 save_page_params.client_id = client_id; |
| 97 save_page_params.proposed_offline_id = request_id; |
| 94 page_model_->SavePage( | 98 page_model_->SavePage( |
| 95 web_contents()->GetLastCommittedURL(), | 99 save_page_params, |
| 96 client_id, | |
| 97 request_id, | |
| 98 delegate_->CreatePageArchiver(web_contents()), | 100 delegate_->CreatePageArchiver(web_contents()), |
| 99 base::Bind(&RecentTabHelper::SavePageCallback, | 101 base::Bind(&RecentTabHelper::SavePageCallback, |
| 100 weak_ptr_factory_.GetWeakPtr())); | 102 weak_ptr_factory_.GetWeakPtr())); |
| 101 } | 103 } |
| 102 | 104 |
| 103 // Initialize lazily. It needs TabAndroid for initialization, which is also a | 105 // Initialize lazily. It needs TabAndroid for initialization, which is also a |
| 104 // TabHelper - so can't initialize in constructor because of uncertain order | 106 // TabHelper - so can't initialize in constructor because of uncertain order |
| 105 // of creation of TabHelpers. | 107 // of creation of TabHelpers. |
| 106 void RecentTabHelper::EnsureInitialized() { | 108 void RecentTabHelper::EnsureInitialized() { |
| 107 if (snapshot_controller_) // Initialized already. | 109 if (snapshot_controller_) // Initialized already. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 236 |
| 235 void RecentTabHelper::ContinueSnapshotAfterPurge( | 237 void RecentTabHelper::ContinueSnapshotAfterPurge( |
| 236 OfflinePageModel::DeletePageResult result) { | 238 OfflinePageModel::DeletePageResult result) { |
| 237 if (!download_info_ || | 239 if (!download_info_ || |
| 238 result != OfflinePageModel::DeletePageResult::SUCCESS || | 240 result != OfflinePageModel::DeletePageResult::SUCCESS || |
| 239 !IsSamePage()) { | 241 !IsSamePage()) { |
| 240 ReportSnapshotCompleted(); | 242 ReportSnapshotCompleted(); |
| 241 return; | 243 return; |
| 242 } | 244 } |
| 243 | 245 |
| 244 page_model_->SavePage(snapshot_url_, | 246 OfflinePageModel::SavePageParams save_page_params; |
| 245 download_info_->client_id_, | 247 save_page_params.url = snapshot_url_; |
| 246 download_info_->request_id_, | 248 save_page_params.client_id = download_info_->client_id_; |
| 249 save_page_params.proposed_offline_id = download_info_->request_id_; |
| 250 page_model_->SavePage(save_page_params, |
| 247 delegate_->CreatePageArchiver(web_contents()), | 251 delegate_->CreatePageArchiver(web_contents()), |
| 248 base::Bind(&RecentTabHelper::SavePageCallback, | 252 base::Bind(&RecentTabHelper::SavePageCallback, |
| 249 weak_ptr_factory_.GetWeakPtr())); | 253 weak_ptr_factory_.GetWeakPtr())); |
| 250 } | 254 } |
| 251 | 255 |
| 252 void RecentTabHelper::SavePageCallback(OfflinePageModel::SavePageResult result, | 256 void RecentTabHelper::SavePageCallback(OfflinePageModel::SavePageResult result, |
| 253 int64_t offline_id) { | 257 int64_t offline_id) { |
| 254 if (!download_info_) | 258 if (!download_info_) |
| 255 return; | 259 return; |
| 256 download_info_->page_snapshot_completed_ = | 260 download_info_->page_snapshot_completed_ = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 bool RecentTabHelper::IsSamePage() const { | 293 bool RecentTabHelper::IsSamePage() const { |
| 290 return web_contents() && | 294 return web_contents() && |
| 291 (web_contents()->GetLastCommittedURL() == snapshot_url_); | 295 (web_contents()->GetLastCommittedURL() == snapshot_url_); |
| 292 } | 296 } |
| 293 | 297 |
| 294 ClientId RecentTabHelper::GetRecentPagesClientId() const { | 298 ClientId RecentTabHelper::GetRecentPagesClientId() const { |
| 295 return ClientId(kLastNNamespace, tab_id_); | 299 return ClientId(kLastNNamespace, tab_id_); |
| 296 } | 300 } |
| 297 | 301 |
| 298 } // namespace offline_pages | 302 } // namespace offline_pages |
| OLD | NEW |