| OLD | NEW |
| (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/keyword_history_service.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 "content/public/browser/notification_details.h" |
| 12 #include "content/public/browser/notification_source.h" |
| 13 |
| 14 KeywordHistoryService::KeywordHistoryService(Profile* profile) |
| 15 : profile_(profile), |
| 16 owner_(NULL) { |
| 17 DCHECK(profile); |
| 18 |
| 19 // Register for notifications. |
| 20 // TODO(sky): bug 1166191. The keywords should be moved into the history |
| 21 // db, which will mean we no longer need this notification and the history |
| 22 // backend can handle automatically adding the search terms as the user |
| 23 // navigates. |
| 24 content::Source<Profile> profile_source(profile->GetOriginalProfile()); |
| 25 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, |
| 26 profile_source); |
| 27 } |
| 28 |
| 29 KeywordHistoryService::~KeywordHistoryService() { |
| 30 } |
| 31 |
| 32 void KeywordHistoryService::SetOwner(TemplateURLService* owner) { |
| 33 DCHECK(!owner_); |
| 34 owner_ = owner; |
| 35 } |
| 36 |
| 37 void KeywordHistoryService::DeleteAllSearchTermsForKeyword(TemplateURLID id) { |
| 38 HistoryService* history_service = |
| 39 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 40 if (history_service) |
| 41 history_service->DeleteAllSearchTermsForKeyword(id); |
| 42 } |
| 43 |
| 44 void KeywordHistoryService::SetKeywordSearchTermsForURL( |
| 45 const GURL& url, |
| 46 TemplateURLID id, |
| 47 const base::string16& term) { |
| 48 HistoryService* history_service = |
| 49 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 50 if (history_service) |
| 51 history_service->SetKeywordSearchTermsForURL(url, id, term); |
| 52 } |
| 53 |
| 54 void KeywordHistoryService::AddKeywordGeneratedVisit(const GURL& url) { |
| 55 HistoryService* history_service = |
| 56 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 57 if (history_service) |
| 58 history_service->AddPage(url, base::Time::Now(), NULL, 0, GURL(), |
| 59 history::RedirectList(), |
| 60 content::PAGE_TRANSITION_KEYWORD_GENERATED, |
| 61 history::SOURCE_BROWSED, false); |
| 62 } |
| 63 |
| 64 void KeywordHistoryService::Observe( |
| 65 int type, |
| 66 const content::NotificationSource& source, |
| 67 const content::NotificationDetails& details) { |
| 68 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED); |
| 69 |
| 70 if (!owner_) |
| 71 return; |
| 72 |
| 73 content::Details<history::URLVisitedDetails> history_details(details); |
| 74 TemplateURLService::URLVisitedDetails visited_details; |
| 75 visited_details.url = history_details->row.url(); |
| 76 visited_details.is_keyword_transition = |
| 77 content::PageTransitionStripQualifier(history_details->transition) == |
| 78 content::PAGE_TRANSITION_KEYWORD; |
| 79 owner_->OnHistoryURLVisited(visited_details); |
| 80 } |
| OLD | NEW |