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

Unified Diff: components/offline_pages/core/prefetch/add_unique_urls_task.cc

Issue 2920083002: Prefetching: Introduce store commands abstractions to be used by tasks. (Closed)
Patch Set: Added TODO for NWake Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/core/prefetch/add_unique_urls_task.cc
diff --git a/components/offline_pages/core/prefetch/add_unique_urls_task.cc b/components/offline_pages/core/prefetch/add_unique_urls_task.cc
index 58f46a0ed03a00df250c1276d8ed5439ac2aeef2..ad01b8c77212688b67852717dfe1cb9ca12718cb 100644
--- a/components/offline_pages/core/prefetch/add_unique_urls_task.cc
+++ b/components/offline_pages/core/prefetch/add_unique_urls_task.cc
@@ -4,22 +4,46 @@
#include "components/offline_pages/core/prefetch/add_unique_urls_task.h"
+#include <memory>
+
#include "base/bind.h"
+#include "url/gurl.h"
namespace offline_pages {
AddUniqueUrlsTask::AddUniqueUrlsTask(
- PrefetchStore* store,
+ std::unique_ptr<AddUrlsStoreCommand> add_urls_command,
+ std::unique_ptr<CleanupZombiesStoreCommand> zombies_cleanup_command,
+ const std::string& name_space,
const std::vector<PrefetchURL>& prefetch_urls)
- : prefetch_store_(store),
+ : add_urls_command_(std::move(add_urls_command)),
+ zombies_cleanup_command_(std::move(zombies_cleanup_command)),
+ name_space_(name_space),
prefetch_urls_(prefetch_urls),
weak_ptr_factory_(this) {}
AddUniqueUrlsTask::~AddUniqueUrlsTask() {}
void AddUniqueUrlsTask::Run() {
- CHECK(prefetch_store_);
- TaskComplete();
+ add_urls_command_->Execute(name_space_, prefetch_urls_,
+ base::BindOnce(&AddUniqueUrlsTask::OnUrlsAdded,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void AddUniqueUrlsTask::OnUrlsAdded(bool success) {
+ if (success) {
+ // TODO(carlosk): schedule NWake here if at least one new entry was added to
+ // the store.
carlosk 2017/06/15 22:29:08 I'll leave this as a TODO right now as it will pro
+ std::vector<GURL> urls_to_keep;
+ for (const PrefetchURL& prefetch_url : prefetch_urls_)
+ urls_to_keep.push_back(prefetch_url.url);
+ zombies_cleanup_command_->Execute(
+ name_space_, urls_to_keep,
+ base::BindOnce(&AddUniqueUrlsTask::TaskComplete,
+ weak_ptr_factory_.GetWeakPtr()));
+ } else {
+ TaskComplete();
+ }
}
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698