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 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/scoped_observation.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/feed/core/shared_prefs/pref_names.h" #include "components/feed/core/shared_prefs/pref_names.h"
#include "components/feed/core/v2/feed_network_impl.h" #include "components/feed/core/v2/feed_network_impl.h"
...@@ -60,7 +61,7 @@ class FeedService::HistoryObserverImpl ...@@ -60,7 +61,7 @@ class FeedService::HistoryObserverImpl
: feed_stream_(feed_stream), identity_manager_(identity_manager) { : feed_stream_(feed_stream), identity_manager_(identity_manager) {
// May be null for some profiles. // May be null for some profiles.
if (history_service) if (history_service)
history_service->AddObserver(this); scoped_history_service_observer_.Observe(history_service);
} }
HistoryObserverImpl(const HistoryObserverImpl&) = delete; HistoryObserverImpl(const HistoryObserverImpl&) = delete;
HistoryObserverImpl& operator=(const HistoryObserverImpl&) = delete; HistoryObserverImpl& operator=(const HistoryObserverImpl&) = delete;
...@@ -76,6 +77,9 @@ class FeedService::HistoryObserverImpl ...@@ -76,6 +77,9 @@ class FeedService::HistoryObserverImpl
private: private:
FeedStream* feed_stream_; FeedStream* feed_stream_;
signin::IdentityManager* identity_manager_; signin::IdentityManager* identity_manager_;
base::ScopedObservation<history::HistoryService,
history::HistoryServiceObserver>
scoped_history_service_observer_{this};
}; };
class FeedService::NetworkDelegateImpl : public FeedNetworkImpl::Delegate { 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