Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / rlz / rlz.cc
index 5df2872..4f0d182 100644 (file)
@@ -20,6 +20,7 @@
 #include "chrome/browser/browser_process.h"
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/google/google_util.h"
+#include "chrome/browser/omnibox/omnibox_log.h"
 #include "chrome/browser/prefs/session_startup_pref.h"
 #include "chrome/browser/search_engines/template_url.h"
 #include "chrome/browser/search_engines/template_url_service.h"
@@ -73,7 +74,8 @@ void RecordProductEvents(bool first_run,
                          bool is_google_in_startpages,
                          bool already_ran,
                          bool omnibox_used,
-                         bool homepage_used) {
+                         bool homepage_used,
+                         bool app_list_used) {
   TRACE_EVENT0("RLZ", "RecordProductEvents");
   // Record the installation of chrome. We call this all the time but the rlz
   // lib should ignore all but the first one.
@@ -84,6 +86,9 @@ void RecordProductEvents(bool first_run,
   rlz_lib::RecordProductEvent(rlz_lib::CHROME,
                               RLZTracker::CHROME_HOME_PAGE,
                               rlz_lib::INSTALL);
+  rlz_lib::RecordProductEvent(rlz_lib::CHROME,
+                              RLZTracker::CHROME_APP_LIST,
+                              rlz_lib::INSTALL);
 #endif  // !defined(OS_IOS)
 
   if (!already_ran) {
@@ -115,6 +120,19 @@ void RecordProductEvents(bool first_run,
                                   RLZTracker::CHROME_HOME_PAGE,
                                   rlz_lib::SET_TO_GOOGLE);
     }
+
+    char app_list_rlz[rlz_lib::kMaxRlzLength + 1];
+    if (!rlz_lib::GetAccessPointRlz(RLZTracker::CHROME_APP_LIST, app_list_rlz,
+                                    rlz_lib::kMaxRlzLength)) {
+      app_list_rlz[0] = 0;
+    }
+
+    // Record if google is the initial search provider and/or home page.
+    if ((first_run || app_list_rlz[0] == 0) && is_google_default_search) {
+      rlz_lib::RecordProductEvent(rlz_lib::CHROME,
+                                  RLZTracker::CHROME_APP_LIST,
+                                  rlz_lib::SET_TO_GOOGLE);
+    }
 #endif  // !defined(OS_IOS)
   }
 
@@ -134,6 +152,14 @@ void RecordProductEvents(bool first_run,
                                 RLZTracker::CHROME_HOME_PAGE,
                                 rlz_lib::FIRST_SEARCH);
   }
+
+  // Record first user interaction with the app list. We call this all the
+  // time but the rlz lib should ingore all but the first one.
+  if (app_list_used) {
+    rlz_lib::RecordProductEvent(rlz_lib::CHROME,
+                                RLZTracker::CHROME_APP_LIST,
+                                rlz_lib::FIRST_SEARCH);
+  }
 #endif  // !defined(OS_IOS)
 }
 
