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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/rlz/rlz_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This code glues the RLZ library DLL with Chrome. It allows Chrome to work 5 // This code glues the RLZ library DLL with Chrome. It allows Chrome to work
6 // with or without the DLL being present. If the DLL is not present the 6 // with or without the DLL being present. If the DLL is not present the
7 // functions do nothing and just return false. 7 // functions do nothing and just return false.
8 8
9 #include "chrome/browser/rlz/rlz.h" 9 #include "chrome/browser/rlz/rlz.h"
10 10
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/omnibox/omnibox_log.h" 23 #include "chrome/browser/omnibox/omnibox_log.h"
24 #include "chrome/browser/prefs/session_startup_pref.h" 24 #include "chrome/browser/prefs/session_startup_pref.h"
25 #include "chrome/browser/search_engines/template_url_service_factory.h" 25 #include "chrome/browser/search_engines/template_url_service_factory.h"
26 #include "chrome/browser/ui/startup/startup_browser_creator.h" 26 #include "chrome/browser/ui/startup/startup_browser_creator.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "components/google/core/browser/google_util.h" 29 #include "components/google/core/browser/google_util.h"
30 #include "components/search_engines/template_url.h" 30 #include "components/search_engines/template_url.h"
31 #include "components/search_engines/template_url_service.h" 31 #include "components/search_engines/template_url_service.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/navigation_controller.h"
34 #include "content/public/browser/navigation_details.h"
33 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
35 #include "net/http/http_util.h" 37 #include "net/http/http_util.h"
36 38
37 #if defined(OS_WIN) 39 #if defined(OS_WIN)
38 #include "chrome/installer/util/google_update_settings.h" 40 #include "chrome/installer/util/google_update_settings.h"
39 #else 41 #else
40 namespace GoogleUpdateSettings { 42 namespace GoogleUpdateSettings {
41 static bool GetLanguage(base::string16* language) { 43 static bool GetLanguage(base::string16* language) {
42 // TODO(thakis): Implement. 44 // TODO(thakis): Implement.
43 NOTIMPLEMENTED(); 45 NOTIMPLEMENTED();
44 return false; 46 return false;
45 } 47 }
46 48
47 // The referral program is defunct and not used. No need to implement these 49 // The referral program is defunct and not used. No need to implement these
48 // functions on non-Win platforms. 50 // functions on non-Win platforms.
49 static bool GetReferral(base::string16* referral) { 51 static bool GetReferral(base::string16* referral) {
50 return true; 52 return true;
51 } 53 }
52 static bool ClearReferral() { 54 static bool ClearReferral() {
53 return true; 55 return true;
54 } 56 }
55 } // namespace GoogleUpdateSettings 57 } // namespace GoogleUpdateSettings
56 #endif 58 #endif
57 59
58 using content::BrowserThread; 60 using content::BrowserThread;
59 using content::NavigationEntry; 61 using content::NavigationEntry;
62 using content::NavigationController;
60 63
61 namespace { 64 namespace {
62 65
63 // Maximum and minimum delay for financial ping we would allow to be set through 66 // Maximum and minimum delay for financial ping we would allow to be set through
64 // master preferences. Somewhat arbitrary, may need to be adjusted in future. 67 // master preferences. Somewhat arbitrary, may need to be adjusted in future.
65 const base::TimeDelta kMaxInitDelay = base::TimeDelta::FromSeconds(200); 68 const base::TimeDelta kMaxInitDelay = base::TimeDelta::FromSeconds(200);
66 const base::TimeDelta kMinInitDelay = base::TimeDelta::FromSeconds(20); 69 const base::TimeDelta kMinInitDelay = base::TimeDelta::FromSeconds(20);
67 70
68 bool IsBrandOrganic(const std::string& brand) { 71 bool IsBrandOrganic(const std::string& brand) {
69 return brand.empty() || google_brand::IsOrganic(brand); 72 return brand.empty() || google_brand::IsOrganic(brand);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 298
296 if (google_brand::GetBrand(&brand_) && !IsBrandOrganic(brand_)) { 299 if (google_brand::GetBrand(&brand_) && !IsBrandOrganic(brand_)) {
297 // Register for notifications from the omnibox so that we can record when 300 // Register for notifications from the omnibox so that we can record when
298 // the user performs a first search. 301 // the user performs a first search.
299 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 302 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
300 content::NotificationService::AllSources()); 303 content::NotificationService::AllSources());
301 304
302 #if !defined(OS_IOS) 305 #if !defined(OS_IOS)
303 // Register for notifications from navigations, to see if the user has used 306 // Register for notifications from navigations, to see if the user has used
304 // the home page. 307 // the home page.
305 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 308 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
306 content::NotificationService::AllSources()); 309 content::NotificationService::AllSources());
307 #endif // !defined(OS_IOS) 310 #endif // !defined(OS_IOS)
308 } 311 }
309 google_brand::GetReactivationBrand(&reactivation_brand_); 312 google_brand::GetReactivationBrand(&reactivation_brand_);
310 313
311 net::URLRequestContextGetter* context_getter = 314 net::URLRequestContextGetter* context_getter =
312 g_browser_process->system_request_context(); 315 g_browser_process->system_request_context();
313 316
314 // Could be NULL; don't run if so. RLZ will try again next restart. 317 // Could be NULL; don't run if so. RLZ will try again next restart.
315 if (context_getter) { 318 if (context_getter) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // it did previously. The RLZ folks want RLZ's "first search" detection 417 // it did previously. The RLZ folks want RLZ's "first search" detection
415 // to remain as unaffected as possible by this change. This test is 418 // to remain as unaffected as possible by this change. This test is
416 // there to keep the old behavior. 419 // there to keep the old behavior.
417 if (!content::Details<OmniboxLog>(details).ptr()->is_popup_open) 420 if (!content::Details<OmniboxLog>(details).ptr()->is_popup_open)
418 break; 421 break;
419 RecordFirstSearch(ChromeOmnibox()); 422 RecordFirstSearch(ChromeOmnibox());
420 registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 423 registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
421 content::NotificationService::AllSources()); 424 content::NotificationService::AllSources());
422 break; 425 break;
423 #if !defined(OS_IOS) 426 #if !defined(OS_IOS)
424 case content::NOTIFICATION_NAV_ENTRY_PENDING: { 427 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
425 const NavigationEntry* entry = 428 // Firstly check if it is a Google search.
426 content::Details<content::NavigationEntry>(details).ptr(); 429 content::LoadCommittedDetails* load_details =
427 if (entry != NULL && 430 content::Details<content::LoadCommittedDetails>(details).ptr();
428 ((entry->GetTransitionType() & 431 if (load_details == NULL)
429 ui::PAGE_TRANSITION_HOME_PAGE) != 0)) { 432 break;
430 RecordFirstSearch(ChromeHomePage()); 433
431 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 434 NavigationEntry* entry = load_details->entry;
432 content::NotificationService::AllSources()); 435 if (entry == NULL)
436 break;
437
438 if (google_util::IsGoogleSearchUrl(entry->GetURL())) {
439 // If it is a Google search, check if it originates from HOMEPAGE by
440 // getting the previous NavigationEntry.
441 NavigationController* controller =
442 content::Source<NavigationController>(source).ptr();
443 if (controller == NULL)
444 break;
445
446 int entry_index = controller->GetLastCommittedEntryIndex();
447 if (entry_index < 1)
448 break;
449
450 const NavigationEntry* previous_entry = controller->GetEntryAtIndex(
451 entry_index - 1);
452
453 if (previous_entry == NULL)
454 break;
455
456 // Make sure it is a Google web page originated from HOMEPAGE.
457 if (google_util::IsGoogleHomePageUrl(previous_entry->GetURL()) &&
458 ((previous_entry->GetTransitionType() &
459 ui::PAGE_TRANSITION_HOME_PAGE) != 0)) {
460 RecordFirstSearch(ChromeHomePage());
461 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
462 content::NotificationService::AllSources());
463 }
433 } 464 }
434 break; 465 break;
435 } 466 }
436 #endif // !defined(OS_IOS) 467 #endif // !defined(OS_IOS)
437 default: 468 default:
438 NOTREACHED(); 469 NOTREACHED();
439 break; 470 break;
440 } 471 }
441 } 472 }
442 473
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 void RLZTracker::EnableZeroDelayForTesting() { 661 void RLZTracker::EnableZeroDelayForTesting() {
631 GetInstance()->min_init_delay_ = base::TimeDelta(); 662 GetInstance()->min_init_delay_ = base::TimeDelta();
632 } 663 }
633 664
634 #if !defined(OS_IOS) 665 #if !defined(OS_IOS)
635 // static 666 // static
636 void RLZTracker::RecordAppListSearch() { 667 void RLZTracker::RecordAppListSearch() {
637 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList()); 668 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList());
638 } 669 }
639 #endif 670 #endif
OLDNEW
« 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