- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / google / google_search_counter.h
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.
4
5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_
6 #define CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_
7
8 #include "base/memory/singleton.h"
9 #include "chrome/browser/google/google_search_metrics.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
12
13 // A listener for counting Google searches from various search access points. No
14 // actual search query content is observed. See GoogleSearchMetrics for more
15 // details about these access points.
16 class GoogleSearchCounter : content::NotificationObserver {
17  public:
18   // Initialize the global instance.
19   static void RegisterForNotifications();
20
21   // Return the singleton instance of GoogleSearchCounter.
22   static GoogleSearchCounter* GetInstance();
23
24  private:
25   friend struct DefaultSingletonTraits<GoogleSearchCounter>;
26   friend class GoogleSearchCounterTest;
27
28   GoogleSearchCounter();
29   virtual ~GoogleSearchCounter();
30
31   void ProcessCommittedEntry(const content::NotificationSource& source,
32                              const content::NotificationDetails& details);
33
34   // Replace the internal metrics object with a dummy or a mock. This instance
35   // takes ownership of |search_metrics|.
36   void SetSearchMetricsForTesting(GoogleSearchMetrics* search_metrics);
37
38   // Register this counter for all notifications we care about.
39   void RegisterForNotificationsInternal();
40
41   // content::NotificationObserver
42   virtual void Observe(int type,
43                        const content::NotificationSource& source,
44                        const content::NotificationDetails& details) OVERRIDE;
45
46   content::NotificationRegistrar registrar_;
47   scoped_ptr<GoogleSearchMetrics> search_metrics_;
48
49   DISALLOW_COPY_AND_ASSIGN(GoogleSearchCounter);
50 };
51
52 #endif  // CHROME_BROWSER_GOOGLE_GOOGLE_SEARCH_COUNTER_H_