Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ios/chrome/browser/reading_list/reading_list_remover_helper.h" | |
| 6 | |
| 7 #include "components/reading_list/ios/reading_list_model.h" | |
| 8 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | |
| 9 #include "ios/chrome/browser/reading_list/reading_list_download_service.h" | |
| 10 #include "ios/chrome/browser/reading_list/reading_list_download_service_factory. h" | |
| 11 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" | |
| 12 | |
| 13 namespace reading_list { | |
| 14 | |
| 15 ReadingListRemoverHelper::ReadingListRemoverHelper( | |
| 16 ios::ChromeBrowserState* browser_state) | |
| 17 : ReadingListModelObserver(), scoped_observer_(this) { | |
| 18 reading_list_model_ = | |
| 19 ReadingListModelFactory::GetForBrowserState(browser_state); | |
| 20 reading_list_download_service_ = | |
| 21 ReadingListDownloadServiceFactory::GetForBrowserState(browser_state); | |
| 22 } | |
| 23 | |
| 24 ReadingListRemoverHelper::~ReadingListRemoverHelper() {} | |
| 25 | |
| 26 void ReadingListRemoverHelper::ReadingListModelLoaded( | |
| 27 const ReadingListModel* model) { | |
| 28 scoped_observer_.Remove(reading_list_model_); | |
| 29 | |
| 30 bool model_cleared = reading_list_model_->DeleteAllEntries(); | |
| 31 reading_list_download_service_->Clear(); | |
| 32 reading_list_model_ = nullptr; | |
| 33 if (completion_) { | |
| 34 // |completion_| may delete this. Do not use the object after this call. | |
| 35 std::move(completion_).Run(model_cleared); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void ReadingListRemoverHelper::ReadingListModelBeingDeleted( | |
| 40 const ReadingListModel* model) { | |
| 41 scoped_observer_.Remove(reading_list_model_); | |
| 42 reading_list_model_ = nullptr; | |
| 43 if (completion_) { | |
| 44 // |completion_| may delete this. Do not use the object after this call. | |
| 45 std::move(completion_).Run(false); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 void ReadingListRemoverHelper::RemoveAllUserReadingListItemsIOS( | |
| 50 Callback completion) { | |
| 51 if (!reading_list_model_) { | |
| 52 std::move(completion_).Run(false); | |
|
sdefresne
2017/03/20 15:09:40
Maybe add the following comment here too:
// |c
Olivier
2017/03/21 10:10:15
Done.
| |
| 53 return; | |
| 54 } | |
| 55 completion_ = std::move(completion); | |
| 56 | |
| 57 // Calls ReadingListModelLoaded if model is already loaded. | |
| 58 scoped_observer_.Add(reading_list_model_); | |
| 59 } | |
| 60 | |
| 61 } // namespace reading_list | |
| OLD | NEW |