Chromium Code Reviews| 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 "components/offline_pages/offline_page_model_impl.h" | 5 #include "components/offline_pages/offline_page_model_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 observers_.AddObserver(observer); | 268 observers_.AddObserver(observer); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void OfflinePageModelImpl::RemoveObserver(Observer* observer) { | 271 void OfflinePageModelImpl::RemoveObserver(Observer* observer) { |
| 272 observers_.RemoveObserver(observer); | 272 observers_.RemoveObserver(observer); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void OfflinePageModelImpl::SavePage( | 275 void OfflinePageModelImpl::SavePage( |
| 276 const GURL& url, | 276 const GURL& url, |
| 277 const ClientId& client_id, | 277 const ClientId& client_id, |
| 278 int64_t proposed_offline_id, | |
| 278 std::unique_ptr<OfflinePageArchiver> archiver, | 279 std::unique_ptr<OfflinePageArchiver> archiver, |
| 279 const SavePageCallback& callback) { | 280 const SavePageCallback& callback) { |
| 280 DCHECK(is_loaded_); | 281 DCHECK(is_loaded_); |
| 281 | 282 |
| 282 // Skip saving the page that is not intended to be saved, like local file | 283 // Skip saving the page that is not intended to be saved, like local file |
| 283 // page. | 284 // page. |
| 284 if (!OfflinePageModel::CanSaveURL(url)) { | 285 if (!OfflinePageModel::CanSaveURL(url)) { |
| 285 InformSavePageDone(callback, SavePageResult::SKIPPED, client_id, | 286 InformSavePageDone(callback, SavePageResult::SKIPPED, client_id, |
| 286 kInvalidOfflineId); | 287 kInvalidOfflineId); |
| 287 return; | 288 return; |
| 288 } | 289 } |
| 289 | 290 |
| 290 // The web contents is not available if archiver is not created and passed. | 291 // The web contents is not available if archiver is not created and passed. |
| 291 if (!archiver.get()) { | 292 if (!archiver.get()) { |
| 292 InformSavePageDone(callback, SavePageResult::CONTENT_UNAVAILABLE, client_id, | 293 InformSavePageDone(callback, SavePageResult::CONTENT_UNAVAILABLE, client_id, |
| 293 kInvalidOfflineId); | 294 kInvalidOfflineId); |
| 294 return; | 295 return; |
| 295 } | 296 } |
| 296 | 297 |
| 297 int64_t offline_id = GenerateOfflineId(); | 298 // If we already have an offline id, use it. If not, generate one. |
| 299 if (proposed_offline_id == 0ul) | |
|
dougarnett
2016/08/18 17:59:07
negative proposed ids ok?
| |
| 300 proposed_offline_id = GenerateOfflineId(); | |
| 298 | 301 |
| 299 archiver->CreateArchive( | 302 archiver->CreateArchive( |
| 300 archives_dir_, offline_id, | 303 archives_dir_, proposed_offline_id, |
| 301 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, | 304 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, |
| 302 weak_ptr_factory_.GetWeakPtr(), url, offline_id, client_id, | 305 weak_ptr_factory_.GetWeakPtr(), url, proposed_offline_id, |
| 303 base::Time::Now(), callback)); | 306 client_id, base::Time::Now(), callback)); |
| 304 pending_archivers_.push_back(std::move(archiver)); | 307 pending_archivers_.push_back(std::move(archiver)); |
| 305 } | 308 } |
| 306 | 309 |
| 307 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { | 310 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { |
| 308 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, | 311 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, |
| 309 weak_ptr_factory_.GetWeakPtr(), offline_id)); | 312 weak_ptr_factory_.GetWeakPtr(), offline_id)); |
| 310 } | 313 } |
| 311 | 314 |
| 312 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { | 315 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { |
| 313 DCHECK(is_loaded_); | 316 DCHECK(is_loaded_); |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1063 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1061 if (!is_loaded_) { | 1064 if (!is_loaded_) { |
| 1062 delayed_tasks_.push_back(task); | 1065 delayed_tasks_.push_back(task); |
| 1063 return; | 1066 return; |
| 1064 } | 1067 } |
| 1065 | 1068 |
| 1066 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1069 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1067 } | 1070 } |
| 1068 | 1071 |
| 1069 } // namespace offline_pages | 1072 } // namespace offline_pages |
| OLD | NEW |