OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 CHROME_BROWSER_METRICS_TAB_REACTIVATION_TRACKER_H_ | |
6 #define CHROME_BROWSER_METRICS_TAB_REACTIVATION_TRACKER_H_ | |
7 | |
8 #include <memory> | |
9 #include <unordered_map> | |
10 | |
11 #include "base/macros.h" | |
12 #include "chrome/browser/ui/browser_tab_strip_tracker.h" | |
13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | |
14 | |
15 namespace metrics { | |
16 | |
17 // This class is used to track tab deactivation/reactivation cycle. A | |
18 // reactivation is defined as a tab that was hidden and then reshown. | |
19 // | |
20 // Note: A closing tab will not trigger a tab deactivation. Also worth noting | |
21 // that tab discarding disrupt the tracking and the discarded tab will be | |
Georges Khalil
2016/09/22 18:38:38
nit:s/disrupt/disrupts
Patrick Monette
2016/09/22 20:18:52
Done.
| |
22 // treated as a new tab. | |
23 class TabReactivationTracker : public TabStripModelObserver { | |
24 public: | |
25 class Delegate { | |
26 public: | |
27 virtual void OnTabDeactivated(content::WebContents* contents) = 0; | |
28 virtual void OnTabReactivated(content::WebContents* contents) = 0; | |
29 }; | |
30 explicit TabReactivationTracker(Delegate* delegate); | |
31 ~TabReactivationTracker() override; | |
32 | |
33 // TabStripModelObserver: | |
34 void TabInsertedAt(TabStripModel* tab_strip_model, | |
35 content::WebContents* contents, | |
36 int index, | |
37 bool foreground) override; | |
38 void TabClosingAt(TabStripModel* tab_strip_model, | |
39 content::WebContents* contents, | |
40 int index) override; | |
41 void ActiveTabChanged(content::WebContents* old_contents, | |
42 content::WebContents* new_contents, | |
43 int index, | |
44 int reason) override; | |
45 | |
46 void NotifyTabDeactivating(content::WebContents* contents); | |
47 void NotifyTabReactivating(content::WebContents* contents); | |
48 | |
49 private: | |
50 class WebContentsHelper; | |
51 | |
52 // Returns the helper for the |contents|, creating it if it doesn't exist. | |
53 WebContentsHelper* GetHelper(content::WebContents* contents); | |
54 | |
55 // Called by the helper when |contents| is being destroyed. | |
56 void OnWebContentsDestroyed(content::WebContents* contents); | |
57 | |
58 // The delegate must outlive this class. | |
59 Delegate* delegate_; | |
60 | |
61 // A helper instance is managed per WebContents. | |
62 std::unordered_map<content::WebContents*, std::unique_ptr<WebContentsHelper>> | |
63 helper_map_; | |
64 | |
65 BrowserTabStripTracker browser_tab_strip_tracker_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(TabReactivationTracker); | |
68 }; | |
69 | |
70 } // namespace metrics | |
71 | |
72 #endif // CHROME_BROWSER_METRICS_TAB_REACTIVATION_TRACKER_H_ | |
OLD | NEW |