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