| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ | 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ |
| 6 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ | 6 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ |
| 7 | 7 |
| 8 #include "base/callback_list.h" | 8 #include "base/callback_list.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 | 11 |
| 12 namespace base { |
| 12 template <typename T> | 13 template <typename T> |
| 13 struct DefaultSingletonTraits; | 14 struct DefaultSingletonTraits; |
| 15 } // namespace base |
| 14 | 16 |
| 15 struct OmniboxLog; | 17 struct OmniboxLog; |
| 16 | 18 |
| 17 // Omnibox code tracks events on a per-user-context basis, but there are | 19 // 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 | 20 // 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 | 21 // (e.g., all Profiles in the //chrome embedder). This class serves as an |
| 20 // intermediary to bridge the gap: omnibox code calls the | 22 // intermediary to bridge the gap: omnibox code calls the |
| 21 // OmniboxEventGlobalTracker singleton on an event of interest, and it then | 23 // OmniboxEventGlobalTracker singleton on an event of interest, and it then |
| 22 // forwards the event to its registered observers. | 24 // forwards the event to its registered observers. |
| 23 class OmniboxEventGlobalTracker { | 25 class OmniboxEventGlobalTracker { |
| 24 public: | 26 public: |
| 25 typedef base::Callback<void(OmniboxLog*)> OnURLOpenedCallback; | 27 typedef base::Callback<void(OmniboxLog*)> OnURLOpenedCallback; |
| 26 | 28 |
| 27 // Returns the instance of OmniboxEventGlobalTracker. | 29 // Returns the instance of OmniboxEventGlobalTracker. |
| 28 static OmniboxEventGlobalTracker* GetInstance(); | 30 static OmniboxEventGlobalTracker* GetInstance(); |
| 29 | 31 |
| 30 // Registers |cb| to be invoked when user open an URL from the omnibox. | 32 // Registers |cb| to be invoked when user open an URL from the omnibox. |
| 31 scoped_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription> | 33 scoped_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription> |
| 32 RegisterCallback(const OnURLOpenedCallback& cb); | 34 RegisterCallback(const OnURLOpenedCallback& cb); |
| 33 | 35 |
| 34 // Called to notify all registered callbacks that an URL was opened from | 36 // Called to notify all registered callbacks that an URL was opened from |
| 35 // the omnibox. | 37 // the omnibox. |
| 36 void OnURLOpened(OmniboxLog* log); | 38 void OnURLOpened(OmniboxLog* log); |
| 37 | 39 |
| 38 private: | 40 private: |
| 39 friend struct DefaultSingletonTraits<OmniboxEventGlobalTracker>; | 41 friend struct base::DefaultSingletonTraits<OmniboxEventGlobalTracker>; |
| 40 | 42 |
| 41 OmniboxEventGlobalTracker(); | 43 OmniboxEventGlobalTracker(); |
| 42 ~OmniboxEventGlobalTracker(); | 44 ~OmniboxEventGlobalTracker(); |
| 43 | 45 |
| 44 base::CallbackList<void(OmniboxLog*)> on_url_opened_callback_list_; | 46 base::CallbackList<void(OmniboxLog*)> on_url_opened_callback_list_; |
| 45 | 47 |
| 46 DISALLOW_COPY_AND_ASSIGN(OmniboxEventGlobalTracker); | 48 DISALLOW_COPY_AND_ASSIGN(OmniboxEventGlobalTracker); |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ | 51 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ |
| OLD | NEW |