cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ios / chrome / browser / search_engines / template_url_service_client_impl.cc
blob04215a2dfc860704335ec2c68dda5558c6838326
1 // Copyright 2015 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 "ios/chrome/browser/search_engines/template_url_service_client_impl.h"
7 #include "base/logging.h"
8 #include "base/time/time.h"
9 #include "components/history/core/browser/history_service.h"
10 #include "components/history/core/browser/history_types.h"
11 #include "components/search_engines/template_url_service.h"
12 #include "ui/base/page_transition_types.h"
14 namespace ios {
16 TemplateURLServiceClientImpl::TemplateURLServiceClientImpl(
17 history::HistoryService* history_service)
18 : owner_(nullptr), history_service_(history_service) {
19 // TODO(sky): bug 1166191. The keywords should be moved into the history
20 // db, which will mean we no longer need this notification and the history
21 // backend can handle automatically adding the search terms as the user
22 // navigates.
23 if (history_service_)
24 history_service_->AddObserver(this);
27 TemplateURLServiceClientImpl::~TemplateURLServiceClientImpl() {}
29 void TemplateURLServiceClientImpl::Shutdown() {
30 // TemplateURLServiceClientImpl is owned by TemplateURLService which is a
31 // KeyedService with a dependency on HistoryService, thus |history_service_|
32 // outlives the ChromeTemplateURLServiceClient.
34 // Remove self from |history_service_| observers in the shutdown phase of the
35 // two-phases since KeyedService are not supposed to use a dependend service
36 // after the Shutdown call.
37 if (history_service_) {
38 history_service_->RemoveObserver(this);
39 history_service_ = nullptr;
43 void TemplateURLServiceClientImpl::SetOwner(TemplateURLService* owner) {
44 DCHECK(owner);
45 DCHECK(!owner_);
46 owner_ = owner;
49 void TemplateURLServiceClientImpl::DeleteAllSearchTermsForKeyword(
50 history::KeywordID keyword_id) {
51 if (history_service_)
52 history_service_->DeleteAllSearchTermsForKeyword(keyword_id);
55 void TemplateURLServiceClientImpl::SetKeywordSearchTermsForURL(
56 const GURL& url,
57 TemplateURLID id,
58 const base::string16& term) {
59 if (history_service_)
60 history_service_->SetKeywordSearchTermsForURL(url, id, term);
63 void TemplateURLServiceClientImpl::AddKeywordGeneratedVisit(const GURL& url) {
64 if (history_service_) {
65 history_service_->AddPage(
66 url, base::Time::Now(), nullptr, 0, GURL(), history::RedirectList(),
67 ui::PAGE_TRANSITION_KEYWORD_GENERATED, history::SOURCE_BROWSED, false);
71 void TemplateURLServiceClientImpl::RestoreExtensionInfoIfNecessary(
72 TemplateURL* template_url) {
73 // iOS does not supports extension, nothing to do.
76 void TemplateURLServiceClientImpl::OnURLVisited(
77 history::HistoryService* history_service,
78 ui::PageTransition transition,
79 const history::URLRow& row,
80 const history::RedirectList& redirects,
81 base::Time visit_time) {
82 DCHECK_EQ(history_service, history_service_);
83 if (!owner_)
84 return;
86 TemplateURLService::URLVisitedDetails details = {
87 row.url(),
88 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_KEYWORD),
90 owner_->OnHistoryURLVisited(details);
93 } // namespace ios