Commit 0d982f9a authored by sdefresne's avatar sdefresne Committed by Commit bot

Implements RLZTrackerDelegate on iOS.

Reland of https://codereview.chromium.org/1242373002/ but correctly rebased
on ToT.

BUG=511570

Review URL: https://codereview.chromium.org/1242743003

Cr-Commit-Position: refs/heads/master@{#339696}
parent fa55c285
......@@ -14,6 +14,7 @@ namespace prefs {
// preference.
const char kAcceptLanguages[] = "intl.accept_languages";
const char kHomePage[] = "homepage";
const char kSavingBrowserHistoryDisabled[] = "history.saving_disabled";
} // namespace prefs
......
......@@ -11,6 +11,7 @@ namespace prefs {
// Preferences in ios::prefs:: are temporary shared with desktop Chrome.
// Non-shared preferences should be in the prefs:: namespace (no ios::).
extern const char kAcceptLanguages[];
extern const char kHomePage[];
extern const char kSavingBrowserHistoryDisabled[];
} // namespace prefs
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "components/google/core/browser/google_util.h"
#include "components/omnibox/browser/omnibox_log.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/google/google_brand.h"
#include "ios/chrome/browser/omnibox/omnibox_event_global_tracker.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/web/public/web_thread.h"
RLZTrackerDelegateImpl::RLZTrackerDelegateImpl() {}
RLZTrackerDelegateImpl::~RLZTrackerDelegateImpl() {}
// static
bool RLZTrackerDelegateImpl::IsGoogleDefaultSearch(
ios::ChromeBrowserState* browser_state) {
bool is_google_default_search = false;
TemplateURLService* template_url_service =
ios::TemplateURLServiceFactory::GetForBrowserState(browser_state);
if (template_url_service) {
const TemplateURL* url_template =
template_url_service->GetDefaultSearchProvider();
is_google_default_search = url_template &&
url_template->url_ref().HasGoogleBaseURLs(
template_url_service->search_terms_data());
}
return is_google_default_search;
}
// static
bool RLZTrackerDelegateImpl::IsGoogleHomepage(
ios::ChromeBrowserState* browser_state) {
return google_util::IsGoogleHomePageUrl(
GURL(browser_state->GetPrefs()->GetString(ios::prefs::kHomePage)));
}
// static
bool RLZTrackerDelegateImpl::IsGoogleInStartpages(
ios::ChromeBrowserState* browser_state) {
// iOS does not have a notion of startpages.
return false;
}
void RLZTrackerDelegateImpl::Cleanup() {
on_omnibox_search_callback_.Reset();
}
bool RLZTrackerDelegateImpl::IsOnUIThread() {
return web::WebThread::CurrentlyOn(web::WebThread::UI);
}
base::SequencedWorkerPool* RLZTrackerDelegateImpl::GetBlockingPool() {
return web::WebThread::GetBlockingPool();
}
net::URLRequestContextGetter* RLZTrackerDelegateImpl::GetRequestContext() {
return GetApplicationContext()->GetSystemURLRequestContext();
}
bool RLZTrackerDelegateImpl::GetBrand(std::string* brand) {
return ios::google_brand::GetBrand(brand);
}
bool RLZTrackerDelegateImpl::IsBrandOrganic(const std::string& brand) {
return brand.empty() || ios::google_brand::IsOrganic(brand);
}
bool RLZTrackerDelegateImpl::GetReactivationBrand(std::string* brand) {
// iOS does not have reactivation brand.
return false;
}
bool RLZTrackerDelegateImpl::ShouldEnableZeroDelayForTesting() {
return false;
}
bool RLZTrackerDelegateImpl::GetLanguage(base::string16* language) {
// TODO(thakis): Implement.
NOTIMPLEMENTED();
return false;
}
bool RLZTrackerDelegateImpl::GetReferral(base::string16* referral) {
// The referral program is defunct and not used. No need to implement this
// function on non-Win platforms.
return true;
}
bool RLZTrackerDelegateImpl::ClearReferral() {
// The referral program is defunct and not used. No need to implement this
// function on non-Win platforms.
return true;
}
void RLZTrackerDelegateImpl::SetOmniboxSearchCallback(
const base::Closure& callback) {
DCHECK(!callback.is_null());
on_omnibox_search_callback_ = callback;
on_omnibox_url_opened_subscription_ =
OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
base::Bind(&RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox,
base::Unretained(this)));
}
void RLZTrackerDelegateImpl::SetHomepageSearchCallback(
const base::Closure& callback) {
NOTREACHED();
}
void RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox(OmniboxLog* log) {
// In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than
// it did previously. The RLZ folks want RLZ's "first search" detection
// to remain as unaffected as possible by this change. This test is
// there to keep the old behavior.
if (!log->is_popup_open)
return;
on_omnibox_url_opened_subscription_.reset();
using std::swap;
base::Closure callback_to_run;
swap(callback_to_run, on_omnibox_search_callback_);
if (!callback_to_run.is_null())
callback_to_run.Run();
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_RLZ_RLZ_TRACKER_DELEGATE_IMPL_H_
#define IOS_CHROME_BROWSER_RLZ_RLZ_TRACKER_DELEGATE_IMPL_H_
#include "base/callback.h"
#include "base/callback_list.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/rlz/rlz_tracker_delegate.h"
struct OmniboxLog;
namespace ios {
class ChromeBrowserState;
}
// RLZTrackerDelegateImpl implements RLZTrackerDelegate abstract interface
// and provides access to Chrome on iOS features.
class RLZTrackerDelegateImpl : public rlz::RLZTrackerDelegate {
public:
RLZTrackerDelegateImpl();
~RLZTrackerDelegateImpl() override;
static bool IsGoogleDefaultSearch(ios::ChromeBrowserState* browser_state);
static bool IsGoogleHomepage(ios::ChromeBrowserState* browser_state);
static bool IsGoogleInStartpages(ios::ChromeBrowserState* browser_state);
private:
// RLZTrackerDelegate implementation.
void Cleanup() override;
bool IsOnUIThread() override;
base::SequencedWorkerPool* GetBlockingPool() override;
net::URLRequestContextGetter* GetRequestContext() override;
bool GetBrand(std::string* brand) override;
bool IsBrandOrganic(const std::string& brand) override;
bool GetReactivationBrand(std::string* brand) override;
bool ShouldEnableZeroDelayForTesting() override;
bool GetLanguage(base::string16* language) override;
bool GetReferral(base::string16* referral) override;
bool ClearReferral() override;
void SetOmniboxSearchCallback(const base::Closure& callback) override;
void SetHomepageSearchCallback(const base::Closure& callback) override;
// Called when user open an URL from the Omnibox.
void OnURLOpenedFromOmnibox(OmniboxLog* log);
base::Closure on_omnibox_search_callback_;
scoped_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription>
on_omnibox_url_opened_subscription_;
DISALLOW_COPY_AND_ASSIGN(RLZTrackerDelegateImpl);
};
#endif // IOS_CHROME_BROWSER_RLZ_RLZ_TRACKER_DELEGATE_IMPL_H_
......@@ -386,6 +386,7 @@
['enable_rlz==1', {
'dependencies': [
'../../components/components.gyp:rlz',
'ios_chrome_browser_rlz',
],
}],
],
......@@ -428,4 +429,25 @@
},
},
],
'conditions': [
['enable_rlz_support==1', {
'targets': [
{
'target_name': 'ios_chrome_browser_rlz',
'type': 'static_library',
'sources': [
'browser/rlz/rlz_tracker_delegate_impl.cc',
'browser/rlz/rlz_tracker_delegate_impl.h',
],
'dependencies': [
'../../components/components.gyp:google_core_browser',
'../../components/components.gyp:omnibox_browser',
'../../components/components.gyp:rlz',
'../../components/components.gyp:search_engines',
'../../rlz/rlz.gyp:rlz_lib',
],
},
],
}],
],
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment