Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2235)

Unified Diff: ios/chrome/browser/reading_list/reading_list_remover_helper.cc

Issue 2745313004: Remove all ReadingList entries on managed account signout. (Closed)
Patch Set: comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..94ab27da6d71b1d0039f19b0e15108dea3518d3e
--- /dev/null
+++ b/ios/chrome/browser/reading_list/reading_list_remover_helper.cc
@@ -0,0 +1,58 @@
+// 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(), completion_(nullptr) {
jif 2017/03/14 15:38:43 Default constructor of base::Callback already init
Olivier 2017/03/14 17:56:19 Done.
+ reading_list_model_ =
+ ReadingListModelFactory::GetForBrowserState(browser_state);
+ reading_list_download_service_ =
+ ReadingListDownloadServiceFactory::GetForBrowserState(browser_state);
+}
+
+ReadingListRemoverHelper::~ReadingListRemoverHelper() {}
+
+void ReadingListRemoverHelper::ReadingListModelLoaded(
+ const ReadingListModel* model) {
+ reading_list_model_->RemoveObserver(this);
+
+ bool model_cleared = reading_list_model_->DeleteAllEntries();
+ reading_list_download_service_->Clear();
+ if (completion_) {
+ completion_.Run(model_cleared);
+ completion_ = Callback();
+ }
+}
+
+void ReadingListRemoverHelper::ReadingListModelBeingDeleted(
+ const ReadingListModel* model) {
+ reading_list_model_->RemoveObserver(this);
+ if (completion_) {
+ completion_.Run(false);
+ completion_ = Callback();
+ }
jif 2017/03/14 15:38:43 reading_list_model_ = nullptr;
Olivier 2017/03/14 17:56:20 Done.
+}
+
+void ReadingListRemoverHelper::RemoveAllUserReadingListItemsIOS(
+ Callback completion) {
+ if (!reading_list_model_) {
+ completion.Run(false);
+ return;
+ }
+ completion_ = std::move(completion);
+ // This will call ReadingListModelLoaded if model is already loaded.
+ 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.
+}
+
+} // namespace reading_list

Powered by Google App Engine
This is Rietveld 408576698