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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 observers_.AddObserver(observer); | 267 observers_.AddObserver(observer); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void OfflinePageModelImpl::RemoveObserver(Observer* observer) { | 270 void OfflinePageModelImpl::RemoveObserver(Observer* observer) { |
| 271 observers_.RemoveObserver(observer); | 271 observers_.RemoveObserver(observer); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void OfflinePageModelImpl::SavePage( | 274 void OfflinePageModelImpl::SavePage( |
| 275 const GURL& url, | 275 const GURL& url, |
| 276 const ClientId& client_id, | 276 const ClientId& client_id, |
| 277 int64_t offline_id, | |
| 277 std::unique_ptr<OfflinePageArchiver> archiver, | 278 std::unique_ptr<OfflinePageArchiver> archiver, |
| 278 const SavePageCallback& callback) { | 279 const SavePageCallback& callback) { |
| 279 DCHECK(is_loaded_); | 280 DCHECK(is_loaded_); |
| 280 | 281 |
| 281 // Skip saving the page that is not intended to be saved, like local file | 282 // Skip saving the page that is not intended to be saved, like local file |
| 282 // page. | 283 // page. |
| 283 if (!OfflinePageModel::CanSaveURL(url)) { | 284 if (!OfflinePageModel::CanSaveURL(url)) { |
| 284 InformSavePageDone(callback, SavePageResult::SKIPPED, client_id, | 285 InformSavePageDone(callback, SavePageResult::SKIPPED, client_id, |
| 285 kInvalidOfflineId); | 286 kInvalidOfflineId); |
| 286 return; | 287 return; |
| 287 } | 288 } |
| 288 | 289 |
| 289 // The web contents is not available if archiver is not created and passed. | 290 // The web contents is not available if archiver is not created and passed. |
| 290 if (!archiver.get()) { | 291 if (!archiver.get()) { |
| 291 InformSavePageDone(callback, SavePageResult::CONTENT_UNAVAILABLE, client_id, | 292 InformSavePageDone(callback, SavePageResult::CONTENT_UNAVAILABLE, client_id, |
| 292 kInvalidOfflineId); | 293 kInvalidOfflineId); |
| 293 return; | 294 return; |
| 294 } | 295 } |
| 295 | 296 |
| 296 int64_t offline_id = GenerateOfflineId(); | 297 // If we already have an offline id, use it. If not, generate one. |
| 298 if (offline_id == 0ul) | |
|
Dmitry Titov
2016/08/16 02:25:00
This should go into the comment for SavePage metho
Pete Williamson
2016/08/16 18:54:56
Done.
| |
| 299 offline_id = GenerateOfflineId(); | |
| 297 | 300 |
| 298 archiver->CreateArchive( | 301 archiver->CreateArchive( |
| 299 archives_dir_, offline_id, | 302 archives_dir_, offline_id, |
| 300 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, | 303 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, |
| 301 weak_ptr_factory_.GetWeakPtr(), url, offline_id, client_id, | 304 weak_ptr_factory_.GetWeakPtr(), url, offline_id, client_id, |
| 302 base::Time::Now(), callback)); | 305 base::Time::Now(), callback)); |
| 303 pending_archivers_.push_back(std::move(archiver)); | 306 pending_archivers_.push_back(std::move(archiver)); |
| 304 } | 307 } |
| 305 | 308 |
| 306 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { | 309 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1057 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1060 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1058 if (!is_loaded_) { | 1061 if (!is_loaded_) { |
| 1059 delayed_tasks_.push_back(task); | 1062 delayed_tasks_.push_back(task); |
| 1060 return; | 1063 return; |
| 1061 } | 1064 } |
| 1062 | 1065 |
| 1063 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1066 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1064 } | 1067 } |
| 1065 | 1068 |
| 1066 } // namespace offline_pages | 1069 } // namespace offline_pages |
| OLD | NEW |