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 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_ |
6 #define CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_ | 6 #define CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_ |
7 | 7 |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "components/google/core/browser/google_search_metrics.h" | 9 #include "components/google/core/browser/google_search_metrics.h" |
10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
12 | 12 |
| 13 namespace content { |
| 14 class NavigationEntry; |
| 15 } |
| 16 |
13 // A listener for counting Google searches from various search access points. No | 17 // A listener for counting Google searches from various search access points. No |
14 // actual search query content is observed. See GoogleSearchMetrics for more | 18 // actual search query content is observed. See GoogleSearchMetrics for more |
15 // details about these access points. | 19 // details about these access points. |
16 class GoogleSearchCounter : content::NotificationObserver { | 20 class GoogleSearchCounter : content::NotificationObserver { |
17 public: | 21 public: |
18 // Initialize the global instance. | 22 // Initialize the global instance. |
19 static void RegisterForNotifications(); | 23 static void RegisterForNotifications(); |
20 | 24 |
21 // Return the singleton instance of GoogleSearchCounter. | 25 // Return the singleton instance of GoogleSearchCounter. |
22 static GoogleSearchCounter* GetInstance(); | 26 static GoogleSearchCounter* GetInstance(); |
23 | 27 |
| 28 // Returns the Google search access point for the given |entry|. This method |
| 29 // assumes that we have already verified that |entry|'s URL is a Google search |
| 30 // URL. |
| 31 GoogleSearchMetrics::AccessPoint GetGoogleSearchAccessPointForSearchNavEntry( |
| 32 const content::NavigationEntry& entry) const; |
| 33 |
| 34 // Returns true if |details| is valid and corresponds to a search results |
| 35 // page. |
| 36 bool ShouldRecordCommittedDetails( |
| 37 const content::NotificationDetails& details) const; |
| 38 |
| 39 const GoogleSearchMetrics* search_metrics() const { |
| 40 return search_metrics_.get(); |
| 41 } |
| 42 |
24 private: | 43 private: |
25 friend struct DefaultSingletonTraits<GoogleSearchCounter>; | 44 friend struct DefaultSingletonTraits<GoogleSearchCounter>; |
26 friend class GoogleSearchCounterTest; | 45 friend class GoogleSearchCounterTest; |
27 | 46 |
28 GoogleSearchCounter(); | 47 GoogleSearchCounter(); |
29 virtual ~GoogleSearchCounter(); | 48 virtual ~GoogleSearchCounter(); |
30 | 49 |
31 void ProcessCommittedEntry(const content::NotificationSource& source, | 50 void ProcessCommittedEntry(const content::NotificationSource& source, |
32 const content::NotificationDetails& details); | 51 const content::NotificationDetails& details); |
33 | 52 |
34 // Replace the internal metrics object with a dummy or a mock. This instance | 53 // Replace the internal metrics object with a dummy or a mock. This instance |
35 // takes ownership of |search_metrics|. | 54 // takes ownership of |search_metrics|. |
36 void SetSearchMetricsForTesting(GoogleSearchMetrics* search_metrics); | 55 void SetSearchMetricsForTesting(GoogleSearchMetrics* search_metrics); |
37 | 56 |
38 // Register this counter for all notifications we care about. | 57 // Register this counter for all notifications we care about. |
39 void RegisterForNotificationsInternal(); | 58 void RegisterForNotificationsInternal(); |
40 | 59 |
41 // content::NotificationObserver | 60 // content::NotificationObserver |
42 virtual void Observe(int type, | 61 virtual void Observe(int type, |
43 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
44 const content::NotificationDetails& details) OVERRIDE; | 63 const content::NotificationDetails& details) OVERRIDE; |
45 | 64 |
46 content::NotificationRegistrar registrar_; | 65 content::NotificationRegistrar registrar_; |
47 scoped_ptr<GoogleSearchMetrics> search_metrics_; | 66 scoped_ptr<GoogleSearchMetrics> search_metrics_; |
48 | 67 |
49 DISALLOW_COPY_AND_ASSIGN(GoogleSearchCounter); | 68 DISALLOW_COPY_AND_ASSIGN(GoogleSearchCounter); |
50 }; | 69 }; |
51 | 70 |
52 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_ | 71 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_ |
OLD | NEW |