Commit bf3a1f1b authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

feed v2: fix unpersonalized feed

If the user signs out, and then signs back in, Chrome was
showing an unpersonalized feed.

Bug: 1117535
Change-Id: I5b247f1d4641bbfbc7e3d9f80623d6afb08909b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362991
Auto-Submit: Dan H <harringtond@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Commit-Queue: Carlos Knippschild <carlosk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799286}
parent 132e1deb
......@@ -43,9 +43,12 @@ class EulaObserver : public web_resource::EulaAcceptedNotifier::Observer {
} // namespace
namespace internal {
bool ShouldClearFeed(const history::DeletionInfo& deletion_info) {
// Only clear the feed if all history is deleted.
return deletion_info.IsAllHistory();
bool ShouldClearFeed(bool is_signed_in,
const history::DeletionInfo& deletion_info) {
// Only clear the feed if all history is deleted while a user is signed-in.
// Clear history events happen between sign-in events, and those should be
// ignored.
return is_signed_in && deletion_info.IsAllHistory();
}
} // namespace internal
......@@ -53,8 +56,9 @@ class FeedService::HistoryObserverImpl
: public history::HistoryServiceObserver {
public:
HistoryObserverImpl(history::HistoryService* history_service,
FeedStream* feed_stream)
: feed_stream_(feed_stream) {
FeedStream* feed_stream,
signin::IdentityManager* identity_manager)
: feed_stream_(feed_stream), identity_manager_(identity_manager) {
// May be null for some profiles.
if (history_service)
history_service->AddObserver(this);
......@@ -65,12 +69,14 @@ class FeedService::HistoryObserverImpl
// history::HistoryServiceObserver.
void OnURLsDeleted(history::HistoryService* history_service,
const history::DeletionInfo& deletion_info) override {
if (internal::ShouldClearFeed(deletion_info))
if (internal::ShouldClearFeed(identity_manager_->HasPrimaryAccount(),
deletion_info))
feed_stream_->OnAllHistoryDeleted();
}
private:
FeedStream* feed_stream_;
signin::IdentityManager* identity_manager_;
};
class FeedService::NetworkDelegateImpl : public FeedNetworkImpl::Delegate {
......@@ -189,7 +195,8 @@ FeedService::FeedService(
chrome_info);
history_observer_ = std::make_unique<HistoryObserverImpl>(
history_service, static_cast<FeedStream*>(stream_.get()));
history_service, static_cast<FeedStream*>(stream_.get()),
identity_manager);
stream_delegate_->Initialize(static_cast<FeedStream*>(stream_.get()));
identity_manager_observer_ = std::make_unique<IdentityManagerObserverImpl>(
......
......@@ -51,7 +51,8 @@ class FeedStream;
class ImageFetcher;
namespace internal {
bool ShouldClearFeed(const history::DeletionInfo& deletion_info);
bool ShouldClearFeed(bool is_signed_in,
const history::DeletionInfo& deletion_info);
} // namespace internal
class FeedService : public KeyedService {
......
......@@ -13,13 +13,15 @@ namespace {
using history::DeletionInfo;
TEST(ShouldClearFeed, ShouldClearFeed) {
EXPECT_TRUE(ShouldClearFeed(DeletionInfo::ForAllHistory()));
EXPECT_FALSE(ShouldClearFeed(DeletionInfo::ForUrls(
{
history::URLRow(GURL("http://url1")),
history::URLRow(GURL("http://url2")),
},
/*favicon_urls=*/{})));
EXPECT_TRUE(ShouldClearFeed(true, DeletionInfo::ForAllHistory()));
EXPECT_FALSE(
ShouldClearFeed(true, DeletionInfo::ForUrls(
{
history::URLRow(GURL("http://url1")),
history::URLRow(GURL("http://url2")),
},
/*favicon_urls=*/{})));
EXPECT_FALSE(ShouldClearFeed(false, DeletionInfo::ForAllHistory()));
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment