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/background_loader_offliner.h" | 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h" |
6 | 6 |
7 #include "base/sys_info.h" | 7 #include "base/sys_info.h" |
8 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 8 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
9 #include "components/offline_pages/core/background/save_page_request.h" | 9 #include "components/offline_pages/core/background/save_page_request.h" |
10 #include "components/offline_pages/core/offline_page_model.h" | 10 #include "components/offline_pages/core/offline_page_model.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 OfflinePageModel::SavePageParams params; | 90 OfflinePageModel::SavePageParams params; |
91 params.url = web_contents->GetLastCommittedURL(); | 91 params.url = web_contents->GetLastCommittedURL(); |
92 params.client_id = request.client_id(); | 92 params.client_id = request.client_id(); |
93 params.proposed_offline_id = request.request_id(); | 93 params.proposed_offline_id = request.request_id(); |
94 offline_page_model_->SavePage( | 94 offline_page_model_->SavePage( |
95 params, std::move(archiver), | 95 params, std::move(archiver), |
96 base::Bind(&BackgroundLoaderOffliner::OnPageSaved, | 96 base::Bind(&BackgroundLoaderOffliner::OnPageSaved, |
97 weak_ptr_factory_.GetWeakPtr())); | 97 weak_ptr_factory_.GetWeakPtr())); |
98 } | 98 } |
99 | 99 |
| 100 void BackgroundLoaderOffliner::RenderProcessGone( |
| 101 base::TerminationStatus status) { |
| 102 if (pending_request_) { |
| 103 SavePageRequest request(*pending_request_.get()); |
| 104 switch (status) { |
| 105 case base::TERMINATION_STATUS_OOM: |
| 106 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 107 case base::TERMINATION_STATUS_STILL_RUNNING: |
| 108 completion_callback_.Run( |
| 109 request, Offliner::RequestStatus::LOADING_FAILED_NO_NEXT); |
| 110 break; |
| 111 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 112 default: |
| 113 completion_callback_.Run(request, |
| 114 Offliner::RequestStatus::LOADING_FAILED); |
| 115 } |
| 116 ResetState(); |
| 117 } |
| 118 } |
| 119 |
| 120 void BackgroundLoaderOffliner::WebContentsDestroyed() { |
| 121 if (pending_request_) { |
| 122 SavePageRequest request(*pending_request_.get()); |
| 123 completion_callback_.Run(*pending_request_.get(), |
| 124 Offliner::RequestStatus::LOADING_FAILED); |
| 125 ResetState(); |
| 126 } |
| 127 } |
| 128 |
100 void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result, | 129 void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result, |
101 int64_t offline_id) { | 130 int64_t offline_id) { |
102 if (!pending_request_) | 131 if (!pending_request_) |
103 return; | 132 return; |
104 | 133 |
105 SavePageRequest request(*pending_request_.get()); | 134 SavePageRequest request(*pending_request_.get()); |
106 ResetState(); | 135 ResetState(); |
107 | 136 |
108 if (save_state_ == DELETE_AFTER_SAVE) { | 137 if (save_state_ == DELETE_AFTER_SAVE) { |
109 save_state_ = NONE; | 138 save_state_ = NONE; |
(...skipping 29 matching lines...) Expand all Loading... |
139 application_state == | 168 application_state == |
140 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { | 169 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { |
141 DVLOG(1) << "App became active, canceling current offlining request"; | 170 DVLOG(1) << "App became active, canceling current offlining request"; |
142 SavePageRequest* request = pending_request_.get(); | 171 SavePageRequest* request = pending_request_.get(); |
143 Cancel(); | 172 Cancel(); |
144 completion_callback_.Run(*request, RequestStatus::FOREGROUND_CANCELED); | 173 completion_callback_.Run(*request, RequestStatus::FOREGROUND_CANCELED); |
145 } | 174 } |
146 } | 175 } |
147 | 176 |
148 } // namespace offline_pages | 177 } // namespace offline_pages |
OLD | NEW |