This source file includes following definitions.
- IsOmniboxGoogleSearchNavigation
- IsSearchAppGoogleSearchNavigation
- RegisterForNotifications
- GetInstance
- ProcessCommittedEntry
- SetSearchMetricsForTesting
- RegisterForNotificationsInternal
- Observe
#include "chrome/browser/google/google_search_counter.h"
#include "base/logging.h"
#include "chrome/browser/google/google_util.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
namespace {
bool IsOmniboxGoogleSearchNavigation(const content::NavigationEntry& entry) {
const content::PageTransition stripped_transition =
PageTransitionStripQualifier(entry.GetTransitionType());
DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
return stripped_transition == content::PAGE_TRANSITION_GENERATED;
}
bool IsSearchAppGoogleSearchNavigation(const content::NavigationEntry& entry) {
DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
return entry.GetURL().query().find("source=search_app") !=
std::string::npos;
}
}
void GoogleSearchCounter::RegisterForNotifications() {
GoogleSearchCounter::GetInstance()->RegisterForNotificationsInternal();
}
GoogleSearchCounter* GoogleSearchCounter::GetInstance() {
return Singleton<GoogleSearchCounter>::get();
}
GoogleSearchCounter::GoogleSearchCounter()
: search_metrics_(new GoogleSearchMetrics) {
}
GoogleSearchCounter::~GoogleSearchCounter() {
}
void GoogleSearchCounter::ProcessCommittedEntry(
const content::NotificationSource& source,
const content::NotificationDetails& details) {
const content::LoadCommittedDetails* commit =
content::Details<content::LoadCommittedDetails>(details).ptr();
const content::NavigationEntry& entry = *commit->entry;
if (!google_util::IsGoogleSearchUrl(entry.GetURL()))
return;
if (IsOmniboxGoogleSearchNavigation(entry)) {
search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_OMNIBOX);
} else if (IsSearchAppGoogleSearchNavigation(entry)) {
search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_SEARCH_APP);
} else {
search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_OTHER);
}
}
void GoogleSearchCounter::SetSearchMetricsForTesting(
GoogleSearchMetrics* search_metrics) {
DCHECK(search_metrics);
search_metrics_.reset(search_metrics);
}
void GoogleSearchCounter::RegisterForNotificationsInternal() {
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
}
void GoogleSearchCounter::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
ProcessCommittedEntry(source, details);
break;
default:
NOTREACHED();
}
}