Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(909)

Unified Diff: chrome/browser/rlz/rlz.cc

Issue 591483002: Only send C2F ping for a search through homepage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/rlz/rlz_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/rlz/rlz.cc
diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc
index 2bc26fdec57e9c18080ed2629dd4261f71018d8d..d2c8b0034dd184c4ba0b3ebf56606315647b3c03 100644
--- a/chrome/browser/rlz/rlz.cc
+++ b/chrome/browser/rlz/rlz.cc
@@ -30,6 +30,8 @@
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/browser_thread.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 "net/http/http_util.h"
@@ -57,6 +59,7 @@ static bool ClearReferral() {
using content::BrowserThread;
using content::NavigationEntry;
+using content::NavigationController;
namespace {
@@ -302,7 +305,7 @@ bool RLZTracker::Init(bool first_run,
#if !defined(OS_IOS)
// Register for notifications from navigations, to see if the user has used
// the home page.
- registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
+ registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
#endif // !defined(OS_IOS)
}
@@ -421,15 +424,43 @@ void RLZTracker::Observe(int type,
content::NotificationService::AllSources());
break;
#if !defined(OS_IOS)
- case content::NOTIFICATION_NAV_ENTRY_PENDING: {
- const NavigationEntry* entry =
- content::Details<content::NavigationEntry>(details).ptr();
- if (entry != NULL &&
- ((entry->GetTransitionType() &
- ui::PAGE_TRANSITION_HOME_PAGE) != 0)) {
- RecordFirstSearch(ChromeHomePage());
- registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
- content::NotificationService::AllSources());
+ case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
+ // Firstly check if it is a Google search.
+ content::LoadCommittedDetails* load_details =
+ content::Details<content::LoadCommittedDetails>(details).ptr();
+ if (load_details == NULL)
+ break;
+
+ NavigationEntry* entry = load_details->entry;
+ if (entry == NULL)
+ break;
+
+ if (google_util::IsGoogleSearchUrl(entry->GetURL())) {
+ // If it is a Google search, check if it originates from HOMEPAGE by
+ // getting the previous NavigationEntry.
+ NavigationController* controller =
+ content::Source<NavigationController>(source).ptr();
+ if (controller == NULL)
+ break;
+
+ int entry_index = controller->GetLastCommittedEntryIndex();
+ if (entry_index < 1)
+ break;
+
+ const NavigationEntry* previous_entry = controller->GetEntryAtIndex(
+ entry_index - 1);
+
+ if (previous_entry == NULL)
+ break;
+
+ // Make sure it is a Google web page originated from HOMEPAGE.
+ if (google_util::IsGoogleHomePageUrl(previous_entry->GetURL()) &&
+ ((previous_entry->GetTransitionType() &
+ ui::PAGE_TRANSITION_HOME_PAGE) != 0)) {
+ RecordFirstSearch(ChromeHomePage());
+ registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ }
}
break;
}
« no previous file with comments | « no previous file | chrome/browser/rlz/rlz_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698