Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/core/prefetch/add_unique_urls_task.h" | 5 #include "components/offline_pages/core/prefetch/add_unique_urls_task.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "url/gurl.h" | |
| 8 | 11 |
| 9 namespace offline_pages { | 12 namespace offline_pages { |
| 10 | 13 |
| 11 AddUniqueUrlsTask::AddUniqueUrlsTask( | 14 AddUniqueUrlsTask::AddUniqueUrlsTask( |
| 12 PrefetchStore* store, | 15 std::unique_ptr<AddUrlsStoreCommand> add_urls_command, |
| 16 std::unique_ptr<CleanupZombiesStoreCommand> zombies_cleanup_command, | |
| 17 const std::string& name_space, | |
| 13 const std::vector<PrefetchURL>& prefetch_urls) | 18 const std::vector<PrefetchURL>& prefetch_urls) |
| 14 : prefetch_store_(store), | 19 : add_urls_command_(std::move(add_urls_command)), |
| 20 zombies_cleanup_command_(std::move(zombies_cleanup_command)), | |
| 21 name_space_(name_space), | |
| 15 prefetch_urls_(prefetch_urls), | 22 prefetch_urls_(prefetch_urls), |
| 16 weak_ptr_factory_(this) {} | 23 weak_ptr_factory_(this) {} |
| 17 | 24 |
| 18 AddUniqueUrlsTask::~AddUniqueUrlsTask() {} | 25 AddUniqueUrlsTask::~AddUniqueUrlsTask() {} |
| 19 | 26 |
| 20 void AddUniqueUrlsTask::Run() { | 27 void AddUniqueUrlsTask::Run() { |
| 21 CHECK(prefetch_store_); | 28 add_urls_command_->Execute(name_space_, prefetch_urls_, |
| 22 TaskComplete(); | 29 base::BindOnce(&AddUniqueUrlsTask::OnUrlsAdded, |
| 30 weak_ptr_factory_.GetWeakPtr())); | |
| 31 } | |
| 32 | |
| 33 void AddUniqueUrlsTask::OnUrlsAdded(bool success) { | |
| 34 if (success) { | |
| 35 // TODO(carlosk): schedule NWake here if at least one new entry was added to | |
| 36 // the store. | |
|
carlosk
2017/06/15 22:29:08
I'll leave this as a TODO right now as it will pro
| |
| 37 std::vector<GURL> urls_to_keep; | |
| 38 for (const PrefetchURL& prefetch_url : prefetch_urls_) | |
| 39 urls_to_keep.push_back(prefetch_url.url); | |
| 40 zombies_cleanup_command_->Execute( | |
| 41 name_space_, urls_to_keep, | |
| 42 base::BindOnce(&AddUniqueUrlsTask::TaskComplete, | |
| 43 weak_ptr_factory_.GetWeakPtr())); | |
| 44 } else { | |
| 45 TaskComplete(); | |
| 46 } | |
| 23 } | 47 } |
| 24 | 48 |
| 25 } // namespace offline_pages | 49 } // namespace offline_pages |
| OLD | NEW |