Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / google / google_search_counter_android.cc
blob17699bee30e8f7293949ffbe3dee06a5640810bf
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.
5 #include "chrome/browser/google/google_search_counter_android.h"
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"
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());
25 GoogleSearchCounterAndroid::~GoogleSearchCounterAndroid() {
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;
36 const content::NavigationEntry& entry =
37 *content::Details<content::LoadCommittedDetails>(details)->entry;
38 prerender::PrerenderManager* prerender_manager =
39 prerender::PrerenderManagerFactory::GetForProfile(profile_);
40 // |prerender_manager| is NULL when prerendering is disabled.
41 bool prerender_enabled =
42 prerender_manager ? prerender_manager->IsEnabled() : false;
43 counter->search_metrics()->RecordAndroidGoogleSearch(
44 counter->GetGoogleSearchAccessPointForSearchNavEntry(entry),
45 prerender_enabled);
48 void GoogleSearchCounterAndroid::Observe(
49 int type,
50 const content::NotificationSource& source,
51 const content::NotificationDetails& details) {
52 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
53 ProcessCommittedEntry(source, details);