OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/google/google_search_counter_android.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "chrome/browser/google/google_search_counter.h" |
| 9 #include "chrome/browser/prerender/prerender_manager.h" |
| 10 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 11 #include "components/google/core/browser/google_search_metrics.h" |
| 12 #include "content/public/browser/navigation_details.h" |
| 13 #include "content/public/browser/navigation_entry.h" |
| 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/notification_types.h" |
| 16 |
| 17 GoogleSearchCounterAndroid::GoogleSearchCounterAndroid(Profile* profile) |
| 18 : profile_(profile) { |
| 19 // We always listen for all COMMITTED navigations from all sources, as any |
| 20 // one of them could be a navigation of interest. |
| 21 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 22 content::NotificationService::AllSources()); |
| 23 } |
| 24 |
| 25 GoogleSearchCounterAndroid::~GoogleSearchCounterAndroid() { |
| 26 } |
| 27 |
| 28 void GoogleSearchCounterAndroid::ProcessCommittedEntry( |
| 29 const content::NotificationSource& source, |
| 30 const content::NotificationDetails& details) { |
| 31 GoogleSearchCounter* counter = GoogleSearchCounter::GetInstance(); |
| 32 DCHECK(counter); |
| 33 if (!counter->ShouldRecordCommittedDetails(details)) |
| 34 return; |
| 35 |
| 36 const content::NavigationEntry& entry = |
| 37 *content::Details<content::LoadCommittedDetails>(details)->entry; |
| 38 prerender::PrerenderManager* prerender_manager = |
| 39 prerender::PrerenderManagerFactory::GetForProfile(profile_); |
| 40 DCHECK(prerender_manager); |
| 41 counter->search_metrics()->RecordAndroidGoogleSearch( |
| 42 counter->GetGoogleSearchAccessPointForSearchNavEntry(entry), |
| 43 prerender_manager->IsEnabled()); |
| 44 } |
| 45 |
| 46 void GoogleSearchCounterAndroid::Observe( |
| 47 int type, |
| 48 const content::NotificationSource& source, |
| 49 const content::NotificationDetails& details) { |
| 50 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
| 51 ProcessCommittedEntry(source, details); |
| 52 } |
OLD | NEW |