Commit fe6a9602 authored by Scott Violet's avatar Scott Violet Committed by Chromium LUCI CQ

feed: makes FeedService::HistoryObserverImpl remove observer

HistoryObserverImpl was adding an observer, but never removing it.
This leads to a use-after-free when the class is deleted and
historyservice notifies observers.

BUG=1158388
TEST=none

Change-Id: I596fb10791dd9a40743fae86f9e24a60a10d8aa9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610991Reviewed-by: default avatarDan H <harringtond@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840805}
parent 5a0906db
......@@ -7,6 +7,7 @@
#include <utility>
#include "base/command_line.h"
#include "base/scoped_observation.h"
#include "build/build_config.h"
#include "components/feed/core/shared_prefs/pref_names.h"
#include "components/feed/core/v2/feed_network_impl.h"
......@@ -60,7 +61,7 @@ class FeedService::HistoryObserverImpl
: feed_stream_(feed_stream), identity_manager_(identity_manager) {
// May be null for some profiles.
if (history_service)
history_service->AddObserver(this);
scoped_history_service_observer_.Observe(history_service);
}
HistoryObserverImpl(const HistoryObserverImpl&) = delete;
HistoryObserverImpl& operator=(const HistoryObserverImpl&) = delete;
......@@ -76,6 +77,9 @@ class FeedService::HistoryObserverImpl
private:
FeedStream* feed_stream_;
signin::IdentityManager* identity_manager_;
base::ScopedObservation<history::HistoryService,
history::HistoryServiceObserver>
scoped_history_service_observer_{this};
};
class FeedService::NetworkDelegateImpl : public FeedNetworkImpl::Delegate {
......
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