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

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 if (completion_) {
33 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
34 completion_ = Callback();
35 }
36 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.
37 }
38
39 void ReadingListRemoverHelper::ReadingListModelBeingDeleted(
40 const ReadingListModel* model) {
41 scoped_observer_.Remove(reading_list_model_);
42 if (completion_) {
43 completion_.Run(false);
44 completion_ = Callback();
45 }
46 reading_list_model_ = nullptr;
47 }
48
49 void ReadingListRemoverHelper::RemoveAllUserReadingListItemsIOS(
50 Callback completion) {
51 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
52 completion.Run(false);
53 return;
54 }
55 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.
56 // 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.
57 scoped_observer_.Add(reading_list_model_);
58 }
59
60 } // namespace reading_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698