| 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_AUDIBLE_CONTENTS_TRACKER_H_ |
| 6 #define CHROME_BROWSER_METRICS_AUDIBLE_CONTENTS_TRACKER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "chrome/browser/ui/browser_list_observer.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 11 |
| 12 namespace metrics { |
| 13 |
| 14 // BrowserList / TabStripModelObserver used for tracking audio status. |
| 15 class AudibleContentsTracker |
| 16 : public chrome::BrowserListObserver, |
| 17 public TabStripModelObserver { |
| 18 public: |
| 19 // Interface for an observer of the AudibleContentsTracker. The only client |
| 20 // of this class is the DesktopEngagementService, but an observer interface |
| 21 // has been created for ease of testing. |
| 22 class Observer { |
| 23 public: |
| 24 Observer() {} |
| 25 virtual ~Observer() {} |
| 26 |
| 27 // Invoked when a first audio source starts playing after a period of no |
| 28 // audio sources. |
| 29 virtual void OnAudioStart() = 0; |
| 30 |
| 31 // Invoked when all audio sources stop playing. |
| 32 virtual void OnAudioEnd() = 0; |
| 33 |
| 34 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(Observer); |
| 36 }; |
| 37 |
| 38 // Creates an audible contents tracker that dispatches its messages to the |
| 39 // provided |observer|. |
| 40 explicit AudibleContentsTracker(Observer* observer); |
| 41 |
| 42 private: |
| 43 |
| 44 // chrome::BrowserListObserver: |
| 45 void OnBrowserAdded(Browser* browser) override; |
| 46 void OnBrowserRemoved(Browser* browser) override; |
| 47 |
| 48 // TabStripModelObserver: |
| 49 void TabClosingAt(TabStripModel* model, |
| 50 content::WebContents* web_contents, |
| 51 int index) override; |
| 52 void TabChangedAt(content::WebContents* web_contents, |
| 53 int index, |
| 54 TabChangeType change_type) override; |
| 55 void TabReplacedAt(TabStripModel* model, |
| 56 content::WebContents* old_web_contents, |
| 57 content::WebContents* new_web_contents, |
| 58 int index) override; |
| 59 |
| 60 // Used for managing audible_contents_, and invoking OnAudioStart and |
| 61 // OnAudioEnd callbacks. |
| 62 void AddAudibleWebContents(content::WebContents* web_contents); |
| 63 void RemoveAudibleWebContents(content::WebContents* web_contents); |
| 64 |
| 65 Observer* observer_; |
| 66 |
| 67 // The set of WebContents that are currently playing audio. |
| 68 std::set<content::WebContents*> audible_contents_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(AudibleContentsTracker); |
| 71 }; |
| 72 |
| 73 } // namespace metrics |
| 74 |
| 75 #endif // CHROME_BROWSER_METRICS_AUDIBLE_CONTENTS_TRACKER_H_ |
| OLD | NEW |