| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/prefs/pref_service.h" | |
| 10 #include "components/google/core/browser/google_util.h" | |
| 11 #include "components/omnibox/browser/omnibox_log.h" | |
| 12 #include "components/search_engines/template_url.h" | |
| 13 #include "components/search_engines/template_url_service.h" | |
| 14 #include "ios/chrome/browser/application_context.h" | |
| 15 #include "ios/chrome/browser/google/google_brand.h" | |
| 16 #include "ios/chrome/browser/omnibox/omnibox_edit_model_observer_relay.h" | |
| 17 #include "ios/chrome/browser/pref_names.h" | |
| 18 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | |
| 19 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.
h" | |
| 20 #include "ios/web/public/web_thread.h" | |
| 21 | |
| 22 RLZTrackerDelegateImpl::RLZTrackerDelegateImpl() {} | |
| 23 | |
| 24 RLZTrackerDelegateImpl::~RLZTrackerDelegateImpl() {} | |
| 25 | |
| 26 // static | |
| 27 bool RLZTrackerDelegateImpl::IsGoogleDefaultSearch( | |
| 28 ios::ChromeBrowserState* browser_state) { | |
| 29 bool is_google_default_search = false; | |
| 30 TemplateURLService* template_url_service = | |
| 31 ios::TemplateURLServiceFactory::GetForBrowserState(browser_state); | |
| 32 if (template_url_service) { | |
| 33 const TemplateURL* url_template = | |
| 34 template_url_service->GetDefaultSearchProvider(); | |
| 35 is_google_default_search = url_template && | |
| 36 url_template->url_ref().HasGoogleBaseURLs( | |
| 37 template_url_service->search_terms_data()); | |
| 38 } | |
| 39 return is_google_default_search; | |
| 40 } | |
| 41 | |
| 42 // static | |
| 43 bool RLZTrackerDelegateImpl::IsGoogleHomepage( | |
| 44 ios::ChromeBrowserState* browser_state) { | |
| 45 return google_util::IsGoogleHomePageUrl( | |
| 46 GURL(browser_state->GetPrefs()->GetString(ios::prefs::kHomePage))); | |
| 47 } | |
| 48 | |
| 49 // static | |
| 50 bool RLZTrackerDelegateImpl::IsGoogleInStartpages( | |
| 51 ios::ChromeBrowserState* browser_state) { | |
| 52 // iOS does not have a notion of startpages. | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 void RLZTrackerDelegateImpl::Cleanup() { | |
| 57 on_omnibox_search_callback_.Reset(); | |
| 58 } | |
| 59 | |
| 60 bool RLZTrackerDelegateImpl::IsOnUIThread() { | |
| 61 return web::WebThread::CurrentlyOn(web::WebThread::UI); | |
| 62 } | |
| 63 | |
| 64 base::SequencedWorkerPool* RLZTrackerDelegateImpl::GetBlockingPool() { | |
| 65 return web::WebThread::GetBlockingPool(); | |
| 66 } | |
| 67 | |
| 68 net::URLRequestContextGetter* RLZTrackerDelegateImpl::GetRequestContext() { | |
| 69 return GetApplicationContext()->GetSystemURLRequestContext(); | |
| 70 } | |
| 71 | |
| 72 bool RLZTrackerDelegateImpl::GetBrand(std::string* brand) { | |
| 73 return ios::google_brand::GetBrand(brand); | |
| 74 } | |
| 75 | |
| 76 bool RLZTrackerDelegateImpl::IsBrandOrganic(const std::string& brand) { | |
| 77 return brand.empty() || ios::google_brand::IsOrganic(brand); | |
| 78 } | |
| 79 | |
| 80 bool RLZTrackerDelegateImpl::GetReactivationBrand(std::string* brand) { | |
| 81 // iOS does not have reactivation brand. | |
| 82 return false; | |
| 83 } | |
| 84 | |
| 85 bool RLZTrackerDelegateImpl::ShouldEnableZeroDelayForTesting() { | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 bool RLZTrackerDelegateImpl::GetLanguage(base::string16* language) { | |
| 90 // TODO(thakis): Implement. | |
| 91 NOTIMPLEMENTED(); | |
| 92 return false; | |
| 93 } | |
| 94 | |
| 95 bool RLZTrackerDelegateImpl::GetReferral(base::string16* referral) { | |
| 96 // The referral program is defunct and not used. No need to implement this | |
| 97 // function on non-Win platforms. | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 bool RLZTrackerDelegateImpl::ClearReferral() { | |
| 102 // The referral program is defunct and not used. No need to implement this | |
| 103 // function on non-Win platforms. | |
| 104 return true; | |
| 105 } | |
| 106 | |
| 107 void RLZTrackerDelegateImpl::SetOmniboxSearchCallback( | |
| 108 const base::Closure& callback) { | |
| 109 DCHECK(!callback.is_null()); | |
| 110 on_omnibox_search_callback_ = callback; | |
| 111 on_omnibox_url_opened_subscription_ = | |
| 112 OmniboxEditModelObserverRelay::GetInstance()->RegisterCallback( | |
| 113 base::Bind(&RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox, | |
| 114 base::Unretained(this))); | |
| 115 } | |
| 116 | |
| 117 void RLZTrackerDelegateImpl::SetHomepageSearchCallback( | |
| 118 const base::Closure& callback) { | |
| 119 NOTREACHED(); | |
| 120 } | |
| 121 | |
| 122 void RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox(OmniboxLog* log) { | |
| 123 // In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than | |
| 124 // it did previously. The RLZ folks want RLZ's "first search" detection | |
| 125 // to remain as unaffected as possible by this change. This test is | |
| 126 // there to keep the old behavior. | |
| 127 if (!log->is_popup_open) | |
| 128 return; | |
| 129 | |
| 130 on_omnibox_url_opened_subscription_.reset(); | |
| 131 | |
| 132 using std::swap; | |
| 133 base::Closure callback_to_run; | |
| 134 swap(callback_to_run, on_omnibox_search_callback_); | |
| 135 if (!callback_to_run.is_null()) | |
| 136 callback_to_run.Run(); | |
| 137 } | |
| OLD | NEW |