Chromium Code Reviews| Index: ios/chrome/browser/reading_list/reading_list_remover_helper.cc |
| diff --git a/ios/chrome/browser/reading_list/reading_list_remover_helper.cc b/ios/chrome/browser/reading_list/reading_list_remover_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db2bc7ae05486d885a9959d414e1ce152e0c28b4 |
| --- /dev/null |
| +++ b/ios/chrome/browser/reading_list/reading_list_remover_helper.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ios/chrome/browser/reading_list/reading_list_remover_helper.h" |
| + |
| +#include "components/reading_list/ios/reading_list_model.h" |
| +#include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| +#include "ios/chrome/browser/reading_list/reading_list_download_service.h" |
| +#include "ios/chrome/browser/reading_list/reading_list_download_service_factory.h" |
| +#include "ios/chrome/browser/reading_list/reading_list_model_factory.h" |
| + |
| +namespace reading_list { |
| + |
| +ReadingListRemoverHelper::ReadingListRemoverHelper( |
| + ios::ChromeBrowserState* browser_state) |
| + : ReadingListModelObserver(), scoped_observer_(this) { |
| + reading_list_model_ = |
| + ReadingListModelFactory::GetForBrowserState(browser_state); |
| + reading_list_download_service_ = |
| + ReadingListDownloadServiceFactory::GetForBrowserState(browser_state); |
| +} |
| + |
| +ReadingListRemoverHelper::~ReadingListRemoverHelper() {} |
| + |
| +void ReadingListRemoverHelper::ReadingListModelLoaded( |
| + const ReadingListModel* model) { |
| + scoped_observer_.Remove(reading_list_model_); |
| + |
| + bool model_cleared = reading_list_model_->DeleteAllEntries(); |
| + reading_list_download_service_->Clear(); |
| + if (completion_) { |
| + completion_.Run(model_cleared); |
|
msarda
2017/03/14 18:46:05
How about std::move(completion_).Run()?
jif
2017/03/14 19:00:22
std::move turns a lvalue into a rvalue.
In this ca
|
| + completion_ = Callback(); |
| + } |
| + reading_list_model_ = nullptr; |
|
msarda
2017/03/14 18:46:06
Here and above: Consider resetting the model befor
Olivier
2017/03/15 09:17:40
Done.
|
| +} |
| + |
| +void ReadingListRemoverHelper::ReadingListModelBeingDeleted( |
| + const ReadingListModel* model) { |
| + scoped_observer_.Remove(reading_list_model_); |
| + if (completion_) { |
| + completion_.Run(false); |
| + completion_ = Callback(); |
| + } |
| + reading_list_model_ = nullptr; |
| +} |
| + |
| +void ReadingListRemoverHelper::RemoveAllUserReadingListItemsIOS( |
| + Callback completion) { |
| + if (!reading_list_model_) { |
|
msarda
2017/03/14 18:46:06
I suppose reading_list_model_ can only be Null if
jif
2017/03/14 19:00:21
reading_list_model_ can also be null if |ReadingLi
Olivier
2017/03/15 09:17:40
I don't want to put this in the constructor as pot
|
| + completion.Run(false); |
| + return; |
| + } |
| + completion_ = std::move(completion); |
|
msarda
2017/03/14 18:46:06
Nit: Blank line for comment s that start at the sa
Olivier
2017/03/15 09:17:40
Done.
|
| + // This will call ReadingListModelLoaded if model is already loaded. |
|
msarda
2017/03/14 18:46:05
Optional nit: s/This will call/Calls
Olivier
2017/03/15 09:17:40
Done.
|
| + scoped_observer_.Add(reading_list_model_); |
| +} |
| + |
| +} // namespace reading_list |