Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / google / google_search_counter.h
blobe1f558d1275b27be5b91c4fc3ca88eac6a15cf08
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_
6 #define CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_
8 #include "base/memory/singleton.h"
9 #include "components/google/core/browser/google_search_metrics.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
13 namespace content {
14 class NavigationEntry;
17 // A listener for counting Google searches from various search access points. No
18 // actual search query content is observed. See GoogleSearchMetrics for more
19 // details about these access points.
20 class GoogleSearchCounter : content::NotificationObserver {
21 public:
22 // Initialize the global instance.
23 static void RegisterForNotifications();
25 // Return the singleton instance of GoogleSearchCounter.
26 static GoogleSearchCounter* GetInstance();
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;
34 // Returns true if |details| is valid and corresponds to a search results
35 // page.
36 bool ShouldRecordCommittedDetails(
37 const content::NotificationDetails& details) const;
39 const GoogleSearchMetrics* search_metrics() const {
40 return search_metrics_.get();
43 private:
44 friend struct DefaultSingletonTraits<GoogleSearchCounter>;
45 friend class GoogleSearchCounterTest;
46 friend class GoogleSearchCounterAndroidTest;
48 GoogleSearchCounter();
49 ~GoogleSearchCounter() override;
51 void ProcessCommittedEntry(const content::NotificationSource& source,
52 const content::NotificationDetails& details);
54 // Replace the internal metrics object with a dummy or a mock. This instance
55 // takes ownership of |search_metrics|.
56 void SetSearchMetricsForTesting(GoogleSearchMetrics* search_metrics);
58 // Register this counter for all notifications we care about.
59 void RegisterForNotificationsInternal();
61 // content::NotificationObserver
62 void Observe(int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) override;
66 content::NotificationRegistrar registrar_;
67 scoped_ptr<GoogleSearchMetrics> search_metrics_;
69 DISALLOW_COPY_AND_ASSIGN(GoogleSearchCounter);
72 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_