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_USAGE_RECORDER_H_ |
| 6 #define CHROME_BROWSER_METRICS_TAB_USAGE_RECORDER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "chrome/browser/metrics/tab_reactivation_tracker.h" |
| 10 #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 12 |
| 13 namespace metrics { |
| 14 |
| 15 // This class is used to record metrics about tab reactivation. Specifically, |
| 16 // it records a histogram value everytime a tab is deactivated or reactivated. |
| 17 // The ratio of both can be calculated for tabs with different properties (e.g. |
| 18 // If the tab is pinned to the tab strip) to see if they are correlated with |
| 19 // higher probability of tab reactivation. |
| 20 class TabUsageRecorder : public TabReactivationTracker::Delegate, |
| 21 public TabStripModelObserver { |
| 22 public: |
| 23 // Needs to be public for DEFINE_WEB_CONTENTS_USER_DATA_KEY. |
| 24 class WebContentsData; |
| 25 |
| 26 // Starts recording tab usage for all browsers. |
| 27 static void Initialize(); |
| 28 |
| 29 // TabReactivationTracker::Delegate: |
| 30 void OnTabDeactivated(content::WebContents* contents) override; |
| 31 void OnTabReactivated(content::WebContents* contents) override; |
| 32 |
| 33 // TabStripModelObserver: |
| 34 void TabInsertedAt(TabStripModel* tab_strip_model, |
| 35 content::WebContents* contents, |
| 36 int index, |
| 37 bool foreground) override; |
| 38 void TabPinnedStateChanged(TabStripModel* tab_strip_model, |
| 39 content::WebContents* contents, |
| 40 int index) override; |
| 41 |
| 42 private: |
| 43 TabUsageRecorder(); |
| 44 ~TabUsageRecorder() override; |
| 45 |
| 46 // Returns the WebContentsData associated with |contents|, creating one if it |
| 47 // doesn't exist. |
| 48 WebContentsData* GetWebContentsData(content::WebContents* contents); |
| 49 |
| 50 TabReactivationTracker tab_reactivation_tracker_; |
| 51 BrowserTabStripTracker browser_tab_strip_tracker_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(TabUsageRecorder); |
| 54 }; |
| 55 |
| 56 } // namespace metrics |
| 57 |
| 58 #endif // CHROME_BROWSER_METRICS_TAB_USAGE_RECORDER_H_ |
OLD | NEW |