Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: components/offline_pages/offline_page_model_impl.cc

Issue 2234873004: Have the RequestCoordinator generate the offline_id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge, and CR fixes per Dimich Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698