Commit 22914292 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

Retire ScopedObserver in /components/ntp_snippets.

ScopedObserver is being deprecated in favor of two new classes:
- base::ScopedObservation for observers that only ever observe
  a single source.
- base::ScopedMultiSourceObservation for observers that do or may
  observe more than a single source.

This CL was uploaded by git cl split.

R=harringtond@chromium.org

Bug: 1145565
Change-Id: I00ea07dd484293ba9cc164f97838def2a4e15615
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532657
Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarDan H <harringtond@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826371}
parent 16caa301
......@@ -56,8 +56,6 @@ ContentSuggestionsService::ContentSuggestionsService(
std::unique_ptr<UserClassifier> user_classifier,
std::unique_ptr<RemoteSuggestionsScheduler> remote_suggestions_scheduler)
: state_(state),
identity_manager_observer_(this),
history_service_observer_(this),
remote_suggestions_provider_(nullptr),
large_icon_service_(large_icon_service),
pref_service_(pref_service),
......@@ -66,11 +64,11 @@ ContentSuggestionsService::ContentSuggestionsService(
category_ranker_(std::move(category_ranker)) {
// Can be null in tests.
if (identity_manager) {
identity_manager_observer_.Add(identity_manager);
identity_manager_observation_.Observe(identity_manager);
}
if (history_service) {
history_service_observer_.Add(history_service);
history_service_observation_.Observe(history_service);
}
RestoreDismissedCategoriesFromPrefs();
......@@ -552,7 +550,8 @@ void ContentSuggestionsService::OnURLsDeleted(
void ContentSuggestionsService::HistoryServiceBeingDeleted(
history::HistoryService* history_service) {
history_service_observer_.RemoveAll();
DCHECK(history_service_observation_.IsObservingSource(history_service));
history_service_observation_.RemoveObservation();
}
bool ContentSuggestionsService::TryRegisterProviderForCategory(
......
......@@ -14,7 +14,7 @@
#include "base/callback_forward.h"
#include "base/observer_list.h"
#include "base/optional.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
#include "components/history/core/browser/history_service.h"
......@@ -378,13 +378,15 @@ class ContentSuggestionsService : public KeyedService,
// Observer for the IdentityManager. All observers are notified when the
// signin state changes so that they can refresh their list of suggestions.
ScopedObserver<signin::IdentityManager, signin::IdentityManager::Observer>
identity_manager_observer_;
base::ScopedObservation<signin::IdentityManager,
signin::IdentityManager::Observer>
identity_manager_observation_{this};
// Observer for the HistoryService. All providers are notified when history is
// deleted.
ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
history_service_observer_;
base::ScopedObservation<history::HistoryService,
history::HistoryServiceObserver>
history_service_observation_{this};
base::ObserverList<Observer>::Unchecked observers_;
......
......@@ -43,7 +43,7 @@ ReadingListSuggestionsProvider::ReadingListSuggestionsProvider(
// If the ReadingListModel is loaded, this will trigger a call to
// ReadingListModelLoaded. Keep it as last instruction.
scoped_observer_.Add(reading_list_model_);
scoped_observation_.Observe(reading_list_model_);
}
ReadingListSuggestionsProvider::~ReadingListSuggestionsProvider() {}
......@@ -160,7 +160,8 @@ void ReadingListSuggestionsProvider::ReadingListModelLoaded(
void ReadingListSuggestionsProvider::ReadingListModelBeingDeleted(
const ReadingListModel* model) {
DCHECK(model == reading_list_model_);
scoped_observer_.Remove(reading_list_model_);
DCHECK(scoped_observation_.IsObservingSource(reading_list_model_));
scoped_observation_.RemoveObservation();
reading_list_model_ = nullptr;
}
......
......@@ -8,7 +8,7 @@
#include <set>
#include <string>
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "components/ntp_snippets/callbacks.h"
#include "components/ntp_snippets/category.h"
#include "components/ntp_snippets/category_info.h"
......@@ -74,8 +74,8 @@ class ReadingListSuggestionsProvider : public ContentSuggestionsProvider,
const Category provided_category_;
ReadingListModel* reading_list_model_;
ScopedObserver<ReadingListModel, ReadingListModelObserver> scoped_observer_{
this};
base::ScopedObservation<ReadingListModel, ReadingListModelObserver>
scoped_observation_{this};
DISALLOW_COPY_AND_ASSIGN(ReadingListSuggestionsProvider);
};
......
......@@ -6,7 +6,7 @@
#define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_STATUS_SERVICE_H_
#include "base/callback.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "components/prefs/pref_change_registrar.h"
namespace ntp_snippets {
......
......@@ -6,7 +6,7 @@
#define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_STATUS_SERVICE_IMPL_H_
#include "base/callback.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "components/ntp_snippets/remote/remote_suggestions_status_service.h"
#include "components/prefs/pref_change_registrar.h"
......
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