| 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 IOS_CHROME_BROWSER_TAB_PARENTING_GLOBAL_OBSERVER_H_ | 5 #ifndef IOS_CHROME_BROWSER_TAB_PARENTING_GLOBAL_OBSERVER_H_ |
| 6 #define IOS_CHROME_BROWSER_TAB_PARENTING_GLOBAL_OBSERVER_H_ | 6 #define IOS_CHROME_BROWSER_TAB_PARENTING_GLOBAL_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback_list.h" | 10 #include "base/callback_list.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 template <typename T> | 14 template <typename T> |
| 14 struct DefaultSingletonTraits; | 15 struct DefaultSingletonTraits; |
| 15 } // namespace base | 16 } // namespace base |
| 16 | 17 |
| 17 namespace web { | 18 namespace web { |
| 18 class WebState; | 19 class WebState; |
| 19 } | 20 } |
| 20 | 21 |
| 21 // Allows clients to observe every tab (i.e., WebState) that is parented. | 22 // Allows clients to observe every tab (i.e., WebState) that is parented. |
| 22 // NOTE: Should be used only to correspond to //chrome flows that listen for | 23 // NOTE: Should be used only to correspond to //chrome flows that listen for |
| 23 // the TAB_PARENTED notification from all sources. | 24 // the TAB_PARENTED notification from all sources. |
| 24 class TabParentingGlobalObserver { | 25 class TabParentingGlobalObserver { |
| 25 public: | 26 public: |
| 26 typedef base::Callback<void(web::WebState*)> OnTabParentedCallback; | 27 typedef base::Callback<void(web::WebState*)> OnTabParentedCallback; |
| 27 | 28 |
| 28 // Returns the instance of TabParentingGlobalObserver. | 29 // Returns the instance of TabParentingGlobalObserver. |
| 29 static TabParentingGlobalObserver* GetInstance(); | 30 static TabParentingGlobalObserver* GetInstance(); |
| 30 | 31 |
| 31 // Registers |cb| to be invoked when a tab is parented. | 32 // Registers |cb| to be invoked when a tab is parented. |
| 32 scoped_ptr<base::CallbackList<void(web::WebState*)>::Subscription> | 33 std::unique_ptr<base::CallbackList<void(web::WebState*)>::Subscription> |
| 33 RegisterCallback(const OnTabParentedCallback& cb); | 34 RegisterCallback(const OnTabParentedCallback& cb); |
| 34 | 35 |
| 35 // Called to notify all registered callbacks that |web_state| was parented. | 36 // Called to notify all registered callbacks that |web_state| was parented. |
| 36 void OnTabParented(web::WebState* web_state); | 37 void OnTabParented(web::WebState* web_state); |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 friend struct base::DefaultSingletonTraits<TabParentingGlobalObserver>; | 40 friend struct base::DefaultSingletonTraits<TabParentingGlobalObserver>; |
| 40 | 41 |
| 41 TabParentingGlobalObserver(); | 42 TabParentingGlobalObserver(); |
| 42 ~TabParentingGlobalObserver(); | 43 ~TabParentingGlobalObserver(); |
| 43 | 44 |
| 44 base::CallbackList<void(web::WebState*)> on_tab_parented_callback_list_; | 45 base::CallbackList<void(web::WebState*)> on_tab_parented_callback_list_; |
| 45 | 46 |
| 46 DISALLOW_COPY_AND_ASSIGN(TabParentingGlobalObserver); | 47 DISALLOW_COPY_AND_ASSIGN(TabParentingGlobalObserver); |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 #endif // IOS_CHROME_BROWSER_TAB_PARENTING_GLOBAL_OBSERVER_H_ | 50 #endif // IOS_CHROME_BROWSER_TAB_PARENTING_GLOBAL_OBSERVER_H_ |
| OLD | NEW |