Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / google / google_search_counter.cc
index ecf670c..9f4cced 100644 (file)
@@ -5,36 +5,13 @@
 #include "chrome/browser/google/google_search_counter.h"
 
 #include "base/logging.h"
-#include "chrome/browser/google/google_util.h"
+#include "components/google/core/browser/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 {
-
-// 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,36 @@ GoogleSearchCounter* GoogleSearchCounter::GetInstance() {
   return Singleton<GoogleSearchCounter>::get();
 }
 
+GoogleSearchMetrics::AccessPoint
+GoogleSearchCounter::GetGoogleSearchAccessPointForSearchNavEntry(
+    const content::NavigationEntry& entry) const {
+  DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
+
+  // If the |entry| is FROM_ADDRESS_BAR, it comes from the omnibox; if it's
+  // GENERATED, the user was doing a search, rather than doing a navigation to a
+  // search URL (e.g. from hisotry, or pasted in).
+  if (entry.GetTransitionType() == (ui::PAGE_TRANSITION_GENERATED |
+      ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) {
+    return GoogleSearchMetrics::AP_OMNIBOX;
+  }
+
+  // The string "source=search_app" in the |entry| URL represents a Google
+  // search from the Google Search App.
+  if (entry.GetURL().query().find("source=search_app") != std::string::npos)
+    return GoogleSearchMetrics::AP_SEARCH_APP;
+
+  // For all other cases that we have not yet implemented or care to measure, we
+  // log a generic "catch-all" metric.
+  return GoogleSearchMetrics::AP_OTHER;
+}
+
+bool GoogleSearchCounter::ShouldRecordCommittedDetails(
+    const content::NotificationDetails& details) const {
+  const content::LoadCommittedDetails* commit =
+      content::Details<content::LoadCommittedDetails>(details).ptr();
+  return google_util::IsGoogleSearchUrl(commit->entry->GetURL());
+}
+
 GoogleSearchCounter::GoogleSearchCounter()
     : search_metrics_(new GoogleSearchMetrics) {
 }
@@ -55,27 +62,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(
+        GetGoogleSearchAccessPointForSearchNavEntry(entry));
   }
 }