Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 return; |
| 430 RecordFirstSearch(ChromeHomePage()); | 433 } |
|
Roger Tawa OOO till Jul 10th
2014/09/30 14:43:35
No need for { and }
yao
2014/09/30 17:10:43
Done.
| |
| 431 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 434 |
| 432 content::NotificationService::AllSources()); | 435 NavigationEntry* entry = load_details->entry; |
| 436 if (entry == NULL) | |
| 437 return; | |
| 438 | |
| 439 if(google_util::IsGoogleSearchUrl(entry->GetURL())) { | |
| 440 // If it is a Google search, check if it originates from HOMEPAGE by | |
| 441 // getting the previous NavigationEntry. | |
| 442 NavigationController* controller = | |
| 443 content::Source<NavigationController>(source).ptr(); | |
| 444 if (controller == NULL) | |
| 445 return; | |
| 446 | |
| 447 int entry_index = controller->GetLastCommittedEntryIndex(); | |
| 448 if (entry_index < 1) | |
| 449 return; | |
| 450 | |
| 451 const NavigationEntry* previous_entry = controller->GetEntryAtIndex( | |
| 452 entry_index - 1); | |
| 453 if (previous_entry != NULL && | |
| 454 ((previous_entry->GetTransitionType() & | |
| 455 ui::PAGE_TRANSITION_HOME_PAGE) != 0)) { | |
|
Roger Tawa OOO till Jul 10th
2014/09/30 14:43:35
Should we also check that the previous entry is a
yao
2014/09/30 17:10:44
hm.. but the previous entry should not be a google
Roger Tawa OOO till Jul 10th
2014/09/30 18:24:36
How about the case where foo.com is the home page,
yao
2014/10/09 15:10:18
Done.
| |
| 456 RecordFirstSearch(ChromeHomePage()); | |
| 457 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 458 content::NotificationService::AllSources()); | |
| 459 } | |
|
Roger Tawa OOO till Jul 10th
2014/09/30 14:43:35
Should all the return statements above be breaks?
yao
2014/09/30 17:10:44
Done.
| |
| 433 } | 460 } |
| 434 break; | 461 break; |
| 435 } | 462 } |
| 436 #endif // !defined(OS_IOS) | 463 #endif // !defined(OS_IOS) |
| 437 default: | 464 default: |
| 438 NOTREACHED(); | 465 NOTREACHED(); |
| 439 break; | 466 break; |
| 440 } | 467 } |
| 441 } | 468 } |
| 442 | 469 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 void RLZTracker::EnableZeroDelayForTesting() { | 657 void RLZTracker::EnableZeroDelayForTesting() { |
| 631 GetInstance()->min_init_delay_ = base::TimeDelta(); | 658 GetInstance()->min_init_delay_ = base::TimeDelta(); |
| 632 } | 659 } |
| 633 | 660 |
| 634 #if !defined(OS_IOS) | 661 #if !defined(OS_IOS) |
| 635 // static | 662 // static |
| 636 void RLZTracker::RecordAppListSearch() { | 663 void RLZTracker::RecordAppListSearch() { |
| 637 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList()); | 664 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList()); |
| 638 } | 665 } |
| 639 #endif | 666 #endif |
| OLD | NEW |