| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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/prerendering_offliner.h" | 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
| 10 #include "components/offline_pages/background/save_page_request.h" | 10 #include "components/offline_pages/background/save_page_request.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // WebContents are being destroyed) - whichever callback occurs first. | 54 // WebContents are being destroyed) - whichever callback occurs first. |
| 55 DCHECK(web_contents); | 55 DCHECK(web_contents); |
| 56 std::unique_ptr<OfflinePageArchiver> archiver( | 56 std::unique_ptr<OfflinePageArchiver> archiver( |
| 57 new OfflinePageMHTMLArchiver(web_contents)); | 57 new OfflinePageMHTMLArchiver(web_contents)); |
| 58 // Pass in the URL from the WebContents in case it is redirected from | 58 // Pass in the URL from the WebContents in case it is redirected from |
| 59 // the requested URL. This is to work around a check in the | 59 // the requested URL. This is to work around a check in the |
| 60 // OfflinePageModel implementation that ensures URL passed in here is | 60 // OfflinePageModel implementation that ensures URL passed in here is |
| 61 // same as LastCommittedURL from the snapshot. | 61 // same as LastCommittedURL from the snapshot. |
| 62 // TODO(dougarnett): Raise issue of how to better deal with redirects. | 62 // TODO(dougarnett): Raise issue of how to better deal with redirects. |
| 63 SavePage(web_contents->GetLastCommittedURL(), request.client_id(), | 63 SavePage(web_contents->GetLastCommittedURL(), request.client_id(), |
| 64 request.request_id(), |
| 64 std::move(archiver), | 65 std::move(archiver), |
| 65 base::Bind(&PrerenderingOffliner::OnSavePageDone, | 66 base::Bind(&PrerenderingOffliner::OnSavePageDone, |
| 66 weak_ptr_factory_.GetWeakPtr(), request)); | 67 weak_ptr_factory_.GetWeakPtr(), request)); |
| 67 } else { | 68 } else { |
| 68 // Clear pending request and app listener then run completion callback. | 69 // Clear pending request and app listener then run completion callback. |
| 69 pending_request_.reset(nullptr); | 70 pending_request_.reset(nullptr); |
| 70 app_listener_.reset(nullptr); | 71 app_listener_.reset(nullptr); |
| 71 completion_callback_.Run(request, load_status); | 72 completion_callback_.Run(request, load_status); |
| 72 } | 73 } |
| 73 } | 74 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 165 } |
| 165 | 166 |
| 166 void PrerenderingOffliner::SetApplicationStateForTesting( | 167 void PrerenderingOffliner::SetApplicationStateForTesting( |
| 167 base::android::ApplicationState application_state) { | 168 base::android::ApplicationState application_state) { |
| 168 OnApplicationStateChange(application_state); | 169 OnApplicationStateChange(application_state); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void PrerenderingOffliner::SavePage( | 172 void PrerenderingOffliner::SavePage( |
| 172 const GURL& url, | 173 const GURL& url, |
| 173 const ClientId& client_id, | 174 const ClientId& client_id, |
| 175 int64_t offline_id, |
| 174 std::unique_ptr<OfflinePageArchiver> archiver, | 176 std::unique_ptr<OfflinePageArchiver> archiver, |
| 175 const SavePageCallback& save_callback) { | 177 const SavePageCallback& save_callback) { |
| 176 DCHECK(offline_page_model_); | 178 DCHECK(offline_page_model_); |
| 177 offline_page_model_->SavePage(url, client_id, std::move(archiver), | 179 offline_page_model_->SavePage(url, client_id, offline_id, std::move(archiver), |
| 178 save_callback); | 180 save_callback); |
| 179 } | 181 } |
| 180 | 182 |
| 181 PrerenderingLoader* PrerenderingOffliner::GetOrCreateLoader() { | 183 PrerenderingLoader* PrerenderingOffliner::GetOrCreateLoader() { |
| 182 if (!loader_) { | 184 if (!loader_) { |
| 183 loader_.reset(new PrerenderingLoader(browser_context_)); | 185 loader_.reset(new PrerenderingLoader(browser_context_)); |
| 184 } | 186 } |
| 185 return loader_.get(); | 187 return loader_.get(); |
| 186 } | 188 } |
| 187 | 189 |
| 188 void PrerenderingOffliner::OnApplicationStateChange( | 190 void PrerenderingOffliner::OnApplicationStateChange( |
| 189 base::android::ApplicationState application_state) { | 191 base::android::ApplicationState application_state) { |
| 190 if (pending_request_ && is_low_end_device_ && | 192 if (pending_request_ && is_low_end_device_ && |
| 191 application_state == | 193 application_state == |
| 192 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { | 194 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { |
| 193 DVLOG(1) << "App became active, canceling current offlining request"; | 195 DVLOG(1) << "App became active, canceling current offlining request"; |
| 194 SavePageRequest* request = pending_request_.get(); | 196 SavePageRequest* request = pending_request_.get(); |
| 195 Cancel(); | 197 Cancel(); |
| 196 completion_callback_.Run(*request, | 198 completion_callback_.Run(*request, |
| 197 Offliner::RequestStatus::FOREGROUND_CANCELED); | 199 Offliner::RequestStatus::FOREGROUND_CANCELED); |
| 198 } | 200 } |
| 199 } | 201 } |
| 200 | 202 |
| 201 } // namespace offline_pages | 203 } // namespace offline_pages |
| OLD | NEW |