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 #include <utility> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
| 12 #include "url/gurl.h" |
8 | 13 |
9 namespace offline_pages { | 14 namespace offline_pages { |
10 | 15 |
| 16 namespace { |
| 17 |
| 18 // Adds new prefetch item entries to the store using the URLs and client IDs |
| 19 // from |prefetch_urls| and the client's |name_space|. Also cleans up entries in |
| 20 // the Zombie state from the client's |name_space| except for the ones |
| 21 // whose URL is contained in |prefetch_urls|. |
| 22 // Returns the number of added prefecth items. |
| 23 static int AddUrlsAndCleanupZombies( |
| 24 const std::string& name_space, |
| 25 const std::vector<PrefetchURL>& prefetch_urls) { |
| 26 NOTIMPLEMENTED(); |
| 27 return 1; |
| 28 } |
| 29 |
| 30 // TODO(fgorski): replace this with the SQL executor. |
| 31 static void Execute(base::RepeatingCallback<int()> command_callback, |
| 32 base::OnceCallback<void(int)> result_callback) { |
| 33 std::move(result_callback).Run(command_callback.Run()); |
| 34 } |
| 35 } |
| 36 |
11 AddUniqueUrlsTask::AddUniqueUrlsTask( | 37 AddUniqueUrlsTask::AddUniqueUrlsTask( |
12 PrefetchStore* store, | 38 const std::string& name_space, |
13 const std::vector<PrefetchURL>& prefetch_urls) | 39 const std::vector<PrefetchURL>& prefetch_urls) |
14 : prefetch_store_(store), | 40 : name_space_(name_space), |
15 prefetch_urls_(prefetch_urls), | 41 prefetch_urls_(prefetch_urls), |
16 weak_ptr_factory_(this) {} | 42 weak_ptr_factory_(this) {} |
17 | 43 |
18 AddUniqueUrlsTask::~AddUniqueUrlsTask() {} | 44 AddUniqueUrlsTask::~AddUniqueUrlsTask() {} |
19 | 45 |
20 void AddUniqueUrlsTask::Run() { | 46 void AddUniqueUrlsTask::Run() { |
21 CHECK(prefetch_store_); | 47 Execute(base::BindRepeating(&AddUrlsAndCleanupZombies, name_space_, |
| 48 prefetch_urls_), |
| 49 base::BindOnce(&AddUniqueUrlsTask::OnUrlsAdded, |
| 50 weak_ptr_factory_.GetWeakPtr())); |
| 51 } |
| 52 |
| 53 void AddUniqueUrlsTask::OnUrlsAdded(int added_entry_count) { |
| 54 // TODO(carlosk): schedule NWake here if at least one new entry was added to |
| 55 // the store. |
22 TaskComplete(); | 56 TaskComplete(); |
23 } | 57 } |
24 | 58 |
25 } // namespace offline_pages | 59 } // namespace offline_pages |
OLD | NEW |