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/google/google_util.h" | |
10 #include "chrome/browser/prerender/prerender_manager.h" | |
11 #include "chrome/browser/prerender/prerender_manager_factory.h" | |
12 #include "components/google/core/browser/google_search_metrics.h" | |
13 #include "content/public/browser/navigation_details.h" | |
14 #include "content/public/browser/navigation_entry.h" | |
15 #include "content/public/browser/notification_service.h" | |
16 #include "content/public/browser/notification_types.h" | |
17 | |
18 GoogleSearchCounterAndroid::GoogleSearchCounterAndroid(Profile* profile) | |
19 : profile_(profile) { | |
20 // We always listen for all COMMITTED navigations from all sources, as any | |
21 // one of them could be a navigation of interest. | |
22 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
23 content::NotificationService::AllSources()); | |
24 } | |
25 | |
26 GoogleSearchCounterAndroid::~GoogleSearchCounterAndroid() { | |
27 } | |
28 | |
29 void GoogleSearchCounterAndroid::ProcessCommittedEntry( | |
30 const content::NotificationSource& source, | |
31 const content::NotificationDetails& details) { | |
32 GoogleSearchCounter* counter = GoogleSearchCounter::GetInstance(); | |
33 DCHECK(counter); | |
34 if (!counter->ShouldRecordCommittedDetails(details)) | |
35 return; | |
36 | |
37 const content::LoadCommittedDetails* commit = | |
38 content::Details<content::LoadCommittedDetails>(details).ptr(); | |
39 const content::NavigationEntry& entry = *commit->entry; | |
40 prerender::PrerenderManager* prerender_manager = | |
41 prerender::PrerenderManagerFactory::GetForProfile(profile_); | |
42 DCHECK(prerender_manager); | |
43 counter->search_metrics()->RecordAndroidGoogleSearch( | |
44 google_util::GetGoogleSearchAccessPointForNavEntry(entry), | |
45 prerender_manager->IsEnabled()); | |
46 } | |
47 | |
48 void GoogleSearchCounterAndroid::Observe( | |
49 int type, | |
50 const content::NotificationSource& source, | |
51 const content::NotificationDetails& details) { | |
52 switch (type) { | |
Peter Kasting
2014/06/19 21:20:32
Just DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COM
kmadhusu
2014/06/19 22:52:49
Done.
| |
53 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
54 ProcessCommittedEntry(source, details); | |
55 break; | |
56 default: | |
57 NOTREACHED(); | |
58 } | |
59 } | |
OLD | NEW |