Chromium Code Reviews| Index: chrome/browser/google/google_search_counter.cc |
| diff --git a/chrome/browser/google/google_search_counter.cc b/chrome/browser/google/google_search_counter.cc |
| index ecf670c87bb36916af32af0739f62b6559c7e703..0963df4b814306138f91c9189daf10bd7e267ecf 100644 |
| --- a/chrome/browser/google/google_search_counter.cc |
| +++ b/chrome/browser/google/google_search_counter.cc |
| @@ -12,29 +12,6 @@ |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_types.h" |
| -namespace { |
| - |
| -// Returns true iff |entry| represents a Google search from the Omnibox. |
| -// This method assumes that we have already verified that |entry|'s URL is a |
| -// Google search URL. |
| -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; |
| -} |
| - |
| -// Returns true iff |entry| represents a Google search from the Google Search |
| -// App. This method assumes that we have already verified that |entry|'s URL is |
| -// a Google search URL. |
| -bool IsSearchAppGoogleSearchNavigation(const content::NavigationEntry& entry) { |
| - DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL())); |
| - return entry.GetURL().query().find("source=search_app") != |
| - std::string::npos; |
| -} |
| - |
| -} // namespace |
| - |
| // static |
| void GoogleSearchCounter::RegisterForNotifications() { |
| GoogleSearchCounter::GetInstance()->RegisterForNotificationsInternal(); |
| @@ -45,6 +22,22 @@ GoogleSearchCounter* GoogleSearchCounter::GetInstance() { |
| return Singleton<GoogleSearchCounter>::get(); |
| } |
| +bool GoogleSearchCounter::ShouldRecordCommittedDetails( |
| + const content::NotificationDetails& details) const { |
| + const content::LoadCommittedDetails* commit = |
| + content::Details<content::LoadCommittedDetails>(details).ptr(); |
| + const content::NavigationEntry& entry = *commit->entry; |
| + |
| + // First see if this is a Google search URL at all. |
| + if (!google_util::IsGoogleSearchUrl(entry.GetURL())) |
| + return false; |
| + |
| + // Avoid double counting. Sometimes, when a navigation entry is committed, we |
| + // receive two notifications events for the same page. |
|
Peter Kasting
2014/06/19 21:20:32
Nit: notifications events -> notifications/notific
kmadhusu
2014/06/19 22:52:49
Done.
Peter Kasting
2014/06/19 22:58:05
:( This would normally cause me to reject this pa
kmadhusu
2014/06/19 23:21:45
My server side changes are still in prototype stag
kmadhusu
2014/06/20 01:15:07
As we discussed offline, I removed this dupe check
|
| + return commit->previous_url.is_valid() && |
| + entry.GetURL() != commit->previous_url; |
| +} |
| + |
| GoogleSearchCounter::GoogleSearchCounter() |
| : search_metrics_(new GoogleSearchMetrics) { |
| } |
| @@ -55,27 +48,15 @@ GoogleSearchCounter::~GoogleSearchCounter() { |
| void GoogleSearchCounter::ProcessCommittedEntry( |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| + // Note that GoogleSearchMetrics logs metrics through UMA, which will only |
| + // transmit these counts to the server if the user has opted into sending |
| + // usage stats. |
| const content::LoadCommittedDetails* commit = |
| content::Details<content::LoadCommittedDetails>(details).ptr(); |
| const content::NavigationEntry& entry = *commit->entry; |
| - |
| - // First see if this is a Google search URL at all. |
| - if (!google_util::IsGoogleSearchUrl(entry.GetURL())) |
| - return; |
| - |
| - // If the commit is a GENERATED commit with a Google search URL, we know it's |
| - // an Omnibox search. |
| - if (IsOmniboxGoogleSearchNavigation(entry)) { |
| - // Note that GoogleSearchMetrics logs metrics through UMA, which will only |
| - // transmit these counts to the server if the user has opted into sending |
| - // usage stats. |
| - search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_OMNIBOX); |
| - } else if (IsSearchAppGoogleSearchNavigation(entry)) { |
| - search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_SEARCH_APP); |
| - } else { |
| - // For all other cases that we have not yet implemented or care to measure, |
| - // we log a generic "catch-all" metric. |
| - search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_OTHER); |
| + if (ShouldRecordCommittedDetails(details)) { |
| + search_metrics_->RecordGoogleSearch( |
| + google_util::GetGoogleSearchAccessPointForNavEntry(entry)); |
| } |
| } |