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/rlz/rlz_tracker_delegate_impl.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "components/omnibox/browser/omnibox_event_global_tracker.h"
10 #include "components/omnibox/browser/omnibox_log.h"
11 #include "components/search_engines/template_url.h"
12 #include "components/search_engines/template_url_service.h"
13 #include "ios/chrome/browser/application_context.h"
14 #include "ios/chrome/browser/google/google_brand.h"
15 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
16 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/web/public/web_thread.h"
19 RLZTrackerDelegateImpl::RLZTrackerDelegateImpl() {}
21 RLZTrackerDelegateImpl::~RLZTrackerDelegateImpl() {}
24 bool RLZTrackerDelegateImpl::IsGoogleDefaultSearch(
25 ios::ChromeBrowserState
* browser_state
) {
26 bool is_google_default_search
= false;
27 TemplateURLService
* template_url_service
=
28 ios::TemplateURLServiceFactory::GetForBrowserState(browser_state
);
29 if (template_url_service
) {
30 const TemplateURL
* url_template
=
31 template_url_service
->GetDefaultSearchProvider();
32 is_google_default_search
= url_template
&&
33 url_template
->url_ref().HasGoogleBaseURLs(
34 template_url_service
->search_terms_data());
36 return is_google_default_search
;
40 bool RLZTrackerDelegateImpl::IsGoogleHomepage(
41 ios::ChromeBrowserState
* browser_state
) {
42 // iOS does not have a notion of home page.
47 bool RLZTrackerDelegateImpl::IsGoogleInStartpages(
48 ios::ChromeBrowserState
* browser_state
) {
49 // iOS does not have a notion of start pages.
53 void RLZTrackerDelegateImpl::Cleanup() {
54 on_omnibox_search_callback_
.Reset();
57 bool RLZTrackerDelegateImpl::IsOnUIThread() {
58 return web::WebThread::CurrentlyOn(web::WebThread::UI
);
61 base::SequencedWorkerPool
* RLZTrackerDelegateImpl::GetBlockingPool() {
62 return web::WebThread::GetBlockingPool();
65 net::URLRequestContextGetter
* RLZTrackerDelegateImpl::GetRequestContext() {
66 return GetApplicationContext()->GetSystemURLRequestContext();
69 bool RLZTrackerDelegateImpl::GetBrand(std::string
* brand
) {
70 return ios::google_brand::GetBrand(brand
);
73 bool RLZTrackerDelegateImpl::IsBrandOrganic(const std::string
& brand
) {
74 return brand
.empty() || ios::google_brand::IsOrganic(brand
);
77 bool RLZTrackerDelegateImpl::GetReactivationBrand(std::string
* brand
) {
78 // iOS does not have reactivation brand.
82 bool RLZTrackerDelegateImpl::ShouldEnableZeroDelayForTesting() {
86 bool RLZTrackerDelegateImpl::GetLanguage(base::string16
* language
) {
87 // TODO(thakis): Implement.
92 bool RLZTrackerDelegateImpl::GetReferral(base::string16
* referral
) {
93 // The referral program is defunct and not used. No need to implement this
94 // function on non-Win platforms.
98 bool RLZTrackerDelegateImpl::ClearReferral() {
99 // The referral program is defunct and not used. No need to implement this
100 // function on non-Win platforms.
104 void RLZTrackerDelegateImpl::SetOmniboxSearchCallback(
105 const base::Closure
& callback
) {
106 DCHECK(!callback
.is_null());
107 on_omnibox_search_callback_
= callback
;
108 on_omnibox_url_opened_subscription_
=
109 OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
110 base::Bind(&RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox
,
111 base::Unretained(this)));
114 void RLZTrackerDelegateImpl::SetHomepageSearchCallback(
115 const base::Closure
& callback
) {
119 void RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox(OmniboxLog
* log
) {
120 // In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than
121 // it did previously. The RLZ folks want RLZ's "first search" detection
122 // to remain as unaffected as possible by this change. This test is
123 // there to keep the old behavior.
124 if (!log
->is_popup_open
)
127 on_omnibox_url_opened_subscription_
.reset();
130 base::Closure callback_to_run
;
131 swap(callback_to_run
, on_omnibox_search_callback_
);
132 if (!callback_to_run
.is_null())
133 callback_to_run
.Run();