summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2014-10-20 05:31:17 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-20 12:31:37 +0000
commitbb1e5752f4c39a37892097460afce447226c457c (patch)
treedb3ce543643ac0639e210d8ad4e289c81312d9d7
parent1eaeb298383496bc150b75bfab399dbcb650c0ab (diff)
downloadchromium_src-bb1e5752f4c39a37892097460afce447226c457c.zip
chromium_src-bb1e5752f4c39a37892097460afce447226c457c.tar.gz
chromium_src-bb1e5752f4c39a37892097460afce447226c457c.tar.bz2
Remove NOTIFICATION_HISTORY_URL_VISITED
Port all client of the NOTIFICATION_HISTORY_URL_VISITED to instead be HistoryServiceObserver or HistoryBackendObserver depending on the thread they want the notification to be delivered. Delete the notification and the notification details types. BUG=373326 TBR=sky@chromium.org Review URL: https://codereview.chromium.org/651193002 Cr-Commit-Position: refs/heads/master@{#300253}
-rw-r--r--athena/extensions/shell/url_search_provider.cc1
-rw-r--r--chrome/browser/android/provider/chrome_browser_provider.cc31
-rw-r--r--chrome/browser/android/provider/chrome_browser_provider.h22
-rw-r--r--chrome/browser/autocomplete/history_quick_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc4
-rw-r--r--chrome/browser/chrome_notification_types.h6
-rw-r--r--chrome/browser/extensions/api/history/history_api.cc56
-rw-r--r--chrome/browser/extensions/api/history/history_api.h18
-rw-r--r--chrome/browser/history/chrome_history_client.cc21
-rw-r--r--chrome/browser/history/chrome_history_client.h9
-rw-r--r--chrome/browser/history/history_backend.cc10
-rw-r--r--chrome/browser/history/history_backend.h8
-rw-r--r--chrome/browser/history/history_backend_unittest.cc73
-rw-r--r--chrome/browser/history/history_notifications.cc5
-rw-r--r--chrome/browser/history/history_notifications.h20
-rw-r--r--chrome/browser/history/in_memory_url_index.cc2
-rw-r--r--chrome/browser/history/in_memory_url_index.h1
-rw-r--r--chrome/browser/search_engines/chrome_template_url_service_client.cc75
-rw-r--r--chrome/browser/search_engines/chrome_template_url_service_client.h22
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.cc5
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.cc10
-rw-r--r--chrome/browser/sync/glue/typed_url_change_processor.h1
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc33
-rw-r--r--chrome/browser/ui/cocoa/history_menu_bridge.h14
-rw-r--r--chrome/browser/ui/cocoa/history_menu_bridge.mm26
-rw-r--r--chrome/browser/ui/views/frame/test_with_browser_view.cc5
-rw-r--r--components/search_engines/template_url_service.cc2
-rw-r--r--components/search_engines/template_url_service_client.h4
-rw-r--r--components/search_engines/template_url_service_unittest.cc2
29 files changed, 254 insertions, 236 deletions
diff --git a/athena/extensions/shell/url_search_provider.cc b/athena/extensions/shell/url_search_provider.cc
index 82dd2fa..b3f0f9e 100644
--- a/athena/extensions/shell/url_search_provider.cc
+++ b/athena/extensions/shell/url_search_provider.cc
@@ -47,6 +47,7 @@ class AthenaTemplateURLServiceClient : public TemplateURLServiceClient {
private:
// TemplateURLServiceClient:
+ virtual void Shutdown() override {}
virtual void SetOwner(TemplateURLService* owner) override {}
virtual void DeleteAllSearchTermsForKeyword(TemplateURLID id) override {}
virtual void SetKeywordSearchTermsForURL(
diff --git a/chrome/browser/android/provider/chrome_browser_provider.cc b/chrome/browser/android/provider/chrome_browser_provider.cc
index ef625f1..9e9e038 100644
--- a/chrome/browser/android/provider/chrome_browser_provider.cc
+++ b/chrome/browser/android/provider/chrome_browser_provider.cc
@@ -27,6 +27,7 @@
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/android/sqlite_cursor.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -1154,6 +1155,7 @@ bool ChromeBrowserProvider::RegisterChromeBrowserProvider(JNIEnv* env) {
ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj)
: weak_java_provider_(env, obj),
+ history_service_observer_(this),
handling_extensive_changes_(false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
profile_ = g_browser_process->profile_manager()->GetLastUsedProfile();
@@ -1165,8 +1167,8 @@ ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj)
// Registers the notifications we are interested.
bookmark_model_->AddObserver(this);
- notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
- content::NotificationService::AllSources());
+ history_service_observer_.Add(
+ HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS));
notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
content::NotificationService::AllSources());
notification_registrar_.Add(this,
@@ -1603,17 +1605,28 @@ void ChromeBrowserProvider::BookmarkModelChanged() {
Java_ChromeBrowserProvider_onBookmarkChanged(env, obj.obj());
}
+void ChromeBrowserProvider::OnHistoryChanged() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env);
+ if (obj.is_null())
+ return;
+ Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj());
+}
+
+void ChromeBrowserProvider::OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) {
+ OnHistoryChanged();
+}
+
void ChromeBrowserProvider::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED ||
- type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env);
- if (obj.is_null())
- return;
- Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj());
+ if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
+ OnHistoryChanged();
} else if (type ==
chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) {
JNIEnv* env = AttachCurrentThread();
diff --git a/chrome/browser/android/provider/chrome_browser_provider.h b/chrome/browser/android/provider/chrome_browser_provider.h
index 776efe4..13c65a4 100644
--- a/chrome/browser/android/provider/chrome_browser_provider.h
+++ b/chrome/browser/android/provider/chrome_browser_provider.h
@@ -8,10 +8,12 @@
#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/memory/scoped_ptr.h"
+#include "base/scoped_observer.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/bookmarks/browser/base_bookmark_model_observer.h"
#include "components/history/core/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"
@@ -29,7 +31,8 @@ class Statement;
// This class implements the native methods of ChromeBrowserProvider.java
class ChromeBrowserProvider : public BaseBookmarkModelObserver,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public history::HistoryServiceObserver {
public:
ChromeBrowserProvider(JNIEnv* env, jobject obj);
void Destroy(JNIEnv*, jobject);
@@ -179,6 +182,16 @@ class ChromeBrowserProvider : public BaseBookmarkModelObserver,
virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) override;
virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) override;
+ // Deals with updates to the history service.
+ void OnHistoryChanged();
+
+ // Override HistoryServiceObserver.
+ virtual void OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) override;
+
// Override NotificationObserver.
virtual void Observe(int type,
const content::NotificationSource& source,
@@ -186,6 +199,11 @@ class ChromeBrowserProvider : public BaseBookmarkModelObserver,
JavaObjectWeakGlobalRef weak_java_provider_;
+ // Profile must outlive this object.
+ //
+ // BookmarkModel, HistoryService and history::TopSites lifetime is bound to
+ // the lifetime of Profile, they are safe to use as long as the Profile is
+ // alive.
Profile* profile_;
BookmarkModel* bookmark_model_;
history::TopSites* top_sites_;
@@ -197,6 +215,8 @@ class ChromeBrowserProvider : public BaseBookmarkModelObserver,
// Used to register/unregister notification observer.
content::NotificationRegistrar notification_registrar_;
+ ScopedObserver<HistoryService, HistoryServiceObserver>
+ history_service_observer_;
bool handling_extensive_changes_;
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
index b0d2512..785f76e 100644
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -131,7 +131,9 @@ class HistoryQuickProviderTest : public testing::Test {
return new TemplateURLService(
profile->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL,
scoped_ptr<TemplateURLServiceClient>(
- new ChromeTemplateURLServiceClient(profile)),
+ new ChromeTemplateURLServiceClient(
+ HistoryServiceFactory::GetForProfile(
+ profile, Profile::EXPLICIT_ACCESS))),
NULL, NULL, base::Closure());
}
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index 0231499..69cba73 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -176,7 +176,9 @@ class HistoryURLProviderTest : public testing::Test,
return new TemplateURLService(
profile->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL,
scoped_ptr<TemplateURLServiceClient>(
- new ChromeTemplateURLServiceClient(profile)),
+ new ChromeTemplateURLServiceClient(
+ HistoryServiceFactory::GetForProfile(
+ profile, Profile::EXPLICIT_ACCESS))),
NULL, NULL, base::Closure());
}
diff --git a/chrome/browser/chrome_notification_types.h b/chrome/browser/chrome_notification_types.h
index 80c9301..4a94b8b 100644
--- a/chrome/browser/chrome_notification_types.h
+++ b/chrome/browser/chrome_notification_types.h
@@ -256,12 +256,6 @@ enum NotificationType {
// added URLs.
NOTIFICATION_HISTORY_URLS_MODIFIED,
- // Sent when the user visits a URL.
- //
- // The source is the profile owning the history service that changed, and
- // the details is history::URLVisitedDetails.
- NOTIFICATION_HISTORY_URL_VISITED,
-
// Sent when one or more URLs are deleted.
//
// The source is the profile owning the history service that changed, and
diff --git a/chrome/browser/extensions/api/history/history_api.cc b/chrome/browser/extensions/api/history/history_api.cc
index 356373c..886d1a1 100644
--- a/chrome/browser/extensions/api/history/history_api.cc
+++ b/chrome/browser/extensions/api/history/history_api.cc
@@ -132,44 +132,36 @@ scoped_ptr<VisitItem> GetVisitItem(const history::VisitRow& row) {
} // namespace
-HistoryEventRouter::HistoryEventRouter(Profile* profile) {
- const content::Source<Profile> source = content::Source<Profile>(profile);
- registrar_.Add(this,
- chrome::NOTIFICATION_HISTORY_URL_VISITED,
- source);
+HistoryEventRouter::HistoryEventRouter(Profile* profile,
+ HistoryService* history_service)
+ : profile_(profile), history_service_observer_(this) {
+ DCHECK(profile);
registrar_.Add(this,
chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- source);
+ content::Source<Profile>(profile));
+ history_service_observer_.Add(history_service);
}
-HistoryEventRouter::~HistoryEventRouter() {}
+HistoryEventRouter::~HistoryEventRouter() {
+}
void HistoryEventRouter::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_HISTORY_URL_VISITED:
- HistoryUrlVisited(
- content::Source<Profile>(source).ptr(),
- content::Details<const history::URLVisitedDetails>(details).ptr());
- break;
- case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
- HistoryUrlsRemoved(
- content::Source<Profile>(source).ptr(),
- content::Details<const history::URLsDeletedDetails>(details).ptr());
- break;
- default:
- NOTREACHED();
- }
-}
-
-void HistoryEventRouter::HistoryUrlVisited(
- Profile* profile,
- const history::URLVisitedDetails* details) {
- scoped_ptr<HistoryItem> history_item = GetHistoryItem(details->row);
+ 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,
+ const history::RedirectList& redirects,
+ base::Time visit_time) {
+ scoped_ptr<HistoryItem> history_item = GetHistoryItem(row);
scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item);
-
- DispatchEvent(profile, api::history::OnVisited::kEventName, args.Pass());
+ DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass());
}
void HistoryEventRouter::HistoryUrlsRemoved(
@@ -235,8 +227,10 @@ void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) {
tracked_objects::ScopedProfile tracking_profile(
FROM_HERE_WITH_EXPLICIT_FUNCTION("HistoryAPI::OnListenerAdded"));
- history_event_router_.reset(
- new HistoryEventRouter(Profile::FromBrowserContext(browser_context_)));
+ Profile* profile = Profile::FromBrowserContext(browser_context_);
+ history_event_router_.reset(new HistoryEventRouter(
+ profile,
+ HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS)));
EventRouter::Get(browser_context_)->UnregisterObserver(this);
}
diff --git a/chrome/browser/extensions/api/history/history_api.h b/chrome/browser/extensions/api/history/history_api.h
index 660f96d..1f89660 100644
--- a/chrome/browser/extensions/api/history/history_api.h
+++ b/chrome/browser/extensions/api/history/history_api.h
@@ -9,11 +9,13 @@
#include <vector>
#include "base/compiler_specific.h"
+#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"
@@ -26,9 +28,10 @@ namespace extensions {
// Observes History service and routes the notifications as events to the
// extension system.
-class HistoryEventRouter : public content::NotificationObserver {
+class HistoryEventRouter : public content::NotificationObserver,
+ public history::HistoryServiceObserver {
public:
- explicit HistoryEventRouter(Profile* profile);
+ HistoryEventRouter(Profile* profile, HistoryService* history_service);
virtual ~HistoryEventRouter();
private:
@@ -37,8 +40,12 @@ class HistoryEventRouter : public content::NotificationObserver {
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
- void HistoryUrlVisited(Profile* profile,
- const history::URLVisitedDetails* details);
+ // history::HistoryServiceObserver.
+ virtual 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);
@@ -49,6 +56,9 @@ class HistoryEventRouter : public content::NotificationObserver {
// Used for tracking registrations to history service notifications.
content::NotificationRegistrar registrar_;
+ Profile* profile_;
+ ScopedObserver<HistoryService, HistoryServiceObserver>
+ history_service_observer_;
DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter);
};
diff --git a/chrome/browser/history/chrome_history_client.cc b/chrome/browser/history/chrome_history_client.cc
index 40b5cac..aab15ff 100644
--- a/chrome/browser/history/chrome_history_client.cc
+++ b/chrome/browser/history/chrome_history_client.cc
@@ -93,27 +93,6 @@ void ChromeHistoryClient::Shutdown() {
}
}
-// TODO(sdefresne): port client listening for NOTIFICATION_HISTORY_URL_VISITED
-// to use the HistoryService::Observer pattern instead and remove this method
-// when this is complete, http://crbug.com/42178
-void ChromeHistoryClient::OnURLVisited(HistoryService* history_service,
- ui::PageTransition transition,
- const history::URLRow& row,
- const history::RedirectList& redirects,
- base::Time visit_time) {
- DCHECK(history_service == history_service_);
- scoped_ptr<history::URLVisitedDetails> details(
- new history::URLVisitedDetails);
- details->transition = transition;
- details->row = row;
- details->redirects = redirects;
- details->visit_time = visit_time;
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_HISTORY_URL_VISITED,
- content::Source<Profile>(profile_),
- content::Details<history::HistoryDetails>(details.get()));
-}
-
void ChromeHistoryClient::TopSitesLoaded(history::TopSites* top_sites) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TOP_SITES_LOADED,
diff --git a/chrome/browser/history/chrome_history_client.h b/chrome/browser/history/chrome_history_client.h
index a5e3243..13ef081 100644
--- a/chrome/browser/history/chrome_history_client.h
+++ b/chrome/browser/history/chrome_history_client.h
@@ -31,7 +31,7 @@ class ChromeHistoryClient : public history::HistoryClient,
// TODO(sdefresne): once NOTIFICATION_HISTORY_URL* notifications are no
// longer used, remove this reference to the HistoryService from the
- // ChromeHistoryClient, http://crbug.com/42178
+ // ChromeHistoryClient, http://crbug.com/373326
void SetHistoryService(HistoryService* history_service);
// history::HistoryClient:
@@ -45,13 +45,6 @@ class ChromeHistoryClient : public history::HistoryClient,
// KeyedService:
virtual void Shutdown() override;
- // HistoryServiceObserver:
- virtual void OnURLVisited(HistoryService* history_service,
- ui::PageTransition transition,
- const history::URLRow& row,
- const history::RedirectList& redirects,
- base::Time visit_time) override;
-
// TopSitesObserver:
virtual void TopSitesLoaded(history::TopSites* top_sites) override;
virtual void TopSitesChanged(history::TopSites* top_sites) override;
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 8293a13..eff5b9a 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -811,7 +811,7 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
// TODO(meelapshah) Disabled due to potential PageCycler regression.
// Re-enable this.
// QueryRedirectsTo(url, &redirects);
- NotifyAddVisit(transition, url_info, redirects, time);
+ NotifyURLVisited(transition, url_info, redirects, time);
// TODO(sdefresne): turn HistoryBackend::Delegate from HistoryService into
// an HistoryBackendObserver and register it so that we can remove this
@@ -826,10 +826,10 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
return std::make_pair(url_id, visit_id);
}
-void HistoryBackend::NotifyAddVisit(ui::PageTransition transition,
- const URLRow& row,
- const RedirectList& redirects,
- base::Time visit_time) {
+void HistoryBackend::NotifyURLVisited(ui::PageTransition transition,
+ const URLRow& row,
+ const RedirectList& redirects,
+ base::Time visit_time) {
FOR_EACH_OBSERVER(
HistoryBackendObserver,
observers_,
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index fbf0ff3..6a7a5da 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -521,10 +521,10 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Notify HistoryBackendObserver that |transition| to |row| occurred at
// |visit_time| following |redirects| (empty if there is no redirects).
- void NotifyAddVisit(ui::PageTransition transition,
- const URLRow& row,
- const RedirectList& redirects,
- base::Time visit_time);
+ void NotifyURLVisited(ui::PageTransition transition,
+ const URLRow& row,
+ const RedirectList& redirects,
+ base::Time visit_time);
private:
friend class base::RefCountedThreadSafe<HistoryBackend>;
diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc
index 582a344..c29075b 100644
--- a/chrome/browser/history/history_backend_unittest.cc
+++ b/chrome/browser/history/history_backend_unittest.cc
@@ -138,6 +138,7 @@ 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;
HistoryBackendTestBase()
: loaded_(false),
@@ -157,6 +158,14 @@ class HistoryBackendTestBase : public testing::Test {
favicon_changed_notifications_ = 0;
}
+ int num_url_visited_notifications() const {
+ return url_visited_notifications_.size();
+ }
+
+ const URLVisitedList& url_visited_notifications() const {
+ return url_visited_notifications_;
+ }
+
int num_broadcasted_notifications() const {
return broadcasted_notifications_.size();
}
@@ -166,6 +175,7 @@ class HistoryBackendTestBase : public testing::Test {
}
void ClearBroadcastedNotifications() {
+ url_visited_notifications_.clear();
STLDeleteValues(&broadcasted_notifications_);
}
@@ -177,6 +187,13 @@ class HistoryBackendTestBase : public testing::Test {
++favicon_changed_notifications_;
}
+ void NotifyURLVisited(ui::PageTransition transition,
+ const URLRow& row,
+ const RedirectList& redirects,
+ base::Time visit_time) {
+ url_visited_notifications_.push_back(std::make_pair(transition, row));
+ }
+
void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
// Send the notifications directly to the in-memory database.
content::Details<HistoryDetails> det(details.get());
@@ -224,6 +241,7 @@ 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_;
base::MessageLoop message_loop_;
base::FilePath test_dir_;
@@ -246,13 +264,7 @@ void HistoryBackendTestDelegate::NotifyURLVisited(ui::PageTransition transition,
const URLRow& row,
const RedirectList& redirects,
base::Time visit_time) {
- scoped_ptr<URLVisitedDetails> details(new URLVisitedDetails());
- details->transition = transition;
- details->row = row;
- details->redirects = redirects;
- details->visit_time = visit_time;
- test_->BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED,
- details.Pass());
+ test_->NotifyURLVisited(transition, row, redirects, visit_time);
}
void HistoryBackendTestDelegate::BroadcastNotifications(
@@ -437,12 +449,6 @@ class InMemoryHistoryBackendTest : public HistoryBackendTestBase {
scoped_ptr<URLsModifiedDetails> details(new URLsModifiedDetails());
details->changed_urls.swap(rows);
BroadcastNotifications(type, details.Pass());
- } else if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED) {
- for (URLRows::const_iterator it = rows.begin(); it != rows.end(); ++it) {
- scoped_ptr<URLVisitedDetails> details(new URLVisitedDetails());
- details->row = *it;
- BroadcastNotifications(type, details.Pass());
- }
} else if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
details->rows = rows;
@@ -1274,30 +1280,23 @@ TEST_F(HistoryBackendTest, AddPageVisitFiresNotificationWithCorrectDetails) {
EXPECT_NE(0, backend_->db_->GetRowForURL(url1, &stored_row1));
EXPECT_NE(0, backend_->db_->GetRowForURL(url2, &stored_row2));
- // Expect that NOTIFICATION_HISTORY_URLS_VISITED has been fired 3x, and that
- // each time, the URLRows have the correct URLs and IDs set.
- ASSERT_EQ(3, num_broadcasted_notifications());
- ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
- broadcasted_notifications()[0].first);
- const URLVisitedDetails* details = static_cast<const URLVisitedDetails*>(
- broadcasted_notifications()[0].second);
- EXPECT_EQ(ui::PAGE_TRANSITION_LINK,
- ui::PageTransitionStripQualifier(details->transition));
- EXPECT_EQ(stored_row1.id(), details->row.id());
- EXPECT_EQ(stored_row1.url(), details->row.url());
-
- // No further checking, this case analogous to the first one.
- ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
- broadcasted_notifications()[1].first);
-
- ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
- broadcasted_notifications()[2].first);
- details = static_cast<const URLVisitedDetails*>(
- broadcasted_notifications()[2].second);
- EXPECT_EQ(ui::PAGE_TRANSITION_TYPED,
- ui::PageTransitionStripQualifier(details->transition));
- EXPECT_EQ(stored_row2.id(), details->row.id());
- EXPECT_EQ(stored_row2.url(), details->row.url());
+ // Expect that HistoryServiceObserver::OnURLVisited has been called 3 times,
+ // and that each time the URLRows have the correct URLs and IDs set.
+ ASSERT_EQ(3, num_url_visited_notifications());
+ EXPECT_TRUE(ui::PageTransitionCoreTypeIs(url_visited_notifications()[0].first,
+ ui::PAGE_TRANSITION_LINK));
+ EXPECT_EQ(stored_row1.id(), url_visited_notifications()[0].second.id());
+ EXPECT_EQ(stored_row1.url(), url_visited_notifications()[0].second.url());
+
+ EXPECT_TRUE(ui::PageTransitionCoreTypeIs(url_visited_notifications()[1].first,
+ ui::PAGE_TRANSITION_TYPED));
+ EXPECT_EQ(stored_row2.id(), url_visited_notifications()[1].second.id());
+ EXPECT_EQ(stored_row2.url(), url_visited_notifications()[1].second.url());
+
+ EXPECT_TRUE(ui::PageTransitionCoreTypeIs(url_visited_notifications()[2].first,
+ ui::PAGE_TRANSITION_TYPED));
+ EXPECT_EQ(stored_row2.id(), url_visited_notifications()[2].second.id());
+ EXPECT_EQ(stored_row2.url(), url_visited_notifications()[2].second.url());
}
TEST_F(HistoryBackendTest, AddPageArgsSource) {
diff --git a/chrome/browser/history/history_notifications.cc b/chrome/browser/history/history_notifications.cc
index 2f30a3b..145cec4 100644
--- a/chrome/browser/history/history_notifications.cc
+++ b/chrome/browser/history/history_notifications.cc
@@ -6,11 +6,6 @@
namespace history {
-URLVisitedDetails::URLVisitedDetails()
- : transition(ui::PAGE_TRANSITION_LINK) {}
-
-URLVisitedDetails::~URLVisitedDetails() {}
-
URLsModifiedDetails::URLsModifiedDetails() {}
URLsModifiedDetails::~URLsModifiedDetails() {}
diff --git a/chrome/browser/history/history_notifications.h b/chrome/browser/history/history_notifications.h
index ca5cba8..fc21e7c2 100644
--- a/chrome/browser/history/history_notifications.h
+++ b/chrome/browser/history/history_notifications.h
@@ -16,26 +16,6 @@
namespace history {
-// Details for NOTIFICATION_HISTORY_URL_VISITED.
-struct URLVisitedDetails : public HistoryDetails {
- URLVisitedDetails();
- virtual ~URLVisitedDetails();
-
- ui::PageTransition transition;
-
- // The affected URLRow. The ID will be set to the value that is currently in
- // effect in the main history database.
- URLRow row;
-
- // A list of redirects leading up to the URL represented by this struct. If
- // we have the redirect chain A -> B -> C and this struct represents visiting
- // C, then redirects[0]=B and redirects[1]=A. If there are no redirects,
- // this will be an empty vector.
- history::RedirectList redirects;
-
- base::Time visit_time;
-};
-
// Details for NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED.
struct URLsModifiedDetails : public HistoryDetails {
URLsModifiedDetails();
diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/history/in_memory_url_index.cc
index 256a165..b761164 100644
--- a/chrome/browser/history/in_memory_url_index.cc
+++ b/chrome/browser/history/in_memory_url_index.cc
@@ -214,7 +214,7 @@ void InMemoryURLIndex::OnURLVisited(HistoryService* history_service,
const URLRow& row,
const RedirectList& redirects,
base::Time visit_time) {
- DCHECK(history_service_ == history_service);
+ DCHECK_EQ(history_service_, history_service);
needs_to_be_cached_ |= private_data_->UpdateURL(history_service_,
row,
languages_,
diff --git a/chrome/browser/history/in_memory_url_index.h b/chrome/browser/history/in_memory_url_index.h
index 0d2b390..74b5b92 100644
--- a/chrome/browser/history/in_memory_url_index.h
+++ b/chrome/browser/history/in_memory_url_index.h
@@ -48,7 +48,6 @@ class HistoryDatabase;
class URLIndexPrivateData;
struct URLsDeletedDetails;
struct URLsModifiedDetails;
-struct URLVisitedDetails;
// The URL history source.
// Holds portions of the URL database in memory in an indexed form. Used to
diff --git a/chrome/browser/search_engines/chrome_template_url_service_client.cc b/chrome/browser/search_engines/chrome_template_url_service_client.cc
index a79f2fc..58447bb 100644
--- a/chrome/browser/search_engines/chrome_template_url_service_client.cc
+++ b/chrome/browser/search_engines/chrome_template_url_service_client.cc
@@ -4,34 +4,36 @@
#include "chrome/browser/search_engines/chrome_template_url_service_client.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/profiles/profile.h"
#include "components/search_engines/template_url_service.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "extensions/common/constants.h"
-ChromeTemplateURLServiceClient::ChromeTemplateURLServiceClient(Profile* profile)
- : profile_(profile),
- owner_(NULL) {
- DCHECK(profile);
-
- // Register for notifications.
+ChromeTemplateURLServiceClient::ChromeTemplateURLServiceClient(
+ HistoryService* history_service)
+ : owner_(NULL), history_service_(history_service) {
// TODO(sky): bug 1166191. The keywords should be moved into the history
// db, which will mean we no longer need this notification and the history
// backend can handle automatically adding the search terms as the user
// navigates.
- content::Source<Profile> profile_source(profile->GetOriginalProfile());
- notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
- profile_source);
+ if (history_service_)
+ history_service_->AddObserver(this);
}
ChromeTemplateURLServiceClient::~ChromeTemplateURLServiceClient() {
}
+void ChromeTemplateURLServiceClient::Shutdown() {
+ // ChromeTemplateURLServiceClient is owned by TemplateURLService which is a
+ // KeyedService with a dependency on HistoryService, thus |history_service_|
+ // outlives the ChromeTemplateURLServiceClient.
+ //
+ // Remove self from |history_service_| observers in the shutdown phase of the
+ // two-phases since KeyedService are not supposed to use a dependend service
+ // after the Shutdown call.
+ if (history_service_)
+ history_service_->RemoveObserver(this);
+}
+
void ChromeTemplateURLServiceClient::SetOwner(TemplateURLService* owner) {
DCHECK(!owner_);
owner_ = owner;
@@ -39,30 +41,24 @@ void ChromeTemplateURLServiceClient::SetOwner(TemplateURLService* owner) {
void ChromeTemplateURLServiceClient::DeleteAllSearchTermsForKeyword(
TemplateURLID id) {
- HistoryService* history_service =
- HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
- if (history_service)
- history_service->DeleteAllSearchTermsForKeyword(id);
+ if (history_service_)
+ history_service_->DeleteAllSearchTermsForKeyword(id);
}
void ChromeTemplateURLServiceClient::SetKeywordSearchTermsForURL(
const GURL& url,
TemplateURLID id,
const base::string16& term) {
- HistoryService* history_service =
- HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
- if (history_service)
- history_service->SetKeywordSearchTermsForURL(url, id, term);
+ if (history_service_)
+ history_service_->SetKeywordSearchTermsForURL(url, id, term);
}
void ChromeTemplateURLServiceClient::AddKeywordGeneratedVisit(const GURL& url) {
- HistoryService* history_service =
- HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
- if (history_service)
- history_service->AddPage(url, base::Time::Now(), NULL, 0, GURL(),
- history::RedirectList(),
- ui::PAGE_TRANSITION_KEYWORD_GENERATED,
- history::SOURCE_BROWSED, false);
+ if (history_service_)
+ history_service_->AddPage(url, base::Time::Now(), NULL, 0, GURL(),
+ history::RedirectList(),
+ ui::PAGE_TRANSITION_KEYWORD_GENERATED,
+ history::SOURCE_BROWSED, false);
}
void ChromeTemplateURLServiceClient::RestoreExtensionInfoIfNecessary(
@@ -77,20 +73,19 @@ void ChromeTemplateURLServiceClient::RestoreExtensionInfoIfNecessary(
}
}
-void ChromeTemplateURLServiceClient::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED);
-
+void ChromeTemplateURLServiceClient::OnURLVisited(
+ HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) {
+ DCHECK_EQ(history_service_, history_service);
if (!owner_)
return;
- content::Details<history::URLVisitedDetails> history_details(details);
TemplateURLService::URLVisitedDetails visited_details;
- visited_details.url = history_details->row.url();
+ visited_details.url = row.url();
visited_details.is_keyword_transition =
- ui::PageTransitionStripQualifier(history_details->transition) ==
- ui::PAGE_TRANSITION_KEYWORD;
+ ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_KEYWORD);
owner_->OnHistoryURLVisited(visited_details);
}
diff --git a/chrome/browser/search_engines/chrome_template_url_service_client.h b/chrome/browser/search_engines/chrome_template_url_service_client.h
index 9bfe2ef..877e5ad 100644
--- a/chrome/browser/search_engines/chrome_template_url_service_client.h
+++ b/chrome/browser/search_engines/chrome_template_url_service_client.h
@@ -5,22 +5,21 @@
#ifndef CHROME_BROWSER_SEARCH_ENGINES_CHROME_TEMPLATE_URL_SERVICE_CLIENT_H_
#define CHROME_BROWSER_SEARCH_ENGINES_CHROME_TEMPLATE_URL_SERVICE_CLIENT_H_
+#include "components/history/core/browser/history_service_observer.h"
#include "components/search_engines/template_url_service_client.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
class HistoryService;
-class Profile;
// ChromeTemplateURLServiceClient provides keyword related history
// functionality for TemplateURLService.
class ChromeTemplateURLServiceClient : public TemplateURLServiceClient,
- public content::NotificationObserver {
+ public history::HistoryServiceObserver {
public:
- explicit ChromeTemplateURLServiceClient(Profile* profile);
+ explicit ChromeTemplateURLServiceClient(HistoryService* history_service);
virtual ~ChromeTemplateURLServiceClient();
// TemplateURLServiceClient:
+ virtual void Shutdown() override;
virtual void SetOwner(TemplateURLService* owner) override;
virtual void DeleteAllSearchTermsForKeyword(
history::KeywordID keyword_Id) override;
@@ -31,15 +30,16 @@ class ChromeTemplateURLServiceClient : public TemplateURLServiceClient,
virtual void RestoreExtensionInfoIfNecessary(
TemplateURL* template_url) override;
- // content::NotificationObserver:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
+ // history::HistoryServiceObserver:
+ virtual void OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) override;
private:
- Profile* profile_;
TemplateURLService* owner_;
- content::NotificationRegistrar notification_registrar_;
+ HistoryService* history_service_;
DISALLOW_COPY_AND_ASSIGN(ChromeTemplateURLServiceClient);
};
diff --git a/chrome/browser/search_engines/template_url_service_factory.cc b/chrome/browser/search_engines/template_url_service_factory.cc
index e626369..1b74546 100644
--- a/chrome/browser/search_engines/template_url_service_factory.cc
+++ b/chrome/browser/search_engines/template_url_service_factory.cc
@@ -50,8 +50,9 @@ KeyedService* TemplateURLServiceFactory::BuildInstanceFor(
scoped_ptr<SearchTermsData>(new UIThreadSearchTermsData(profile)),
WebDataServiceFactory::GetKeywordWebDataForProfile(
profile, Profile::EXPLICIT_ACCESS),
- scoped_ptr<TemplateURLServiceClient>(
- new ChromeTemplateURLServiceClient(profile)),
+ scoped_ptr<TemplateURLServiceClient>(new ChromeTemplateURLServiceClient(
+ HistoryServiceFactory::GetForProfile(profile,
+ Profile::EXPLICIT_ACCESS))),
GoogleURLTrackerFactory::GetForProfile(profile),
g_browser_process->rappor_service(),
dsp_change_callback);
diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc
index fc11cca..4c739f4 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.cc
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc
@@ -6,6 +6,7 @@
#include "base/message_loop/message_loop_proxy.h"
#include "base/run_loop.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/search_engines/chrome_template_url_service_client.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
@@ -21,9 +22,9 @@ namespace {
class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient {
public:
- TestingTemplateURLServiceClient(Profile* profile,
+ TestingTemplateURLServiceClient(HistoryService* history_service,
base::string16* search_term)
- : ChromeTemplateURLServiceClient(profile),
+ : ChromeTemplateURLServiceClient(history_service),
search_term_(search_term) {}
virtual void SetKeywordSearchTermsForURL(
@@ -115,7 +116,10 @@ void TemplateURLServiceTestUtil::ResetModel(bool verify_load) {
profile()->GetPrefs(), scoped_ptr<SearchTermsData>(search_terms_data_),
web_data_service_.get(),
scoped_ptr<TemplateURLServiceClient>(
- new TestingTemplateURLServiceClient(profile(), &search_term_)),
+ new TestingTemplateURLServiceClient(
+ HistoryServiceFactory::GetForProfileIfExists(
+ profile(), Profile::EXPLICIT_ACCESS),
+ &search_term_)),
NULL, NULL, base::Closure()));
model()->AddObserver(this);
changed_count_ = 0;
diff --git a/chrome/browser/sync/glue/typed_url_change_processor.h b/chrome/browser/sync/glue/typed_url_change_processor.h
index f77294b..71403a4 100644
--- a/chrome/browser/sync/glue/typed_url_change_processor.h
+++ b/chrome/browser/sync/glue/typed_url_change_processor.h
@@ -32,7 +32,6 @@ namespace history {
class HistoryBackend;
struct URLsDeletedDetails;
struct URLsModifiedDetails;
-struct URLVisitedDetails;
class URLRow;
};
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 c5092e4..1cf59eb 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -327,21 +327,26 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
EXPECT_CALL((*history_backend_.get()), DeleteURL(_)).Times(0);
}
- void SendNotificationAddVisit(ui::PageTransition transition,
- const history::URLRow& row) {
- base::Time visit_time;
- history::RedirectList redirects;
+ void SendNotification(const base::Closure& task) {
history_thread_->task_runner()->PostTaskAndReply(
FROM_HERE,
- base::Bind(&HistoryBackendMock::NotifyAddVisit,
+ task,
+ base::Bind(&base::MessageLoop::QuitNow,
+ base::Unretained(base::MessageLoop::current())));
+ base::MessageLoop::current()->Run();
+ }
+
+ void SendNotificationURLVisited(ui::PageTransition transition,
+ const history::URLRow& row) {
+ base::Time visit_time;
+ history::RedirectList redirects;
+ SendNotification(
+ base::Bind(&HistoryBackendMock::NotifyURLVisited,
base::Unretained(history_backend_.get()),
transition,
row,
redirects,
- visit_time),
- base::Bind(&base::MessageLoop::QuitNow,
- base::Unretained(base::MessageLoop::current())));
- base::MessageLoop::current()->Run();
+ visit_time));
}
static bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) {
@@ -721,7 +726,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddFromVisit) {
CreateRootHelper create_root(this, syncer::TYPED_URLS);
StartSyncService(create_root.callback());
- SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, added_entry);
+ SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, added_entry);
history::URLRows new_sync_entries;
GetTypedUrlsFromSyncDB(&new_sync_entries);
@@ -753,7 +758,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdateFromVisit) {
WillOnce(DoAll(SetArgumentPointee<2>(updated_visits),
Return(true)));
- SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, updated_entry);
+ SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, updated_entry);
history::URLRows new_sync_entries;
GetTypedUrlsFromSyncDB(&new_sync_entries);
@@ -787,7 +792,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) {
&updated_visits));
// Should ignore this change because it's not TYPED.
- SendNotificationAddVisit(ui::PAGE_TRANSITION_RELOAD, updated_entry);
+ SendNotificationURLVisited(ui::PAGE_TRANSITION_RELOAD, updated_entry);
GetTypedUrlsFromSyncDB(&new_sync_entries);
// Should be no changes to the sync DB from this notification.
@@ -799,7 +804,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) {
history::URLRow twelve_visits(MakeTypedUrlEntry("http://mine.com", "entry",
12, 15, false,
&updated_visits));
- SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, twelve_visits);
+ SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, twelve_visits);
GetTypedUrlsFromSyncDB(&new_sync_entries);
// Should be no changes to the sync DB from this notification.
@@ -811,7 +816,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) {
history::URLRow twenty_visits(MakeTypedUrlEntry("http://mine.com", "entry",
20, 15, false,
&updated_visits));
- SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, twenty_visits);
+ SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, twenty_visits);
GetTypedUrlsFromSyncDB(&new_sync_entries);
ASSERT_EQ(1U, 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 088ac24..0428f5e 100644
--- a/chrome/browser/ui/cocoa/history_menu_bridge.h
+++ b/chrome/browser/ui/cocoa/history_menu_bridge.h
@@ -17,6 +17,7 @@
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/sessions/tab_restore_service_observer.h"
#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"
@@ -58,7 +59,8 @@ struct FaviconImageResult;
// class does the bulk of the work.
class HistoryMenuBridge : public content::NotificationObserver,
public TabRestoreServiceObserver,
- public MainMenuItem {
+ public MainMenuItem,
+ public history::HistoryServiceObserver {
public:
// This is a generalization of the data we store in the history menu because
// we pull things from different sources with different data types.
@@ -139,6 +141,13 @@ class HistoryMenuBridge : public content::NotificationObserver,
virtual void ResetMenu() override;
virtual void BuildMenu() override;
+ // history::HistoryServiceObserver:
+ virtual void OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const history::URLRow& row,
+ const history::RedirectList& redirects,
+ base::Time visit_time) override;
+
// Looks up an NSMenuItem in the |menu_item_map_| and returns the
// corresponding HistoryItem.
HistoryItem* HistoryItemForMenuItem(NSMenuItem* item);
@@ -176,6 +185,9 @@ class HistoryMenuBridge : public content::NotificationObserver,
// Does the query for the history information to create the menu.
void CreateMenu();
+ // Invoked when the History information has changed.
+ void OnHistoryChanged();
+
// Callback method for when HistoryService query results are ready with the
// most recently-visited sites.
void OnVisitedHistoryResults(history::QueryResults* results);
diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.mm b/chrome/browser/ui/cocoa/history_menu_bridge.mm
index d006a27..50456dc 100644
--- a/chrome/browser/ui/cocoa/history_menu_bridge.mm
+++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm
@@ -117,10 +117,9 @@ HistoryMenuBridge::~HistoryMenuBridge() {
if (history_service_) {
registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
content::Source<Profile>(profile_));
- registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
- content::Source<Profile>(profile_));
registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
content::Source<Profile>(profile_));
+ history_service_->RemoveObserver(this);
} else {
registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_LOADED,
content::Source<Profile>(profile_));
@@ -158,9 +157,8 @@ void HistoryMenuBridge::Observe(int type,
}
// All other notification types that we observe indicate that the history has
- // changed and we need to rebuild.
- need_recreate_ = true;
- CreateMenu();
+ // changed.
+ OnHistoryChanged();
}
void HistoryMenuBridge::TabRestoreServiceChanged(TabRestoreService* service) {
@@ -274,6 +272,14 @@ 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();
+}
+
HistoryMenuBridge::HistoryItem* HistoryMenuBridge::HistoryItemForMenuItem(
NSMenuItem* item) {
std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.find(item);
@@ -360,12 +366,12 @@ NSMenuItem* HistoryMenuBridge::AddItemToMenu(HistoryItem* item,
}
void HistoryMenuBridge::Init() {
+ DCHECK(history_service_);
registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
content::Source<Profile>(profile_));
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
- content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
content::Source<Profile>(profile_));
+ history_service_->AddObserver(this);
}
void HistoryMenuBridge::CreateMenu() {
@@ -389,6 +395,12 @@ void HistoryMenuBridge::CreateMenu() {
&cancelable_task_tracker_);
}
+void HistoryMenuBridge::OnHistoryChanged() {
+ // History has changed, rebuild menu.
+ need_recreate_ = true;
+ CreateMenu();
+}
+
void HistoryMenuBridge::OnVisitedHistoryResults(
history::QueryResults* results) {
NSMenu* menu = HistoryMenu();
diff --git a/chrome/browser/ui/views/frame/test_with_browser_view.cc b/chrome/browser/ui/views/frame/test_with_browser_view.cc
index c54a075..97e405a 100644
--- a/chrome/browser/ui/views/frame/test_with_browser_view.cc
+++ b/chrome/browser/ui/views/frame/test_with_browser_view.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_controller.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/predictors/predictor_database.h"
#include "chrome/browser/search_engines/chrome_template_url_service_client.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
@@ -39,7 +40,9 @@ KeyedService* CreateTemplateURLService(content::BrowserContext* context) {
WebDataServiceFactory::GetKeywordWebDataForProfile(
profile, Profile::EXPLICIT_ACCESS),
scoped_ptr<TemplateURLServiceClient>(
- new ChromeTemplateURLServiceClient(profile)),
+ new ChromeTemplateURLServiceClient(
+ HistoryServiceFactory::GetForProfile(profile,
+ Profile::EXPLICIT_ACCESS))),
NULL, NULL, base::Closure());
}
diff --git a/components/search_engines/template_url_service.cc b/components/search_engines/template_url_service.cc
index d935153..0165af4 100644
--- a/components/search_engines/template_url_service.cc
+++ b/components/search_engines/template_url_service.cc
@@ -955,6 +955,8 @@ void TemplateURLService::OnHistoryURLVisited(const URLVisitedDetails& details) {
}
void TemplateURLService::Shutdown() {
+ if (client_)
+ client_->Shutdown();
// This check has to be done at Shutdown() instead of in the dtor to ensure
// that no clients of KeywordWebDataService are holding ptrs to it after the
// first phase of the KeyedService Shutdown() process.
diff --git a/components/search_engines/template_url_service_client.h b/components/search_engines/template_url_service_client.h
index e223eea..46147ae 100644
--- a/components/search_engines/template_url_service_client.h
+++ b/components/search_engines/template_url_service_client.h
@@ -19,6 +19,10 @@ class TemplateURLServiceClient {
public:
virtual ~TemplateURLServiceClient() {}
+ // Called by TemplateURLService::Shutdown as part of the two phase shutdown
+ // of the KeyedService.
+ virtual void Shutdown() = 0;
+
// Sets the pointer to the owner of this object.
virtual void SetOwner(TemplateURLService* owner) = 0;
diff --git a/components/search_engines/template_url_service_unittest.cc b/components/search_engines/template_url_service_unittest.cc
index 1385e7e..7b8980b 100644
--- a/components/search_engines/template_url_service_unittest.cc
+++ b/components/search_engines/template_url_service_unittest.cc
@@ -980,9 +980,9 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) {
// Make sure TemplateURLService generates a KEYWORD_GENERATED visit for
// KEYWORD visits.
TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
- test_util()->VerifyLoad();
test_util()->profile()->CreateBookmarkModel(false);
ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false));
+ test_util()->ResetModel(true);
// Create a keyword.
TemplateURL* t_url = AddKeywordWithDate(