@@ -143,6 +169,7 @@ bool SendFinancialPing(const std::string& brand,
   rlz_lib::AccessPoint points[] = {RLZTracker::CHROME_OMNIBOX,
 #if !defined(OS_IOS)
                                    RLZTracker::CHROME_HOME_PAGE,
+                                   RLZTracker::CHROME_APP_LIST,
 #endif
                                    rlz_lib::NO_ACCESS_POINT};
   std::string lang_ascii(base::UTF16ToASCII(lang));
@@ -168,6 +195,9 @@ const rlz_lib::AccessPoint RLZTracker::CHROME_OMNIBOX =
 // static
 const rlz_lib::AccessPoint RLZTracker::CHROME_HOME_PAGE =
     rlz_lib::CHROME_HOME_PAGE;
+// static
+const rlz_lib::AccessPoint RLZTracker::CHROME_APP_LIST =
+    rlz_lib::CHROME_APP_LIST;
 #elif defined(OS_IOS)
 // static
 const rlz_lib::AccessPoint RLZTracker::CHROME_OMNIBOX =
@@ -179,6 +209,9 @@ const rlz_lib::AccessPoint RLZTracker::CHROME_OMNIBOX =
 // static
 const rlz_lib::AccessPoint RLZTracker::CHROME_HOME_PAGE =
     rlz_lib::CHROME_MAC_HOME_PAGE;
+// static
+const rlz_lib::AccessPoint RLZTracker::CHROME_APP_LIST =
+    rlz_lib::CHROME_MAC_APP_LIST;
 #elif defined(OS_CHROMEOS)
 // static
 const rlz_lib::AccessPoint RLZTracker::CHROME_OMNIBOX =
@@ -186,6 +219,9 @@ const rlz_lib::AccessPoint RLZTracker::CHROME_OMNIBOX =
 // static
 const rlz_lib::AccessPoint RLZTracker::CHROME_HOME_PAGE =
     rlz_lib::CHROMEOS_HOME_PAGE;
+// static
+const rlz_lib::AccessPoint RLZTracker::CHROME_APP_LIST =
+    rlz_lib::CHROMEOS_APP_LIST;
 #endif
 
 RLZTracker* RLZTracker::tracker_ = NULL;
@@ -205,6 +241,7 @@ RLZTracker::RLZTracker()
       already_ran_(false),
       omnibox_used_(false),
       homepage_used_(false),
+      app_list_used_(false),
       min_init_delay_(kMinInitDelay) {
 }
 
@@ -335,7 +372,8 @@ void RLZTracker::DelayedInit() {
   if (!IsBrandOrganic(brand_)) {
     RecordProductEvents(first_run_, is_google_default_search_,
                         is_google_homepage_, is_google_in_startpages_,
-                        already_ran_, omnibox_used_, homepage_used_);
+                        already_ran_, omnibox_used_, homepage_used_,
+                        app_list_used_);
     schedule_ping = true;
   }
 
@@ -345,7 +383,8 @@ void RLZTracker::DelayedInit() {
     rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str());
     RecordProductEvents(first_run_, is_google_default_search_,
                         is_google_homepage_, is_google_in_startpages_,
-                        already_ran_, omnibox_used_, homepage_used_);
+                        already_ran_, omnibox_used_, homepage_used_,
+                        app_list_used_);
     schedule_ping = true;
   }
 
@@ -384,6 +423,7 @@ void RLZTracker::PingNowImpl() {
     GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, NULL);
 #if !defined(OS_IOS)
     GetAccessPointRlz(RLZTracker::CHROME_HOME_PAGE, NULL);
+    GetAccessPointRlz(RLZTracker::CHROME_APP_LIST, NULL);
 #endif  // !defined(OS_IOS)
   }
 
@@ -404,6 +444,12 @@ void RLZTracker::Observe(int type,
                          const content::NotificationDetails& details) {
   switch (type) {
     case chrome::NOTIFICATION_OMNIBOX_OPENED_URL:
+      // 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 (!content::Details<OmniboxLog>(details).ptr()->is_popup_open)
+        break;
       RecordFirstSearch(CHROME_OMNIBOX);
       registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
                         content::NotificationService::AllSources());
@@ -476,13 +522,7 @@ void RLZTracker::RecordFirstSearch(rlz_lib::AccessPoint point) {
   if (ScheduleRecordFirstSearch(point))
     return;
 
-#if !defined(OS_IOS)
-  bool* record_used = point == CHROME_OMNIBOX ?
-      &omnibox_used_ : &homepage_used_;
-#else
-  DCHECK_EQ(CHROME_OMNIBOX, point);
-  bool* record_used = &omnibox_used_;
-#endif
+  bool* record_used = GetAccessPointRecord(point);
 
   // Try to record event now, else set the flag to try later when we
   // attempt the ping.
@@ -504,6 +544,19 @@ bool RLZTracker::ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) {
   return true;
 }
 
+bool* RLZTracker::GetAccessPointRecord(rlz_lib::AccessPoint point) {
+  if (point == CHROME_OMNIBOX)
+    return &omnibox_used_;
+#if !defined(OS_IOS)
+  if (point == CHROME_HOME_PAGE)
+    return &homepage_used_;
+  if (point == CHROME_APP_LIST)
+    return &app_list_used_;
+#endif  // !defined(OS_IOS)
+  NOTREACHED();
+  return NULL;
+}
+
 // static
 std::string RLZTracker::GetAccessPointHttpHeader(rlz_lib::AccessPoint point) {
   TRACE_EVENT0("RLZ", "RLZTracker::GetAccessPointHttpHeader");
@@ -611,3 +664,10 @@ void RLZTracker::CleanupRlz() {
 void RLZTracker::EnableZeroDelayForTesting() {
   GetInstance()->min_init_delay_ = base::TimeDelta();
 }
+
+#if !defined(OS_IOS)
+// static
+void RLZTracker::RecordAppListSearch() {
+  GetInstance()->RecordFirstSearch(RLZTracker::CHROME_APP_LIST);
+}
+#endif