Commit 4e6fdede authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

Retire ScopedObserver in /components/history.

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=sky@chromium.org

Bug: 1145565
Change-Id: Ieb10240f6035314a206ea814709c43c1c739ac7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532954
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826827}
parent e6510933
......@@ -173,12 +173,12 @@ BrowsingHistoryService::BrowsingHistoryService(
// Get notifications when history is cleared.
if (local_history_)
history_service_observer_.Add(local_history_);
history_service_observation_.Observe(local_history_);
// Get notifications when web history is deleted.
WebHistoryService* web_history = driver_->GetWebHistoryService();
if (web_history) {
web_history_service_observer_.Add(web_history);
web_history_service_observation_.Observe(web_history);
} else if (sync_service_) {
// If |web_history| is not available, it means that history sync is
// disabled. If |sync_service_| is not null, it means that syncing is
......@@ -187,7 +187,7 @@ BrowsingHistoryService::BrowsingHistoryService(
// observing. This is okay because sync will never start for us, for example
// it may be disabled by flag or we're part of an incognito/guest mode
// window.
sync_service_observer_.Add(sync_service_);
sync_service_observation_.Observe(sync_service_);
}
}
......@@ -201,9 +201,9 @@ void BrowsingHistoryService::OnStateChanged(syncer::SyncService* sync) {
// This method should not be called after we already added the observer.
WebHistoryService* web_history = driver_->GetWebHistoryService();
if (web_history) {
DCHECK(!web_history_service_observer_.IsObserving(web_history));
web_history_service_observer_.Add(web_history);
sync_service_observer_.RemoveAll();
DCHECK(!web_history_service_observation_.IsObserving());
web_history_service_observation_.Observe(web_history);
sync_service_observation_.RemoveObservation();
}
}
......
......@@ -17,7 +17,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/strings/string16.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/clock.h"
......@@ -227,16 +227,16 @@ class BrowsingHistoryService : public HistoryServiceObserver,
std::unique_ptr<base::OneShotTimer> web_history_timer_;
// HistoryService (local history) observer.
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_{this};
base::ScopedObservation<HistoryService, HistoryServiceObserver>
history_service_observation_{this};
// WebHistoryService (synced history) observer.
ScopedObserver<WebHistoryService, WebHistoryServiceObserver>
web_history_service_observer_{this};
base::ScopedObservation<WebHistoryService, WebHistoryServiceObserver>
web_history_service_observation_{this};
// SyncService observer listens to late initialization of history sync.
ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver>
sync_service_observer_{this};
base::ScopedObservation<syncer::SyncService, syncer::SyncServiceObserver>
sync_service_observation_{this};
// Whether the last call to Web History returned synced results.
bool has_synced_results_ = false;
......
......@@ -17,7 +17,7 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
......
......@@ -27,7 +27,7 @@ void InMemoryHistoryBackend::AttachToHistoryService(
HistoryService* history_service) {
DCHECK(db_);
DCHECK(history_service);
history_service_observer_.Add(history_service);
history_service_observation_.Observe(history_service);
}
void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword(
......
......@@ -25,7 +25,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/keyword_id.h"
......@@ -91,8 +91,8 @@ class InMemoryHistoryBackend : public HistoryServiceObserver {
std::unique_ptr<InMemoryDatabase> db_;
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_{this};
base::ScopedObservation<HistoryService, HistoryServiceObserver>
history_service_observation_{this};
DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend);
};
......
......@@ -214,7 +214,8 @@ void TopSitesImpl::OnNavigationCommitted(const GURL& url) {
void TopSitesImpl::ShutdownOnUIThread() {
history_service_ = nullptr;
history_service_observer_.RemoveAll();
if (history_service_observation_.IsObserving())
history_service_observation_.RemoveObservation();
// Cancel all requests so that the service doesn't callback to us after we've
// invoked Shutdown (this could happen if we have a pending request and
// Shutdown is invoked).
......@@ -398,7 +399,7 @@ void TopSitesImpl::MoveStateToLoaded() {
std::move(callback).Run(urls);
if (history_service_)
history_service_observer_.Add(history_service_);
history_service_observation_.Observe(history_service_);
NotifyTopSitesLoaded();
}
......
......@@ -14,7 +14,7 @@
#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/synchronization/lock.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/threading/thread_checker.h"
......@@ -210,8 +210,8 @@ class TopSitesImpl : public TopSites, public HistoryServiceObserver {
// The histogram should only be recorded once for each Chrome execution.
static bool histogram_recorded_;
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_{this};
base::ScopedObservation<HistoryService, HistoryServiceObserver>
history_service_observation_{this};
DISALLOW_COPY_AND_ASSIGN(TopSitesImpl);
};
......
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