Chromium Code Reviews| Index: chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h |
| diff --git a/chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h b/chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63b17d4a1ca9141e607de371d69f1d84c9a16e76 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h |
| @@ -0,0 +1,80 @@ |
| +// 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_DESKTOP_ENGAGEMENT_AUDIBLE_CONTENTS_TRACKER_H_ |
| +#define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_AUDIBLE_CONTENTS_TRACKER_H_ |
| + |
| +#include <set> |
| + |
| +#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() {} |
| + ~Observer() {} |
|
chrisha
2016/07/29 15:21:26
virtual ~Observer() as this is an abstract base cl
gayane -on leave until 09-2017
2016/07/29 19:37:39
Done.
|
| + |
| + // Invoked when a first audio source starts playing after a period of no |
| + // audio sources. Overridden by tests. |
| + virtual void OnAudioStart(); |
| + |
| + // Invoked when all audio sources stop playing. Overridden by tests. |
| + virtual void OnAudioEnd(); |
|
Alexei Svitkine (slow)
2016/07/28 21:31:45
Make this a pure virtual class and just have Deskt
chrisha
2016/07/29 15:21:25
+1
gayane -on leave until 09-2017
2016/07/29 19:37:38
Acknowledged.
gayane -on leave until 09-2017
2016/07/29 19:37:39
Done.
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(Observer); |
| + }; |
| + |
| + // Creates an audible contents tracker that dispatches its messages to the |
| + // provided |observer|. |
| + explicit AudibleContentsTracker(Observer* observer); |
| + ~AudibleContentsTracker() override; |
| + |
| + // Creates the |AudibleContentsTracker| instance and its observer which |
| + // observe and notify audio status changes. |
| + static void Initialize(); |
| + |
| + 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_DESKTOP_ENGAGEMENT_AUDIBLE_CONTENTS_TRACKER_H_ |