summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines
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 /chrome/browser/search_engines
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}
Diffstat (limited to 'chrome/browser/search_engines')
-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
4 files changed, 56 insertions, 56 deletions
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;