summaryrefslogtreecommitdiffstats
path: root/components/history/core
diff options
context:
space:
mode:
authorfserb <fserb@chromium.org>2015-06-29 14:31:59 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-29 21:32:29 +0000
commitdb57511e74dda6b32844ab1e77d8d3f2cf171726 (patch)
tree03da8537ee9804d9a3853c9e1fb507bca83a3ade /components/history/core
parent8a2ebfa1cb92700c36390a6ce9e83e8810655a62 (diff)
downloadchromium_src-db57511e74dda6b32844ab1e77d8d3f2cf171726.zip
chromium_src-db57511e74dda6b32844ab1e77d8d3f2cf171726.tar.gz
chromium_src-db57511e74dda6b32844ab1e77d8d3f2cf171726.tar.bz2
Prevent Topsites bubbling of update tiles when adding forced URLs
BUG=499947 Review URL: https://codereview.chromium.org/1184823002 Cr-Commit-Position: refs/heads/master@{#336649}
Diffstat (limited to 'components/history/core')
-rw-r--r--components/history/core/browser/top_sites.cc6
-rw-r--r--components/history/core/browser/top_sites.h3
-rw-r--r--components/history/core/browser/top_sites_impl.cc14
-rw-r--r--components/history/core/browser/top_sites_impl.h4
-rw-r--r--components/history/core/browser/top_sites_observer.h13
-rw-r--r--components/history/core/test/wait_top_sites_loaded_observer.cc3
-rw-r--r--components/history/core/test/wait_top_sites_loaded_observer.h3
7 files changed, 34 insertions, 12 deletions
diff --git a/components/history/core/browser/top_sites.cc b/components/history/core/browser/top_sites.cc
index 49de259..987d86b 100644
--- a/components/history/core/browser/top_sites.cc
+++ b/components/history/core/browser/top_sites.cc
@@ -42,8 +42,10 @@ void TopSites::NotifyTopSitesLoaded() {
FOR_EACH_OBSERVER(TopSitesObserver, observer_list_, TopSitesLoaded(this));
}
-void TopSites::NotifyTopSitesChanged() {
- FOR_EACH_OBSERVER(TopSitesObserver, observer_list_, TopSitesChanged(this));
+void TopSites::NotifyTopSitesChanged(
+ const TopSitesObserver::ChangeReason reason) {
+ FOR_EACH_OBSERVER(TopSitesObserver, observer_list_,
+ TopSitesChanged(this, reason));
}
} // namespace history
diff --git a/components/history/core/browser/top_sites.h b/components/history/core/browser/top_sites.h
index f7a6aac..911a57b 100644
--- a/components/history/core/browser/top_sites.h
+++ b/components/history/core/browser/top_sites.h
@@ -13,6 +13,7 @@
#include "base/observer_list.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/history/core/browser/history_types.h"
+#include "components/history/core/browser/top_sites_observer.h"
#include "components/history/core/common/thumbnail_score.h"
#include "components/keyed_service/core/refcounted_keyed_service.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -178,7 +179,7 @@ class TopSites : public RefcountedKeyedService {
protected:
void NotifyTopSitesLoaded();
- void NotifyTopSitesChanged();
+ void NotifyTopSitesChanged(const TopSitesObserver::ChangeReason reason);
~TopSites() override;
private:
diff --git a/components/history/core/browser/top_sites_impl.cc b/components/history/core/browser/top_sites_impl.cc
index 854cfd4..a3fee18 100644
--- a/components/history/core/browser/top_sites_impl.cc
+++ b/components/history/core/browser/top_sites_impl.cc
@@ -28,6 +28,7 @@
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/page_usage_data.h"
#include "components/history/core/browser/top_sites_cache.h"
+#include "components/history/core/browser/top_sites_observer.h"
#include "components/history/core/browser/url_utils.h"
#include "components/history/core/common/thumbnail_score.h"
#include "ui/base/l10n/l10n_util.h"
@@ -334,7 +335,7 @@ void TopSitesImpl::AddBlacklistedURL(const GURL& url) {
}
ResetThreadSafeCache();
- NotifyTopSitesChanged();
+ NotifyTopSitesChanged(TopSitesObserver::ChangeReason::BLACKLIST);
}
void TopSitesImpl::RemoveBlacklistedURL(const GURL& url) {
@@ -345,7 +346,7 @@ void TopSitesImpl::RemoveBlacklistedURL(const GURL& url) {
blacklist->RemoveWithoutPathExpansion(GetURLHash(url), nullptr);
}
ResetThreadSafeCache();
- NotifyTopSitesChanged();
+ NotifyTopSitesChanged(TopSitesObserver::ChangeReason::BLACKLIST);
}
bool TopSitesImpl::IsBlacklisted(const GURL& url) {
@@ -363,7 +364,7 @@ void TopSitesImpl::ClearBlacklistedURLs() {
blacklist->Clear();
}
ResetThreadSafeCache();
- NotifyTopSitesChanged();
+ NotifyTopSitesChanged(TopSitesObserver::ChangeReason::BLACKLIST);
}
void TopSitesImpl::ShutdownOnUIThread() {
@@ -618,7 +619,7 @@ bool TopSitesImpl::AddForcedURL(const GURL& url, const base::Time& time) {
new_list.insert(mid, new_url);
mid = new_list.begin() + num_forced; // Mid was invalidated.
std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator);
- SetTopSites(new_list, CALL_LOCATION_FROM_OTHER_PLACES);
+ SetTopSites(new_list, CALL_LOCATION_FROM_FORCED_URLS);
return true;
}
@@ -795,7 +796,10 @@ void TopSitesImpl::SetTopSites(const MostVisitedURLList& new_top_sites,
ResetThreadSafeCache();
ResetThreadSafeImageCache();
- NotifyTopSitesChanged();
+ if (location == CALL_LOCATION_FROM_FORCED_URLS)
+ NotifyTopSitesChanged(TopSitesObserver::ChangeReason::FORCED_URL);
+ else
+ NotifyTopSitesChanged(TopSitesObserver::ChangeReason::MOST_VISITED);
// Restart the timer that queries history for top sites. This is done to
// ensure we stay in sync with history.
diff --git a/components/history/core/browser/top_sites_impl.h b/components/history/core/browser/top_sites_impl.h
index 3eb95dd..dab8392 100644
--- a/components/history/core/browser/top_sites_impl.h
+++ b/components/history/core/browser/top_sites_impl.h
@@ -118,8 +118,10 @@ class TopSitesImpl : public TopSites, public HistoryServiceObserver {
enum CallLocation {
// SetTopSites is called from function OnGotMostVisitedThumbnails.
CALL_LOCATION_FROM_ON_GOT_MOST_VISITED_THUMBNAILS,
+ // SetTopSites is called from AddForcedURLs.
+ CALL_LOCATION_FROM_FORCED_URLS,
// All other situations.
- CALL_LOCATION_FROM_OTHER_PLACES
+ CALL_LOCATION_FROM_OTHER_PLACES,
};
friend class TopSitesImplTest;
diff --git a/components/history/core/browser/top_sites_observer.h b/components/history/core/browser/top_sites_observer.h
index 443b33f..29b0910 100644
--- a/components/history/core/browser/top_sites_observer.h
+++ b/components/history/core/browser/top_sites_observer.h
@@ -14,6 +14,16 @@ class TopSites;
// Interface for observing notifications from TopSites.
class TopSitesObserver {
public:
+ // An enum representing different for TopSitesChanged to happen.
+ enum class ChangeReason {
+ // TopSites was changed by most visited.
+ MOST_VISITED,
+ // TopSites was changed by add/remove/clear blacklist.
+ BLACKLIST,
+ // TopSites was changed by AddForcedURLs.
+ FORCED_URL,
+ };
+
TopSitesObserver() {}
virtual ~TopSitesObserver() {}
@@ -22,7 +32,8 @@ class TopSitesObserver {
// Is called when either one of the most visited urls
// changed, or one of the images changes.
- virtual void TopSitesChanged(TopSites* top_sites) = 0;
+ virtual void TopSitesChanged(TopSites* top_sites,
+ ChangeReason change_reason) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(TopSitesObserver);
diff --git a/components/history/core/test/wait_top_sites_loaded_observer.cc b/components/history/core/test/wait_top_sites_loaded_observer.cc
index 79b1a38..b3418ab 100644
--- a/components/history/core/test/wait_top_sites_loaded_observer.cc
+++ b/components/history/core/test/wait_top_sites_loaded_observer.cc
@@ -29,7 +29,8 @@ void WaitTopSitesLoadedObserver::TopSitesLoaded(TopSites* top_sites) {
run_loop_.Quit();
}
-void WaitTopSitesLoadedObserver::TopSitesChanged(TopSites* top_sites) {
+void WaitTopSitesLoadedObserver::TopSitesChanged(TopSites* top_sites,
+ ChangeReason change_reason) {
}
} // namespace history
diff --git a/components/history/core/test/wait_top_sites_loaded_observer.h b/components/history/core/test/wait_top_sites_loaded_observer.h
index d21cf7c..0d1de24 100644
--- a/components/history/core/test/wait_top_sites_loaded_observer.h
+++ b/components/history/core/test/wait_top_sites_loaded_observer.h
@@ -26,7 +26,8 @@ class WaitTopSitesLoadedObserver : public TopSitesObserver {
private:
// TopSitesObserver implementation.
void TopSitesLoaded(TopSites* top_sites) override;
- void TopSitesChanged(TopSites* top_sites) override;
+ void TopSitesChanged(TopSites* top_sites,
+ ChangeReason change_reason) override;
scoped_refptr<TopSites> top_sites_;
base::RunLoop run_loop_;