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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_remover_helper.cc

Issue 2745313004: Remove all ReadingList entries on managed account signout. (Closed)
Patch Set: feedback 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 unified diff | Download patch
OLDNEW
(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 // |completion_| may delete this. Do not use the object after this call.
53 std::move(completion_).Run(false);
54 return;
55 }
56 completion_ = std::move(completion);
57
58 // Calls ReadingListModelLoaded if model is already loaded.
59 scoped_observer_.Add(reading_list_model_);
60 }
61
62 } // namespace reading_list
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_remover_helper.h ('k') | ios/chrome/browser/reading_list/url_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698