Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2129)

Unified Diff: chrome/browser/metrics/tab_reactivation_tracker.h

Issue 2335203003: Add metrics to keep track of the tab activate/deactivate cycle (Closed)
Patch Set: Removed a problematic dcheck Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/tab_reactivation_tracker.h
diff --git a/chrome/browser/metrics/tab_reactivation_tracker.h b/chrome/browser/metrics/tab_reactivation_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..177e18f7cfb4bd12d9b746f3087cbd3c7acff28f
--- /dev/null
+++ b/chrome/browser/metrics/tab_reactivation_tracker.h
@@ -0,0 +1,72 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_METRICS_TAB_REACTIVATION_TRACKER_H_
+#define CHROME_BROWSER_METRICS_TAB_REACTIVATION_TRACKER_H_
+
+#include <memory>
+#include <unordered_map>
+
+#include "base/macros.h"
+#include "chrome/browser/ui/browser_tab_strip_tracker.h"
+#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
+
+namespace metrics {
+
+// This class is used to track tab deactivation/reactivation cycle. A
+// reactivation is defined as a tab that was hidden and then reshown.
+//
+// Note: A closing tab will not trigger a tab deactivation. Also worth noting
+// that tab discarding disrupts the tracking and the discarded tab will be
+// treated as a new tab.
+class TabReactivationTracker : public TabStripModelObserver {
+ public:
+ class Delegate {
+ public:
+ virtual void OnTabDeactivated(content::WebContents* contents) = 0;
+ virtual void OnTabReactivated(content::WebContents* contents) = 0;
+ };
+ explicit TabReactivationTracker(Delegate* delegate);
+ ~TabReactivationTracker() override;
+
+ // TabStripModelObserver:
+ void TabInsertedAt(TabStripModel* tab_strip_model,
+ content::WebContents* contents,
+ int index,
+ bool foreground) override;
+ void TabClosingAt(TabStripModel* tab_strip_model,
+ content::WebContents* contents,
+ int index) override;
+ void ActiveTabChanged(content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index,
+ int reason) override;
+
+ void NotifyTabDeactivating(content::WebContents* contents);
+ void NotifyTabReactivating(content::WebContents* contents);
+
+ private:
+ class WebContentsHelper;
+
+ // Returns the helper for the |contents|, creating it if it doesn't exist.
+ WebContentsHelper* GetHelper(content::WebContents* contents);
+
+ // Called by the helper when |contents| is being destroyed.
+ void OnWebContentsDestroyed(content::WebContents* contents);
+
+ // The delegate must outlive this class.
+ Delegate* delegate_;
+
+ // A helper instance is managed per WebContents.
+ std::unordered_map<content::WebContents*, std::unique_ptr<WebContentsHelper>>
+ helper_map_;
+
+ BrowserTabStripTracker browser_tab_strip_tracker_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabReactivationTracker);
+};
+
+} // namespace metrics
+
+#endif // CHROME_BROWSER_METRICS_TAB_REACTIVATION_TRACKER_H_
« no previous file with comments | « chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc ('k') | chrome/browser/metrics/tab_reactivation_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698