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::DeletePagesByURLPredicate( | |
292 const base::Callback<bool(const GURL&)> predicate, | |
293 const DeletePageCallback& callback) { | |
294 if (!is_loaded_) { | |
295 delayed_tasks_.push_back( | |
296 base::Bind(&OfflinePageModel::DoDeletePagesByURLPredicate, | |
297 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); | |
298 | |
299 return; | |
300 } | |
301 DoDeletePagesByURLPredicate(predicate, callback); | |
302 } | |
303 | |
304 void OfflinePageModel::DoDeletePagesByURLPredicate( | |
305 const base::Callback<bool(const GURL&)> predicate, | |
306 const DeletePageCallback& callback) { | |
307 DCHECK(is_loaded_); | |
308 | |
309 std::vector<int64_t> offline_ids; | |
310 for (const auto& id_page_pair : offline_pages_) { | |
311 if (!id_page_pair.second.IsMarkedForDeletion() && | |
312 predicate.Run(id_page_pair.second.url)) | |
fgorski
2016/04/11 20:07:27
wrap with {} since the if statement spans more tha
dmurph
2016/04/11 22:29:29
Done.
| |
313 offline_ids.push_back(id_page_pair.first); | |
314 } | |
315 DoDeletePagesByOfflineId(offline_ids, callback); | |
316 } | |
317 | |
291 bool OfflinePageModel::HasOfflinePages() const { | 318 bool OfflinePageModel::HasOfflinePages() const { |
292 // Since offline pages feature is enabled by default, | 319 // Since offline pages feature is enabled by default, |
293 // NetErrorTabHelper::SetHasOfflinePages might call this before the model is | 320 // NetErrorTabHelper::SetHasOfflinePages might call this before the model is |
294 // fully loaded. To address this, we need to switch to asynchonous model | 321 // 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 | 322 // (crbug.com/589526). But for now, we just bail out to work around the test |
296 // issue. | 323 // issue. |
297 if (!is_loaded_) | 324 if (!is_loaded_) |
298 return false; | 325 return false; |
299 | 326 |
300 // Check that at least one page is not marked for deletion. Because we have | 327 // 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, | 815 base::Bind(&OfflinePageModel::MarkPageForDeletion, |
789 weak_ptr_factory_.GetWeakPtr(), offline_ids[i], callback)); | 816 weak_ptr_factory_.GetWeakPtr(), offline_ids[i], callback)); |
790 } | 817 } |
791 return; | 818 return; |
792 } | 819 } |
793 for (const auto& id : offline_ids) { | 820 for (const auto& id : offline_ids) { |
794 MarkPageForDeletion(id, callback); | 821 MarkPageForDeletion(id, callback); |
795 } | 822 } |
796 } | 823 } |
797 } // namespace offline_pages | 824 } // namespace offline_pages |
OLD | NEW |