Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: chrome/browser/search_engines/chrome_template_url_service_client.cc

Issue 367863005: No chrome dependencies in TemplateURLService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename to TemplateURLServiceClient Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
6
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/history/history_service.h"
9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_source.h"
14
15 ChromeTemplateURLServiceClient::ChromeTemplateURLServiceClient(Profile* profile)
16 : profile_(profile),
17 owner_(NULL) {
18 DCHECK(profile);
19
20 // Register for notifications.
21 // TODO(sky): bug 1166191. The keywords should be moved into the history
22 // db, which will mean we no longer need this notification and the history
23 // backend can handle automatically adding the search terms as the user
24 // navigates.
25 content::Source<Profile> profile_source(profile->GetOriginalProfile());
26 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
27 profile_source);
28 }
29
30 ChromeTemplateURLServiceClient::~ChromeTemplateURLServiceClient() {
31 }
32
33 void ChromeTemplateURLServiceClient::SetOwner(TemplateURLService* owner) {
34 DCHECK(!owner_);
35 owner_ = owner;
36 }
37
38 void ChromeTemplateURLServiceClient::DeleteAllSearchTermsForKeyword(
39 TemplateURLID id) {
40 HistoryService* history_service =
41 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
42 if (history_service)
43 history_service->DeleteAllSearchTermsForKeyword(id);
44 }
45
46 void ChromeTemplateURLServiceClient::SetKeywordSearchTermsForURL(
47 const GURL& url,
48 TemplateURLID id,
49 const base::string16& term) {
50 HistoryService* history_service =
51 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
52 if (history_service)
53 history_service->SetKeywordSearchTermsForURL(url, id, term);
54 }
55
56 void ChromeTemplateURLServiceClient::AddKeywordGeneratedVisit(const GURL& url) {
57 HistoryService* history_service =
58 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
59 if (history_service)
60 history_service->AddPage(url, base::Time::Now(), NULL, 0, GURL(),
61 history::RedirectList(),
62 content::PAGE_TRANSITION_KEYWORD_GENERATED,
63 history::SOURCE_BROWSED, false);
64 }
65
66 void ChromeTemplateURLServiceClient::Observe(
67 int type,
68 const content::NotificationSource& source,
69 const content::NotificationDetails& details) {
70 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED);
71
72 if (!owner_)
73 return;
74
75 content::Details<history::URLVisitedDetails> history_details(details);
76 TemplateURLService::URLVisitedDetails visited_details;
77 visited_details.url = history_details->row.url();
78 visited_details.is_keyword_transition =
79 content::PageTransitionStripQualifier(history_details->transition) ==
80 content::PAGE_TRANSITION_KEYWORD;
81 owner_->OnHistoryURLVisited(visited_details);
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698