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(), completion_(nullptr) { | |
|
jif
2017/03/14 15:38:43
Default constructor of base::Callback already init
Olivier
2017/03/14 17:56:19
Done.
| |
| 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 reading_list_model_->RemoveObserver(this); | |
| 29 | |
| 30 bool model_cleared = reading_list_model_->DeleteAllEntries(); | |
| 31 reading_list_download_service_->Clear(); | |
| 32 if (completion_) { | |
| 33 completion_.Run(model_cleared); | |
| 34 completion_ = Callback(); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 void ReadingListRemoverHelper::ReadingListModelBeingDeleted( | |
| 39 const ReadingListModel* model) { | |
| 40 reading_list_model_->RemoveObserver(this); | |
| 41 if (completion_) { | |
| 42 completion_.Run(false); | |
| 43 completion_ = Callback(); | |
| 44 } | |
|
jif
2017/03/14 15:38:43
reading_list_model_ = nullptr;
Olivier
2017/03/14 17:56:20
Done.
| |
| 45 } | |
| 46 | |
| 47 void ReadingListRemoverHelper::RemoveAllUserReadingListItemsIOS( | |
| 48 Callback completion) { | |
| 49 if (!reading_list_model_) { | |
| 50 completion.Run(false); | |
| 51 return; | |
| 52 } | |
| 53 completion_ = std::move(completion); | |
| 54 // This will call ReadingListModelLoaded if model is already loaded. | |
| 55 reading_list_model_->AddObserver(this); | |
|
jif
2017/03/14 15:38:43
What happens if |this| is deleted after |RemoveAll
Olivier
2017/03/14 17:56:19
Done.
| |
| 56 } | |
| 57 | |
| 58 } // namespace reading_list | |
| OLD | NEW |