OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "components/offline_pages/offline_page_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 | 281 |
282 std::vector<int64_t> offline_ids; | 282 std::vector<int64_t> offline_ids; |
283 for (const auto& id_page_pair : offline_pages_) | 283 for (const auto& id_page_pair : offline_pages_) |
284 offline_ids.push_back(id_page_pair.first); | 284 offline_ids.push_back(id_page_pair.first); |
285 DeletePagesByOfflineId( | 285 DeletePagesByOfflineId( |
286 offline_ids, | 286 offline_ids, |
287 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, | 287 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, |
288 weak_ptr_factory_.GetWeakPtr(), callback)); | 288 weak_ptr_factory_.GetWeakPtr(), callback)); |
289 } | 289 } |
290 | 290 |
291 void OfflinePageModel::ClearWithURLPredicate( | |
292 const base::Callback<bool(const GURL&)> predicate, | |
293 const base::Closure& callback) { | |
294 DCHECK(is_loaded_); | |
fgorski
2016/04/07 17:02:49
You can push back to delayed tasks here if you wan
dmurph
2016/04/08 23:33:45
Done.
| |
295 | |
296 std::vector<int64_t> offline_ids; | |
297 for (const auto& id_page_pair : offline_pages_) { | |
298 if (predicate.Run(GURL(id_page_pair.second.url))) | |
fgorski
2016/04/07 17:02:49
id_page_pair.second.url is already a GURL.
Anothe
dmurph
2016/04/08 23:33:45
Done.
| |
299 offline_ids.push_back(id_page_pair.first); | |
300 } | |
301 DeletePagesByOfflineId( | |
302 offline_ids, | |
303 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, | |
fgorski
2016/04/07 17:02:49
No this will not do, as this wipes the whole store
dmurph
2016/04/08 23:33:45
Whoops, thanks.
| |
304 weak_ptr_factory_.GetWeakPtr(), callback)); | |
305 } | |
306 | |
291 bool OfflinePageModel::HasOfflinePages() const { | 307 bool OfflinePageModel::HasOfflinePages() const { |
292 // Since offline pages feature is enabled by default, | 308 // Since offline pages feature is enabled by default, |
293 // NetErrorTabHelper::SetHasOfflinePages might call this before the model is | 309 // NetErrorTabHelper::SetHasOfflinePages might call this before the model is |
294 // fully loaded. To address this, we need to switch to asynchonous model | 310 // fully loaded. To address this, we need to switch to asynchonous model |
295 // (crbug.com/589526). But for now, we just bail out to work around the test | 311 // (crbug.com/589526). But for now, we just bail out to work around the test |
296 // issue. | 312 // issue. |
297 if (!is_loaded_) | 313 if (!is_loaded_) |
298 return false; | 314 return false; |
299 | 315 |
300 // Check that at least one page is not marked for deletion. Because we have | 316 // Check that at least one page is not marked for deletion. Because we have |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 base::Bind(&OfflinePageModel::MarkPageForDeletion, | 804 base::Bind(&OfflinePageModel::MarkPageForDeletion, |
789 weak_ptr_factory_.GetWeakPtr(), offline_ids[i], callback)); | 805 weak_ptr_factory_.GetWeakPtr(), offline_ids[i], callback)); |
790 } | 806 } |
791 return; | 807 return; |
792 } | 808 } |
793 for (const auto& id : offline_ids) { | 809 for (const auto& id : offline_ids) { |
794 MarkPageForDeletion(id, callback); | 810 MarkPageForDeletion(id, callback); |
795 } | 811 } |
796 } | 812 } |
797 } // namespace offline_pages | 813 } // namespace offline_pages |
OLD | NEW |