| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef IOS_CHROME_BROWSER_OMNIBOX_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ | |
| 6 #define IOS_CHROME_BROWSER_OMNIBOX_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ | |
| 7 | |
| 8 #include "base/callback_list.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 | |
| 12 template <typename T> | |
| 13 struct DefaultSingletonTraits; | |
| 14 | |
| 15 struct OmniboxLog; | |
| 16 | |
| 17 // Omnibox code tracks events on a per-BrowserState basis, but there are | |
| 18 // several clients who need to observe these events for all BrowserStates. | |
| 19 // This class serves as an intermediary to bridge the gap: omnibox code calls | |
| 20 // the OmniboxEventGlobalTracker singleton on an event of interest, and it | |
| 21 // then forwards the event to its registered observers. | |
| 22 class OmniboxEventGlobalTracker { | |
| 23 public: | |
| 24 typedef base::Callback<void(OmniboxLog*)> OnURLOpenedCallback; | |
| 25 | |
| 26 // Returns the instance of OmniboxEventGlobalTracker. | |
| 27 static OmniboxEventGlobalTracker* GetInstance(); | |
| 28 | |
| 29 // Registers |cb| to be invoked when user open an URL from the omnibox. | |
| 30 scoped_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription> | |
| 31 RegisterCallback(const OnURLOpenedCallback& cb); | |
| 32 | |
| 33 // Called to notify all registered callbacks that an URL was opened from | |
| 34 // the omnibox. | |
| 35 void OnURLOpened(OmniboxLog* log); | |
| 36 | |
| 37 private: | |
| 38 friend struct DefaultSingletonTraits<OmniboxEventGlobalTracker>; | |
| 39 | |
| 40 OmniboxEventGlobalTracker(); | |
| 41 ~OmniboxEventGlobalTracker(); | |
| 42 | |
| 43 base::CallbackList<void(OmniboxLog*)> on_url_opened_callback_list_; | |
| 44 | |
| 45 DISALLOW_COPY_AND_ASSIGN(OmniboxEventGlobalTracker); | |
| 46 }; | |
| 47 | |
| 48 #endif // IOS_CHROME_BROWSER_OMNIBOX_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ | |
| OLD | NEW |