| 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..e25cc54a9bccf404e2d713a7de3dc98b4638e3a4 100644
|
| --- a/components/offline_pages/core/prefetch/add_unique_urls_task.cc
|
| +++ b/components/offline_pages/core/prefetch/add_unique_urls_task.cc
|
| @@ -4,21 +4,55 @@
|
|
|
| #include "components/offline_pages/core/prefetch/add_unique_urls_task.h"
|
|
|
| +#include <memory>
|
| +#include <utility>
|
| +
|
| #include "base/bind.h"
|
| +#include "base/callback.h"
|
| +#include "url/gurl.h"
|
|
|
| namespace offline_pages {
|
|
|
| +namespace {
|
| +
|
| +// Adds new prefetch item entries to the store using the URLs and client IDs
|
| +// from |prefetch_urls| and the client's |name_space|. Also cleans up entries in
|
| +// the Zombie state from the client's |name_space| except for the ones
|
| +// whose URL is contained in |prefetch_urls|.
|
| +// Returns the number of added prefecth items.
|
| +static int AddUrlsAndCleanupZombies(
|
| + const std::string& name_space,
|
| + const std::vector<PrefetchURL>& prefetch_urls) {
|
| + NOTIMPLEMENTED();
|
| + return 1;
|
| +}
|
| +
|
| +// TODO(fgorski): replace this with the SQL executor.
|
| +static void Execute(base::RepeatingCallback<int()> command_callback,
|
| + base::OnceCallback<void(int)> result_callback) {
|
| + std::move(result_callback).Run(command_callback.Run());
|
| +}
|
| +}
|
| +
|
| AddUniqueUrlsTask::AddUniqueUrlsTask(
|
| - PrefetchStore* store,
|
| + const std::string& name_space,
|
| const std::vector<PrefetchURL>& prefetch_urls)
|
| - : prefetch_store_(store),
|
| + : name_space_(name_space),
|
| prefetch_urls_(prefetch_urls),
|
| weak_ptr_factory_(this) {}
|
|
|
| AddUniqueUrlsTask::~AddUniqueUrlsTask() {}
|
|
|
| void AddUniqueUrlsTask::Run() {
|
| - CHECK(prefetch_store_);
|
| + Execute(base::BindRepeating(&AddUrlsAndCleanupZombies, name_space_,
|
| + prefetch_urls_),
|
| + base::BindOnce(&AddUniqueUrlsTask::OnUrlsAdded,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +void AddUniqueUrlsTask::OnUrlsAdded(int added_entry_count) {
|
| + // TODO(carlosk): schedule NWake here if at least one new entry was added to
|
| + // the store.
|
| TaskComplete();
|
| }
|
|
|
|
|