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

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

Issue 2127143002: Integrate audible tab tracking into desktop engagement service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | chrome/browser/metrics/audible_contents_tracker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/metrics/audible_contents_tracker.h
diff --git a/chrome/browser/metrics/audible_contents_tracker.h b/chrome/browser/metrics/audible_contents_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..0df6aa61997a24b3ffd9457f63a791141161805f
--- /dev/null
+++ b/chrome/browser/metrics/audible_contents_tracker.h
@@ -0,0 +1,75 @@
+// 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_AUDIBLE_CONTENTS_TRACKER_H_
+#define CHROME_BROWSER_METRICS_AUDIBLE_CONTENTS_TRACKER_H_
+
+#include "base/callback.h"
+#include "chrome/browser/ui/browser_list_observer.h"
+#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
+
+namespace metrics {
+
+// BrowserList / TabStripModelObserver used for tracking audio status.
+class AudibleContentsTracker
+ : public chrome::BrowserListObserver,
+ public TabStripModelObserver {
+ public:
+ // Interface for an observer of the AudibleContentsTracker. The only client
+ // of this class is the DesktopEngagementService, but an observer interface
+ // has been created for ease of testing.
+ class Observer {
+ public:
+ Observer() {}
+ virtual ~Observer() {}
+
+ // Invoked when a first audio source starts playing after a period of no
+ // audio sources.
+ virtual void OnAudioStart() = 0;
+
+ // Invoked when all audio sources stop playing.
+ virtual void OnAudioEnd() = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Observer);
+ };
+
+ // Creates an audible contents tracker that dispatches its messages to the
+ // provided |observer|.
+ explicit AudibleContentsTracker(Observer* observer);
+
+ private:
+
+ // chrome::BrowserListObserver:
+ void OnBrowserAdded(Browser* browser) override;
+ void OnBrowserRemoved(Browser* browser) override;
+
+ // TabStripModelObserver:
+ void TabClosingAt(TabStripModel* model,
+ content::WebContents* web_contents,
+ int index) override;
+ void TabChangedAt(content::WebContents* web_contents,
+ int index,
+ TabChangeType change_type) override;
+ void TabReplacedAt(TabStripModel* model,
+ content::WebContents* old_web_contents,
+ content::WebContents* new_web_contents,
+ int index) override;
+
+ // Used for managing audible_contents_, and invoking OnAudioStart and
+ // OnAudioEnd callbacks.
+ void AddAudibleWebContents(content::WebContents* web_contents);
+ void RemoveAudibleWebContents(content::WebContents* web_contents);
+
+ Observer* observer_;
+
+ // The set of WebContents that are currently playing audio.
+ std::set<content::WebContents*> audible_contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudibleContentsTracker);
+};
+
+} // namespace metrics
+
+#endif // CHROME_BROWSER_METRICS_AUDIBLE_CONTENTS_TRACKER_H_
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | chrome/browser/metrics/audible_contents_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698