summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornaiem.shaik <naiem.shaik@gmail.com>2015-01-27 15:52:13 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-27 23:53:09 +0000
commit5017fc699bb6c353538103770944216450eaa43c (patch)
treed01e6aa2f21654b2a0be2956d5537e768ac54dec
parentdf3f06a5459de59fd314972519952bae27036a20 (diff)
downloadchromium_src-5017fc699bb6c353538103770944216450eaa43c.zip
chromium_src-5017fc699bb6c353538103770944216450eaa43c.tar.gz
chromium_src-5017fc699bb6c353538103770944216450eaa43c.tar.bz2
Remove NOTIFICATION_HISTORY_URLS_DELETED
Add the method OnURLsDeleted() to History{Backend,Service}Observer and change History{Backend,Service} to call this method instead of sending the notification. Port client code to implement the History{Backend,Service}Observer interface instead of using chrome::NOTIFICATION_HISTORY_URLS_DELETED. Remove obsolete code for broadcasting notification from history code and HistoryDetails type. BUG=373326 Review URL: https://codereview.chromium.org/773103004 Cr-Commit-Position: refs/heads/master@{#313406}
-rw-r--r--chrome/browser/android/provider/chrome_browser_provider.cc24
-rw-r--r--chrome/browser/android/provider/chrome_browser_provider.h15
-rw-r--r--chrome/browser/autocomplete/history_quick_provider_unittest.cc53
-rw-r--r--chrome/browser/autocomplete/shortcuts_backend.cc53
-rw-r--r--chrome/browser/autocomplete/shortcuts_backend.h14
-rw-r--r--chrome/browser/autocomplete/shortcuts_backend_factory.cc2
-rw-r--r--chrome/browser/autocomplete/shortcuts_provider.cc1
-rw-r--r--chrome/browser/chrome_notification_types.h8
-rw-r--r--chrome/browser/extensions/api/history/history_api.cc34
-rw-r--r--chrome/browser/extensions/api/history/history_api.h23
-rw-r--r--chrome/browser/favicon/DEPS1
-rw-r--r--chrome/browser/history/android/android_provider_backend.h1
-rw-r--r--chrome/browser/history/android/android_provider_backend_unittest.cc15
-rw-r--r--chrome/browser/history/expire_history_backend_unittest.cc1
-rw-r--r--chrome/browser/history/history_backend.cc33
-rw-r--r--chrome/browser/history/history_backend.h23
-rw-r--r--chrome/browser/history/history_backend_unittest.cc94
-rw-r--r--chrome/browser/history/history_details.h20
-rw-r--r--chrome/browser/history/history_notifications.cc20
-rw-r--r--chrome/browser/history/history_notifications.h53
-rw-r--r--chrome/browser/history/history_service.cc148
-rw-r--r--chrome/browser/history/history_service.h34
-rw-r--r--chrome/browser/history/history_unittest.cc17
-rw-r--r--chrome/browser/history/in_memory_history_backend.cc91
-rw-r--r--chrome/browser/history/in_memory_history_backend.h36
-rw-r--r--chrome/browser/history/in_memory_url_index.cc48
-rw-r--r--chrome/browser/history/in_memory_url_index.h21
-rw-r--r--chrome/browser/history/in_memory_url_index_unittest.cc24
-rw-r--r--chrome/browser/history/top_sites.cc1
-rw-r--r--chrome/browser/history/top_sites.h3
-rw-r--r--chrome/browser/history/top_sites_impl.cc74
-rw-r--r--chrome/browser/history/top_sites_impl.h15
-rw-r--r--chrome/browser/history/top_sites_impl_unittest.cc1
-rw-r--r--chrome/browser/history/typed_url_syncable_service.h1
-rw-r--r--chrome/browser/predictors/autocomplete_action_predictor.cc38
-rw-r--r--chrome/browser/predictors/autocomplete_action_predictor.h5
-rw-r--r--chrome/browser/predictors/resource_prefetch_predictor.cc80
-rw-r--r--chrome/browser/predictors/resource_prefetch_predictor.h18
-rw-r--r--chrome/browser/sync/glue/favicon_cache.cc84
-rw-r--r--chrome/browser/sync/glue/favicon_cache.h26
-rw-r--r--chrome/browser/sync/glue/favicon_cache_unittest.cc20
-rw-r--r--chrome/browser/sync/glue/typed_url_change_processor.cc122
-rw-r--r--chrome/browser/sync/glue/typed_url_change_processor.h47
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc40
-rw-r--r--chrome/browser/ui/cocoa/history_menu_bridge.h36
-rw-r--r--chrome/browser/ui/cocoa/history_menu_bridge.mm64
-rw-r--r--chrome/browser/ui/webui/history_ui.cc40
-rw-r--r--chrome/browser/ui/webui/history_ui.h22
-rw-r--r--chrome/chrome_browser.gypi3
-rw-r--r--components/history/core/browser/history_backend_observer.h18
-rw-r--r--components/history/core/browser/history_service_observer.h14
51 files changed, 698 insertions, 981 deletions
diff --git a/chrome/browser/android/provider/chrome_browser_provider.cc b/chrome/browser/android/provider/chrome_browser_provider.cc
index d1e9c1a..b0a1015 100644
--- a/chrome/browser/android/provider/chrome_browser_provider.cc
+++ b/chrome/browser/android/provider/chrome_browser_provider.cc
@@ -23,7 +23,6 @@
#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
#include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/android/sqlite_cursor.h"
@@ -39,7 +38,6 @@
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_service.h"
#include "jni/ChromeBrowserProvider_jni.h"
#include "sql/statement.h"
#include "ui/base/layout.h"
@@ -1172,12 +1170,10 @@ ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj)
profile_, ServiceAccessType::EXPLICIT_ACCESS),
service_.reset(new AndroidHistoryProviderService(profile_));
- // Registers the notifications we are interested.
+ // Register as observer for service we are interested.
bookmark_model_->AddObserver(this);
history_service_observer_.Add(HistoryServiceFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS));
- notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::NotificationService::AllSources());
TemplateURLService* template_service =
TemplateURLServiceFactory::GetForProfile(profile_);
if (!template_service->loaded())
@@ -1189,6 +1185,7 @@ ChromeBrowserProvider::~ChromeBrowserProvider() {
}
void ChromeBrowserProvider::Destroy(JNIEnv*, jobject) {
+ history_service_observer_.RemoveAll();
delete this;
}
@@ -1625,6 +1622,14 @@ void ChromeBrowserProvider::OnURLVisited(HistoryService* history_service,
OnHistoryChanged();
}
+void ChromeBrowserProvider::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ OnHistoryChanged();
+}
+
void ChromeBrowserProvider::OnKeywordSearchTermUpdated(
HistoryService* history_service,
const history::URLRow& row,
@@ -1639,12 +1644,5 @@ void ChromeBrowserProvider::OnKeywordSearchTermUpdated(
void ChromeBrowserProvider::OnKeywordSearchTermDeleted(
HistoryService* history_service,
- history::URLID url_id) {}
-
-void ChromeBrowserProvider::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED);
- OnHistoryChanged();
+ history::URLID url_id) {
}
diff --git a/chrome/browser/android/provider/chrome_browser_provider.h b/chrome/browser/android/provider/chrome_browser_provider.h
index 56b4ffd..6fc7661 100644
--- a/chrome/browser/android/provider/chrome_browser_provider.h
+++ b/chrome/browser/android/provider/chrome_browser_provider.h
@@ -14,8 +14,6 @@
#include "components/bookmarks/browser/base_bookmark_model_observer.h"
#include "components/history/core/browser/android/android_history_types.h"
#include "components/history/core/browser/history_service_observer.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
class AndroidHistoryProviderService;
class FaviconService;
@@ -31,7 +29,6 @@ class Statement;
// This class implements the native methods of ChromeBrowserProvider.java
class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver,
- public content::NotificationObserver,
public history::HistoryServiceObserver {
public:
ChromeBrowserProvider(JNIEnv* env, jobject obj);
@@ -193,6 +190,11 @@ class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver,
const history::URLRow& row,
const history::RedirectList& redirects,
base::Time visit_time) override;
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void OnKeywordSearchTermUpdated(HistoryService* history_service,
const history::URLRow& row,
history::KeywordID keyword_id,
@@ -200,11 +202,6 @@ class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver,
void OnKeywordSearchTermDeleted(HistoryService* history_service,
history::URLID url_id) override;
- // Override content::NotificationObserver.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
JavaObjectWeakGlobalRef weak_java_provider_;
// Profile must outlive this object.
@@ -221,8 +218,6 @@ class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver,
base::CancelableTaskTracker cancelable_task_tracker_;
- // Used to register/unregister notification observer.
- content::NotificationRegistrar notification_registrar_;
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_;
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
index 9b4cde9..2345278 100644
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -19,7 +19,6 @@
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
@@ -31,6 +30,7 @@
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/history/core/browser/history_database.h"
+#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/url_database.h"
#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/omnibox/autocomplete_match.h"
@@ -38,7 +38,6 @@
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
-#include "content/public/browser/notification_service.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
#include "sql/transaction.h"
@@ -104,6 +103,51 @@ struct TestURLInfo {
"83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0}
};
+// Waits for OnURLsDeletedNotification and when run quits the supplied run loop.
+class WaitForURLsDeletedObserver : public history::HistoryServiceObserver {
+ public:
+ explicit WaitForURLsDeletedObserver(base::RunLoop* runner);
+ ~WaitForURLsDeletedObserver() override;
+
+ private:
+ // history::HistoryServiceObserver:
+ void OnURLsDeleted(HistoryService* service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
+
+ // Weak. Owned by our owner.
+ base::RunLoop* runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(WaitForURLsDeletedObserver);
+};
+
+WaitForURLsDeletedObserver::WaitForURLsDeletedObserver(base::RunLoop* runner)
+ : runner_(runner) {
+}
+
+WaitForURLsDeletedObserver::~WaitForURLsDeletedObserver() {
+}
+
+void WaitForURLsDeletedObserver::OnURLsDeleted(
+ HistoryService* service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ runner_->Quit();
+}
+
+void WaitForURLsDeletedNotification(HistoryService* history_service) {
+ base::RunLoop runner;
+ WaitForURLsDeletedObserver observer(&runner);
+ ScopedObserver<HistoryService, history::HistoryServiceObserver>
+ scoped_observer(&observer);
+ scoped_observer.Add(history_service);
+ runner.Run();
+}
+
class HistoryQuickProviderTest : public testing::Test {
public:
HistoryQuickProviderTest()
@@ -574,10 +618,7 @@ TEST_F(HistoryQuickProviderTest, DeleteMatch) {
// InMemoryURLIndex) will drop any data they might have pertaining to the URL.
// To ensure that the deletion has been propagated everywhere before we start
// verifying post-deletion states, first wait until we see the notification.
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::NotificationService::AllSources());
- observer.Wait();
+ WaitForURLsDeletedNotification(history_service_);
EXPECT_FALSE(history_backend()->GetURL(test_url, NULL));
// Just to be on the safe side, explicitly verify that we have deleted enough
diff --git a/chrome/browser/autocomplete/shortcuts_backend.cc b/chrome/browser/autocomplete/shortcuts_backend.cc
index 8f436c5..c8c959b 100644
--- a/chrome/browser/autocomplete/shortcuts_backend.cc
+++ b/chrome/browser/autocomplete/shortcuts_backend.cc
@@ -15,8 +15,8 @@
#include "base/strings/string_util.h"
#include "chrome/browser/autocomplete/shortcuts_database.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/omnibox/omnibox_log.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
@@ -79,6 +79,7 @@ AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) {
ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
: profile_(profile),
current_state_(NOT_INITIALIZED),
+ history_service_observer_(this),
no_db_access_(suppress_db) {
if (!suppress_db) {
db_ = new history::ShortcutsDatabase(
@@ -92,9 +93,10 @@ ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile));
#endif
- notification_registrar_.Add(
- this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile));
+ HistoryService* hs = HistoryServiceFactory::GetForProfile(
+ profile, ServiceAccessType::EXPLICIT_ACCESS);
+ if (hs)
+ history_service_observer_.Add(hs);
}
}
@@ -174,40 +176,47 @@ void ShortcutsBackend::ShutdownOnUIThread() {
DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
notification_registrar_.RemoveAll();
+ history_service_observer_.RemoveAll();
}
void ShortcutsBackend::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
+#if defined(ENABLE_EXTENSIONS)
+ DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, type);
if (!initialized())
return;
-#if defined(ENABLE_EXTENSIONS)
- if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
- // When an extension is unloaded, we want to remove any Shortcuts associated
- // with it.
- DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>(
- details)->extension->url(), false);
- return;
- }
+ // When an extension is unloaded, we want to remove any Shortcuts associated
+ // with it.
+ DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>(
+ details)->extension->url(),
+ false);
#endif
+}
+
+void ShortcutsBackend::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ if (!initialized())
+ return;
- DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type);
- const history::URLsDeletedDetails* deleted_details =
- content::Details<const history::URLsDeletedDetails>(details).ptr();
- if (deleted_details->all_history) {
+ if (all_history) {
DeleteAllShortcuts();
return;
}
- const history::URLRows& rows(deleted_details->rows);
history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
- for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end();
- ++it) {
+ for (const auto& guid_pair : guid_map_) {
if (std::find_if(
- rows.begin(), rows.end(), history::URLRow::URLRowHasURL(
- it->second->second.match_core.destination_url)) != rows.end())
- shortcut_ids.push_back(it->first);
+ deleted_rows.begin(), deleted_rows.end(),
+ history::URLRow::URLRowHasURL(
+ guid_pair.second->second.match_core.destination_url)) !=
+ deleted_rows.end()) {
+ shortcut_ids.push_back(guid_pair.first);
+ }
}
DeleteShortcutsWithIDs(shortcut_ids);
}
diff --git a/chrome/browser/autocomplete/shortcuts_backend.h b/chrome/browser/autocomplete/shortcuts_backend.h
index 7f4add7..1f5ae98 100644
--- a/chrome/browser/autocomplete/shortcuts_backend.h
+++ b/chrome/browser/autocomplete/shortcuts_backend.h
@@ -14,10 +14,12 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "base/synchronization/lock.h"
#include "base/time/time.h"
#include "chrome/browser/autocomplete/shortcuts_database.h"
+#include "components/history/core/browser/history_service_observer.h"
#include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/omnibox/autocomplete_match.h"
#include "content/public/browser/notification_observer.h"
@@ -33,7 +35,8 @@ class ShortcutsDatabase;
// This class manages the shortcut provider backend - access to database on the
// db thread, etc.
class ShortcutsBackend : public RefcountedKeyedService,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public history::HistoryServiceObserver {
public:
typedef std::multimap<base::string16,
const history::ShortcutsDatabase::Shortcut> ShortcutMap;
@@ -104,6 +107,13 @@ class ShortcutsBackend : public RefcountedKeyedService,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
+ // history::HistoryServiceObserver:
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
+
// Internal initialization of the back-end. Posted by Init() to the DB thread.
// On completion posts InitCompleted() back to UI thread.
void InitInternal();
@@ -144,6 +154,8 @@ class ShortcutsBackend : public RefcountedKeyedService,
GuidMap guid_map_;
content::NotificationRegistrar notification_registrar_;
+ ScopedObserver<HistoryService, HistoryServiceObserver>
+ history_service_observer_;
// For some unit-test only.
bool no_db_access_;
diff --git a/chrome/browser/autocomplete/shortcuts_backend_factory.cc b/chrome/browser/autocomplete/shortcuts_backend_factory.cc
index adf93db..3b8bdfa 100644
--- a/chrome/browser/autocomplete/shortcuts_backend_factory.cc
+++ b/chrome/browser/autocomplete/shortcuts_backend_factory.cc
@@ -6,6 +6,7 @@
#include "base/prefs/pref_service.h"
#include "chrome/browser/autocomplete/shortcuts_backend.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
@@ -54,6 +55,7 @@ ShortcutsBackendFactory::ShortcutsBackendFactory()
: RefcountedBrowserContextKeyedServiceFactory(
"ShortcutsBackend",
BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(HistoryServiceFactory::GetInstance());
}
ShortcutsBackendFactory::~ShortcutsBackendFactory() {}
diff --git a/chrome/browser/autocomplete/shortcuts_provider.cc b/chrome/browser/autocomplete/shortcuts_provider.cc
index 9f8d91d..7bd3dfb 100644
--- a/chrome/browser/autocomplete/shortcuts_provider.cc
+++ b/chrome/browser/autocomplete/shortcuts_provider.cc
@@ -20,7 +20,6 @@
#include "base/time/time.h"
#include "chrome/browser/autocomplete/history_provider.h"
#include "chrome/browser/autocomplete/shortcuts_backend_factory.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
diff --git a/chrome/browser/chrome_notification_types.h b/chrome/browser/chrome_notification_types.h
index db170e9..97858c1 100644
--- a/chrome/browser/chrome_notification_types.h
+++ b/chrome/browser/chrome_notification_types.h
@@ -228,13 +228,7 @@ enum NotificationType {
// the LoginHandler that should be cancelled.
NOTIFICATION_AUTH_CANCELLED,
- // History -----------------------------------------------------------------
-
- // Sent when one or more URLs are deleted.
- //
- // The source is the profile owning the history service that changed, and
- // the details is history::URLsDeletedDetails that lists the deleted URLs.
- NOTIFICATION_HISTORY_URLS_DELETED,
+ // Favicon ------------------------------------------------------------------
// Sent by FaviconTabHelper when a tab's favicon has been successfully
// updated. The details are a bool indicating whether the
diff --git a/chrome/browser/extensions/api/history/history_api.cc b/chrome/browser/extensions/api/history/history_api.cc
index 37ca08e..ec1c748 100644
--- a/chrome/browser/extensions/api/history/history_api.cc
+++ b/chrome/browser/extensions/api/history/history_api.cc
@@ -18,7 +18,6 @@
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
#include "base/values.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
@@ -27,8 +26,6 @@
#include "chrome/common/extensions/api/history.h"
#include "chrome/common/pref_names.h"
#include "components/history/core/browser/history_types.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system_provider.h"
#include "extensions/browser/extensions_browser_client.h"
@@ -135,24 +132,12 @@ HistoryEventRouter::HistoryEventRouter(Profile* profile,
HistoryService* history_service)
: profile_(profile), history_service_observer_(this) {
DCHECK(profile);
- registrar_.Add(this,
- chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile));
history_service_observer_.Add(history_service);
}
HistoryEventRouter::~HistoryEventRouter() {
}
-void HistoryEventRouter::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED);
- HistoryUrlsRemoved(
- content::Source<Profile>(source).ptr(),
- content::Details<const history::URLsDeletedDetails>(details).ptr());
-}
-
void HistoryEventRouter::OnURLVisited(HistoryService* history_service,
ui::PageTransition transition,
const history::URLRow& row,
@@ -163,21 +148,22 @@ void HistoryEventRouter::OnURLVisited(HistoryService* history_service,
DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass());
}
-void HistoryEventRouter::HistoryUrlsRemoved(
- Profile* profile,
- const history::URLsDeletedDetails* details) {
+void HistoryEventRouter::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
OnVisitRemoved::Removed removed;
- removed.all_history = details->all_history;
+ removed.all_history = all_history;
std::vector<std::string>* urls = new std::vector<std::string>();
- for (history::URLRows::const_iterator iterator = details->rows.begin();
- iterator != details->rows.end(); ++iterator) {
- urls->push_back(iterator->url().spec());
- }
+ for (const auto& row : deleted_rows)
+ urls->push_back(row.url().spec());
removed.urls.reset(urls);
scoped_ptr<base::ListValue> args = OnVisitRemoved::Create(removed);
- DispatchEvent(profile, api::history::OnVisitRemoved::kEventName, args.Pass());
+ DispatchEvent(profile_, api::history::OnVisitRemoved::kEventName,
+ args.Pass());
}
void HistoryEventRouter::DispatchEvent(
diff --git a/chrome/browser/extensions/api/history/history_api.h b/chrome/browser/extensions/api/history/history_api.h
index ccae66f..02a7af6 100644
--- a/chrome/browser/extensions/api/history/history_api.h
+++ b/chrome/browser/extensions/api/history/history_api.h
@@ -12,14 +12,13 @@
#include "base/scoped_observer.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
-#include "chrome/browser/history/history_notifications.h"
-#include "chrome/browser/history/history_service.h"
#include "chrome/common/extensions/api/history.h"
#include "components/history/core/browser/history_service_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
+class HistoryService;
+
namespace base {
class ListValue;
}
@@ -28,34 +27,28 @@ namespace extensions {
// Observes History service and routes the notifications as events to the
// extension system.
-class HistoryEventRouter : public content::NotificationObserver,
- public history::HistoryServiceObserver {
+class HistoryEventRouter : public history::HistoryServiceObserver {
public:
HistoryEventRouter(Profile* profile, HistoryService* history_service);
~HistoryEventRouter() override;
private:
- // content::NotificationObserver::Observe.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
// history::HistoryServiceObserver.
void OnURLVisited(HistoryService* history_service,
ui::PageTransition transition,
const history::URLRow& row,
const history::RedirectList& redirects,
base::Time visit_time) override;
-
- void HistoryUrlsRemoved(Profile* profile,
- const history::URLsDeletedDetails* details);
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void DispatchEvent(Profile* profile,
const std::string& event_name,
scoped_ptr<base::ListValue> event_args);
- // Used for tracking registrations to history service notifications.
- content::NotificationRegistrar registrar_;
Profile* profile_;
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_;
diff --git a/chrome/browser/favicon/DEPS b/chrome/browser/favicon/DEPS
index de7131b..d80d538 100644
--- a/chrome/browser/favicon/DEPS
+++ b/chrome/browser/favicon/DEPS
@@ -20,7 +20,6 @@ include_rules = [
# and please do not introduce more #includes of these files.
"!chrome/browser/bookmarks/bookmark_model_factory.h",
"!chrome/browser/history/history_backend.h",
- "!chrome/browser/history/history_details.h",
"!chrome/browser/history/history_service.h",
"!chrome/browser/history/history_service_factory.h",
"!chrome/browser/history/select_favicon_frames.h",
diff --git a/chrome/browser/history/android/android_provider_backend.h b/chrome/browser/history/android/android_provider_backend.h
index 20a5e68..064c6fb 100644
--- a/chrome/browser/history/android/android_provider_backend.h
+++ b/chrome/browser/history/android/android_provider_backend.h
@@ -14,7 +14,6 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
-#include "chrome/browser/history/history_notifications.h"
#include "components/history/core/browser/android/android_cache_database.h"
#include "components/history/core/browser/android/android_history_types.h"
#include "components/history/core/browser/android/sql_handler.h"
diff --git a/chrome/browser/history/android/android_provider_backend_unittest.cc b/chrome/browser/history/android/android_provider_backend_unittest.cc
index 59e189e..122766b 100644
--- a/chrome/browser/history/android/android_provider_backend_unittest.cc
+++ b/chrome/browser/history/android/android_provider_backend_unittest.cc
@@ -13,7 +13,6 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/chrome_history_client.h"
#include "chrome/browser/history/chrome_history_client_factory.h"
#include "chrome/browser/history/history_backend.h"
@@ -87,18 +86,16 @@ class AndroidProviderBackendDelegate : public HistoryBackend::Delegate {
void NotifyURLsModified(const history::URLRows& rows) override {
modified_details_.reset(new history::URLRows(rows));
}
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override {
+ deleted_details_.reset(new history::URLRows(deleted_rows));
+ }
void NotifyKeywordSearchTermUpdated(const URLRow& row,
KeywordID keyword_id,
const base::string16& term) override {}
void NotifyKeywordSearchTermDeleted(URLID url_id) override {}
- void BroadcastNotifications(
- int type,
- scoped_ptr<HistoryDetails> details) override {
- DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED);
- scoped_ptr<URLsDeletedDetails> urls_deleted_details(
- static_cast<URLsDeletedDetails*>(details.release()));
- deleted_details_.reset(new history::URLRows(urls_deleted_details->rows));
- }
void DBLoaded() override {}
history::URLRows* deleted_details() const { return deleted_details_.get(); }
diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc
index d5e1981..b8c21db 100644
--- a/chrome/browser/history/expire_history_backend_unittest.cc
+++ b/chrome/browser/history/expire_history_backend_unittest.cc
@@ -109,7 +109,6 @@ class ExpireHistoryTest : public testing::Test,
// Time at the beginning of the test, so everybody agrees what "now" is.
const Time now_;
- // Details received from HistoryObserver events.
typedef std::vector<URLRows> URLsModifiedNotificationList;
URLsModifiedNotificationList urls_modified_notifications_;
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 9e1a584..c34f9b4 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -24,7 +24,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/in_memory_history_backend.h"
#include "chrome/browser/history/in_memory_history_backend.h"
#include "chrome/browser/history/top_sites.h"
@@ -2489,15 +2488,6 @@ void HistoryBackend::ProcessDBTask(
ProcessDBTaskImpl();
}
-void HistoryBackend::BroadcastNotifications(
- int type,
- scoped_ptr<HistoryDetails> details) {
- // |delegate_| may be NULL if |this| is in the process of closing (closed by
- // HistoryService -> HistoryBackend::Closing().
- if (delegate_)
- delegate_->BroadcastNotifications(type, details.Pass());
-}
-
void HistoryBackend::NotifyFaviconChanged(const std::set<GURL>& urls) {
if (delegate_)
delegate_->NotifyFaviconChanged(urls);
@@ -2542,19 +2532,22 @@ void HistoryBackend::NotifyURLsDeleted(bool all_history,
bool expired,
const URLRows& rows,
const std::set<GURL>& favicon_urls) {
- scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails);
- details->all_history = all_history;
- details->expired = expired;
- details->rows = rows;
- details->favicon_urls = favicon_urls;
-
+ URLRows copied_rows(rows);
if (typed_url_syncable_service_.get()) {
- typed_url_syncable_service_->OnUrlsDeleted(
- all_history, expired, &details->rows);
+ typed_url_syncable_service_->OnUrlsDeleted(all_history, expired,
+ &copied_rows);
}
- BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- details.Pass());
+ FOR_EACH_OBSERVER(
+ HistoryBackendObserver, observers_,
+ OnURLsDeleted(this, all_history, expired, copied_rows, favicon_urls));
+
+ // TODO(sdefresne): turn HistoryBackend::Delegate from HistoryService into
+ // an HistoryBackendObserver and register it so that we can remove this
+ // method.
+ if (delegate_)
+ delegate_->NotifyURLsDeleted(all_history, expired, copied_rows,
+ favicon_urls);
}
// Deleting --------------------------------------------------------------------
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index ee51160..3af0a5a 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -144,6 +144,14 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// be forwarded to the HistoryServiceObservers in the correct thread.
virtual void NotifyURLsModified(const URLRows& changed_urls) = 0;
+ // Notify HistoryService that some or all of the URLs have been deleted.
+ // The event will be forwarded to the HistoryServiceObservers in the correct
+ // thread.
+ virtual void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) = 0;
+
// Notify HistoryService that some keyword has been searched using omnibox.
// The event will be forwarded to the HistoryServiceObservers in the correct
// thread.
@@ -156,13 +164,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// thread.
virtual void NotifyKeywordSearchTermDeleted(URLID url_id) = 0;
- // Broadcasts the specified notification to the notification service.
- // This is implemented here because notifications must only be sent from
- // the main thread. This is the only method that doesn't identify the
- // caller because notifications must always be sent.
- virtual void BroadcastNotifications(int type,
- scoped_ptr<HistoryDetails> details) = 0;
-
// Invoked when the backend has finished loading the db.
virtual void DBLoaded() = 0;
};
@@ -597,7 +598,8 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, UpdateVisitDuration);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, ExpireHistoryForTimes);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteFTSIndexDatabases);
-
+ FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTypedUrlTest,
+ ProcessUserChangeRemove);
friend class ::TestingProfile;
// Computes the name of the specified database on disk.
@@ -798,11 +800,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// to be invoked again if there are more tasks that need to run.
void ProcessDBTaskImpl();
- // Broadcasts the specified notification to the notification service on both
- // the main thread and the history thread if a notification service is
- // running.
- void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details);
-
// HistoryBackendNotifier:
void NotifyFaviconChanged(const std::set<GURL>& urls) override;
void NotifyURLVisited(ui::PageTransition transition,
diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc
index 21d67c0..cbf82bf 100644
--- a/chrome/browser/history/history_backend_unittest.cc
+++ b/chrome/browser/history/history_backend_unittest.cc
@@ -21,8 +21,6 @@
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/in_memory_history_backend.h"
@@ -32,13 +30,12 @@
#include "chrome/test/base/testing_profile.h"
#include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_database_params.h"
+#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/in_memory_database.h"
#include "components/history/core/browser/keyword_search_term.h"
#include "components/history/core/browser/visit_filter.h"
#include "components/history/core/test/history_client_fake_bookmarks.h"
#include "components/history/core/test/test_history_database.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -128,12 +125,14 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
const RedirectList& redirects,
base::Time visit_time) override;
void NotifyURLsModified(const URLRows& changed_urls) override;
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void NotifyKeywordSearchTermUpdated(const URLRow& row,
KeywordID keyword_id,
const base::string16& term) override;
void NotifyKeywordSearchTermDeleted(URLID url_id) override;
- void BroadcastNotifications(int type,
- scoped_ptr<HistoryDetails> details) override;
void DBLoaded() override;
private:
@@ -145,9 +144,9 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
class HistoryBackendTestBase : public testing::Test {
public:
- typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList;
typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList;
typedef std::vector<URLRows> URLsModifiedList;
+ typedef std::vector<std::pair<bool, bool>> URLsDeletedList;
HistoryBackendTestBase()
: loaded_(false),
@@ -155,7 +154,6 @@ class HistoryBackendTestBase : public testing::Test {
ui_thread_(content::BrowserThread::UI, &message_loop_) {}
~HistoryBackendTestBase() override {
- STLDeleteValues(&broadcasted_notifications_);
}
protected:
@@ -183,18 +181,14 @@ class HistoryBackendTestBase : public testing::Test {
return urls_modified_notifications_;
}
- int num_broadcasted_notifications() const {
- return broadcasted_notifications_.size();
- }
-
- const NotificationList& broadcasted_notifications() const {
- return broadcasted_notifications_;
+ const URLsDeletedList& urls_deleted_notifications() const {
+ return urls_deleted_notifications_;
}
void ClearBroadcastedNotifications() {
url_visited_notifications_.clear();
urls_modified_notifications_.clear();
- STLDeleteValues(&broadcasted_notifications_);
+ urls_deleted_notifications_.clear();
}
base::FilePath test_dir() {
@@ -220,6 +214,15 @@ class HistoryBackendTestBase : public testing::Test {
urls_modified_notifications_.push_back(changed_urls);
}
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ mem_backend_->OnURLsDeleted(nullptr, all_history, expired, deleted_rows,
+ favicon_urls);
+ urls_deleted_notifications_.push_back(std::make_pair(all_history, expired));
+ }
+
void NotifyKeywordSearchTermUpdated(const URLRow& row,
KeywordID keyword_id,
const base::string16& term) {
@@ -230,17 +233,6 @@ class HistoryBackendTestBase : public testing::Test {
mem_backend_->OnKeywordSearchTermDeleted(nullptr, url_id);
}
- void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
- // Send the notifications directly to the in-memory database.
- content::Details<HistoryDetails> det(details.get());
- mem_backend_->Observe(
- type, content::Source<HistoryBackendTestBase>(NULL), det);
-
- // The backend passes ownership of the details pointer to us.
- broadcasted_notifications_.push_back(
- std::make_pair(type, details.release()));
- }
-
history::HistoryClientFakeBookmarks history_client_;
scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure.
scoped_ptr<InMemoryHistoryBackend> mem_backend_;
@@ -276,10 +268,10 @@ class HistoryBackendTestBase : public testing::Test {
}
// The types and details of notifications which were broadcasted.
- NotificationList broadcasted_notifications_;
int favicon_changed_notifications_;
URLVisitedList url_visited_notifications_;
URLsModifiedList urls_modified_notifications_;
+ URLsDeletedList urls_deleted_notifications_;
base::MessageLoop message_loop_;
base::FilePath test_dir_;
@@ -310,6 +302,14 @@ void HistoryBackendTestDelegate::NotifyURLsModified(
test_->NotifyURLsModified(changed_urls);
}
+void HistoryBackendTestDelegate::NotifyURLsDeleted(
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ test_->NotifyURLsDeleted(all_history, expired, deleted_rows, favicon_urls);
+}
+
void HistoryBackendTestDelegate::NotifyKeywordSearchTermUpdated(
const URLRow& row,
KeywordID keyword_id,
@@ -321,12 +321,6 @@ void HistoryBackendTestDelegate::NotifyKeywordSearchTermDeleted(URLID url_id) {
test_->NotifyKeywordSearchTermDeleted(url_id);
}
-void HistoryBackendTestDelegate::BroadcastNotifications(
- int type,
- scoped_ptr<HistoryDetails> details) {
- test_->BroadcastNotifications(type, details.Pass());
-}
-
void HistoryBackendTestDelegate::DBLoaded() {
test_->loaded_ = true;
}
@@ -494,20 +488,15 @@ class InMemoryHistoryBackendTest : public HistoryBackendTestBase {
~InMemoryHistoryBackendTest() override {}
protected:
- void SimulateNotification(int type,
- const URLRow* row1,
- const URLRow* row2 = NULL,
- const URLRow* row3 = NULL) {
- DCHECK(type == chrome::NOTIFICATION_HISTORY_URLS_DELETED);
-
+ void SimulateNotificationURLsDeleted(const URLRow* row1,
+ const URLRow* row2 = NULL,
+ const URLRow* row3 = NULL) {
URLRows rows;
rows.push_back(*row1);
if (row2) rows.push_back(*row2);
if (row3) rows.push_back(*row3);
- scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
- details->rows = rows;
- BroadcastNotifications(type, details.Pass());
+ NotifyURLsDeleted(false, false, rows, std::set<GURL>());
}
size_t GetNumberOfMatchingSearchTerms(const int keyword_id,
@@ -710,13 +699,9 @@ TEST_F(HistoryBackendTest, DeleteAll) {
EXPECT_TRUE(history_client_.IsBookmarked(row1.url()));
// Check that we fire the notification about all history having been deleted.
- ASSERT_EQ(1u, broadcasted_notifications().size());
- ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- broadcasted_notifications()[0].first);
- const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>(
- broadcasted_notifications()[0].second);
- EXPECT_TRUE(details->all_history);
- EXPECT_FALSE(details->expired);
+ ASSERT_EQ(1u, urls_deleted_notifications().size());
+ EXPECT_TRUE(urls_deleted_notifications()[0].first);
+ EXPECT_FALSE(urls_deleted_notifications()[0].second);
}
// Checks that adding a visit, then calling DeleteAll, and then trying to add
@@ -3166,8 +3151,7 @@ TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) {
// Notify the in-memory database that the second typed URL and the non-typed
// URL has been deleted.
- SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- &row2, &row3);
+ SimulateNotificationURLsDeleted(&row2, &row3);
// Expect that the first typed URL remains intact, the second typed URL is
// correctly removed, and the non-typed URL does not magically appear.
@@ -3186,10 +3170,8 @@ TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) {
SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3);
// Now notify the in-memory database that all history has been deleted.
- scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
- details->all_history = true;
- BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- details.Pass());
+ mem_backend_->OnURLsDeleted(nullptr, true, false, URLRows(),
+ std::set<GURL>());
// Expect that everything goes away.
EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL));
@@ -3299,7 +3281,7 @@ TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedWithSearchTerms) {
PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2);
// Notify the in-memory database that the second typed URL has been deleted.
- SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, &row2);
+ SimulateNotificationURLsDeleted(&row2);
// Verify that the second term is no longer returned as result, and also check
// at the low level that it is gone for good. The term corresponding to the
diff --git a/chrome/browser/history/history_details.h b/chrome/browser/history/history_details.h
deleted file mode 100644
index a93fbd7..0000000
--- a/chrome/browser/history/history_details.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_HISTORY_HISTORY_DETAILS_H_
-#define CHROME_BROWSER_HISTORY_HISTORY_DETAILS_H_
-
-namespace history {
-
-// Base class for history notifications. This needs only a virtual destructor
-// so that the history service's broadcaster can delete it when the request
-// is complete.
-struct HistoryDetails {
- public:
- virtual ~HistoryDetails() {}
-};
-
-} // namespace history
-
-#endif // CHROME_BROWSER_HISTORY_HISTORY_DETAILS_H_
diff --git a/chrome/browser/history/history_notifications.cc b/chrome/browser/history/history_notifications.cc
deleted file mode 100644
index 47efa27..0000000
--- a/chrome/browser/history/history_notifications.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/history/history_notifications.h"
-
-namespace history {
-
-URLsModifiedDetails::URLsModifiedDetails() {}
-
-URLsModifiedDetails::~URLsModifiedDetails() {}
-
-URLsDeletedDetails::URLsDeletedDetails()
- : all_history(false),
- expired(false) {
-}
-
-URLsDeletedDetails::~URLsDeletedDetails() {}
-
-} // namespace history
diff --git a/chrome/browser/history/history_notifications.h b/chrome/browser/history/history_notifications.h
deleted file mode 100644
index 564ee90..0000000
--- a/chrome/browser/history/history_notifications.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Structs that hold data used in broadcasting notifications.
-
-#ifndef CHROME_BROWSER_HISTORY_HISTORY_NOTIFICATIONS_H__
-#define CHROME_BROWSER_HISTORY_HISTORY_NOTIFICATIONS_H__
-
-#include <set>
-
-#include "chrome/browser/history/history_details.h"
-#include "components/history/core/browser/history_types.h"
-#include "url/gurl.h"
-
-namespace history {
-
-// Details for NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED.
-struct URLsModifiedDetails : public HistoryDetails {
- URLsModifiedDetails();
- ~URLsModifiedDetails() override;
-
- // Lists the information for each of the URLs affected. The rows will have the
- // IDs that are currently in effect in the main history database.
- URLRows changed_urls;
-};
-
-// Details for NOTIFICATION_HISTORY_URLS_DELETED.
-struct URLsDeletedDetails : public HistoryDetails {
- URLsDeletedDetails();
- ~URLsDeletedDetails() override;
-
- // Set when all history was deleted. False means just a subset was deleted.
- bool all_history;
-
- // True if the data was expired due to old age. False if the data was deleted
- // in response to an explicit user action through the History UI.
- bool expired;
-
- // The URLRows of URLs deleted. This is valid only when |all_history| is false
- // indicating that a subset of history has been deleted. The rows will have
- // the IDs that had been in effect before the deletion in the main history
- // database.
- URLRows rows;
-
- // The list of deleted favicon urls. This is valid only when |all_history| is
- // false, indicating that a subset of history has been deleted.
- std::set<GURL> favicon_urls;
-};
-
-} // namespace history
-
-#endif // CHROME_BROWSER_HISTORY_HISTORY_NOTIFICATIONS_H__
diff --git a/chrome/browser/history/history_service.cc b/chrome/browser/history/history_service.cc
index 5e830ec..5a36bbc 100644
--- a/chrome/browser/history/history_service.cc
+++ b/chrome/browser/history/history_service.cc
@@ -30,9 +30,7 @@
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_backend.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/in_memory_history_backend.h"
#include "chrome/browser/history/in_memory_url_index.h"
#include "chrome/browser/history/top_sites.h"
@@ -58,7 +56,6 @@
#include "components/visitedlink/browser/visitedlink_master.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item.h"
-#include "content/public/browser/notification_service.h"
#include "sync/api/sync_error_factory.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -131,12 +128,9 @@ class HistoryService::BackendDelegate : public HistoryBackend::Delegate {
public:
BackendDelegate(
const base::WeakPtr<HistoryService>& history_service,
- const scoped_refptr<base::SequencedTaskRunner>& service_task_runner,
- Profile* profile)
+ const scoped_refptr<base::SequencedTaskRunner>& service_task_runner)
: history_service_(history_service),
- service_task_runner_(service_task_runner),
- profile_(profile) {
- }
+ service_task_runner_(service_task_runner) {}
void NotifyProfileError(sql::InitStatus init_status) override {
// Send to the history service on the main thread.
@@ -184,10 +178,18 @@ class HistoryService::BackendDelegate : public HistoryBackend::Delegate {
void NotifyURLsModified(const history::URLRows& changed_urls) override {
service_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&HistoryService::NotifyURLsModified,
+ history_service_, changed_urls));
+ }
+
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override {
+ service_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&HistoryService::NotifyURLsModified,
- history_service_,
- changed_urls));
+ base::Bind(&HistoryService::NotifyURLsDeleted, history_service_,
+ all_history, expired, deleted_rows, favicon_urls));
}
void NotifyKeywordSearchTermUpdated(const history::URLRow& row,
@@ -204,22 +206,6 @@ class HistoryService::BackendDelegate : public HistoryBackend::Delegate {
history_service_, url_id));
}
- void BroadcastNotifications(
- int type,
- scoped_ptr<history::HistoryDetails> details) override {
- // Send the notification on the history thread.
- if (content::NotificationService::current()) {
- content::Details<history::HistoryDetails> det(details.get());
- content::NotificationService::current()->Notify(
- type, content::Source<Profile>(profile_), det);
- }
- // Send the notification to the history service on the main thread.
- service_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&HistoryService::BroadcastNotificationsHelper,
- history_service_, type, base::Passed(&details)));
- }
-
void DBLoaded() override {
service_task_runner_->PostTask(
FROM_HERE,
@@ -229,7 +215,6 @@ class HistoryService::BackendDelegate : public HistoryBackend::Delegate {
private:
const base::WeakPtr<HistoryService> history_service_;
const scoped_refptr<base::SequencedTaskRunner> service_task_runner_;
- Profile* const profile_;
};
// The history thread is intentionally not a BrowserThread because the
@@ -254,8 +239,6 @@ HistoryService::HistoryService(history::HistoryClient* client, Profile* profile)
no_db_(false),
weak_ptr_factory_(this) {
DCHECK(profile_);
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
}
HistoryService::~HistoryService() {
@@ -955,42 +938,6 @@ void HistoryService::Cleanup() {
delete thread;
}
-void HistoryService::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (!thread_)
- return;
-
- switch (type) {
- case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
- // Update the visited link system for deleted URLs. We will update the
- // visited link system for added URLs as soon as we get the add
- // notification (we don't have to wait for the backend, which allows us to
- // be faster to update the state).
- //
- // For deleted URLs, we don't typically know what will be deleted since
- // delete notifications are by time. We would also like to be more
- // respectful of privacy and never tell the user something is gone when it
- // isn't. Therefore, we update the delete URLs after the fact.
- if (visitedlink_master_) {
- content::Details<history::URLsDeletedDetails> deleted_details(details);
-
- if (deleted_details->all_history) {
- visitedlink_master_->DeleteAllURLs();
- } else {
- URLIteratorFromURLRows iterator(deleted_details->rows);
- visitedlink_master_->DeleteURLs(&iterator);
- }
- }
- break;
- }
-
- default:
- NOTREACHED();
- }
-}
-
void HistoryService::RebuildTable(
const scoped_refptr<URLEnumerator>& enumerator) {
DCHECK(thread_) << "History service being called after cleanup";
@@ -1022,13 +969,10 @@ bool HistoryService::Init(
}
// Create the history backend.
- scoped_refptr<HistoryBackend> backend(
- new HistoryBackend(history_dir_,
- new BackendDelegate(
- weak_ptr_factory_.GetWeakPtr(),
- base::ThreadTaskRunnerHandle::Get(),
- profile_),
- history_client_));
+ scoped_refptr<HistoryBackend> backend(new HistoryBackend(
+ history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(),
+ base::ThreadTaskRunnerHandle::Get()),
+ history_client_));
history_backend_.swap(backend);
// There may not be a profile when unit testing.
@@ -1142,7 +1086,7 @@ void HistoryService::SetInMemoryBackend(
in_memory_backend_.reset(mem_backend.release());
// The database requires additional initialization once we own it.
- in_memory_backend_->AttachToHistoryService(profile_, this);
+ in_memory_backend_->AttachToHistoryService(this);
}
void HistoryService::NotifyProfileError(sql::InitStatus init_status) {
@@ -1227,31 +1171,6 @@ void HistoryService::ExpireLocalAndRemoteHistoryBetween(
ExpireHistoryBetween(restrict_urls, begin_time, end_time, callback, tracker);
}
-void HistoryService::BroadcastNotificationsHelper(
- int type,
- scoped_ptr<history::HistoryDetails> details) {
- DCHECK(thread_checker_.CalledOnValidThread());
- // TODO(evanm): this is currently necessitated by generate_profile, which
- // runs without a browser process. generate_profile should really create
- // a browser process, at which point this check can then be nuked.
- if (!g_browser_process)
- return;
-
- if (!thread_)
- return;
-
- // The source of all of our notifications is the profile. Note that this
- // pointer is NULL in unit tests.
- content::Source<Profile> source(profile_);
-
- // The details object just contains the pointer to the object that the
- // backend has allocated for us. The receiver of the notification will cast
- // this to the proper type.
- content::Details<history::HistoryDetails> det(details.get());
-
- content::NotificationService::current()->Notify(type, source, det);
-}
-
void HistoryService::OnDBLoaded() {
DCHECK(thread_checker_.CalledOnValidThread());
backend_loaded_ = true;
@@ -1287,6 +1206,37 @@ void HistoryService::NotifyURLsModified(const history::URLRows& changed_urls) {
OnURLsModified(this, changed_urls));
}
+void HistoryService::NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!thread_)
+ return;
+
+ // Update the visited link system for deleted URLs. We will update the
+ // visited link system for added URLs as soon as we get the add
+ // notification (we don't have to wait for the backend, which allows us to
+ // be faster to update the state).
+ //
+ // For deleted URLs, we don't typically know what will be deleted since
+ // delete notifications are by time. We would also like to be more
+ // respectful of privacy and never tell the user something is gone when it
+ // isn't. Therefore, we update the delete URLs after the fact.
+ if (visitedlink_master_) {
+ if (all_history) {
+ visitedlink_master_->DeleteAllURLs();
+ } else {
+ URLIteratorFromURLRows iterator(deleted_rows);
+ visitedlink_master_->DeleteURLs(&iterator);
+ }
+ }
+
+ FOR_EACH_OBSERVER(
+ history::HistoryServiceObserver, observers_,
+ OnURLsDeleted(this, all_history, expired, deleted_rows, favicon_urls));
+}
+
void HistoryService::NotifyHistoryServiceLoaded() {
DCHECK(thread_checker_.CalledOnValidThread());
FOR_EACH_OBSERVER(history::HistoryServiceObserver, observers_,
diff --git a/chrome/browser/history/history_service.h b/chrome/browser/history/history_service.h
index 4ea16f6..bbf4f1b 100644
--- a/chrome/browser/history/history_service.h
+++ b/chrome/browser/history/history_service.h
@@ -31,8 +31,6 @@
#include "components/keyed_service/core/keyed_service.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
#include "content/public/browser/download_manager_delegate.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "sql/init_status.h"
#include "sync/api/syncable_service.h"
#include "ui/base/page_transition_types.h"
@@ -74,7 +72,6 @@ class URLDatabase;
class VisitFilter;
struct DownloadRow;
struct HistoryAddPageArgs;
-struct HistoryDetails;
struct KeywordSearchTermVisit;
} // namespace history
@@ -84,8 +81,7 @@ struct KeywordSearchTermVisit;
//
// This service is thread safe. Each request callback is invoked in the
// thread that made the request.
-class HistoryService : public content::NotificationObserver,
- public syncer::SyncableService,
+class HistoryService : public syncer::SyncableService,
public KeyedService,
public visitedlink::VisitedLinkDelegate {
public:
@@ -557,11 +553,6 @@ class HistoryService : public content::NotificationObserver,
// still in memory (pending requests may be holding a reference to us).
void Cleanup();
- // Implementation of content::NotificationObserver.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
// Implementation of visitedlink::VisitedLinkDelegate.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
@@ -576,12 +567,6 @@ class HistoryService : public content::NotificationObserver,
void ScheduleAutocomplete(const base::Callback<
void(history::HistoryBackend*, history::URLDatabase*)>& callback);
- // Broadcasts the given notification. This is called by the backend so that
- // the notification will be broadcast on the main thread.
- void BroadcastNotificationsHelper(
- int type,
- scoped_ptr<history::HistoryDetails> details);
-
// Notification from the backend that it has finished loading. Sends
// notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true.
void OnDBLoaded();
@@ -611,11 +596,24 @@ class HistoryService : public content::NotificationObserver,
// modified. |changed_urls| contains the list of affects URLs.
void NotifyURLsModified(const history::URLRows& changed_urls);
+ // Notify all HistoryServiceObservers registered that URLs have been deleted.
+ // |all_history| is set to true, if all the URLs are deleted.
+ // When set to true, |deleted_rows| and |favicon_urls| are
+ // undefined.
+ // |expired| is set to true, if the URL deletion is due to expiration.
+ // |deleted_rows| list of the deleted URLs.
+ // |favicon_urls| list of favicon URLs that correspond to the deleted URLs.
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls);
+
// Notify all HistoryServiceObservers registered that the
// HistoryService has finished loading.
void NotifyHistoryServiceLoaded();
- // HistoryService is being deleted.
+ // Notify all HistoryServiceObservers registered that HistoryService is being
+ // deleted.
void NotifyHistoryServiceBeingDeleted();
// Notify all HistoryServiceObservers registered that a keyword search term
@@ -869,8 +867,6 @@ class HistoryService : public content::NotificationObserver,
base::ThreadChecker thread_checker_;
- content::NotificationRegistrar registrar_;
-
// The thread used by the history service to run complicated operations.
// |thread_| is NULL once |Cleanup| is NULL.
base::Thread* thread_;
diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc
index e30a9b8..3daf4ac 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -43,7 +43,6 @@
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "chrome/browser/history/history_backend.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/in_memory_history_backend.h"
#include "chrome/common/chrome_constants.h"
@@ -108,12 +107,14 @@ class BackendDelegate : public HistoryBackend::Delegate {
const RedirectList& redirects,
base::Time visit_time) override {}
void NotifyURLsModified(const URLRows& changed_urls) override {}
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override {}
void NotifyKeywordSearchTermUpdated(const URLRow& row,
KeywordID keyword_id,
const base::string16& term) override {}
void NotifyKeywordSearchTermDeleted(URLID url_id) override {}
- void BroadcastNotifications(int type,
- scoped_ptr<HistoryDetails> details) override;
void DBLoaded() override {}
private:
@@ -234,16 +235,6 @@ void BackendDelegate::SetInMemoryBackend(
history_test_->in_mem_backend_.swap(backend);
}
-void BackendDelegate::BroadcastNotifications(
- int type,
- scoped_ptr<HistoryDetails> details) {
- // Currently, just send the notifications directly to the in-memory database.
- // We may want do do something more fancy in the future.
- content::Details<HistoryDetails> det(details.get());
- history_test_->in_mem_backend_->Observe(type,
- content::Source<HistoryBackendDBTest>(NULL), det);
-}
-
TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {
CreateBackendAndDatabase();
diff --git a/chrome/browser/history/in_memory_history_backend.cc b/chrome/browser/history/in_memory_history_backend.cc
index 1165d23..27a3b88 100644
--- a/chrome/browser/history/in_memory_history_backend.cc
+++ b/chrome/browser/history/in_memory_history_backend.cc
@@ -10,22 +10,14 @@
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
-#include "chrome/browser/profiles/profile.h"
#include "components/history/core/browser/in_memory_database.h"
#include "components/history/core/browser/url_database.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
namespace history {
InMemoryHistoryBackend::InMemoryHistoryBackend()
- : profile_(nullptr),
- history_service_observer_(this),
- history_service_(nullptr) {
+ : history_service_observer_(this) {
}
InMemoryHistoryBackend::~InMemoryHistoryBackend() {
@@ -37,29 +29,10 @@ bool InMemoryHistoryBackend::Init(const base::FilePath& history_filename) {
}
void InMemoryHistoryBackend::AttachToHistoryService(
- Profile* profile,
HistoryService* history_service) {
- if (!db_) {
- NOTREACHED();
- return;
- }
-
- profile_ = profile;
-
+ DCHECK(db_);
DCHECK(history_service);
history_service_observer_.Add(history_service);
- history_service_ = history_service;
-
- // TODO(evanm): this is currently necessitated by generate_profile, which
- // runs without a browser process. generate_profile should really create
- // a browser process, at which point this check can then be nuked.
- if (!g_browser_process)
- return;
-
- // Register for the notifications we care about.
- // We only want notifications for the associated profile.
- content::Source<Profile> source(profile_);
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source);
}
void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword(
@@ -84,6 +57,30 @@ void InMemoryHistoryBackend::OnURLsModified(HistoryService* history_service,
}
}
+void InMemoryHistoryBackend::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ DCHECK(db_);
+
+ if (all_history) {
+ // When all history is deleted, the individual URLs won't be listed. Just
+ // create a new database to quickly clear everything out.
+ db_.reset(new InMemoryDatabase);
+ if (!db_->InitFromScratch())
+ db_.reset();
+ return;
+ }
+
+ // Delete all matching URLs in our database.
+ for (const auto& row : deleted_rows) {
+ // This will also delete the corresponding keyword search term.
+ // Ignore errors, as we typically only cache a subset of URLRows.
+ db_->DeleteURLRow(row.id());
+ }
+}
+
void InMemoryHistoryBackend::OnKeywordSearchTermUpdated(
HistoryService* history_service,
const URLRow& row,
@@ -102,21 +99,6 @@ void InMemoryHistoryBackend::OnKeywordSearchTermDeleted(
db_->DeleteKeywordSearchTermForURL(url_id);
}
-void InMemoryHistoryBackend::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
- OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr());
- break;
- default:
- // For simplicity, the unit tests send us all notifications, even when
- // we haven't registered for them, so don't assert here.
- break;
- }
-}
-
void InMemoryHistoryBackend::OnURLVisitedOrModified(const URLRow& url_row) {
DCHECK(db_);
DCHECK(url_row.id());
@@ -126,25 +108,4 @@ void InMemoryHistoryBackend::OnURLVisitedOrModified(const URLRow& url_row) {
db_->DeleteURLRow(url_row.id());
}
-void InMemoryHistoryBackend::OnURLsDeleted(const URLsDeletedDetails& details) {
- DCHECK(db_);
-
- if (details.all_history) {
- // When all history is deleted, the individual URLs won't be listed. Just
- // create a new database to quickly clear everything out.
- db_.reset(new InMemoryDatabase);
- if (!db_->InitFromScratch())
- db_.reset();
- return;
- }
-
- // Delete all matching URLs in our database.
- for (URLRows::const_iterator row = details.rows.begin();
- row != details.rows.end(); ++row) {
- // This will also delete the corresponding keyword search term.
- // Ignore errors, as we typically only cache a subset of URLRows.
- db_->DeleteURLRow(row->id());
- }
-}
-
} // namespace history
diff --git a/chrome/browser/history/in_memory_history_backend.h b/chrome/browser/history/in_memory_history_backend.h
index 2799984..0fea8fc 100644
--- a/chrome/browser/history/in_memory_history_backend.h
+++ b/chrome/browser/history/in_memory_history_backend.h
@@ -28,11 +28,8 @@
#include "base/scoped_observer.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/keyword_id.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
class HistoryService;
-class Profile;
namespace base {
class FilePath;
@@ -43,11 +40,8 @@ namespace history {
class InMemoryDatabase;
class URLDatabase;
class URLRow;
-struct URLsDeletedDetails;
-struct URLsModifiedDetails;
-class InMemoryHistoryBackend : public HistoryServiceObserver,
- public content::NotificationObserver {
+class InMemoryHistoryBackend : public HistoryServiceObserver {
public:
InMemoryHistoryBackend();
~InMemoryHistoryBackend() override;
@@ -59,8 +53,7 @@ class InMemoryHistoryBackend : public HistoryServiceObserver,
// Does initialization work when this object is attached to the history
// system on the main thread. The argument is the profile with which the
// attached history service is under.
- void AttachToHistoryService(Profile* profile,
- HistoryService* history_service);
+ void AttachToHistoryService(HistoryService* history_service);
// Deletes all search terms for the specified keyword.
void DeleteAllSearchTermsForKeyword(KeywordID keyword_id);
@@ -72,6 +65,12 @@ class InMemoryHistoryBackend : public HistoryServiceObserver,
return db_.get();
}
+ private:
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
+ FRIEND_TEST_ALL_PREFIXES(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse);
+ friend class HistoryBackendTestBase;
+ friend class InMemoryHistoryBackendTest;
+
// HistoryServiceObserver:
void OnURLVisited(HistoryService* history_service,
ui::PageTransition transition,
@@ -80,6 +79,11 @@ class InMemoryHistoryBackend : public HistoryServiceObserver,
base::Time visit_time) override;
void OnURLsModified(HistoryService* history_service,
const URLRows& changed_urls) override;
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void OnKeywordSearchTermUpdated(HistoryService* history_service,
const URLRow& row,
KeywordID keyword_id,
@@ -87,30 +91,16 @@ class InMemoryHistoryBackend : public HistoryServiceObserver,
void OnKeywordSearchTermDeleted(HistoryService* history_service,
URLID url_id) override;
- // Notification callback.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
private:
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
// Handler for HISTORY_URL_VISITED and HISTORY_URLS_MODIFIED.
void OnURLVisitedOrModified(const URLRow& url_row);
- // Handler for HISTORY_URLS_DELETED.
- void OnURLsDeleted(const URLsDeletedDetails& details);
-
- content::NotificationRegistrar registrar_;
-
scoped_ptr<InMemoryDatabase> db_;
- // The profile that this object is attached. May be NULL before
- // initialization.
- Profile* profile_;
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_;
- HistoryService* history_service_;
DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend);
};
diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/history/in_memory_url_index.cc
index 7a8ec01..bf6ac74 100644
--- a/chrome/browser/history/in_memory_url_index.cc
+++ b/chrome/browser/history/in_memory_url_index.cc
@@ -7,8 +7,6 @@
#include "base/debug/trace_event.h"
#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/url_index_private_data.h"
@@ -16,9 +14,6 @@
#include "chrome/common/url_constants.h"
#include "components/history/core/browser/url_database.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_source.h"
using in_memory_url_index::InMemoryURLIndexCacheItem;
@@ -104,11 +99,7 @@ InMemoryURLIndex::InMemoryURLIndex(Profile* profile,
needs_to_be_cached_(false),
history_service_observer_(this) {
InitializeSchemeWhitelist(&scheme_whitelist_);
- if (profile) {
- // TODO(mrossetti): Register for language change notifications.
- content::Source<Profile> source(profile);
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source);
- }
+ // TODO(mrossetti): Register for language change notifications.
if (history_service_)
history_service_observer_.Add(history_service_);
}
@@ -140,7 +131,6 @@ void InMemoryURLIndex::Init() {
void InMemoryURLIndex::ShutDown() {
history_service_observer_.RemoveAll();
- registrar_.RemoveAll();
cache_reader_tracker_.TryCancelAll();
shutdown_ = true;
base::FilePath path;
@@ -182,21 +172,6 @@ void InMemoryURLIndex::DeleteURL(const GURL& url) {
private_data_->DeleteURL(url);
}
-void InMemoryURLIndex::Observe(int notification_type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (notification_type) {
- case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
- OnURLsDeleted(
- content::Details<history::URLsDeletedDetails>(details).ptr());
- break;
- default:
- // For simplicity, the unit tests send us all notifications, even when
- // we haven't registered for them, so don't assert here.
- break;
- }
-}
-
void InMemoryURLIndex::OnURLVisited(HistoryService* history_service,
ui::PageTransition transition,
const URLRow& row,
@@ -222,18 +197,17 @@ void InMemoryURLIndex::OnURLsModified(HistoryService* history_service,
}
}
-void InMemoryURLIndex::OnHistoryServiceLoaded(HistoryService* history_service) {
- ScheduleRebuildFromHistory();
-}
-
-void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) {
- if (details->all_history) {
+void InMemoryURLIndex::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ if (all_history) {
ClearPrivateData();
needs_to_be_cached_ = true;
} else {
- for (URLRows::const_iterator row = details->rows.begin();
- row != details->rows.end(); ++row)
- needs_to_be_cached_ |= private_data_->DeleteURL(row->url());
+ for (const auto& row : deleted_rows)
+ needs_to_be_cached_ |= private_data_->DeleteURL(row.url());
}
// If we made changes, destroy the previous cache. Otherwise, if we go
// through an unclean shutdown (and therefore fail to write a new cache file),
@@ -256,6 +230,10 @@ void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) {
}
}
+void InMemoryURLIndex::OnHistoryServiceLoaded(HistoryService* history_service) {
+ ScheduleRebuildFromHistory();
+}
+
// Restoring from Cache --------------------------------------------------------
void InMemoryURLIndex::PostRestoreFromCacheFileTask() {
diff --git a/chrome/browser/history/in_memory_url_index.h b/chrome/browser/history/in_memory_url_index.h
index 69b5b90..fdbcea1 100644
--- a/chrome/browser/history/in_memory_url_index.h
+++ b/chrome/browser/history/in_memory_url_index.h
@@ -23,9 +23,6 @@
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/history_types.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "sql/connection.h"
class HistoryService;
@@ -47,8 +44,6 @@ namespace imui = in_memory_url_index;
class HistoryClient;
class HistoryDatabase;
class URLIndexPrivateData;
-struct URLsDeletedDetails;
-struct URLsModifiedDetails;
// The URL history source.
// Holds portions of the URL database in memory in an indexed form. Used to
@@ -70,7 +65,6 @@ struct URLsModifiedDetails;
// is being searched on and which character occurs as the second char16 of a
// multi-char16 instance.
class InMemoryURLIndex : public HistoryServiceObserver,
- public content::NotificationObserver,
public base::SupportsWeakPtr<InMemoryURLIndex> {
public:
// Defines an abstract class which is notified upon completion of restoring
@@ -151,6 +145,7 @@ class InMemoryURLIndex : public HistoryServiceObserver,
friend class ::HistoryQuickProviderTest;
friend class InMemoryURLIndexTest;
friend class InMemoryURLIndexCacheTest;
+ FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow);
FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization);
// Creating one of me without a history path is not allowed (tests excepted).
@@ -235,11 +230,6 @@ class InMemoryURLIndex : public HistoryServiceObserver,
// |succeeded| is true on a successful save.
void OnCacheSaveDone(bool succeeded);
- // Handles notifications of history changes.
- void Observe(int notification_type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
// HistoryServiceObserver:
void OnURLVisited(HistoryService* history_service,
ui::PageTransition transition,
@@ -248,11 +238,13 @@ class InMemoryURLIndex : public HistoryServiceObserver,
base::Time visit_time) override;
void OnURLsModified(HistoryService* history_service,
const URLRows& changed_urls) override;
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void OnHistoryServiceLoaded(HistoryService* history_service) override;
- // Notification handlers.
- void OnURLsDeleted(const URLsDeletedDetails* details);
-
// Sets the directory wherein the cache file will be maintained.
// For unit test usage only.
void set_history_dir(const base::FilePath& dir_path) {
@@ -298,7 +290,6 @@ class InMemoryURLIndex : public HistoryServiceObserver,
base::CancelableTaskTracker private_data_tracker_;
base::CancelableTaskTracker cache_reader_tracker_;
- content::NotificationRegistrar registrar_;
// Set to true once the shutdown process has begun.
bool shutdown_;
diff --git a/chrome/browser/history/in_memory_url_index_unittest.cc b/chrome/browser/history/in_memory_url_index_unittest.cc
index 7501e63..3e25d3c 100644
--- a/chrome/browser/history/in_memory_url_index_unittest.cc
+++ b/chrome/browser/history/in_memory_url_index_unittest.cc
@@ -15,9 +15,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_backend.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/in_memory_url_index.h"
@@ -29,8 +27,6 @@
#include "components/history/core/browser/history_client.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/in_memory_url_index_types.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "sql/transaction.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -113,9 +109,6 @@ class InMemoryURLIndexTest : public testing::Test {
bool GetCacheFilePath(base::FilePath* file_path) const;
void PostRestoreFromCacheFileTask();
void PostSaveToCacheFileTask();
- void Observe(int notification_type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details);
const std::set<std::string>& scheme_whitelist();
@@ -176,13 +169,6 @@ void InMemoryURLIndexTest::PostSaveToCacheFileTask() {
url_index_->PostSaveToCacheFileTask();
}
-void InMemoryURLIndexTest::Observe(
- int notification_type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- url_index_->Observe(notification_type, source, details);
-}
-
const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() {
return url_index_->scheme_whitelist();
}
@@ -899,12 +885,10 @@ TEST_F(InMemoryURLIndexTest, ExpireRow) {
// Determine the row id for the result, remember that id, broadcast a
// delete notification, then ensure that the row has been deleted.
- URLsDeletedDetails deleted_details;
- deleted_details.all_history = false;
- deleted_details.rows.push_back(matches[0].url_info);
- Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<InMemoryURLIndexTest>(this),
- content::Details<history::HistoryDetails>(&deleted_details));
+ URLRows deleted_rows;
+ deleted_rows.push_back(matches[0].url_info);
+ url_index_->OnURLsDeleted(nullptr, false, false, deleted_rows,
+ std::set<GURL>());
EXPECT_TRUE(url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty());
}
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
index 2186a26..a83077b 100644
--- a/chrome/browser/history/top_sites.cc
+++ b/chrome/browser/history/top_sites.cc
@@ -9,6 +9,7 @@
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h"
+#include "components/history/core/browser/top_sites_observer.h"
#include "grit/theme_resources.h"
namespace history {
diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h
index 6fa5826..0dd87a5 100644
--- a/chrome/browser/history/top_sites.h
+++ b/chrome/browser/history/top_sites.h
@@ -12,9 +12,9 @@
#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 "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/image/image.h"
@@ -30,6 +30,7 @@ class RefCountedMemory;
namespace history {
class TopSitesCache;
+class TopSitesObserver;
// Interface for TopSites, which stores the data for the top "most visited"
// sites. This includes a cache of the most visited data from history, as well
diff --git a/chrome/browser/history/top_sites_impl.cc b/chrome/browser/history/top_sites_impl.cc
index 5d1a78d..e6c27b1 100644
--- a/chrome/browser/history/top_sites_impl.cc
+++ b/chrome/browser/history/top_sites_impl.cc
@@ -22,7 +22,6 @@
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_backend.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
@@ -101,13 +100,12 @@ TopSitesImpl::TopSitesImpl(Profile* profile)
thread_safe_cache_(new TopSitesCache()),
profile_(profile),
last_num_urls_changed_(0),
- loaded_(false) {
+ loaded_(false),
+ history_service_observer_(this) {
if (!profile_)
return;
if (content::NotificationService::current()) {
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
// Listen for any nav commits. We'll ignore those not related to this
// profile when we get the notification.
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
@@ -739,34 +737,10 @@ base::TimeDelta TopSitesImpl::GetUpdateDelay() {
void TopSitesImpl::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
+ DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
if (!loaded_)
return;
- if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
- content::Details<history::URLsDeletedDetails> deleted_details(details);
- if (deleted_details->all_history) {
- SetTopSites(MostVisitedURLList());
- backend_->ResetDatabase();
- } else {
- std::set<size_t> indices_to_delete; // Indices into top_sites_.
- for (URLRows::const_iterator i = deleted_details->rows.begin();
- i != deleted_details->rows.end(); ++i) {
- if (cache_->IsKnownURL(i->url()))
- indices_to_delete.insert(cache_->GetURLIndex(i->url()));
- }
-
- if (indices_to_delete.empty())
- return;
-
- MostVisitedURLList new_top_sites(cache_->top_sites());
- for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin();
- i != indices_to_delete.rend(); i++) {
- new_top_sites.erase(new_top_sites.begin() + *i);
- }
- SetTopSites(new_top_sites);
- }
- StartQueryForMostVisited();
- } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
NavigationController* controller =
content::Source<NavigationController>(source).ptr();
Profile* profile = Profile::FromBrowserContext(
@@ -783,7 +757,6 @@ void TopSitesImpl::Observe(int type,
RestartQueryForTopSitesTimer(GetUpdateDelay());
}
}
- }
}
void TopSitesImpl::SetTopSites(const MostVisitedURLList& new_top_sites) {
@@ -874,6 +847,12 @@ void TopSitesImpl::MoveStateToLoaded() {
for (size_t i = 0; i < pending_callbacks.size(); i++)
pending_callbacks[i].Run(filtered_urls_all, filtered_urls_nonforced);
+ HistoryService* hs = HistoryServiceFactory::GetForProfile(
+ profile_, ServiceAccessType::EXPLICIT_ACCESS);
+ // |hs| may be null during unit tests.
+ if (hs)
+ history_service_observer_.Add(hs);
+
NotifyTopSitesLoaded();
}
@@ -925,4 +904,39 @@ void TopSitesImpl::OnTopSitesAvailableFromHistory(
SetTopSites(*pages);
}
+void TopSitesImpl::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ if (!loaded_)
+ return;
+
+ if (all_history) {
+ SetTopSites(MostVisitedURLList());
+ backend_->ResetDatabase();
+ } else {
+ std::set<size_t> indices_to_delete; // Indices into top_sites_.
+ for (const auto& row : deleted_rows) {
+ if (cache_->IsKnownURL(row.url()))
+ indices_to_delete.insert(cache_->GetURLIndex(row.url()));
+ }
+
+ if (indices_to_delete.empty())
+ return;
+
+ MostVisitedURLList new_top_sites(cache_->top_sites());
+ for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin();
+ i != indices_to_delete.rend(); i++) {
+ new_top_sites.erase(new_top_sites.begin() + *i);
+ }
+ SetTopSites(new_top_sites);
+ }
+ StartQueryForMostVisited();
+}
+
+void TopSitesImpl::HistoryServiceBeingDeleted(HistoryService* history_service) {
+ history_service_observer_.Remove(history_service);
+}
+
} // namespace history
diff --git a/chrome/browser/history/top_sites_impl.h b/chrome/browser/history/top_sites_impl.h
index cea6f84..130eb58 100644
--- a/chrome/browser/history/top_sites_impl.h
+++ b/chrome/browser/history/top_sites_impl.h
@@ -15,6 +15,7 @@
#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/scoped_observer.h"
#include "base/synchronization/lock.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
@@ -22,6 +23,7 @@
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/history/top_sites_backend.h"
+#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/page_usage_data.h"
#include "components/history/core/common/thumbnail_score.h"
@@ -46,7 +48,7 @@ class TopSitesImplTest;
// thread. All other methods must be invoked on the UI thread. All mutations
// to internal state happen on the UI thread and are scheduled to update the
// db using TopSitesBackend.
-class TopSitesImpl : public TopSites {
+class TopSitesImpl : public TopSites, public HistoryServiceObserver {
public:
explicit TopSitesImpl(Profile* profile);
@@ -210,6 +212,14 @@ class TopSitesImpl : public TopSites {
// Called when history service returns a list of top URLs.
void OnTopSitesAvailableFromHistory(const MostVisitedURLList* data);
+ // history::HistoryServiceObserver:
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
+ void HistoryServiceBeingDeleted(HistoryService* history_service) override;
+
scoped_refptr<TopSitesBackend> backend_;
// The top sites data.
@@ -257,6 +267,9 @@ class TopSitesImpl : public TopSites {
// Are we loaded?
bool loaded_;
+ ScopedObserver<HistoryService, HistoryServiceObserver>
+ history_service_observer_;
+
DISALLOW_COPY_AND_ASSIGN(TopSitesImpl);
};
diff --git a/chrome/browser/history/top_sites_impl_unittest.cc b/chrome/browser/history/top_sites_impl_unittest.cc
index b8f02f1..b1aa4d5 100644
--- a/chrome/browser/history/top_sites_impl_unittest.cc
+++ b/chrome/browser/history/top_sites_impl_unittest.cc
@@ -16,6 +16,7 @@
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/top_sites_cache.h"
+#include "components/history/core/browser/top_sites_observer.h"
#include "components/history/core/test/history_unittest_base.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chrome/browser/history/typed_url_syncable_service.h b/chrome/browser/history/typed_url_syncable_service.h
index a0303a9..d7e27c7 100644
--- a/chrome/browser/history/typed_url_syncable_service.h
+++ b/chrome/browser/history/typed_url_syncable_service.h
@@ -8,7 +8,6 @@
#include <set>
#include <vector>
-#include "chrome/browser/history/history_notifications.h"
#include "components/history/core/browser/history_types.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_data.h"
diff --git a/chrome/browser/predictors/autocomplete_action_predictor.cc b/chrome/browser/predictors/autocomplete_action_predictor.cc
index bb1a19c..2afdd8c 100644
--- a/chrome/browser/predictors/autocomplete_action_predictor.cc
+++ b/chrome/browser/predictors/autocomplete_action_predictor.cc
@@ -16,7 +16,6 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/omnibox/omnibox_log.h"
@@ -125,11 +124,10 @@ void AutocompleteActionPredictor::RegisterTransitionalMatches(
transitional_match);
}
- for (AutocompleteResult::const_iterator i(result.begin()); i != result.end();
- ++i) {
+ for (const auto& i : result) {
if (std::find(match_it->urls.begin(), match_it->urls.end(),
- i->destination_url) == match_it->urls.end()) {
- match_it->urls.push_back(i->destination_url);
+ i.destination_url) == match_it->urls.end()) {
+ match_it->urls.push_back(i.destination_url);
}
}
}
@@ -231,19 +229,6 @@ void AutocompleteActionPredictor::Observe(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
break;
-
- case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
- DCHECK(initialized_);
- const content::Details<const history::URLsDeletedDetails>
- urls_deleted_details =
- content::Details<const history::URLsDeletedDetails>(details);
- if (urls_deleted_details->all_history)
- DeleteAllRows();
- else
- DeleteRowsWithURLs(urls_deleted_details->rows);
- break;
- }
-
case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: {
DCHECK(initialized_);
@@ -557,8 +542,6 @@ void AutocompleteActionPredictor::FinishInitialization() {
// opens the non-incognito history (and lets users delete from there).
notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
content::Source<Profile>(profile_));
- notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_->GetOriginalProfile()));
initialized_ = true;
}
@@ -594,6 +577,21 @@ void AutocompleteActionPredictor::Shutdown() {
history_service_observer_.RemoveAll();
}
+void AutocompleteActionPredictor::OnURLsDeleted(
+ HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ if (!initialized_)
+ return;
+
+ if (all_history)
+ DeleteAllRows();
+ else
+ DeleteRowsWithURLs(deleted_rows);
+}
+
void AutocompleteActionPredictor::OnHistoryServiceLoaded(
HistoryService* history_service) {
TryDeleteOldEntries(history_service);
diff --git a/chrome/browser/predictors/autocomplete_action_predictor.h b/chrome/browser/predictors/autocomplete_action_predictor.h
index dfd3eb6..85981cd 100644
--- a/chrome/browser/predictors/autocomplete_action_predictor.h
+++ b/chrome/browser/predictors/autocomplete_action_predictor.h
@@ -221,6 +221,11 @@ class AutocompleteActionPredictor
void Shutdown() override;
// history::HistoryServiceObserver:
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void OnHistoryServiceLoaded(HistoryService* history_service) override;
Profile* profile_;
diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc
index 1058a91..68db96e 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
@@ -15,8 +15,6 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/predictors/predictor_database.h"
@@ -29,9 +27,6 @@
#include "components/history/core/browser/history_db_task.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/notification_types.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/web_contents.h"
#include "net/base/mime_util.h"
@@ -437,43 +432,12 @@ void ResourcePrefetchPredictor::FinishedPrefetchForNavigation(
}
}
-void ResourcePrefetchPredictor::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
- switch (type) {
- case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
- DCHECK_EQ(initialization_state_, INITIALIZED);
- const content::Details<const history::URLsDeletedDetails>
- urls_deleted_details =
- content::Details<const history::URLsDeletedDetails>(details);
- if (urls_deleted_details->all_history) {
- DeleteAllUrls();
- UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
- REPORTING_EVENT_ALL_HISTORY_CLEARED,
- REPORTING_EVENT_COUNT);
- } else {
- DeleteUrls(urls_deleted_details->rows);
- UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
- REPORTING_EVENT_PARTIAL_HISTORY_CLEARED,
- REPORTING_EVENT_COUNT);
- }
- break;
- }
-
- default:
- NOTREACHED() << "Unexpected notification observed.";
- break;
- }
-}
-
void ResourcePrefetchPredictor::Shutdown() {
if (prefetch_manager_.get()) {
prefetch_manager_->ShutdownOnUIThread();
prefetch_manager_ = NULL;
}
+ history_service_observer_.RemoveAll();
}
void ResourcePrefetchPredictor::OnMainFrameRequest(
@@ -709,7 +673,7 @@ void ResourcePrefetchPredictor::StopPrefetching(
void ResourcePrefetchPredictor::StartInitialization() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK_EQ(initialization_state_, NOT_INITIALIZED);
+ DCHECK_EQ(NOT_INITIALIZED, initialization_state_);
initialization_state_ = INITIALIZING;
// Create local caches using the database as loaded.
@@ -731,7 +695,7 @@ void ResourcePrefetchPredictor::CreateCaches(
scoped_ptr<PrefetchDataMap> host_data_map) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK_EQ(initialization_state_, INITIALIZING);
+ DCHECK_EQ(INITIALIZING, initialization_state_);
DCHECK(!url_table_cache_);
DCHECK(!host_table_cache_);
DCHECK(inflight_navigations_.empty());
@@ -749,19 +713,13 @@ void ResourcePrefetchPredictor::CreateCaches(
void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK_EQ(initialization_state_, INITIALIZING);
-
- notification_registrar_.Add(this,
- chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
+ DCHECK_EQ(INITIALIZING, initialization_state_);
// Initialize the prefetch manager only if prefetching is enabled.
if (config_.IsPrefetchingEnabled(profile_)) {
prefetch_manager_ = new ResourcePrefetcherManager(
this, config_, profile_->GetRequestContext());
}
-
- history_service_observer_.RemoveAll();
initialization_state_ = INITIALIZED;
}
@@ -807,15 +765,14 @@ void ResourcePrefetchPredictor::DeleteUrls(const history::URLRows& urls) {
// in the cache.
std::vector<std::string> urls_to_delete, hosts_to_delete;
- for (history::URLRows::const_iterator it = urls.begin(); it != urls.end();
- ++it) {
- const std::string url_spec = it->url().spec();
+ for (const auto& it : urls) {
+ const std::string& url_spec = it.url().spec();
if (url_table_cache_->find(url_spec) != url_table_cache_->end()) {
urls_to_delete.push_back(url_spec);
url_table_cache_->erase(url_spec);
}
- const std::string host = it->url().host();
+ const std::string& host = it.url().host();
if (host_table_cache_->find(host) != host_table_cache_->end()) {
hosts_to_delete.push_back(host);
host_table_cache_->erase(host);
@@ -1339,6 +1296,29 @@ void ResourcePrefetchPredictor::ReportPredictedAccuracyStatsHelper(
#undef RPP_PREDICTED_HISTOGRAM_COUNTS
}
+void ResourcePrefetchPredictor::OnURLsDeleted(
+ HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (INITIALIZED != initialization_state_)
+ return;
+
+ if (all_history) {
+ DeleteAllUrls();
+ UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
+ REPORTING_EVENT_ALL_HISTORY_CLEARED,
+ REPORTING_EVENT_COUNT);
+ } else {
+ DeleteUrls(deleted_rows);
+ UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
+ REPORTING_EVENT_PARTIAL_HISTORY_CLEARED,
+ REPORTING_EVENT_COUNT);
+ }
+}
+
void ResourcePrefetchPredictor::OnHistoryServiceLoaded(
HistoryService* history_service) {
OnHistoryAndCacheLoaded();
diff --git a/chrome/browser/predictors/resource_prefetch_predictor.h b/chrome/browser/predictors/resource_prefetch_predictor.h
index 1225a22..bf209e2 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor.h
@@ -22,18 +22,12 @@
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/history_types.h"
#include "components/keyed_service/core/keyed_service.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "content/public/common/resource_type.h"
#include "url/gurl.h"
class PredictorsHandler;
class Profile;
-namespace content {
-class WebContents;
-}
-
namespace net {
class URLRequest;
}
@@ -76,7 +70,6 @@ class ResourcePrefetcherManager;
// with main frame.
class ResourcePrefetchPredictor
: public KeyedService,
- public content::NotificationObserver,
public history::HistoryServiceObserver,
public base::SupportsWeakPtr<ResourcePrefetchPredictor> {
public:
@@ -186,11 +179,6 @@ class ResourcePrefetchPredictor
// Returns true if the request (should have a response in it) is cacheable.
static bool IsCacheable(const net::URLRequest* request);
- // content::NotificationObserver methods override.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
// KeyedService methods override.
void Shutdown() override;
@@ -297,6 +285,11 @@ class ResourcePrefetchPredictor
size_t max_assumed_prefetched) const;
// history::HistoryServiceObserver:
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void OnHistoryServiceLoaded(HistoryService* history_service) override;
// Used to connect to HistoryService or register for service loaded
@@ -313,7 +306,6 @@ class ResourcePrefetchPredictor
InitializationState initialization_state_;
scoped_refptr<ResourcePrefetchPredictorTables> tables_;
scoped_refptr<ResourcePrefetcherManager> prefetch_manager_;
- content::NotificationRegistrar notification_registrar_;
base::CancelableTaskTracker history_lookup_consumer_;
// Map of all the navigations in flight to their resource requests.
diff --git a/chrome/browser/sync/glue/favicon_cache.cc b/chrome/browser/sync/glue/favicon_cache.cc
index 342a049..1a331e7 100644
--- a/chrome/browser/sync/glue/favicon_cache.cc
+++ b/chrome/browser/sync/glue/favicon_cache.cc
@@ -6,13 +6,11 @@
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
-#include "chrome/browser/history/history_notifications.h"
+#include "chrome/browser/history/history_service.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "components/history/core/browser/history_types.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "sync/api/time.h"
#include "sync/protocol/favicon_image_specifics.pb.h"
#include "sync/protocol/favicon_tracking_specifics.pb.h"
@@ -226,10 +224,15 @@ bool FaviconInfoHasValidTypeData(const SyncedFaviconInfo& favicon_info,
FaviconCache::FaviconCache(Profile* profile, int max_sync_favicon_limit)
: profile_(profile),
max_sync_favicon_limit_(max_sync_favicon_limit),
+ history_service_observer_(this),
weak_ptr_factory_(this) {
- notification_registrar_.Add(this,
- chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
+ HistoryService* hs = NULL;
+ if (profile_) {
+ hs = HistoryServiceFactory::GetForProfile(
+ profile_, ServiceAccessType::EXPLICIT_ACCESS);
+ }
+ if (hs)
+ history_service_observer_.Add(hs);
DVLOG(1) << "Setting favicon limit to " << max_sync_favicon_limit;
}
@@ -571,41 +574,6 @@ void FaviconCache::OnReceivedSyncFaviconImpl(
syncer::SyncChange::ACTION_UPDATE));
}
-void FaviconCache::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED);
-
- content::Details<history::URLsDeletedDetails> deleted_details(details);
-
- // We only care about actual user (or sync) deletions.
- if (deleted_details->expired)
- return;
-
- if (!deleted_details->all_history) {
- DeleteSyncedFavicons(deleted_details->favicon_urls);
- return;
- }
-
- // All history was cleared: just delete all favicons.
- DVLOG(1) << "History clear detected, deleting all synced favicons.";
- syncer::SyncChangeList image_deletions, tracking_deletions;
- while (!synced_favicons_.empty()) {
- DeleteSyncedFavicon(synced_favicons_.begin(),
- &image_deletions,
- &tracking_deletions);
- }
-
- if (favicon_images_sync_processor_.get()) {
- favicon_images_sync_processor_->ProcessSyncChanges(FROM_HERE,
- image_deletions);
- }
- if (favicon_tracking_sync_processor_.get()) {
- favicon_tracking_sync_processor_->ProcessSyncChanges(FROM_HERE,
- tracking_deletions);
- }
-}
-
bool FaviconCache::FaviconRecencyFunctor::operator()(
const linked_ptr<SyncedFaviconInfo>& lhs,
const linked_ptr<SyncedFaviconInfo>& rhs) const {
@@ -1065,4 +1033,36 @@ size_t FaviconCache::NumTasksForTest() const {
return page_task_map_.size();
}
+void FaviconCache::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ // We only care about actual user (or sync) deletions.
+ if (expired)
+ return;
+
+ if (!all_history) {
+ DeleteSyncedFavicons(favicon_urls);
+ return;
+ }
+
+ // All history was cleared: just delete all favicons.
+ DVLOG(1) << "History clear detected, deleting all synced favicons.";
+ syncer::SyncChangeList image_deletions, tracking_deletions;
+ while (!synced_favicons_.empty()) {
+ DeleteSyncedFavicon(synced_favicons_.begin(), &image_deletions,
+ &tracking_deletions);
+ }
+
+ if (favicon_images_sync_processor_.get()) {
+ favicon_images_sync_processor_->ProcessSyncChanges(FROM_HERE,
+ image_deletions);
+ }
+ if (favicon_tracking_sync_processor_.get()) {
+ favicon_tracking_sync_processor_->ProcessSyncChanges(FROM_HERE,
+ tracking_deletions);
+ }
+}
+
} // namespace browser_sync
diff --git a/chrome/browser/sync/glue/favicon_cache.h b/chrome/browser/sync/glue/favicon_cache.h
index 0913d63..2c3e03e 100644
--- a/chrome/browser/sync/glue/favicon_cache.h
+++ b/chrome/browser/sync/glue/favicon_cache.h
@@ -15,11 +15,11 @@
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/scoped_observer.h"
#include "base/task/cancelable_task_tracker.h"
+#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/history_types.h"
#include "components/sessions/session_id.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_error_factory.h"
#include "sync/api/syncable_service.h"
@@ -46,7 +46,7 @@ struct SyncedFaviconInfo;
// Encapsulates the logic for loading and storing synced favicons.
// TODO(zea): make this a KeyedService.
class FaviconCache : public syncer::SyncableService,
- public content::NotificationObserver {
+ public history::HistoryServiceObserver {
public:
FaviconCache(Profile* profile, int max_sync_favicon_limit);
~FaviconCache() override;
@@ -96,13 +96,10 @@ class FaviconCache : public syncer::SyncableService,
const std::string& icon_bytes,
int64 visit_time_ms);
- // NotificationObserver implementation.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
private:
friend class SyncFaviconCacheTest;
+ FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistoryFullClear);
+ FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistorySubsetClear);
// Functor for ordering SyncedFaviconInfo objects by recency;
struct FaviconRecencyFunctor {
@@ -196,6 +193,13 @@ class FaviconCache : public syncer::SyncableService,
size_t NumFaviconsForTest() const;
size_t NumTasksForTest() const;
+ // history::HistoryServiceObserver:
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
+
// Trask tracker for loading favicons.
base::CancelableTaskTracker cancelable_task_tracker_;
@@ -220,12 +224,12 @@ class FaviconCache : public syncer::SyncableService,
scoped_ptr<syncer::SyncChangeProcessor> favicon_images_sync_processor_;
scoped_ptr<syncer::SyncChangeProcessor> favicon_tracking_sync_processor_;
- // For listening to history deletions.
- content::NotificationRegistrar notification_registrar_;
-
// Maximum number of favicons to sync. 0 means no limit.
const size_t max_sync_favicon_limit_;
+ ScopedObserver<HistoryService, HistoryServiceObserver>
+ history_service_observer_;
+
// Weak pointer factory for favicon loads.
base::WeakPtrFactory<FaviconCache> weak_ptr_factory_;
diff --git a/chrome/browser/sync/glue/favicon_cache_unittest.cc b/chrome/browser/sync/glue/favicon_cache_unittest.cc
index 9ba4091..085af28 100644
--- a/chrome/browser/sync/glue/favicon_cache_unittest.cc
+++ b/chrome/browser/sync/glue/favicon_cache_unittest.cc
@@ -8,8 +8,6 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "content/public/browser/notification_service.h"
#include "sync/api/attachments/attachment_id.h"
#include "sync/api/sync_change_processor_wrapper_for_test.h"
@@ -1469,13 +1467,9 @@ TEST_F(SyncFaviconCacheTest, HistoryFullClear) {
syncer::SyncChangeList changes = processor()->GetAndResetChangeList();
EXPECT_TRUE(changes.empty());
- history::URLsDeletedDetails deletions;
- deletions.all_history = true;
EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount());
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(NULL),
- content::Details<history::URLsDeletedDetails>(&deletions));
+ cache()->OnURLsDeleted(nullptr, true, false, history::URLRows(),
+ std::set<GURL>());
EXPECT_EQ(0U, GetFaviconCount());
changes = processor()->GetAndResetChangeList();
ASSERT_EQ(changes.size(), (unsigned long)kFaviconBatchSize*2);
@@ -1500,13 +1494,13 @@ TEST_F(SyncFaviconCacheTest, HistorySubsetClear) {
syncer::SyncDataList initial_image_data, initial_tracking_data;
std::vector<int> expected_icons;
std::vector<syncer::SyncChange::SyncChangeType> expected_deletions;
- history::URLsDeletedDetails deletions;
+ std::set<GURL> favicon_urls_to_delete;
for (int i = 0; i < kFaviconBatchSize; ++i) {
TestFaviconData test_data = BuildFaviconData(i);
if (i < kFaviconBatchSize/2) {
expected_icons.push_back(i);
expected_deletions.push_back(syncer::SyncChange::ACTION_DELETE);
- deletions.favicon_urls.insert(test_data.icon_url);
+ favicon_urls_to_delete.insert(test_data.icon_url);
}
sync_pb::EntitySpecifics image_specifics, tracking_specifics;
FillImageSpecifics(test_data,
@@ -1532,10 +1526,8 @@ TEST_F(SyncFaviconCacheTest, HistorySubsetClear) {
EXPECT_TRUE(changes.empty());
EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount());
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(NULL),
- content::Details<history::URLsDeletedDetails>(&deletions));
+ cache()->OnURLsDeleted(nullptr, false, false, history::URLRows(),
+ favicon_urls_to_delete);
EXPECT_EQ((unsigned long)kFaviconBatchSize/2, GetFaviconCount());
changes = processor()->GetAndResetChangeList();
ASSERT_EQ(changes.size(), (unsigned long)kFaviconBatchSize);
diff --git a/chrome/browser/sync/glue/typed_url_change_processor.cc b/chrome/browser/sync/glue/typed_url_change_processor.cc
index 6ce366f..16dfdbf 100644
--- a/chrome/browser/sync/glue/typed_url_change_processor.cc
+++ b/chrome/browser/sync/glue/typed_url_change_processor.cc
@@ -8,14 +8,11 @@
#include "base/metrics/histogram.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_backend.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/typed_url_model_associator.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_service.h"
#include "sync/internal_api/public/change_record.h"
#include "sync/internal_api/public/read_node.h"
#include "sync/internal_api/public/write_node.h"
@@ -45,15 +42,12 @@ TypedUrlChangeProcessor::TypedUrlChangeProcessor(
model_associator_(model_associator),
history_backend_(history_backend),
backend_loop_(base::MessageLoop::current()),
- disconnected_(false) {
+ disconnected_(false),
+ history_backend_observer_(this) {
DCHECK(model_associator);
DCHECK(history_backend);
DCHECK(error_handler);
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
- // When running in unit tests, there is already a NotificationService object.
- // Since only one can exist at a time per thread, check first.
- if (!content::NotificationService::current())
- notification_service_.reset(content::NotificationService::Create());
}
TypedUrlChangeProcessor::~TypedUrlChangeProcessor() {
@@ -62,24 +56,6 @@ TypedUrlChangeProcessor::~TypedUrlChangeProcessor() {
history_backend_->RemoveObserver(this);
}
-void TypedUrlChangeProcessor::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK(backend_loop_ == base::MessageLoop::current());
- DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED);
-
- base::AutoLock al(disconnect_lock_);
- if (disconnected_)
- return;
-
- DVLOG(1) << "Observed typed_url change.";
- HandleURLsDeleted(
- content::Details<history::URLsDeletedDetails>(details).ptr());
- UMA_HISTOGRAM_PERCENTAGE("Sync.TypedUrlChangeProcessorErrors",
- model_associator_->GetErrorPercentage());
-}
-
void TypedUrlChangeProcessor::OnURLVisited(
history::HistoryBackend* history_backend,
ui::PageTransition transition,
@@ -123,6 +99,54 @@ void TypedUrlChangeProcessor::OnURLsModified(
model_associator_->GetErrorPercentage());
}
+void TypedUrlChangeProcessor::OnURLsDeleted(
+ history::HistoryBackend* history_backend,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ DCHECK(backend_loop_ == base::MessageLoop::current());
+
+ base::AutoLock al(disconnect_lock_);
+ if (disconnected_)
+ return;
+
+ DVLOG(1) << "Observed typed_url change.";
+
+ syncer::WriteTransaction trans(FROM_HERE, share_handle());
+
+ // Ignore archivals (we don't want to sync them as deletions, to avoid
+ // extra traffic up to the server, and also to make sure that a client with
+ // a bad clock setting won't go on an archival rampage and delete all
+ // history from every client). The server will gracefully age out the sync DB
+ // entries when they've been idle for long enough.
+ if (expired)
+ return;
+
+ if (all_history) {
+ if (!model_associator_->DeleteAllNodes(&trans)) {
+ syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
+ "Failed to delete local nodes.",
+ syncer::TYPED_URLS);
+ error_handler()->OnSingleDataTypeUnrecoverableError(error);
+ return;
+ }
+ } else {
+ for (const auto& row : deleted_rows) {
+ syncer::WriteNode sync_node(&trans);
+ // The deleted URL could have been non-typed, so it might not be found
+ // in the sync DB.
+ if (sync_node.InitByClientTagLookup(syncer::TYPED_URLS,
+ row.url().spec()) ==
+ syncer::BaseNode::INIT_OK) {
+ sync_node.Tombstone();
+ }
+ }
+ }
+ UMA_HISTOGRAM_PERCENTAGE("Sync.TypedUrlChangeProcessorErrors",
+ model_associator_->GetErrorPercentage());
+}
+
bool TypedUrlChangeProcessor::CreateOrUpdateSyncNode(
history::URLRow url, syncer::WriteTransaction* trans) {
DCHECK_GT(url.typed_count(), 0);
@@ -182,42 +206,6 @@ bool TypedUrlChangeProcessor::CreateOrUpdateSyncNode(
return true;
}
-void TypedUrlChangeProcessor::HandleURLsDeleted(
- history::URLsDeletedDetails* details) {
- syncer::WriteTransaction trans(FROM_HERE, share_handle());
-
- // Ignore archivals (we don't want to sync them as deletions, to avoid
- // extra traffic up to the server, and also to make sure that a client with
- // a bad clock setting won't go on an archival rampage and delete all
- // history from every client). The server will gracefully age out the sync DB
- // entries when they've been idle for long enough.
- if (details->expired)
- return;
-
- if (details->all_history) {
- if (!model_associator_->DeleteAllNodes(&trans)) {
- syncer::SyncError error(FROM_HERE,
- syncer::SyncError::DATATYPE_ERROR,
- "Failed to delete local nodes.",
- syncer::TYPED_URLS);
- error_handler()->OnSingleDataTypeUnrecoverableError(error);
- return;
- }
- } else {
- for (history::URLRows::const_iterator row = details->rows.begin();
- row != details->rows.end(); ++row) {
- syncer::WriteNode sync_node(&trans);
- // The deleted URL could have been non-typed, so it might not be found
- // in the sync DB.
- if (sync_node.InitByClientTagLookup(syncer::TYPED_URLS,
- row->url().spec()) ==
- syncer::BaseNode::INIT_OK) {
- sync_node.Tombstone();
- }
- }
- }
-}
-
bool TypedUrlChangeProcessor::ShouldSyncVisit(int typed_count,
ui::PageTransition transition) {
// Just use an ad-hoc criteria to determine whether to ignore this
@@ -347,20 +335,14 @@ void TypedUrlChangeProcessor::StartObserving() {
DCHECK(backend_loop_ == base::MessageLoop::current());
DCHECK(history_backend_);
DCHECK(profile_);
- notification_registrar_.Add(
- this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
- history_backend_->AddObserver(this);
+ history_backend_observer_.Add(history_backend_);
}
void TypedUrlChangeProcessor::StopObserving() {
DCHECK(backend_loop_ == base::MessageLoop::current());
DCHECK(history_backend_);
DCHECK(profile_);
- notification_registrar_.Remove(
- this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
- history_backend_->RemoveObserver(this);
+ history_backend_observer_.RemoveAll();
}
} // namespace browser_sync
diff --git a/chrome/browser/sync/glue/typed_url_change_processor.h b/chrome/browser/sync/glue/typed_url_change_processor.h
index 5431af5..21c1aa7 100644
--- a/chrome/browser/sync/glue/typed_url_change_processor.h
+++ b/chrome/browser/sync/glue/typed_url_change_processor.h
@@ -10,13 +10,11 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/scoped_observer.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/typed_url_model_associator.h"
#include "components/history/core/browser/history_backend_observer.h"
#include "components/sync_driver/data_type_error_handler.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_types.h"
class Profile;
@@ -24,14 +22,8 @@ namespace base {
class MessageLoop;
}
-namespace content {
-class NotificationService;
-}
-
namespace history {
class HistoryBackend;
-struct URLsDeletedDetails;
-struct URLsModifiedDetails;
class URLRow;
};
@@ -43,7 +35,6 @@ class DataTypeErrorHandler;
// applying them to the sync API 'syncable' model, and vice versa. All
// operations and use of this class are from the UI thread.
class TypedUrlChangeProcessor : public sync_driver::ChangeProcessor,
- public content::NotificationObserver,
public history::HistoryBackendObserver {
public:
TypedUrlChangeProcessor(Profile* profile,
@@ -52,21 +43,6 @@ class TypedUrlChangeProcessor : public sync_driver::ChangeProcessor,
sync_driver::DataTypeErrorHandler* error_handler);
~TypedUrlChangeProcessor() override;
- // content::NotificationObserver implementation.
- // History -> sync API change application.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
- // history::HistoryBackendObserver:
- void OnURLVisited(history::HistoryBackend* history_backend,
- ui::PageTransition transition,
- const history::URLRow& row,
- const history::RedirectList& redirects,
- base::Time visit_time) override;
- void OnURLsModified(history::HistoryBackend* history_backend,
- const history::URLRows& changed_urls) override;
-
// sync API model -> WebDataService change application.
void ApplyChangesFromSyncModel(
const syncer::BaseTransaction* trans,
@@ -88,7 +64,19 @@ class TypedUrlChangeProcessor : public sync_driver::ChangeProcessor,
void StartObserving();
void StopObserving();
- void HandleURLsDeleted(history::URLsDeletedDetails* details);
+ // history::HistoryBackendObserver:
+ void OnURLVisited(history::HistoryBackend* history_backend,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) override;
+ void OnURLsModified(history::HistoryBackend* history_backend,
+ const history::URLRows& changed_urls) override;
+ void OnURLsDeleted(history::HistoryBackend* history_backend,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
// Returns true if the caller should sync as a result of the passed visit
// notification. We use this to throttle the number of sync changes we send
@@ -114,10 +102,6 @@ class TypedUrlChangeProcessor : public sync_driver::ChangeProcessor,
history::HistoryBackend* history_backend_;
base::MessageLoop* backend_loop_;
- content::NotificationRegistrar notification_registrar_;
-
- scoped_ptr<content::NotificationService> notification_service_;
-
// The set of pending changes that will be written out on the next
// CommitChangesFromSyncModel() call.
history::URLRows pending_new_urls_;
@@ -129,6 +113,9 @@ class TypedUrlChangeProcessor : public sync_driver::ChangeProcessor,
bool disconnected_;
base::Lock disconnect_lock_;
+ ScopedObserver<history::HistoryBackend, history::HistoryBackendObserver>
+ history_backend_observer_;
+
DISALLOW_COPY_AND_ASSIGN(TypedUrlChangeProcessor);
};
diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
index c6cb335..899b220 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -17,9 +17,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_backend.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/invalidation/fake_invalidation_service.h"
@@ -357,6 +355,16 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
rows));
}
+ void SendNotificationURLsDeleted(bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ SendNotification(base::Bind(&HistoryBackendNotifier::NotifyURLsDeleted,
+ base::Unretained(history_backend_.get()),
+ all_history, expired, deleted_rows,
+ favicon_urls));
+ }
+
static bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) {
// Only verify the fields we explicitly sync (i.e. don't verify typed_count
// or visit_count because we rely on the history DB to manage those values
@@ -841,15 +849,11 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemove) {
CreateRootHelper create_root(this, syncer::TYPED_URLS);
StartSyncService(create_root.callback());
- history::URLsDeletedDetails changes;
- changes.all_history = false;
- changes.rows.push_back(history::URLRow(GURL("http://mine.com")));
+ history::URLRows rows;
+ rows.push_back(history::URLRow(GURL("http://mine.com")));
scoped_refptr<ThreadNotifier> notifier(
new ThreadNotifier(history_thread_.get()));
- notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_),
- content::Details<history::URLsDeletedDetails>(&changes));
-
+ SendNotificationURLsDeleted(false, false, rows, std::set<GURL>());
history::URLRows new_sync_entries;
GetTypedUrlsFromSyncDB(&new_sync_entries);
ASSERT_EQ(1U, new_sync_entries.size());
@@ -878,17 +882,12 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveExpired) {
CreateRootHelper create_root(this, syncer::TYPED_URLS);
StartSyncService(create_root.callback());
- history::URLsDeletedDetails changes;
- changes.all_history = false;
// Setting expired=true should cause the sync code to ignore this deletion.
- changes.expired = true;
- changes.rows.push_back(history::URLRow(GURL("http://mine.com")));
+ history::URLRows rows;
+ rows.push_back(history::URLRow(GURL("http://mine.com")));
scoped_refptr<ThreadNotifier> notifier(
new ThreadNotifier(history_thread_.get()));
- notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_),
- content::Details<history::URLsDeletedDetails>(&changes));
-
+ SendNotificationURLsDeleted(false, true, rows, std::set<GURL>());
history::URLRows new_sync_entries;
GetTypedUrlsFromSyncDB(&new_sync_entries);
// Both URLs should still be there.
@@ -921,13 +920,10 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveAll) {
GetTypedUrlsFromSyncDB(&new_sync_entries);
ASSERT_EQ(2U, new_sync_entries.size());
- history::URLsDeletedDetails changes;
- changes.all_history = true;
scoped_refptr<ThreadNotifier> notifier(
new ThreadNotifier(history_thread_.get()));
- notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_),
- content::Details<history::URLsDeletedDetails>(&changes));
+ SendNotificationURLsDeleted(true, false, history::URLRows(),
+ std::set<GURL>());
GetTypedUrlsFromSyncDB(&new_sync_entries);
ASSERT_EQ(0U, new_sync_entries.size());
diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.h b/chrome/browser/ui/cocoa/history_menu_bridge.h
index 9907344..d7f3041 100644
--- a/chrome/browser/ui/cocoa/history_menu_bridge.h
+++ b/chrome/browser/ui/cocoa/history_menu_bridge.h
@@ -20,9 +20,7 @@
#import "chrome/browser/ui/cocoa/main_menu_item.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/sessions/session_id.h"
-#include "content/public/browser/notification_observer.h"
-class NotificationRegistrar;
class PageUsageData;
class Profile;
class TabRestoreService;
@@ -58,8 +56,7 @@ struct FaviconImageResult;
// unlike the typical ownership model, this bridge owns its controller. The
// controller is very thin and only exists to interact with Cocoa, but this
// class does the bulk of the work.
-class HistoryMenuBridge : public content::NotificationObserver,
- public TabRestoreServiceObserver,
+class HistoryMenuBridge : public TabRestoreServiceObserver,
public MainMenuItem,
public history::HistoryServiceObserver {
public:
@@ -129,11 +126,6 @@ class HistoryMenuBridge : public content::NotificationObserver,
explicit HistoryMenuBridge(Profile* profile);
~HistoryMenuBridge() override;
- // content::NotificationObserver:
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
// TabRestoreServiceObserver:
void TabRestoreServiceChanged(TabRestoreService* service) override;
void TabRestoreServiceDestroyed(TabRestoreService* service) override;
@@ -142,16 +134,6 @@ class HistoryMenuBridge : public content::NotificationObserver,
void ResetMenu() override;
void BuildMenu() override;
- // history::HistoryServiceObserver:
- void OnURLVisited(HistoryService* history_service,
- ui::PageTransition transition,
- const history::URLRow& row,
- const history::RedirectList& redirects,
- base::Time visit_time) override;
- void OnURLsModified(HistoryService* history_service,
- const history::URLRows& changed_urls) override;
- void OnHistoryServiceLoaded(HistoryService* service) override;
-
// Looks up an NSMenuItem in the |menu_item_map_| and returns the
// corresponding HistoryItem.
HistoryItem* HistoryItemForMenuItem(NSMenuItem* item);
@@ -219,13 +201,27 @@ class HistoryMenuBridge : public content::NotificationObserver,
friend class ::HistoryMenuBridgeTest;
friend class HistoryMenuCocoaControllerTest;
+ // history::HistoryServiceObserver:
+ void OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) override;
+ void OnURLsModified(HistoryService* history_service,
+ const history::URLRows& changed_urls) override;
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
+ void OnHistoryServiceLoaded(HistoryService* service) override;
+
base::scoped_nsobject<HistoryMenuCocoaController> controller_; // strong
Profile* profile_; // weak
HistoryService* history_service_; // weak
TabRestoreService* tab_restore_service_; // weak
- content::NotificationRegistrar registrar_;
base::CancelableTaskTracker cancelable_task_tracker_;
// Mapping of NSMenuItems to HistoryItems. This owns the HistoryItems until
diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.mm b/chrome/browser/ui/cocoa/history_menu_bridge.mm
index bd90453..8b97d05 100644
--- a/chrome/browser/ui/cocoa/history_menu_bridge.mm
+++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm
@@ -10,15 +10,12 @@
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h"
#include "chrome/grit/generated_resources.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_source.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
@@ -112,10 +109,6 @@ HistoryMenuBridge::HistoryMenuBridge(Profile* profile)
HistoryMenuBridge::~HistoryMenuBridge() {
// Unregister ourselves as observers and notifications.
DCHECK(profile_);
- if (history_service_) {
- registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
- }
if (tab_restore_service_)
tab_restore_service_->RemoveObserver(this);
@@ -129,15 +122,6 @@ HistoryMenuBridge::~HistoryMenuBridge() {
}
}
-void HistoryMenuBridge::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- // chrome::NOTIFICATION_HISTORY_URLS_DELETED is the only notification we are
- // registered for. OnHistoryChanged is the generic function called for any
- // History modifications.
- OnHistoryChanged();
-}
-
void HistoryMenuBridge::TabRestoreServiceChanged(TabRestoreService* service) {
const TabRestoreService::Entries& entries = service->entries();
@@ -249,25 +233,6 @@ void HistoryMenuBridge::BuildMenu() {
CreateMenu();
}
-void HistoryMenuBridge::OnURLVisited(HistoryService* history_service,
- ui::PageTransition transition,
- const history::URLRow& row,
- const history::RedirectList& redirects,
- base::Time visit_time) {
- OnHistoryChanged();
-}
-
-void HistoryMenuBridge::OnURLsModified(HistoryService* history_service,
- const history::URLRows& changed_urls) {
- OnHistoryChanged();
-}
-
-void HistoryMenuBridge::OnHistoryServiceLoaded(
- HistoryService* history_service) {
- history_service_ = history_service;
- Init();
-}
-
HistoryMenuBridge::HistoryItem* HistoryMenuBridge::HistoryItemForMenuItem(
NSMenuItem* item) {
std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.find(item);
@@ -355,8 +320,6 @@ NSMenuItem* HistoryMenuBridge::AddItemToMenu(HistoryItem* item,
void HistoryMenuBridge::Init() {
DCHECK(history_service_);
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile_));
}
void HistoryMenuBridge::CreateMenu() {
@@ -469,3 +432,30 @@ void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) {
item->icon_task_id = base::CancelableTaskTracker::kBadTaskId;
}
}
+
+void HistoryMenuBridge::OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) {
+ OnHistoryChanged();
+}
+
+void HistoryMenuBridge::OnURLsModified(HistoryService* history_service,
+ const history::URLRows& changed_urls) {
+ OnHistoryChanged();
+}
+
+void HistoryMenuBridge::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ OnHistoryChanged();
+}
+
+void HistoryMenuBridge::OnHistoryServiceLoaded(
+ HistoryService* history_service) {
+ history_service_ = history_service;
+ Init();
+}
diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc
index a5c892f1..b580d6e 100644
--- a/chrome/browser/ui/webui/history_ui.cc
+++ b/chrome/browser/ui/webui/history_ui.cc
@@ -22,7 +22,7 @@
#include "base/values.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
+#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/web_history_service.h"
#include "chrome/browser/history/web_history_service_factory.h"
@@ -44,8 +44,6 @@
#include "components/search/search.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync_driver/device_info.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
@@ -418,6 +416,7 @@ bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending(
BrowsingHistoryHandler::BrowsingHistoryHandler()
: has_pending_delete_request_(false),
+ history_service_observer_(this),
weak_factory_(this) {
}
@@ -433,8 +432,10 @@ void BrowsingHistoryHandler::RegisterMessages() {
profile, new FaviconSource(profile, FaviconSource::ANY));
// Get notifications when history is cleared.
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile->GetOriginalProfile()));
+ HistoryService* hs = HistoryServiceFactory::GetForProfile(
+ profile, ServiceAccessType::EXPLICIT_ACCESS);
+ if (hs)
+ history_service_observer_.Add(hs);
web_ui()->RegisterMessageCallback("queryHistory",
base::Bind(&BrowsingHistoryHandler::HandleQueryHistory,
@@ -987,34 +988,27 @@ static bool DeletionsDiffer(const history::URLRows& deleted_rows,
const std::set<GURL>& urls_to_be_deleted) {
if (deleted_rows.size() != urls_to_be_deleted.size())
return true;
- for (history::URLRows::const_iterator i = deleted_rows.begin();
- i != deleted_rows.end(); ++i) {
- if (urls_to_be_deleted.find(i->url()) == urls_to_be_deleted.end())
+ for (const auto& i : deleted_rows) {
+ if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end())
return true;
}
return false;
}
-void BrowsingHistoryHandler::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- if (type != chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
- NOTREACHED();
- return;
- }
- history::URLsDeletedDetails* deletedDetails =
- content::Details<history::URLsDeletedDetails>(details).ptr();
- if (deletedDetails->all_history ||
- DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_))
- web_ui()->CallJavascriptFunction("historyDeleted");
-}
-
std::string BrowsingHistoryHandler::GetAcceptLanguages() const {
Profile* profile = Profile::FromWebUI(web_ui());
return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
}
+void BrowsingHistoryHandler::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_))
+ web_ui()->CallJavascriptFunction("historyDeleted");
+}
+
////////////////////////////////////////////////////////////////////////////////
//
// HistoryUI
diff --git a/chrome/browser/ui/webui/history_ui.h b/chrome/browser/ui/webui/history_ui.h
index 2048409..cb880b9 100644
--- a/chrome/browser/ui/webui/history_ui.h
+++ b/chrome/browser/ui/webui/history_ui.h
@@ -8,16 +8,17 @@
#include <string>
#include "base/memory/weak_ptr.h"
+#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/timer/timer.h"
#include "base/values.h"
-#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/web_history_service.h"
-#include "content/public/browser/notification_registrar.h"
+#include "components/history/core/browser/history_service_observer.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_message_handler.h"
+class HistoryService;
class ProfileSyncService;
class SupervisedUserService;
@@ -27,7 +28,7 @@ class BookmarkModel;
// The handler for Javascript messages related to the "history" view.
class BrowsingHistoryHandler : public content::WebUIMessageHandler,
- public content::NotificationObserver {
+ public history::HistoryServiceObserver {
public:
// Represents a history entry to be shown to the user, representing either
// a local or remote visit. A single entry can represent multiple visits,
@@ -109,11 +110,6 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
// Handler for "removeBookmark" message.
void HandleRemoveBookmark(const base::ListValue* args);
- // content::NotificationObserver implementation.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
// Merges duplicate entries from the query results, only retaining the most
// recent visit to a URL on a particular day. That visit contains the
// timestamps of the other visits.
@@ -173,7 +169,12 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
// kAcceptLanguages pref value.
std::string GetAcceptLanguages() const;
- content::NotificationRegistrar registrar_;
+ // history::HistoryServiceObserver:
+ void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
// Tracker for search requests to the history service.
base::CancelableTaskTracker query_task_tracker_;
@@ -203,6 +204,9 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
// Timer used to implement a timeout on a Web History response.
base::OneShotTimer<BrowsingHistoryHandler> web_history_timer_;
+ ScopedObserver<HistoryService, HistoryServiceObserver>
+ history_service_observer_;
+
base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler);
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 18d4c52..e6692cf 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1493,9 +1493,6 @@
'browser/history/history_backend.cc',
'browser/history/history_backend.h',
'browser/history/history_backend_android.cc',
- 'browser/history/history_details.h',
- 'browser/history/history_notifications.cc',
- 'browser/history/history_notifications.h',
'browser/history/history_service.cc',
'browser/history/history_service.h',
'browser/history/history_service_factory.cc',
diff --git a/components/history/core/browser/history_backend_observer.h b/components/history/core/browser/history_backend_observer.h
index 0d537b2..8016092 100644
--- a/components/history/core/browser/history_backend_observer.h
+++ b/components/history/core/browser/history_backend_observer.h
@@ -35,8 +35,22 @@ class HistoryBackendObserver {
// |changed_urls| lists the information for each of the URLs affected. The
// rows will have the IDs that are currently in effect in the main history
// database.
- virtual void OnURLsModified(history::HistoryBackend* history_backend,
- const history::URLRows& changed_urls) = 0;
+ virtual void OnURLsModified(HistoryBackend* history_backend,
+ const URLRows& changed_urls) = 0;
+
+ // Called when one or more of URLs are deleted.
+ //
+ // |all_history| is set to true, if all the URLs are deleted.
+ // When set to true, |deleted_rows| and |favicon_urls| are
+ // undefined.
+ // |expired| is set to true, if the URL deletion is due to expiration.
+ // |deleted_rows| list of the deleted URLs.
+ // |favicon_urls| list of favicon URLs that correspond to the deleted URLs.
+ virtual void OnURLsDeleted(HistoryBackend* history_backend,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(HistoryBackendObserver);
diff --git a/components/history/core/browser/history_service_observer.h b/components/history/core/browser/history_service_observer.h
index 834f39b..a734f4a 100644
--- a/components/history/core/browser/history_service_observer.h
+++ b/components/history/core/browser/history_service_observer.h
@@ -43,6 +43,20 @@ class HistoryServiceObserver {
virtual void OnAddVisit(HistoryService* history_service,
const BriefVisitInfo& info) {}
+ // Called when one or more of URLs are deleted.
+ //
+ // |all_history| is set to true, if all the URLs are deleted.
+ // When set to true, |deleted_rows| and |favicon_urls| are
+ // undefined.
+ // |expired| is set to true, if the URL deletion is due to expiration.
+ // |deleted_rows| list of the deleted URLs.
+ // |favicon_urls| list of favicon URLs that correspond to the deleted URLs.
+ virtual void OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {}
+
// Is called to notify when |history_service| has finished loading.
virtual void OnHistoryServiceLoaded(HistoryService* history_service) {}