Chromium Code Reviews| Index: components/offline_pages/offline_page_model_impl.cc |
| diff --git a/components/offline_pages/offline_page_model_impl.cc b/components/offline_pages/offline_page_model_impl.cc |
| index 577dd26082d8e6984fbfcf1c5a1afeda6ae89955..f261184edbbd9f9732d0c4bcc3cd70effe95b453 100644 |
| --- a/components/offline_pages/offline_page_model_impl.cc |
| +++ b/components/offline_pages/offline_page_model_impl.cc |
| @@ -335,37 +335,36 @@ void OfflinePageModelImpl::RemoveObserver(Observer* observer) { |
| } |
| void OfflinePageModelImpl::SavePage( |
| - const GURL& url, |
| - const ClientId& client_id, |
| - int64_t proposed_offline_id, |
| + const SavePageInfo& save_page_info, |
| std::unique_ptr<OfflinePageArchiver> archiver, |
| const SavePageCallback& callback) { |
| DCHECK(is_loaded_); |
| // Skip saving the page that is not intended to be saved, like local file |
| // page. |
| - if (!OfflinePageModel::CanSaveURL(url)) { |
| - InformSavePageDone(callback, SavePageResult::SKIPPED, client_id, |
| - kInvalidOfflineId); |
| + if (!OfflinePageModel::CanSaveURL(save_page_info.url)) { |
| + InformSavePageDone(callback, SavePageResult::SKIPPED, |
| + save_page_info.client_id, kInvalidOfflineId); |
| return; |
| } |
| // The web contents is not available if archiver is not created and passed. |
| if (!archiver.get()) { |
| - InformSavePageDone(callback, SavePageResult::CONTENT_UNAVAILABLE, client_id, |
| - kInvalidOfflineId); |
| + InformSavePageDone(callback, SavePageResult::CONTENT_UNAVAILABLE, |
| + save_page_info.client_id, kInvalidOfflineId); |
| return; |
| } |
| // If we already have an offline id, use it. If not, generate one. |
| - if (proposed_offline_id == kInvalidOfflineId) |
| - proposed_offline_id = GenerateOfflineId(); |
| + int64_t offline_id = save_page_info.proposed_offline_id; |
| + if (offline_id == kInvalidOfflineId) |
| + offline_id = GenerateOfflineId(); |
|
fgorski
2016/11/10 23:56:13
why don't you set it on the info/params object?
jianli
2016/11/16 01:25:40
I can't do it because save_page_info is const.
|
| archiver->CreateArchive( |
| - archives_dir_, proposed_offline_id, |
| + archives_dir_, offline_id, |
| base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, |
| - weak_ptr_factory_.GetWeakPtr(), url, proposed_offline_id, |
| - client_id, GetCurrentTime(), callback)); |
| + weak_ptr_factory_.GetWeakPtr(), save_page_info, offline_id, |
| + GetCurrentTime(), callback)); |
| pending_archivers_.push_back(std::move(archiver)); |
| } |
| @@ -726,36 +725,37 @@ OfflineEventLogger* OfflinePageModelImpl::GetLogger() { |
| return &offline_event_logger_; |
| } |
| -void OfflinePageModelImpl::OnCreateArchiveDone(const GURL& requested_url, |
| - int64_t offline_id, |
| - const ClientId& client_id, |
| - const base::Time& start_time, |
| - const SavePageCallback& callback, |
| - OfflinePageArchiver* archiver, |
| - ArchiverResult archiver_result, |
| - const GURL& url, |
| - const base::FilePath& file_path, |
| - const base::string16& title, |
| - int64_t file_size) { |
| - if (requested_url != url) { |
| +void OfflinePageModelImpl::OnCreateArchiveDone( |
| + const SavePageInfo& save_page_info, |
| + int64_t offline_id, |
|
fgorski
2016/11/10 23:56:13
needed? (relevant with the prior comment)
jianli
2016/11/16 01:25:40
Yes because save_page_info can't be changed. Also
|
| + const base::Time& start_time, |
| + const SavePageCallback& callback, |
| + OfflinePageArchiver* archiver, |
| + ArchiverResult archiver_result, |
| + const GURL& url, |
| + const base::FilePath& file_path, |
| + const base::string16& title, |
| + int64_t file_size) { |
| + if (save_page_info.url != url) { |
| DVLOG(1) << "Saved URL does not match requested URL."; |
| // TODO(fgorski): We have created an archive for a wrong URL. It should be |
| // deleted from here, once archiver has the right functionality. |
| InformSavePageDone(callback, SavePageResult::ARCHIVE_CREATION_FAILED, |
| - client_id, offline_id); |
| + save_page_info.client_id, offline_id); |
| DeletePendingArchiver(archiver); |
| return; |
| } |
| if (archiver_result != ArchiverResult::SUCCESSFULLY_CREATED) { |
| SavePageResult result = ToSavePageResult(archiver_result); |
| - InformSavePageDone(callback, result, client_id, offline_id); |
| + InformSavePageDone(callback, result, save_page_info.client_id, offline_id); |
| DeletePendingArchiver(archiver); |
| return; |
| } |
| - OfflinePageItem offline_page_item(url, offline_id, client_id, file_path, |
| - file_size, start_time); |
| + OfflinePageItem offline_page_item(url, offline_id, save_page_info.client_id, |
| + file_path, file_size, start_time); |
| offline_page_item.title = title; |
| + offline_page_item.original_url = save_page_info.original_url; |
| store_->AddOfflinePage(offline_page_item, |
| base::Bind(&OfflinePageModelImpl::OnAddOfflinePageDone, |
| weak_ptr_factory_.GetWeakPtr(), archiver, |