Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / search_engines / chrome_template_url_service_client.cc
blob74f8f183726398e0d34769a31b5b87ab9a6a6ec5
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.
5 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
7 #include "components/history/core/browser/history_service.h"
8 #include "components/search_engines/template_url_service.h"
9 #include "extensions/common/constants.h"
11 ChromeTemplateURLServiceClient::ChromeTemplateURLServiceClient(
12 history::HistoryService* history_service)
13 : owner_(NULL),
14 history_service_observer_(this),
15 history_service_(history_service) {
16 // TODO(sky): bug 1166191. The keywords should be moved into the history
17 // db, which will mean we no longer need this notification and the history
18 // backend can handle automatically adding the search terms as the user
19 // navigates.
20 if (history_service_)
21 history_service_observer_.Add(history_service_);
24 ChromeTemplateURLServiceClient::~ChromeTemplateURLServiceClient() {
27 void ChromeTemplateURLServiceClient::Shutdown() {
28 // ChromeTemplateURLServiceClient is owned by TemplateURLService which is a
29 // KeyedService with a dependency on HistoryService, thus |history_service_|
30 // outlives the ChromeTemplateURLServiceClient.
32 // Remove self from |history_service_| observers in the shutdown phase of the
33 // two-phases since KeyedService are not supposed to use a dependend service
34 // after the Shutdown call.
35 history_service_observer_.RemoveAll();
38 void ChromeTemplateURLServiceClient::SetOwner(TemplateURLService* owner) {
39 DCHECK(!owner_);
40 owner_ = owner;
43 void ChromeTemplateURLServiceClient::DeleteAllSearchTermsForKeyword(
44 TemplateURLID id) {
45 if (history_service_)
46 history_service_->DeleteAllSearchTermsForKeyword(id);
49 void ChromeTemplateURLServiceClient::SetKeywordSearchTermsForURL(
50 const GURL& url,
51 TemplateURLID id,
52 const base::string16& term) {
53 if (history_service_)
54 history_service_->SetKeywordSearchTermsForURL(url, id, term);
57 void ChromeTemplateURLServiceClient::AddKeywordGeneratedVisit(const GURL& url) {
58 if (history_service_)
59 history_service_->AddPage(url, base::Time::Now(), NULL, 0, GURL(),
60 history::RedirectList(),
61 ui::PAGE_TRANSITION_KEYWORD_GENERATED,
62 history::SOURCE_BROWSED, false);
65 void ChromeTemplateURLServiceClient::RestoreExtensionInfoIfNecessary(
66 TemplateURL* template_url) {
67 const TemplateURLData& data = template_url->data();
68 GURL url(data.url());
69 if (url.SchemeIs(extensions::kExtensionScheme)) {
70 const std::string& extension_id = url.host();
71 template_url->set_extension_info(make_scoped_ptr(
72 new TemplateURL::AssociatedExtensionInfo(
73 TemplateURL::OMNIBOX_API_EXTENSION, extension_id)));
77 void ChromeTemplateURLServiceClient::OnURLVisited(
78 history::HistoryService* history_service,
79 ui::PageTransition transition,
80 const history::URLRow& row,
81 const history::RedirectList& redirects,
82 base::Time visit_time) {
83 DCHECK_EQ(history_service_, history_service);
84 if (!owner_)
85 return;
87 TemplateURLService::URLVisitedDetails visited_details;
88 visited_details.url = row.url();
89 visited_details.is_keyword_transition =
90 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_KEYWORD);
91 owner_->OnHistoryURLVisited(visited_details);