1 // Copyright 2015 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 COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_
6 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_
8 #include "base/callback_list.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
14 struct DefaultSingletonTraits
;
19 // Omnibox code tracks events on a per-user-context basis, but there are
20 // several clients who need to observe these events for all user contexts
21 // (e.g., all Profiles in the //chrome embedder). This class serves as an
22 // intermediary to bridge the gap: omnibox code calls the
23 // OmniboxEventGlobalTracker singleton on an event of interest, and it then
24 // forwards the event to its registered observers.
25 class OmniboxEventGlobalTracker
{
27 typedef base::Callback
<void(OmniboxLog
*)> OnURLOpenedCallback
;
29 // Returns the instance of OmniboxEventGlobalTracker.
30 static OmniboxEventGlobalTracker
* GetInstance();
32 // Registers |cb| to be invoked when user open an URL from the omnibox.
33 scoped_ptr
<base::CallbackList
<void(OmniboxLog
*)>::Subscription
>
34 RegisterCallback(const OnURLOpenedCallback
& cb
);
36 // Called to notify all registered callbacks that an URL was opened from
38 void OnURLOpened(OmniboxLog
* log
);
41 friend struct base::DefaultSingletonTraits
<OmniboxEventGlobalTracker
>;
43 OmniboxEventGlobalTracker();
44 ~OmniboxEventGlobalTracker();
46 base::CallbackList
<void(OmniboxLog
*)> on_url_opened_callback_list_
;
48 DISALLOW_COPY_AND_ASSIGN(OmniboxEventGlobalTracker
);
51 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_